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 18, 2024
1 parent ab05c50 commit 8df0661
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 187 deletions.
44 changes: 2 additions & 42 deletions docs/src/circuit-simulation-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,9 @@ julia> quantumstate(stabmx)
𝒮𝓉𝒶𝒷
- XX
- X_
julia> stabmz = apply!(rng, copy(reg), sMZ(1, 1));
julia> quantumstate(stabmz)
𝒟ℯ𝓈𝓉𝒶𝒷
- XX
- ZZ
𝒮𝓉𝒶𝒷
+ Z_
+ ZY
julia> stabmy = apply!(rng, copy(reg), sMY(1, 1));
julia> quantumstate(stabmy)
𝒟ℯ𝓈𝓉𝒶𝒷
- XX
- YY
𝒮𝓉𝒶𝒷
+ Y_
- YZ
```

Projective measurements with automatic phase randomization, including [`projectY!`](@ref), [`projectZ!`](@ref) and [`projectrand!`](@ref) are available for the [`Register`](@ref) object.
Projective measurements with automatic phase randomization, including [`projectXrand!`](@ref), [`projectYrand!`](@ref), [`projectZrand!`](@ref), and [`projectrand!`](@ref) are available for the [`Register`](@ref) object.

```jldoctest
julia> rng = StableRNG(42); # hide
Expand All @@ -117,31 +97,11 @@ julia> quantumstate(px[1])
𝒮𝓉𝒶𝒷
+ X_
- _X
julia> py = projectYrand!(rng, copy(reg), 1);
julia> quantumstate(py[1])
𝒟ℯ𝓈𝓉𝒶𝒷
+ X_
- _X
𝒮𝓉𝒶𝒷
+ Y_
+ _Z
julia> pz = projectZrand!(rng, copy(reg), 2);
julia> quantumstate(pz[1])
𝒟ℯ𝓈𝓉𝒶𝒷
+ YZ
- XX
𝒮𝓉𝒶𝒷
+ X_
+ _Z
```

# Pauli Frame

[`PauliFrame`](@ref) is a wrapper for a "frame" tableau. Each row represents the Pauli operation differing
[`PauliFrame`](@ref) is a wrapper for a "frame" tableau. Each row represents the Pauli operation differing
the frame from the reference, behaving uniquely under Clifford operations.

```jldoctest frame
Expand Down
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
6 changes: 3 additions & 3 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ tab(s::AbstractStabilizer) = s.tab
"""
A destabilizer `𝒟` associated with a stabilizer `𝒮 = ⟨𝓈₁, 𝓈₂,…,𝓈ᵣ⟩` is a subgroup of Pauli
group `𝒫ₙ`​. For `𝒟` to be a valid destabilizer, it must have the same number of generators
as `𝒮`, hence `𝒟 = ⟨𝒹₁, 𝒹₂,…,𝒹ᵣ⟩`. Additionally, each generator `𝒹ᵢ` of `𝒟` must anti-commute
group `𝒫ₙ`​. For `𝒟` to be a valid destabilizer, it must have the same number of generators
as `𝒮`, hence `𝒟 = ⟨𝒹₁, 𝒹₂,…,𝒹ᵣ⟩`. Additionally, each generator `𝒹ᵢ` of `𝒟` must anti-commute
with the corresponding `𝓈ᵢ`​ and commute with all other `𝓈ⱼ​` where `j≠i`.
Internally, it is represented as a tableau pure stabilizer state. The tableau tracks the
Internally, it is a tableau representation of a pure stabilizer state. The tableau tracks the
destabilizers as well, for efficient projections. On initialization there are
no checks that the provided state is indeed pure. This enables the use of this
data structure for mixed stabilizer state, but a better choice would be to use
Expand Down
54 changes: 0 additions & 54 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 @@ -190,26 +169,6 @@ julia> quantumstate(reg)
𝒮𝓉𝒶𝒷
+ X_
- _X
julia> projectYrand!(rng, reg, 1);
julia> quantumstate(reg)
𝒟ℯ𝓈𝓉𝒶𝒷
+ X_
+ _Z
𝒮𝓉𝒶𝒷
+ Y_
- _X
julia> projectZrand!(rng, reg, 2);
julia> quantumstate(reg)
𝒟ℯ𝓈𝓉𝒶𝒷
+ X_
- _X
𝒮𝓉𝒶𝒷
+ Y_
+ _Z
```
See also: [`projectY!`](@ref), [`projectZ!`](@ref), [`projectrand!`](@ref), [`sMY`](@ref), [`sMZ`](@ref),
Expand All @@ -220,38 +179,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 +211,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 +236,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
Loading

0 comments on commit 8df0661

Please sign in to comment.