From bbe53c4751f3630ab24fb06fa170d0ffd3e67bef Mon Sep 17 00:00:00 2001 From: Luise Prielinger Date: Tue, 15 Apr 2025 11:11:12 +0200 Subject: [PATCH 1/2] added BSM circuit that can be used for quantum teleportation --- src/CircuitZoo/CircuitZoo.jl | 43 +++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/CircuitZoo/CircuitZoo.jl b/src/CircuitZoo/CircuitZoo.jl index 9966b4bb..16fd76c8 100644 --- a/src/CircuitZoo/CircuitZoo.jl +++ b/src/CircuitZoo/CircuitZoo.jl @@ -6,7 +6,7 @@ using DocStringExtensions export EntanglementSwap, LocalEntanglementSwap, Purify2to1, Purify2to1Node, Purify3to1, Purify3to1Node, PurifyStringent, PurifyStringentNode, PurifyExpedient, PurifyExpedientNode, - SDDecode, SDEncode + SDDecode, SDEncode, BellStateMeasurement abstract type AbstractCircuit end @@ -938,4 +938,45 @@ function (circuit::SDDecode)(rrefA, rrefB) return b1-1, b2-1 end +""" +$TYPEDEF + +Fields: + +$FIELDS + +Bell State measurement circuit used in the Teleportation protocol. When Alice and Bob share a Bell pair, Alice can locally apply this circuit to teleport her qubit to Bob. +The circuit takes as arguments the qubit to be teleported and the half of the Bell pair that Alice has. Both qubits are measured and the circuit returns the measurement results. +These results are used to apply the necessary correction gates on Bob's side to recover the original qubit. + +```jldoctest +julia> regA = Register(2); regB = Register(1); + +julia> initialize!(regA[1], Y1); + +julia> initialize!((regA[2], regB[1]), StabilizerState("XX ZZ")); + +julia> xmeas, zmeas = BellStateMeasurement()(regA[1], regA[2]); + +julia> if xmeas==2 apply!(regB[1], X) end + +julia> if zmeas==2 apply!(regB[1], Z) end + +julia> observable(regB[1], projector(Y1)) +0.9999999999999997 + 0.0im +``` +""" +struct BellStateMeasurement <: AbstractCircuit +end + +function (circuit::BellStateMeasurement)(tobeteleported::RegRef, bellpairhalf::RegRef) + apply!((tobeteleported, bellpairhalf), CNOT) + apply!(tobeteleported, H) + zmeas = project_traceout!(tobeteleported, σᶻ) + xmeas = project_traceout!(bellpairhalf, σᶻ) + xmeas, zmeas +end + + + end # module From 867a006ea4d9feab1edd2975dceb8ab97fba7215 Mon Sep 17 00:00:00 2001 From: Luise Prielinger Date: Tue, 15 Apr 2025 18:32:54 +0200 Subject: [PATCH 2/2] added test for bsm circuit --- test/test_circuitzoo_bellstatemeasurement.jl | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/test_circuitzoo_bellstatemeasurement.jl diff --git a/test/test_circuitzoo_bellstatemeasurement.jl b/test/test_circuitzoo_bellstatemeasurement.jl new file mode 100644 index 00000000..e4923818 --- /dev/null +++ b/test/test_circuitzoo_bellstatemeasurement.jl @@ -0,0 +1,29 @@ +@testitem "Bell State Measurement" tags=[:circuitzoo_bsm] begin +using QuantumSavory.CircuitZoo: BellStateMeasurement +using Random + + for _ in 1:10 + # Randomly generate a state for Alice to send + a = rand() + state_to_send = √(a)*X1 + √(1-a)*X2 + # Create a Bell state + bell = StabilizerState("XX ZZ") + # Create registers for Alice and Bob + regA = Register(2); + regB = Register(1); + + # Initialize the registers + initialize!(regA[1], state_to_send); + initialize!((regA[2], regB[1]), bell); + + # Execute BSM + xmeas, zmeas = BellStateMeasurement()(regA[1], regA[2]); + + # Apply corrections on Bob's end + if xmeas==2 apply!(regB[1], X) end + if zmeas==2 apply!(regB[1], Z) end + + @test real(observable(regB[1], projector(state_to_send))) ≈ 1.0 + @test isnothing(regA.staterefs[1]) & isnothing(regA.staterefs[2]) + end +end