Skip to content

Commit

Permalink
debug bellstateindex, T1noise simulation and test running
Browse files Browse the repository at this point in the history
  • Loading branch information
Yipiao committed Oct 22, 2024
1 parent 9ce2f74 commit 7c7dee6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 39 deletions.
42 changes: 21 additions & 21 deletions src/BPGates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,41 +558,41 @@ function QuantumClifford.apply!(state::BellState, g::T1NoiseOp)
output_state = if input_state==1
if r < 0.5*λ₁^2 - λ₁ + 1
1
elseif r < 0.5*λ₁^2 - λ₁ + 1 + 0.5*λ₁*(1-λ₁)
2
elseif r < 0.5*λ₁^2 - λ₁ + 1 + 0.5*λ₁*(1-λ₁) + 0.5*λ₁^2
3
elseif r < 0.5*λ₁^2 - λ₁ + 1 + 0.5*λ₁^2
2 # XXX
elseif r < 0.5*λ₁^2 - λ₁ + 1 + 0.5*λ₁^2 + 0.5*λ₁*(1-λ₁)
3 # XXX
else # r < 1 = 0.5*λ₁^2 - λ₁ + 1 + 0.5*λ₁*(1-λ₁) + 0.5*λ₁^2 + 0.5*λ₁*(1-λ₁)
4
end
elseif input_state==2
if r < 0.5*λ₁
if r < 0.5*λ₁^2
1
elseif r < 0.5*λ₁ + 1-λ₁
2
elseif r < 0.5*λ₁ + 1-λ₁ + 0.5*λ₁
3
else # r < 1 = 0.5*λ₁ + 1-λ₁ + 0.5*λ₁ + 0
elseif r < 0.5*λ₁^2 + 0.5*λ₁^2 -λ₁ + 1
2 # XXX
elseif r < 0.5*λ₁^2 + 0.5*λ₁^2 -λ₁ + 1 + 0.5*λ₁*(1-λ₁)
3 # XXX
else # r < 1 = 0.5*λ₁^2 + 0.5*λ₁^2 -λ₁ + 1 + 0.5*λ₁*(1-λ₁) + 0.5*λ₁*(1-λ₁)
4
end
elseif input_state==3
if r < 0.25*λ₁*(λ₁+1)
if r < 0.5*λ₁
1
elseif r < 0.25*λ₁*(λ₁+1) + 0.5*λ₁*(1-λ₁)
2
elseif r < 0.25*λ₁*(λ₁+1) + 0.5*λ₁*(1-λ₁) + 0.25*λ₁*(λ₁+1)
3
else # r < 1 = 0.25*λ₁*(λ₁+1) + 0.5*λ₁*(1-λ₁) + 0.25*λ₁*(λ₁+1) + 0.5*λ₁*(1-λ₁)
elseif r < 0.5*λ₁ + 0.5*λ₁
2 # XXX
elseif r < 0.5*λ₁ + 0.5*λ₁ + (1-λ₁)
3 # XXX
else # r < 1 = 0.5*λ₁ + 0.5*λ₁ + (1-λ₁) + 0
4
end
else # input_state==4
if r < 0.5*λ₁
1
# elseif r < 0.5*λ₁ + 0 # output_state 2 is never reached
# 2
elseif r < 0.5*λ₁ + 0 + 0.5*λ₁
3
else # r < 1 = 0.5*λ₁ + 0 + 0.5*λ₁ + 1-λ₁
elseif r < 0.5*λ₁ + 0.5*λ₁
2 # XXX
# elseif r < 0.5*λ₁ + 0.5*λ₁ + 0 # output_state 3 is never reached
# 3 # XXX
else # r < 1 = 0.5*λ₁ + 0.5*λ₁ + 0 + 1-λ₁
4
end
end
Expand Down
47 changes: 29 additions & 18 deletions test/test_quantumoptics.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@testitem "QuantumOptics comparisons" begin

using BPGates, QuantumClifford, QuantumOptics
using Test

using BPGates, QuantumClifford, QuantumOpticsBase

using BPGates: T1NoiseOp

Expand All @@ -9,47 +11,56 @@ using LinearAlgebra: diag
# define some BP objects
λ = 0.2
N = 100000
s = BellState(1)
opBP = T1NoiseOp(1, λ)

