Skip to content

Commit

Permalink
misc cleanup and removing superficial changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed Aug 11, 2024
1 parent ab05c50 commit 4123c2b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 48 deletions.
2 changes: 1 addition & 1 deletion docs/src/noisycircuits_mc.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ n = NoiseOpAll(UnbiasedUncorrelatedNoise(epsilon))
circuit = [n,g1,g2,m,v]
```

And we can run a Monte Carlo simulation on the above circuit with [`mctrajectories`](@ref).
And we can run a Monte Carlo simulation of that circuit with [`mctrajectories`](@ref).

```@example 1
mctrajectories(initial_state, circuit, trajectories=500)
Expand Down
34 changes: 0 additions & 34 deletions src/classical_register.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ struct Register{T<:Tableau} <: AbstractQCState # TODO simplify type parameters (
Register(s::MixedDestabilizer{T}, bits) where {T} = new{T}(s,bits)
end

"""$(TYPEDSIGNATURES)"""
Register(s,bits) = Register(MixedDestabilizer(s), bits)

"""$(TYPEDSIGNATURES)"""
Register(s) = Register(s, Bool[])

"""$(TYPEDSIGNATURES)"""
Register(s::MixedDestabilizer,nbits::Int) = Register(s, falses(nbits))

Base.copy(r::Register) = Register(copy(r.stab),copy(r.bits))
Expand All @@ -80,46 +75,34 @@ quantumstate(r::Register) = r.stab

tab(r::Register) = tab(quantumstate(r))

"""$(TYPEDSIGNATURES)"""
tensor(regs::Register...) = Register(tensor((quantumstate(r) for r in regs)...), [bit for r in regs for bit in r.bits])

"""$(TYPEDSIGNATURES)"""
function apply!(r::Register, op, args...; kwargs...)
apply!(quantumstate(r), op, args...; kwargs...)
r
end

"""$(TYPEDSIGNATURES)"""
function apply!(rng::AbstractRNG, r::Register, m::sMX)
_, res = projectXrand!(rng, r,m.qubit)
m.bit!=0 && (bitview(r)[m.bit] = !iszero(res))
r
end

"""$(TYPEDSIGNATURES)"""
apply!(r::Register, m::sMX) = apply!(GLOBAL_RNG, r, m)

"""$(TYPEDSIGNATURES)"""
function apply!(rng::AbstractRNG, r::Register, m::sMY)
_, res = projectYrand!(rng, r,m.qubit)
m.bit!=0 && (bitview(r)[m.bit] = !iszero(res))
r
end

"""$(TYPEDSIGNATURES)"""
apply!(r::Register, m::sMY) = apply!(GLOBAL_RNG, r, m)

"""$(TYPEDSIGNATURES)"""
function apply!(rng::AbstractRNG, r::Register, m::sMZ)
_, res = projectZrand!(rng, r,m.qubit)
m.bit!=0 && (bitview(r)[m.bit] = !iszero(res))
r
end

"""$(TYPEDSIGNATURES)"""
apply!(r::Register, m::sMZ) = apply!(GLOBAL_RNG, r, m)

"""$(TYPEDSIGNATURES)"""
function apply!(r::Register, m::sMRX) # TODO sMRY
_, anticom, res = projectX!(quantumstate(r),m.qubit)
mres = if isnothing(res)
Expand All @@ -135,8 +118,6 @@ function apply!(r::Register, m::sMRX) # TODO sMRY
end
r
end

"""$(TYPEDSIGNATURES)"""
function apply!(r::Register, m::sMRZ) # TODO sMRY
_, anticom, res = projectZ!(quantumstate(r),m.qubit)
mres = if isnothing(res)
Expand All @@ -152,8 +133,6 @@ function apply!(r::Register, m::sMRZ) # TODO sMRY
end
r
end

