Stabilizer tableau circuit simulation using backtracking method from Stim#551
Stabilizer tableau circuit simulation using backtracking method from Stim#551sagnikpal2004 wants to merge 28 commits intoQuantumSavory:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #551 +/- ##
===========================================
- Coverage 84.46% 73.81% -10.66%
===========================================
Files 95 103 +8
Lines 5956 6610 +654
===========================================
- Hits 5031 4879 -152
- Misses 925 1731 +806 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/backtrajectory.jl
Outdated
| resolved by transforming their observables to the initial state; deterministic measurements are directly computed from tableau signs, | ||
| while random measurements are simplified and simulated with randomized gate insertions. | ||
|
|
||
| Reference: |
There was a problem hiding this comment.
for references we have @cite and a bibtex file
src/backtrajectory.jl
Outdated
|
|
||
|
|
||
|
|
||
| function do_op!(T, op::sMX) |
There was a problem hiding this comment.
to not explode the name space, let's either use a name like _backtraj_do_meas or put this in a module from which we just make backtrajectory available
src/backtrajectory.jl
Outdated
| T = one(CliffordOperator, n) | ||
| result = Register(one(Stabilizer, n), falses(m)) |
There was a problem hiding this comment.
these guys together seem to represent something, so a structure that has them together might be useful, e.g. BacktrajectoryRegister
src/backtrajectory.jl
Outdated
| if op isa AbstractCliffordOperator | ||
| apply_right!(T, op) | ||
| elseif op isa AbstractMeasurement | ||
| res = do_op!(T, op) | ||
| op.bit!=0 && (bitview(result)[op.bit] = res) | ||
| elseif typeof(op) ∈ [sMRX, sMRY, sMRZ] | ||
| res = do_op!(T, op) | ||
| op.bit!=0 && (bitview(result)[op.bit] = res) | ||
| elseif op isa AbstractReset | ||
| do_op!(T, op) | ||
| else | ||
| error("Unsupported operation: $(typeof(op))") |
There was a problem hiding this comment.
if you are using isa you are probably doing something unidiomatic. This whole if/else tree should probably be multimethods
(and we will need to discuss issues with "union splitting" and "sum types" later on)
src/backtrajectory.jl
Outdated
| return pivot | ||
| end | ||
|
|
||
| @inline is_deterministic_x(T, q::Int) = all(getxbytes(T, q) .== 0) |
There was a problem hiding this comment.
the T would lead folks to think this is a Type
src/QuantumClifford.jl
Outdated
| SparseGate, | ||
| sMX, sMY, sMZ, PauliMeasurement, Reset, sMRX, sMRY, sMRZ, | ||
| sMX, sMY, sMZ, PauliMeasurement, | ||
| Reset, sMRX, sMRY, sMRZ, sRX, sRY, sRZ, |
There was a problem hiding this comment.
let's not export the new resets until their API is fully implemented
Krastanov
left a comment
There was a problem hiding this comment.
some minor suggestions for changes
let's discuss again when the tests are done
| using LinearAlgebra: inv, mul!, rank, Adjoint, dot, tr | ||
| import DataStructures | ||
| using DataStructures: DefaultDict, Accumulator | ||
| using DataStructures: DefaultDict, Accumulator, counter |
There was a problem hiding this comment.
double check that the recent 0.19 does not break this
src/backtrajectory.jl
Outdated
|
|
||
| nqubits(r::StimRegister) = nqubits(r.inv_circuit) | ||
| bitview(r::StimRegister) = r.bits | ||
| quantumstate(r::StimRegister) = apply_inv!(one(Stabilizer, nqubits(r)), r.inv_circuit) |
There was a problem hiding this comment.
maybe add a docstring that using this is not a view and it requires calling inv(::CliffordOperator) which is relatively slow?
you should add a header to make it more obvious that it is for this method. DocStringExtensions provides an automated way to do that
| @inline getxrow(s::Tableau, r::Int) = s.xzs[1:2:end, r] | ||
| @inline getzrow(s::Tableau, r::Int) = s.xzs[2:2:end, r] No newline at end of file |
There was a problem hiding this comment.
is there elsewhere in the codebase that functions like this are defined, maybe in the linalg file or somewhere near where Tableau is defined -- just double check that there is no better place to put them
| @@ -0,0 +1,4 @@ | |||
| @testitem "test backtrajectory" begin | |||
|
|
|||
There was a problem hiding this comment.
let's discuss again after we have the tests
This PR introduces a new method
backtrajectory, implementing an efficient stabilizer simulation algorithm inspired by Craig Gidney’s Stim paper (Quantum, 2021). Instead of evolving stabilizer states forward through the circuit, this method incrementally folds inverse operations into an identity tableau, resolving measurements in reverse to efficiently extract outcomes.Currently, the simulator can perform the following operations:
<:AbstractCliffordOperator(anything supported byapply_right!)<:AbstractMeasurement->PauliMeasurement,sMX,sMY,sMZ<:AbstractReset->sRX,sRY,sRZsMRX,sMRY,sMRZNot supported yet
Reset,BellMeasurement,NoisyCircuitsChecklist:
Changelog:
BacktrackRegisterNotes:
<:AbstractReset->sRX,sRY,sRZbacktrajectory.jlDependency:
apply_right!PR apply_right #561References:
Gidney, C. (2021). Stim: A fast stabilizer circuit simulator. Quantum, 5, 497. https://doi.org/10.22331/q-2021-07-06-497