From 8f9cd2d1c1edaaba90ecc853d090baa94afa964b Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 7 Nov 2024 15:02:47 +0500 Subject: [PATCH] noncliff: Inner Product between two GeneralizedStabilizers --- .../QuantumCliffordQOpticsExt.jl | 38 ++++++++++++++++++- src/nonclifford.jl | 13 +++++++ test/test_nonclifford_quantumoptics.jl | 1 + 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/ext/QuantumCliffordQOpticsExt/QuantumCliffordQOpticsExt.jl b/ext/QuantumCliffordQOpticsExt/QuantumCliffordQOpticsExt.jl index cca3011df..443a986e7 100644 --- a/ext/QuantumCliffordQOpticsExt/QuantumCliffordQOpticsExt.jl +++ b/ext/QuantumCliffordQOpticsExt/QuantumCliffordQOpticsExt.jl @@ -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) @@ -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 + +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₂))) +end + end ## diff --git a/src/nonclifford.jl b/src/nonclifford.jl index 524085025..8317200a7 100644 --- a/src/nonclifford.jl +++ b/src/nonclifford.jl @@ -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 + diff --git a/test/test_nonclifford_quantumoptics.jl b/test/test_nonclifford_quantumoptics.jl index 3b4ba307f..d11470ea3 100644 --- a/test/test_nonclifford_quantumoptics.jl +++ b/test/test_nonclifford_quantumoptics.jl @@ -82,6 +82,7 @@ end apply!(sm, embed(n, i, pcT)) smcopy = copy(sm) @test smcopy == sm + @test dot(sm, smcopy) ≈ 1 nc = embed(n, rand(1:n), pcT) @test copy(nc) == nc end