"""$(TYPEDSIGNATURES)"""
function apply!(r::Register, m::PauliMeasurement{A,B}) where {A,B}
_, res = projectrand!(r,m.pauli)
m.bit!=0 && (bitview(r)[m.bit] = !iszero(res))
Expand Down Expand Up @@ -220,38 +199,28 @@ function projectXrand!(rng::AbstractRNG, r::Register, m)
_, res = projectXrand!(rng, q,m)
r, res
end

"""$(TYPEDSIGNATURES)"""
projectXrand!(r::Register, m) = projectXrand!(GLOBAL_RNG, r, m)

"""$(TYPEDSIGNATURES)"""
function projectYrand!(rng::AbstractRNG, r::Register, m)
q = quantumstate(r)
_, res = projectYrand!(rng, q,m)
r, res
end

"""$(TYPEDSIGNATURES)"""
projectYrand!(r::Register, m) = projectYrand!(GLOBAL_RNG, r, m)

"""$(TYPEDSIGNATURES)"""
function projectZrand!(rng::AbstractRNG, r::Register, m)
q = quantumstate(r)
_, res = projectZrand!(rng, q,m)
r, res
end

"""$(TYPEDSIGNATURES)"""
projectZrand!(r::Register, m) = projectZrand!(GLOBAL_RNG, r, m)

"""$(TYPEDSIGNATURES)"""
function projectrand!(r::Register, m)
q = quantumstate(r)
_, res = projectrand!(q,m)
r, res
end

"""$(TYPEDSIGNATURES)"""
function traceout!(r::Register, arg)
q = quantumstate(r)
traceout!(q,arg)
Expand All @@ -262,13 +231,11 @@ end
# petrajectories, applynoise_branches
##

"""$(TYPEDSIGNATURES)"""
function applynoise_branches(state::Register, noise, indices; max_order=1)
[(Register(newstate,copy(state.bits)), prob, order)
for (newstate, prob, order) in applynoise_branches(quantumstate(state), noise, indices; max_order=max_order)]
end

"""$(TYPEDSIGNATURES)"""
function applybranches(s::Register, op::PauliMeasurement; max_order=1) # TODO this is almost the same as `applybranches(s::Register, op::AbstractMeasurement; max_order=1)` defined below
stab = s.stab
stab, anticom, r = project!(stab, op.pauli)
Expand All @@ -289,7 +256,6 @@ function applybranches(s::Register, op::PauliMeasurement; max_order=1) # TODO th
new_branches
end

"""$(TYPEDSIGNATURES)"""
function applybranches(s::Register, op::AbstractMeasurement; max_order=1)
stab = s.stab
stab, anticom, r = project!(stab, op)
Expand Down
9 changes: 0 additions & 9 deletions src/pauli_frames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,13 @@ function initZ!(rng::AbstractRNG, frame::PauliFrame)
return frame
end

"""$(TYPEDSIGNATURES)"""
initZ!(frame::PauliFrame) = initZ!(GLOBAL_RNG, frame)

"""$(TYPEDSIGNATURES)"""
function apply!(f::PauliFrame, op::AbstractCliffordOperator)
_apply!(f.frame, op; phases=Val(false))
return f
end

"""$(TYPEDSIGNATURES)"""
function apply!(frame::PauliFrame, xor::ClassicalXOR)
for f in eachindex(frame)
value = frame.measurements[f,xor.bits[1]]
Expand All @@ -75,20 +72,17 @@ function apply!(frame::PauliFrame, xor::ClassicalXOR)
return frame
end

"""$(TYPEDSIGNATURES)"""
function apply!(frame::PauliFrame, op::sMX) # TODO implement a faster direct version
op.bit == 0 && return frame
apply!(frame, sHadamard(op.qubit))
apply!(frame, sMZ(op.qubit, op.bit))
end

"""$(TYPEDSIGNATURES)"""
function apply!(frame::PauliFrame, op::sMRX) # TODO implement a faster direct version
apply!(frame, sHadamard(op.qubit))
apply!(frame, sMRZ(op.qubit, op.bit))
end

