Skip to content

Commit

Permalink
add code review suggestions - when the invsparity is 1, just do norma…
Browse files Browse the repository at this point in the history
…lization.
  • Loading branch information
Fe-r-oz committed Dec 21, 2024
1 parent 52e5e54 commit ee53a6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/nonclifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ julia> prob₁ = (real(χ′)+1)/2
See also: [`expect`](@ref)
"""
function projectrand!(sm::GeneralizedStabilizer, p::PauliOperator)
function _projectrand_notnorm(sm::GeneralizedStabilizer, p::PauliOperator)
# Returns the updated `GeneralizedStabilizer` state sm′ = (χ′, B(S′, D′)),
# where (S′, D′) is derived from (S, D) through the traditional stabilizer update,
# and χ′ is the updated density matrix after measurement. Note: Λ(χ′) ≤ Λ(χ).
Expand Down Expand Up @@ -285,6 +285,19 @@ function projectrand!(sm::GeneralizedStabilizer, p::PauliOperator)
end
end

function projectrand!(sm::GeneralizedStabilizer, p::PauliOperator)
sm, res = _projectrand_notnorm(sm, p)
dict = sm.destabweights
if sm |> QuantumClifford.invsparsity == 1
for ((dᵢ, dⱼ), χ) in dict
χ′ = χ/LinearAlgebra.tr(χ) # normalization
sm.destabweights[(dᵢ, dⱼ)] = χ′
end
return sm, res
end
return sm, res
end

function project!(s::GeneralizedStabilizer, p::PauliOperator)
throw(MethodError(project!, (s, p)))
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_nonclifford_quantumoptics.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using QuantumClifford
using QuantumClifford: GeneralizedStabilizer, rowdecompose, PauliChannel, mul_left!, mul_right!, invsparsity
using QuantumClifford: GeneralizedStabilizer, rowdecompose, PauliChannel, mul_left!, mul_right!, invsparsity, _projectrand_notnorm
using QuantumClifford: @S_str, random_stabilizer
using QuantumOpticsBase
using LinearAlgebra
Expand Down Expand Up @@ -156,7 +156,7 @@ end
genstab = GeneralizedStabilizer(s)
apply!(genstab, pcT) # in-place
prob1 = (real(expect(p, genstab))+1)/2
projectrand!(genstab, p)[1] # in-place
_projectrand_notnorm(genstab, p)[1] # in-place
dict = genstab.destabweights
trace_χ′ = real(tr(collect(values(dict))[1])) # Tr[χ′]
@test isapprox(prob1, trace_χ′; atol=1e-5)
Expand Down

0 comments on commit ee53a6b

Please sign in to comment.