-
Notifications
You must be signed in to change notification settings - Fork 47
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
Inconsistencies in projection tests for Stabilizer/MixedDestabilizer states using multi-qubit random_stabilizers and multi random_paulis #418
Comments
… multi-qubit random_stabilizer and random_pauli for MixedDestabilizer/Stabilizer states
The primary issue in the current testing lies in a scaling discrepancy within one branch, as demonstrated in the tests below: julia> @testset "projection for Stabilizer/MixedStabilizer" begin
for repetition in 1:5
n = 1
s = random_stabilizer(n) # or md = MixedDestabilizer(random_stabilizer(n))
p = random_pauli(n)
println(s)
println(p)
apply!(s, p)
qo_state = Operator(s)
projectrand!(s, p)[1] # or project(s, p)[1]
qo_state_after_proj = Operator(s)
println(qo_state_after_proj)
qo_pauli = Operator(p)
qo_proj1 = (identityoperator(qo_pauli) - qo_pauli)/2
qo_proj2 = (identityoperator(qo_pauli) + qo_pauli)/2
result1 = qo_proj1*qo_state*qo_proj1'
result2 = qo_proj2*qo_state*qo_proj2'
println(result1)
println(result2)
@test qo_state_after_proj ≈ result2 || qo_state_after_proj ≈ result1
end
end
- Y
+ Z
Operator(dim=2x2)
basis: Spin(1/2)
0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.0+0.0im 0.0+0.0im
0.0+0.0im 0.5+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.5+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im
projection for Stabilizer/MixedStabilizer: Test Failed at REPL[12]:20
Expression: qo_state_after_proj ≈ result2 || qo_state_after_proj ≈ result1
Stacktrace:
[1] macro expansion
@ ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/Test/src/Test.jl:679 [inlined]
[2] macro expansion
@ ./REPL[12]:20 [inlined]
[3] macro expansion
@ ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/Test/src/Test.jl:1700 [inlined]
[4] top-level scope
@ ./REPL[12]:2
[5] eval
@ ./boot.jl:430 [inlined]
[6] eval_user_input(ast::Any, backend::REPL.REPLBackend, mod::Module)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:245
[7] repl_backend_loop(backend::REPL.REPLBackend, get_module::Function)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:342
[8] start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:327
[9] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool, backend::Any)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:483
[10] run_repl(repl::REPL.AbstractREPL, consumer::Any)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:469
[11] (::Base.var"#1139#1141"{Bool, Symbol, Bool})(REPL::Module)
@ Base ./client.jl:446
[12] #invokelatest#2
@ ./essentials.jl:1055 [inlined]
[13] invokelatest
@ ./essentials.jl:1052 [inlined]
[14] run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool, color_set::Bool)
@ Base ./client.jl:430
[15] repl_main
@ ./client.jl:567 [inlined]
[16] _start()
@ Base ./client.jl:541
+ X
+ _
Operator(dim=2x2)
basis: Spin(1/2)
0.5+0.0im 0.5+0.0im
0.5+0.0im 0.5+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.5+0.0im 0.5+0.0im
0.5+0.0im 0.5+0.0im
- X
+ _
Operator(dim=2x2)
basis: Spin(1/2)
0.5+0.0im -0.5-0.0im
-0.5+0.0im 0.5+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.5+0.0im -0.5+0.0im
-0.5+0.0im 0.5+0.0im
- Z
+ X
Operator(dim=2x2)
basis: Spin(1/2)
0.5+0.0im -0.5-0.0im
-0.5+0.0im 0.5+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.25+0.0im -0.25+0.0im
-0.25+0.0im 0.25+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.25+0.0im 0.25+0.0im
0.25+0.0im 0.25+0.0im
projection for Stabilizer/MixedStabilizer: Test Failed at REPL[12]:20
Expression: qo_state_after_proj ≈ result2 || qo_state_after_proj ≈ result1
Stacktrace:
[1] macro expansion
@ ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/Test/src/Test.jl:679 [inlined]
[2] macro expansion
@ ./REPL[12]:20 [inlined]
[3] macro expansion
@ ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/Test/src/Test.jl:1700 [inlined]
[4] top-level scope
@ ./REPL[12]:2
[5] eval
@ ./boot.jl:430 [inlined]
[6] eval_user_input(ast::Any, backend::REPL.REPLBackend, mod::Module)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:245
[7] repl_backend_loop(backend::REPL.REPLBackend, get_module::Function)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:342
[8] start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:327
[9] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool, backend::Any)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:483
[10] run_repl(repl::REPL.AbstractREPL, consumer::Any)
@ REPL ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:469
[11] (::Base.var"#1139#1141"{Bool, Symbol, Bool})(REPL::Module)
@ Base ./client.jl:446
[12] #invokelatest#2
@ ./essentials.jl:1055 [inlined]
[13] invokelatest
@ ./essentials.jl:1052 [inlined]
[14] run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool, color_set::Bool)
@ Base ./client.jl:430
[15] repl_main
@ ./client.jl:567 [inlined]
[16] _start()
@ Base ./client.jl:541
+ Y
+ Y
Operator(dim=2x2)
basis: Spin(1/2)
0.5+0.0im 0.0-0.5im
0.0+0.5im 0.5+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im
Operator(dim=2x2)
basis: Spin(1/2)
0.5+0.0im 0.0-0.5im
0.0+0.5im 0.5+0.0im
Test Summary: | Pass Fail Total Time
projection for Stabilizer/MixedStabilizer | 3 2 5 3.8s
ERROR: Some tests did not pass: 3 passed, 2 failed, 0 errored, 0 broken. The fix: julia> using Test; using QuantumClifford; using QuantumOpticsBase;
julia> @testset "projection for Stabilizer/MixedStabilizer" begin
for n in 1:10
for repetition in 1:5
s = random_stabilizer(n) # or md = MixedDestabilizer(random_stabilizer(n))
p = random_pauli(n)
apply!(s, p)
qo_state = Operator(s)
projectrand!(s, p)[1] # or project(s, p)[1]
qo_state_after_proj = Operator(s)
qo_pauli = Operator(p)
qo_proj1 = (identityoperator(qo_pauli) - qo_pauli)/2
qo_proj2 = (identityoperator(qo_pauli) + qo_pauli)/2
result1 = qo_proj1*qo_state*qo_proj1'
result2 = qo_proj2*qo_state*qo_proj2'
@test qo_state_after_proj ≈ result2 || qo_state_after_proj ≈ result1 || qo_state_after_proj ≈ 2*result2 || qo_state_after_proj ≈ 2*result1
end
end
end |
I think that the proper fix is to normalize the projected states: norm_qo_state_after_proj = qo_state_after_proj / tr(qo_state_after_proj)
norm_result1 = result1 / tr(result1)
norm_result2 = result2 / tr(result2)
@test norm_qo_state_after_proj ≈ norm_result2 || norm_qo_state_after_proj ≈ norm_result1 This test was originally suggested by Stefan in this comment. However, the projected states in the original suggestion were not normalized, which led to errors for |
Yup, it seems some normalizations were missing from my example. Thanks for clarifying it. The issue tracker is not the best place to discuss issues about unmerged (and even not yet written) PRs. Let's keep such discussions within the appropriate PRs. |
Describe the bug 🐞
The projection tests for
Stabilizer/MixedDestabilizer
states are conducted when applying the projection operator. The projection operatorsqo_proj1
andqo_proj2
are defined as follows:These operators are intended to project onto the eigenspaces corresponding to the eigenvalues of the Pauli operator
p
. The expected results from these projections can be computed using:and
These calculations should reflect the post-projection state of the original
Stabilizer/MixedDestabilizer
state.The tests currently pass only for specific, simple, single-qubit stages when working with the
Stabilizer
orMixedDestabilizer
states, as shown below. However, inconsistencies arise when projecting states using theproject!
orprojectrand!
functions.These discrepancies become evident when comparing the projected states with the theoretical results based on the MREs, especially in scenarios involving multi-qubit stabilizer states and multi-qubit Pauli operators. This issue is particularly noticeable when using
random_stabilizer
andrandom_pauli
functions in these cases.Expected behavior
I think these tests should not fail.
Minimal Reproducible Example 👇
Testing with multi-qubit Stabilizer and multi-qubit Pauli Operators;
Let's try the simple case: a single qubit but with repetition. It is observed that the same error occurs with single-qubit states when using repeated projections with
random_stabilizer
andrandom_pauli
.Error & Stacktrace or other complete output produced by the MRE⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
This MRE is reproduced with the
nonclif
branch.using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
The text was updated successfully, but these errors were encountered: