diff --git a/src/BPGates.jl b/src/BPGates.jl index 8b858b7..0c53dfe 100644 --- a/src/BPGates.jl +++ b/src/BPGates.jl @@ -564,6 +564,7 @@ end # this works. # Defines the probabilities of transitioning from one bell state to another function get_mixed_transition_probs(λ::Float64, cur_state_idx::Int) + # 0 <= λ <= 1 (λ = 1 - e ^(-t / T1)) mixed_state_tuple = ( (0.5 * λ^2 - λ + 1, 0.5 * λ * (1 - λ), 0.5 * λ^2, 0.5 * λ * (1 - λ)), (0.5 * λ, 1 - λ, 0.5 * λ, 0), diff --git a/test/test_bpgates.jl b/test/test_bpgates.jl index 0dcf3af..2b834dc 100644 --- a/test/test_bpgates.jl +++ b/test/test_bpgates.jl @@ -3,6 +3,8 @@ using Logging using BPGates +using QuantumClifford + function test_pauliz_constructor() test_pauliz = PauliZOp(1, 0.5) @@ -20,10 +22,10 @@ function test_pauliz_application_guaranteed() test_state = BellState(n_bellpairs) test_guaranteed_pauliz = PauliZOp(changed_bp_idx, 1) - apply!(test_state, test_guaranteed_pauliz) + QuantumClifford.apply!(test_state, test_guaranteed_pauliz) - @test test_state[2*changed_bp_idx - 1] == 0 - @test test_state[2*changed_bp_idx] == 1 + @test test_state.phases[2*changed_bp_idx - 1] == 0 + @test test_state.phases[2*changed_bp_idx] == 1 end function test_pauliz_application_guaranteed_none() @@ -35,8 +37,61 @@ function test_pauliz_application_guaranteed_none() # TODO: do I have to import QuantumClifford to use it when testing? QuantumClifford.apply!(test_state, test_guaranteed_pauliz) - @test test_state[2*changed_bp_idx - 1] == 0 - @test test_state[2*changed_bp_idx] == 0 + @test test_state.phases[2*changed_bp_idx - 1] == 0 + @test test_state.phases[2*changed_bp_idx] == 0 +end + +function test_mixed_state_op_constructor() + mixed_state_op = MixedStateOp(1, 0.5) + + @test mixed_state_op isa MixedStateOp + + @test mixed_state_op.idx == 1 + + @test mixed_state_op.lambda == 0.5 +end + +function test_apply_mixed_state_op() + n_bellpairs = 1 + changed_bp_idx = 1 + test_state = BellState(n_bellpairs) + mixed_state_op = MixedStateOp(changed_bp_idx, 0.0) + + QuantumClifford.apply!(test_state, mixed_state_op) + + @test test_state.phases[2 * changed_bp_idx - 1] == 0 + @test test_state.phases[2 * changed_bp_idx] == 0 +end + +function test_apply_mixed_state_op_diff_bellstate() + n_bellpairs = 1 + changed_bp_idx = 1 + test_state = BellState((0, 1)) + mixed_state_op = MixedStateOp(changed_bp_idx, 0.0) + + QuantumClifford.apply!(test_state, mixed_state_op) + + @test test_state.phases[2 * changed_bp_idx - 1] == 0 + @test test_state.phases[2 * changed_bp_idx] == 1 +end + +function test_apply_both_memory_errors() + n_bellpairs = 1 + changed_bp_idx = 1 + + test_state = BellState(n_bellpairs) + + noise_ops = Vector{AbstractNoiseBellOp}() + + push!(noise_ops, PauliZOp(changed_bp_idx, 0)) + push!(noise_ops, MixedStateOp(changed_bp_idx, 0.0)) + + for noise_op in noise_ops + QuantumClifford.apply!(test_state, noise_op) + end + + @test test_state.phases[2 * changed_bp_idx - 1] == 0 + @test test_state.phases[2 * changed_bp_idx] == 0 end @testset "BPGates.jl, PauliZOp tests" begin @@ -44,3 +99,10 @@ end test_pauliz_application_guaranteed() test_pauliz_application_guaranteed_none() end + +@testset "BPGates.jl, MixedStateOp tests" begin + test_mixed_state_op_constructor() + test_apply_mixed_state_op() + test_apply_mixed_state_op_diff_bellstate() + test_apply_both_memory_errors() +end