"""$(TYPEDSIGNATURES)"""
function apply!(frame::PauliFrame, op::sMZ) # TODO sMY, and faster sMX
op.bit == 0 && return frame
i = op.qubit
Expand All @@ -107,7 +101,6 @@ function apply!(frame::PauliFrame, op::sMZ) # TODO sMY, and faster sMX
return frame
end

"""$(TYPEDSIGNATURES)"""
function apply!(frame::PauliFrame, op::sMRZ) # TODO sMRY, and faster sMRX
i = op.qubit
xzs = frame.frame.tab.xzs
Expand All @@ -131,7 +124,6 @@ function apply!(frame::PauliFrame, op::sMRZ) # TODO sMRY, and faster sMRX
return frame
end

"""$(TYPEDSIGNATURES)"""
function applynoise!(frame::PauliFrame,noise::UnbiasedUncorrelatedNoise,i::Int)
p = noise.p
T = eltype(frame.frame.tab.xzs)
Expand All @@ -156,7 +148,6 @@ function applynoise!(frame::PauliFrame,noise::UnbiasedUncorrelatedNoise,i::Int)
return frame
end

"""$(TYPEDSIGNATURES)"""
function applynoise!(frame::PauliFrame,noise::PauliNoise,i::Int)
T = eltype(frame.frame.tab.xzs)

Expand Down
8 changes: 5 additions & 3 deletions src/project_trace_reset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ end
$TYPEDSIGNATURES
Trace out a qubit.
See also: [`delete_columns`](@ref)
""" # TODO all of these should raise an error if length(qubits)>rank
function traceout!(s::Stabilizer, qubits; phases=true, rank=false)
_,i = canonicalize_rref!(s,qubits;phases=phases)
Expand All @@ -754,7 +756,9 @@ function traceout!(s::Stabilizer, qubits; phases=true, rank=false)
if rank return (s, i) else return s end
end

"""$TYPEDSIGNATURES"""
"""
$TYPEDSIGNATURES
"""
function traceout!(s::Union{MixedStabilizer, MixedDestabilizer}, qubits; phases=true, rank=false)
_,i = canonicalize_rref!(s,qubits;phases=phases)
s.rank = i
Expand Down Expand Up @@ -792,7 +796,6 @@ function reset_qubits!(s::Stabilizer, newstate, qubits; phases=true)
s
end

"""$TYPEDSIGNATURES"""
function reset_qubits!(s::MixedStabilizer, newstate, qubits; phases=true) # TODO create the necessary interfaces so that Stabilizer and MixedStabilizer share this code
nqubits(newstate)==length(qubits) || throw(DimensionMismatch("`qubits` and `newstate` have to be of consistent size"))
length(qubits) <= nqubits(s) || throw(DimensionMismatch("the stabilizer is not big enough to contain the new state"))
Expand Down Expand Up @@ -1008,7 +1011,6 @@ function projectremoverand!(s::MixedDestabilizer, projfunc::F, qubit) where {F<:
s, res
end

"""$TYPEDSIGNATURES"""
function traceoutremove!(s::MixedDestabilizer, qubit)
traceout!(s,[qubit]) # TODO this can be optimized thanks to the information already known from projfunc
s = _remove_rowcol!(s, nqubits(s), qubit)
Expand Down
2 changes: 1 addition & 1 deletion test/test_projections.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testitem "Projective measurements" begin
using QuantumClifford: stab_looks_good, destab_looks_good, mixed_stab_looks_good, mixed_destab_looks_good,
using QuantumClifford: stab_looks_good, destab_looks_good, mixed_stab_looks_good, mixed_destab_looks_good
using QuantumClifford: projectremoverand!
using StableRNGs

Expand Down

0 comments on commit 4123c2b

Please sign in to comment.