This document provides a detailed overview of the engine module, which implements quantum entanglement purification protocols.
The engine module simulates the quantum mechanical process of entanglement purification. It provides two different simulation approaches:
- Average Simulation - Calculates the average outcome of quantum operations
- Monte Carlo Simulation - Performs true randomized operations in the computational basis
The module provides the core functionality for:
- Creating noisy entangled quantum states
- Implementing the BBPSSW purification protocol
- Tracking the state of quantum pairs through multiple purification rounds
- Calculating fidelities and measuring success rates
The module consists of these main files:
types.ts- Type definitions for the simulation and engine interfaceaverageSimulationEngine.ts- Implements simulation using average outcomes in the Bell basismonteCarloSimulationEngine.ts- Implements simulation using randomized operations in the computational basisoperations.ts- Quantum operations for purification (Bell basis)quantumStates.ts- Quantum state creation and manipulation (Bell basis)
// Represents a single entangled qubit pair
export type QubitPair = {
id: number;
densityMatrix: DensityMatrix;
fidelity: number;
};
// Parameters controlling the simulation
export type SimulationParameters = {
initialPairs: number;
noiseParameter: number; // Controls the amount of noise in initial pairs
targetFidelity: number; // Purification target
};
// Tracks which step of the purification protocol is active
export type PurificationStep = 'initial' | 'twirled' | 'exchanged' | 'cnot' | 'measured' | 'completed';
// Complete state of the simulation
export interface SimulationState {
pairs: QubitPair[];
round: number;
complete: boolean;
purificationStep: PurificationStep;
averageFidelity: number; // Average fidelity across all pairs
pendingPairs?: {
controlPairs: QubitPair[];
targetPairs: QubitPair[];
results?: {
control: QubitPair;
successful: boolean;
}[];
};
}
// Engine interface and types
export interface ISimulationEngine {
nextStep(): SimulationState;
step(): SimulationState;
reset(): SimulationState;
getCurrentState(): SimulationState;
updateParams(params: SimulationParameters): void;
}
export enum EngineType {
// Calculates the average outcome of quantum operations in Bell basis
Average = 'average',
// Performs true randomized operations in computational basis
MonteCarlo = 'monte-carlo',
}This file provides functions for creating and manipulating quantum states.
Creates a noisy EPR pair using the specified noise channel and parameter.
// Usage
const noisyState = createNoisyEPRWithChannel(0.2, NoiseChannel.UniformNoise); // Creates a state with 20% uniform noiseThe function:
- Creates a perfect Bell state |Ψ⁻⟩ in the computational basis
- Applies the specified noise channel to Bob's qubit
- Returns a density matrix representing the noisy state
This file implements the quantum operations needed for entanglement purification.
Converts a quantum state to Werner form by depolarizing/twirling the pair.
// Usage
const wernerState = depolarize(initialState);Exchanges the |Ψ⁻⟩ and |Φ⁺⟩ components (Step 2 of BBPSSW protocol).
// Usage
const exchangedState = exchangePsiMinusPhiPlus(wernerState);Performs a bilateral CNOT operation between two entangled pairs and simulates measurement.
// Usage
const result = bilateralCNOT(controlPair, targetPair);
// Result includes:
// - resultAfterCNOT: The joint state after CNOT
// - afterMeasurement.controlPair: The resulting control pair
// - afterMeasurement.successful: Whether purification succeededThe Bell-basis controller for the entanglement purification simulation. This engine calculates the average outcome of quantum operations, rather than performing true randomized operations.
constructor(params: SimulationParameters)Initializes the simulation with the specified parameters.
Advances the simulation by one step in the purification protocol.
Completes a full round of purification.
Resets the simulation to its initial state.
Returns the current state of the simulation.
Updates the simulation parameters and resets the simulation.
The engine implements the BBPSSW protocol through these steps:
- Initialization: Create initial noisy EPR pairs
- Depolarize/Twirl: Convert pairs to Werner form
- Exchange: Swap |Ψ⁻⟩ and |Φ⁺⟩ components
- Bilateral CNOT: Apply CNOT gates between control and target pairs
- Measurement: Measure target pairs and update control pairs
- Discard: Discard failed pairs and prepare for next round
The simulation continues rounds until either:
- The target fidelity is reached
- There are fewer than 2 pairs remaining (cannot continue purification)
The computational-basis controller for entanglement purification simulation. This engine performs true randomized operations in the computational basis, providing a more physically realistic simulation.
constructor(params: SimulationParameters)Initializes the simulation with the specified parameters.
The Monte Carlo engine implements the same interface as the Average engine:
nextStep(): SimulationState
step(): SimulationState
reset(): SimulationState
getCurrentState(): SimulationState
updateParams(params: SimulationParameters): voidThe engine implements the BBPSSW protocol with these Monte Carlo-specific steps:
- Initialization: Create initial noisy EPR pairs in computational basis
- Random Twirling: Apply randomized twirling operations instead of calculating the average
- Preparation: Prepare for bilateral CNOT in computational basis
- Bilateral CNOT: Apply CNOT gates between control and target pairs
- Monte Carlo Measurement: Perform randomized measurements with probabilities based on the quantum state
- Discard: Discard failed pairs and prepare for next round
The engine module relies on calculations from the engine_real_calculations module for:
- Complex number arithmetic
- Density matrix operations
- Bell basis calculations
- Fidelity measurements
This separation ensures that the engine module can focus on the protocol implementation while delegating mathematical calculations to specialized components.
The Monte Carlo engine in particular makes extensive use of the computational basis operators in the real calculations module.
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.
The average fidelity is calculated using the calculateAverageFidelity utility function from src/utils/fidelityUtils.ts, which:
- Takes an array of QubitPair objects
- Extracts the fidelity value from each pair
- Returns the arithmetic mean of all fidelities
- Handles edge cases (empty arrays return 0)
This metric is automatically updated in the getCurrentState() method of both engines and is displayed in the control panel UI for real-time monitoring.
The simulation controller allows selecting between the two engine types:
// Usage
const controller = new SimulationController(
simulationParameters,
stateChangeCallback,
EngineType.MonteCarlo // or EngineType.Average
);This enables comparison between the average-based approach and the more physically realistic Monte Carlo simulation.