Skip to content

Commit 4fbcdc9

Browse files
committed
better method for calcuting number of qubits required
1 parent 4abcabc commit 4fbcdc9

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/affectedqubits.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ affectedqubits(n::NoiseOp) = n.indices
1010
affectedqubits(g::PauliMeasurement) = 1:length(g.pauli)
1111
affectedqubits(p::PauliOperator) = 1:length(p)
1212
affectedqubits(m::Union{AbstractMeasurement,sMRX,sMRY,sMRZ}) = (m.qubit,)
13+
affectedqubits(m::AbstractReset) = (m.qubit,)
1314
affectedqubits(v::VerifyOp) = v.indices
1415
affectedqubits(c::CliffordOperator) = 1:nqubits(c)
1516
affectedqubits(c::ClassicalXOR) = ()

src/backtrajectory.jl

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,28 @@ end
215215
# return backtrajectory(circuit0, nqubits(state))
216216
# end
217217

218-
function backtrajectory(circuit::Vector{<:AbstractOperation})
219-
n = 0
220-
for op in circuit
221-
if op isa AbstractSingleQubitOperator
222-
n = max(n, op.q)
223-
elseif op isa AbstractTwoQubitOperator
224-
n = max(n, op.q1, op.q2)
225-
elseif op isa AbstractMeasurement
226-
n = max(n, op.qubit)
227-
elseif op isa AbstractReset
228-
n = max(n, op.qubit)
229-
elseif typeof(op) in [sMRX, sMRY, sMRZ]
230-
n = max(n, op.qubit)
231-
else
232-
error("Unsupported operation: $(typeof(op))")
233-
end
234-
end
218+
# function backtrajectory(circuit::Vector{<:AbstractOperation})
219+
# n = 0
220+
# for op in circuit
221+
# if op isa AbstractSingleQubitOperator
222+
# n = max(n, op.q)
223+
# elseif op isa AbstractTwoQubitOperator
224+
# n = max(n, op.q1, op.q2)
225+
# elseif op isa AbstractMeasurement
226+
# n = max(n, op.qubit)
227+
# elseif op isa AbstractReset
228+
# n = max(n, op.qubit)
229+
# elseif typeof(op) in [sMRX, sMRY, sMRZ]
230+
# n = max(n, op.qubit)
231+
# else
232+
# error("Unsupported operation: $(typeof(op))")
233+
# end
234+
# end
235+
236+
# return backtrajectory(circuit, n)
237+
# end
235238

239+
function backtrajectory(circuit::Vector{<:AbstractOperation})
240+
n = maximum(Iterators.flatten(affectedqubits.(circuit)))
236241
return backtrajectory(circuit, n)
237242
end

0 commit comments

Comments
 (0)