Skip to content

Commit

Permalink
Added tests for MixedStateOp
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonhan3 committed Jul 24, 2024
1 parent e8c9fbb commit 6aed465
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/BPGates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
72 changes: 67 additions & 5 deletions test/test_bpgates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ using Logging

using BPGates

using QuantumClifford

function test_pauliz_constructor()

test_pauliz = PauliZOp(1, 0.5)
Expand All @@ -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()
Expand All @@ -35,12 +37,72 @@ 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
test_pauliz_constructor()
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

0 comments on commit 6aed465

Please sign in to comment.