Skip to content

Commit 4abcabc

Browse files
committed
reset
1 parent b4cda36 commit 4abcabc

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/QuantumClifford.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export
6060
sSQRTZZ, sInvSQRTZZ, sSQRTXX, sInvSQRTXX, sSQRTYY, sInvSQRTYY,
6161
# Misc Ops
6262
SparseGate,
63-
sMX, sMY, sMZ, PauliMeasurement, Reset, sMRX, sMRY, sMRZ,
63+
sMX, sMY, sMZ, PauliMeasurement,
64+
Reset, sMRX, sMRY, sMRZ, sRX, sRY, sRZ,
6465
BellMeasurement, ClassicalXOR,
6566
VerifyOp,
6667
Register,

src/backtrajectory.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
# new symbolics
2+
abstract type AbstractReset <: AbstractOperation end
3+
4+
"""Reset a qubit to the |+⟩ state.
5+
6+
See also: [`sMRX`](@ref), [`Reset`](@ref)"""
7+
struct sRX <: AbstractReset
8+
qubit::Int
9+
sRX(q) = if q<=0 throw(NoZeroQubit) else new(q) end
10+
end
11+
12+
"""Reset a qubit to the |i₊⟩ state.
13+
14+
See also: [`sMRY`](@ref), [`Reset`](@ref)"""
15+
struct sRY <: AbstractReset
16+
qubit::Int
17+
sRY(q) = if q<=0 throw(NoZeroQubit) else new(q) end
18+
end
19+
20+
"""Reset a qubit to the |0⟩ state.
21+
22+
See also: [`sMRZ`](@ref), [`Reset`](@ref)"""
23+
struct sRZ <: AbstractReset
24+
qubit::Int
25+
sRZ(q) = if q<=0 throw(NoZeroQubit) else new(q) end
26+
end
27+
28+
129
"""
230
Simulates measurement results of a Clifford circuit acting on an `n`-qubit |0⟩^⊗n state using the stabilizer tableau backtracking method,
331
as described by Gidney (2021).
@@ -28,6 +56,8 @@ function backtrajectory(circuit::Vector{<:AbstractOperation}, n::Int)
2856
push!(results, do_MRY!(T, op))
2957
elseif op isa sMRZ
3058
push!(results, do_MRZ!(T, op))
59+
elseif op isa AbstractReset
60+
do_reset!(T, op)
3161
else
3262
error("Unsupported operation: $(typeof(op))")
3363
end
@@ -50,6 +80,12 @@ function do_MRX!(T, op::sMRX)
5080
return result
5181
end
5282

83+
function do_reset!(T, op::sRX)
84+
collapse_x!(T, op.qubit)
85+
phases(tab(T))[op.qubit] = 0x00
86+
phases(tab(T))[nqubits(T)+op.qubit] = 0x00
87+
end
88+
5389
function collapse_x!(T, q::Int)
5490
if is_deterministic_x(T, q)
5591
return
@@ -74,6 +110,13 @@ function do_MRY!(T, op::sMRY)
74110
return result
75111
end
76112

113+
function do_reset!(T, op::sRY)
114+
collapse_y!(T, op.qubit)
115+
if eval_y_obs(T, op.qubit).phase[] != 0x00
116+
phases(tab(T))[nqubits(T)+op.qubit] ⊻= 0x02
117+
end
118+
end
119+
77120
function collapse_y!(T, q::Int)
78121
if is_deterministic_y(T, q)
79122
return
@@ -111,6 +154,12 @@ function do_MRZ!(T, op::sMRZ)
111154
return result
112155
end
113156

157+
function do_reset!(T, op::sRZ)
158+
collapse_z!(T, op.qubit)
159+
phases(tab(T))[op.qubit] = 0x00
160+
phases(tab(T))[nqubits(T)+op.qubit] = 0x00
161+
end
162+
114163
function collapse_z!(T, q::Int)
115164
if is_deterministic_z(T, q)
116165
return
@@ -175,6 +224,8 @@ function backtrajectory(circuit::Vector{<:AbstractOperation})
175224
n = max(n, op.q1, op.q2)
176225
elseif op isa AbstractMeasurement
177226
n = max(n, op.qubit)
227+
elseif op isa AbstractReset
228+
n = max(n, op.qubit)
178229
elseif typeof(op) in [sMRX, sMRY, sMRZ]
179230
n = max(n, op.qubit)
180231
else

0 commit comments

Comments
 (0)