Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noncliff: Inner Product between two GeneralizedStabilizers #423

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion ext/QuantumCliffordQOpticsExt/QuantumCliffordQOpticsExt.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module QuantumCliffordQOpticsExt

using QuantumClifford
import QuantumClifford: mul_left!, mul_right!
import QuantumClifford: mul_left!, mul_right!, dot
using QuantumOpticsBase
using Graphs
using DocStringExtensions
import QuantumOpticsBase: Ket, Operator
using LinearAlgebra

const _b2 = SpinBasis(1//2)
const _l0 = spinup(_b2)
Expand Down Expand Up @@ -234,6 +235,41 @@ function Operator(c::CliffordOperator)
cliff_to_unitary(c)
end

"""
The inner product of two [`GeneralizedStabilizer`](@ref) states, `sm₁` and `sm₂`.

```jldoctest
julia> using QuantumOpticsBase; using LinearAlgebra; # hide
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not hide these, otherwise the reader might not know how to run these examples


julia> sm = GeneralizedStabilizer(S"X")
A mixture ∑ ϕᵢⱼ Pᵢ ρ Pⱼ† where ρ is
𝒟ℯ𝓈𝓉𝒶𝒷
+ Z
𝒮𝓉𝒶𝒷
+ X
with ϕᵢⱼ | Pᵢ | Pⱼ:
1.0+0.0im | + _ | + _

julia> apply!(sm, pcT)
A mixture ∑ ϕᵢⱼ Pᵢ ρ Pⱼ† where ρ is
𝒟ℯ𝓈𝓉𝒶𝒷
+ Z
𝒮𝓉𝒶𝒷
+ X
with ϕᵢⱼ | Pᵢ | Pⱼ:
0.0+0.353553im | + _ | + Z
0.0-0.353553im | + Z | + _
0.853553+0.0im | + _ | + _
0.146447+0.0im | + Z | + Z

julia> dot(sm, sm)
0.9999999999999994
```
"""
function LinearAlgebra.dot(sm₁::GeneralizedStabilizer, sm₂::GeneralizedStabilizer)
return real(tr(Operator(sm₁)' * Operator(sm₂)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just converts the two generalized stabilizers to density matrices. This is an exponentially expensive operation that does not seem to be implementing what is shown in the paper. This can be a useful correctness test in the test suite, but it is not an appropriate implementation for this library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Thank you!

I think the right hand side (shown in the proof section) is the faster version that uses in-place operations.

end

end

##
13 changes: 13 additions & 0 deletions src/nonclifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,16 @@ const pcT = UnitaryPauliChannel(
(I, Z),
((1+exp(im*π/4))/2, (1-exp(im*π/4))/2)
)

##
# QuantumOpticsBaseExt methods
##

function LinearAlgebra.dot(args...)
ext = Base.get_extension(QuantumClifford, :QuantumCliffordOpticsBase)
if isnothing(ext)
throw("The `LinearAlgebra.dot` depends on the package `QuantumOpticsBase` but you have not installed or imported it yet. Immediately after you import `QuantumOpticsBase`, the `LinearAlgebra.dot` will be available.")
end
return ext.LinearAlgebra.dot(args...)
end

1 change: 1 addition & 0 deletions test/test_nonclifford_quantumoptics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ end
apply!(sm, embed(n, i, pcT))
smcopy = copy(sm)
@test smcopy == sm
@test dot(sm, smcopy) ≈ 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having tests that do not always use the same state on both sides would make this much more trustworthy

nc = embed(n, rand(1:n), pcT)
@test copy(nc) == nc
end
Expand Down
Loading