Skip to content

Commit ab8f00a

Browse files
Merge pull request #16 from DeDuckProject/add-more-pairs
Added average fidelity indication
2 parents e058f08 + 48b3e46 commit ab8f00a

17 files changed

Lines changed: 198 additions & 6 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ dist
1212
dist-ssr
1313
*.local
1414

15+
# TypeScript
16+
*.d.ts
17+
1518
# Editor directories and files
1619
.vscode/*
1720
!.vscode/extensions.json

epp-engine.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface SimulationState {
5454
round: number;
5555
complete: boolean;
5656
purificationStep: PurificationStep;
57+
averageFidelity: number; // Average fidelity across all pairs
5758
pendingPairs?: {
5859
controlPairs: QubitPair[];
5960
targetPairs: QubitPair[];
@@ -239,6 +240,18 @@ This separation ensures that the engine module can focus on the protocol impleme
239240

240241
The Monte Carlo engine in particular makes extensive use of the computational basis operators in the real calculations module.
241242

243+
## Average Fidelity Calculation
244+
245+
Both simulation engines automatically calculate and maintain the average fidelity across all pairs in the current state. This provides a real-time measure of the overall quality of the entangled pairs during the purification process.
246+
247+
The average fidelity is calculated using the `calculateAverageFidelity` utility function from `src/utils/fidelityUtils.ts`, which:
248+
- Takes an array of QubitPair objects
249+
- Extracts the fidelity value from each pair
250+
- Returns the arithmetic mean of all fidelities
251+
- Handles edge cases (empty arrays return 0)
252+
253+
This metric is automatically updated in the `getCurrentState()` method of both engines and is displayed in the control panel UI for real-time monitoring.
254+
242255
## Engine Selection
243256

244257
The simulation controller allows selecting between the two engine types:

epp_components.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This document defines all UI components used in the EPP (Entanglement Purificati
1717
- `currentRound`: number - The current purification round
1818
- `currentStep`: PurificationStep - The current step within the purification process
1919
- `pairsRemaining`: number - Number of qubit pairs remaining in the simulation
20+
- `averageFidelity`: number - Average fidelity across all pairs (displayed to 3 decimal places)
2021

2122
**Example Usage**:
2223
```tsx
@@ -30,6 +31,7 @@ This document defines all UI components used in the EPP (Entanglement Purificati
3031
currentRound={currentRound}
3132
currentStep={purificationStep}
3233
pairsRemaining={pairs.length}
34+
averageFidelity={averageFidelity}
3335
/>
3436
```
3537

src/components/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const App: React.FC = () => {
7676
currentRound={state.round}
7777
currentStep={state.purificationStep}
7878
pairsRemaining={state.pairs.length}
79+
averageFidelity={state.averageFidelity}
7980
engineType={engineType}
8081
viewBasis={viewBasis}
8182
/>

src/components/ControlPanel.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface ControlPanelProps {
1313
currentRound: number;
1414
currentStep: PurificationStep;
1515
pairsRemaining: number;
16+
averageFidelity: number;
1617
engineType: EngineType;
1718
viewBasis: Basis;
1819
className?: string;

src/components/ControlPanel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface ControlPanelProps {
1818
currentRound: number;
1919
currentStep: PurificationStep;
2020
pairsRemaining: number;
21+
averageFidelity: number;
2122
engineType: EngineType;
2223
viewBasis: Basis;
2324
className?: string;
@@ -37,6 +38,7 @@ const ControlPanel: React.FC<ControlPanelProps> = ({
3738
currentRound,
3839
currentStep,
3940
pairsRemaining,
41+
averageFidelity,
4042
engineType,
4143
viewBasis,
4244
className = '',
@@ -205,6 +207,7 @@ const ControlPanel: React.FC<ControlPanelProps> = ({
205207
<p><strong>Distillation Round:</strong> {currentRound}</p>
206208
<p><strong>Current Step:</strong> {currentStep}</p>
207209
<p><strong>Pairs Remaining:</strong> {pairsRemaining}</p>
210+
<p><strong>Average Fidelity:</strong> {averageFidelity.toFixed(3)}</p>
208211
<p><strong>Status:</strong> {isComplete ? 'Complete' : 'In Progress'}</p>
209212
</div>
210213
</CollapsibleSection>

src/engine/averageSimulationEngine.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {createNoisyEPRWithChannel} from './quantumStates';
33
import {bilateralCNOT, depolarize, exchangePsiMinusPhiPlus, preparePairsForCNOT} from './operations';
44
import {BellState, fidelityFromBellBasisMatrix, toBellBasis} from "../engine_real_calculations/bell/bell-basis.ts";
55
import {DensityMatrix} from "../engine_real_calculations/matrix/densityMatrix";
6+
import {calculateAverageFidelity} from '../utils/fidelityUtils';
67

78
export class AverageSimulationEngine implements ISimulationEngine {
89
private params: SimulationParameters;
@@ -34,11 +35,14 @@ export class AverageSimulationEngine implements ISimulationEngine {
3435
});
3536
}
3637

38+
const averageFidelity = calculateAverageFidelity(pairs);
39+
3740
return {
3841
pairs,
3942
round: 0,
4043
complete: false,
41-
purificationStep: 'initial'
44+
purificationStep: 'initial',
45+
averageFidelity
4246
};
4347
}
4448

@@ -245,7 +249,11 @@ export class AverageSimulationEngine implements ISimulationEngine {
245249
}
246250

247251
public getCurrentState(): SimulationState {
248-
return { ...this.state };
252+
const averageFidelity = calculateAverageFidelity(this.state.pairs);
253+
return {
254+
...this.state,
255+
averageFidelity
256+
};
249257
}
250258

251259
public updateParams(params: SimulationParameters): void {

src/engine/monteCarloSimulationEngine.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {pauliTwirl} from "../engine_real_calculations/operations/pauliTwirling";
66
import {applyPauli, applyCNOT, tensor, measureQubit} from "../engine_real_calculations";
77
import {partialTrace} from "../engine_real_calculations/operations/partialTrace";
88
import {preparePairsForCNOT} from "./operations";
9+
import {calculateAverageFidelity} from '../utils/fidelityUtils';
910

1011
/**
1112
* Monte Carlo Simulation Engine that uses the computational basis for calculations
@@ -58,11 +59,14 @@ export class MonteCarloSimulationEngine implements ISimulationEngine {
5859
});
5960
}
6061

62+
const averageFidelity = calculateAverageFidelity(pairs);
63+
6164
return {
6265
pairs,
6366
round: 0,
6467
complete: false,
65-
purificationStep: 'initial'
68+
purificationStep: 'initial',
69+
averageFidelity
6670
};
6771
}
6872

@@ -394,7 +398,11 @@ export class MonteCarloSimulationEngine implements ISimulationEngine {
394398
}
395399

396400
public getCurrentState(): SimulationState {
397-
return { ...this.state };
401+
const averageFidelity = calculateAverageFidelity(this.state.pairs);
402+
return {
403+
...this.state,
404+
averageFidelity
405+
};
398406
}
399407

400408
public updateParams(params: SimulationParameters): void {

src/engine/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface SimulationState {
2727
round: number;
2828
complete: boolean;
2929
purificationStep: PurificationStep;
30+
averageFidelity: number;
3031
pendingPairs?: {
3132
controlPairs: QubitPair[];
3233
targetPairs: QubitPair[];

src/engine/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface SimulationState {
3535
round: number;
3636
complete: boolean;
3737
purificationStep: PurificationStep; // Track which step we're on within a round
38+
averageFidelity: number; // Add average fidelity calculation
3839
pendingPairs?: { // Store intermediate state during a round
3940
controlPairs: QubitPair[];
4041
targetPairs: QubitPair[];

0 commit comments

Comments
 (0)