# compute using BP the density matrix after T1 noise
ρBP = sum([dm(Ket(Stabilizer(apply!(s,op)))) for i in 1:N])/N

# define some QO objects
b = SpinBasis(1//2)
l0 = spinup(b)
l1 = spindown(b)
l00 = l0l0
l01 = l0l1
l10 = l1l0
l01 = l1l0 # XXX be careful with the reversed endiandness - this is ket [0 1 0 0]
l10 = l0l1 # XXX be careful with the reversed endiandness - this is ket [0 0 1 0]
l11 = l1l1
bell00 = (l00+l11)/sqrt(2)
bell01 = (l01+l10)/sqrt(2)
bell10 = (l00-l11)/sqrt(2)
bell10 = (l00-l11)/sqrt(2) # XXX # bellstateindex = 2
bell01 = (l01+l10)/sqrt(2) # XXX # bellstateindex = 3
bell11 = (l01-l10)/sqrt(2)
#|`00`|`+XX +ZZ`|`∣00⟩+∣11⟩`|`∣++⟩+∣--⟩`|`∣i₊i₋⟩+∣i₋i₊⟩`|
#|`01`|`+XX -ZZ`|`∣01⟩+∣10⟩`|`∣++⟩-∣--⟩`|`∣i₊i₊⟩-∣i₋i₋⟩`|
#|`10`|`-XX +ZZ`|`∣00⟩-∣11⟩`|`∣+-⟩+∣-+⟩`|`∣i₊i₊⟩+∣i₋i₋⟩`|
#|`10`|`-XX +ZZ`|`∣00⟩-∣11⟩`|`∣+-⟩+∣-+⟩`|`∣i₊i₊⟩+∣i₋i₋⟩`| # be careful : bellstateindex = 2
#|`01`|`+XX -ZZ`|`∣01⟩+∣10⟩`|`∣++⟩-∣--⟩`|`∣i₊i₊⟩-∣i₋i₋⟩`| # be careful : bellstateindex = 3
#|`11`|`-XX -ZZ`|`∣01⟩-∣10⟩`|`∣+-⟩-∣-+⟩`|`∣i₊i₋⟩-∣i₋i₊⟩`|

# compute using QO the density matrix after T1 noise
# T1 noise in the QO formalism
krausOp1 = projector(l0) + (1-λ) * projector(l1)
krausOp2 = (λ) * projector(l0, l1')
id = identityoperator(b)
k1 = krausOp1id
k2 = krausOp2id
k3 = idkrausOp1
k4 = idkrausOp2
ρ0 = dm(bell00)
ρ1 = k1*ρ0*k1' + k2*ρ0*k2'
ρQO = k3*ρ1*k3' + k4*ρ1*k4'

# switch to the Bell basis
to_bell_basis = projector(l00,bell00')+projector(l01,bell01')+projector(l10,bell10')+projector(l11,bell11')

ρbBP = to_bell_basis*ρBP*to_bell_basis'
ρbQO = to_bell_basis*ρQO*to_bell_basis'
for bellstateindex in 1:4

# compute using BP the density matrix after T1 noise
s = BellState(BPGates.int_to_bit(bellstateindex, Val(2)))
ρBP = sum([dm(Ket(Stabilizer(apply!(copy(s),opBP)))) for i in 1:N])/N

# compute using QO the density matrix after T1 noise
ψ = [bell00,bell10,bell01,bell11][bellstateindex]

@test_broken isapprox(diag(ρbBP.data), diag(ρbQO.data), atol=10/sqrt(N))
@test abs' * Ket(Stabilizer(s))) 1
ρ0 = dm(ψ)
ρ1 = k1*ρ0*k1' + k2*ρ0*k2'
ρQO = k3*ρ1*k3' + k4*ρ1*k4'

ρbBP = to_bell_basis*ρBP*to_bell_basis'
ρbQO = to_bell_basis*ρQO*to_bell_basis'

@test isapprox(diag(ρbBP.data), diag(ρbQO.data), atol=10/sqrt(N))

end

end

0 comments on commit 7c7dee6

Please sign in to comment.