From 4123c2b39b2e7519b1d926a0882c1d3c7d913c30 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Fri, 9 Aug 2024 22:10:29 +0500 Subject: [PATCH] misc cleanup and removing superficial changes --- docs/src/noisycircuits_mc.md | 2 +- src/classical_register.jl | 34 ---------------------------------- src/pauli_frames.jl | 9 --------- src/project_trace_reset.jl | 8 +++++--- test/test_projections.jl | 2 +- 5 files changed, 7 insertions(+), 48 deletions(-) diff --git a/docs/src/noisycircuits_mc.md b/docs/src/noisycircuits_mc.md index 3b39e8d65..ddbd4a9bf 100644 --- a/docs/src/noisycircuits_mc.md +++ b/docs/src/noisycircuits_mc.md @@ -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) diff --git a/src/classical_register.jl b/src/classical_register.jl index e403b3823..0eb0298d3 100644 --- a/src/classical_register.jl +++ b/src/classical_register.jl @@ -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)) @@ -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) @@ -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) @@ -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)) @@ -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) @@ -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) @@ -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) diff --git a/src/pauli_frames.jl b/src/pauli_frames.jl index d46a1162e..581b4a39e 100644 --- a/src/pauli_frames.jl +++ b/src/pauli_frames.jl @@ -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]] @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/src/project_trace_reset.jl b/src/project_trace_reset.jl index 66fb8dc6a..b4f02ea1a 100644 --- a/src/project_trace_reset.jl +++ b/src/project_trace_reset.jl @@ -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) @@ -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 @@ -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")) @@ -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) diff --git a/test/test_projections.jl b/test/test_projections.jl index f660a0680..fa600f922 100644 --- a/test/test_projections.jl +++ b/test/test_projections.jl @@ -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