Skip to content

Commit

Permalink
Cleanup of Register (informed by JET)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Jul 20, 2022
1 parent c2519bb commit 55dad95
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
let
judgement = BenchmarkCI._loadjudge(BenchmarkCI.DEFAULT_WORKSPACE)
title = "JET Benchmark Result"
title = "Benchmark Result"
ciresult = BenchmarkCI.CIResult(; judgement, title)
BenchmarkCI.printcommentmd(stdout::IO, ciresult)
end
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# News

## v0.5.6 - dev
## v0.5.6 - 2022-07-20

- **(fix)** Bug-fixes to `PauliMeasurement` and `Reset`, detected by JET.
- **(fix)** Bug-fixes to `PauliMeasurement`, `Reset`, and `Register`, detected by JET.

## v0.5.5 - 2022-07-05

Expand Down
14 changes: 10 additions & 4 deletions src/classical_register.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct Register{Tzv<:AbstractVector{UInt8},Tm<:AbstractMatrix{<:Unsigned}} <: Ab
end

Register(s,bits) = Register(MixedDestabilizer(s), bits)
Register(s) = Register(s, Bool[])

Base.copy(r::Register) = Register(copy(r.stab),copy(r.bits))

Expand Down Expand Up @@ -34,22 +35,27 @@ function apply!(r::Register, op::AbstractCliffordOperator, indices; kwargs...)
end

function apply!(r::Register, m::sMX{T}) where T
_, res = projectXrand!(quantumstate(r),m.qubit)
_, res = projectXrand!(r,m.qubit)
T==Int && (bitview(r)[m.bit] = iszero(res))
r
end
function apply!(r::Register, m::sMY{T}) where T
_, res = projectYrand!(quantumstate(r),m.qubit)
_, res = projectYrand!(r,m.qubit)
T==Int && (bitview(r)[m.bit] = iszero(res))
r
end
function apply!(r::Register, m::sMZ{T}) where T
_, res = projectZrand!(quantumstate(r),m.qubit)
_, res = projectZrand!(r,m.qubit)
T==Int && (bitview(r)[m.bit] = iszero(res))
r
end
function apply!(r::Register, m::PauliMeasurement{A,B,T}) where {A,B,T}
_, res = projectrand!(quantumstate(r),m.pauli)
_, res = projectrand!(r,m.pauli)
T==Int && (bitview(r)[m.storagebit] = iszero(res))
r
end
function projectrand!(r::Register, m)
q = quantumstate(r)
_, res = projectrand!(q,m)
r, res
end
4 changes: 2 additions & 2 deletions src/experimental/NoisyCircuits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function QuantumClifford.apply!(s::AbstractStabilizer, mr::NoiseOp)
end

# TODO this one needs more testing
function applywstatus!(s::AbstractStabilizer, v::VerifyOp) # XXX It assumes the other qubits are measured or traced out
function applywstatus!(s::AbstractQCState, v::VerifyOp) # XXX It assumes the other qubits are measured or traced out
# TODO QuantumClifford should implement some submatrix comparison
canonicalize_rref!(quantumstate(s),v.indices) # Document why rref is used
sv = stabilizerview(s)
Expand Down Expand Up @@ -374,7 +374,7 @@ end

function applynoise_branches(state::Register, noise, indices; max_order=1)
[(Register(newstate,copy(state.bits)), prob, order)
for (newstate, prob, order) in applynoise_branches(s, nop.noise, 1:n, max_order=max_order)]
for (newstate, prob, order) in applynoise_branches(state, noise, indices, max_order=max_order)]
end

# TODO tests for this
Expand Down
8 changes: 4 additions & 4 deletions src/project_trace_reset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ See also: [`project!`](@ref), [`projectX!`](@ref), [`projectZrand!`](@ref), [`pr
"""
function projectXrand!(state, qubit)
_, anticom, res = projectX!(state, qubit)
anticom>0 && (res = stabilizerview(state).phases[anticom] = rand((0x0, 0x2)))
isnothing(res) && (res = stabilizerview(state).phases[anticom] = rand((0x0, 0x2)))
return state, res
end

Expand All @@ -593,7 +593,7 @@ See also: [`project!`](@ref), [`projectZ!`](@ref), [`projectXrand!`](@ref), [`pr
"""
function projectZrand!(state, qubit)
_, anticom, res = projectZ!(state, qubit)
anticom>0 && (res = stabilizerview(state).phases[anticom] = rand((0x0, 0x2)))
isnothing(res) && (res = stabilizerview(state).phases[anticom] = rand((0x0, 0x2)))
return state, res
end

Expand All @@ -608,7 +608,7 @@ See also: [`project!`](@ref), [`projectY!`](@ref), [`projectXrand!`](@ref), [`pr
"""
function projectYrand!(state, qubit)
_, anticom, res = projectY!(state, qubit)
anticom>0 && (res = stabilizerview(state).phases[anticom] = rand((0x0, 0x2)))
isnothing(res) && (res = stabilizerview(state).phases[anticom] = rand((0x0, 0x2)))
return state, res
end

Expand All @@ -623,7 +623,7 @@ See also: [`project!`](@ref), [`projectXrand!`](@ref), [`projectZrand!`](@ref),
"""
function projectrand!(state, pauli)
_, anticom, res = project!(state, pauli)
anticom>0 && (res = stabilizerview(state).phases[anticom] = rand((0x0, 0x2)))
isnothing(res) && (res = stabilizerview(state).phases[anticom] = rand((0x0, 0x2)))
return state, res
end

Expand Down
10 changes: 5 additions & 5 deletions src/symbolic_cliffords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ macro qubitop1(name, kernel)
q::Int
end
@doc $docstring $prefixname
@inline $(esc(:qubit_kernel))(::$prefixname, x, z) = $kernel
@inline $(esc(:qubit_kernel))(::$prefixname, x, z) = $kernel
end
end

Expand Down Expand Up @@ -187,7 +187,7 @@ function CliffordOperator(op::SingleQubitOperator, n; compact=false)
c = one(CliffordOperator, n)
c[op.q,op.q] = op.xx, op.xz # TODO define an `embed` helper function
c[n+op.q,op.q] = op.zx, op.zz
c.tab.phases[op.q] = op.px ? 0x2 : 0x0 # TODO define a `phasesview` or `phases` helper function
c.tab.phases[op.q] = op.px ? 0x2 : 0x0 # TODO define a `phasesview` or `phases` helper function
c.tab.phases[n+op.q] = op.pz ? 0x2 : 0x0
return c
end
Expand Down Expand Up @@ -247,7 +247,7 @@ macro qubitop2(name, kernel)
q2::Int
end
@doc $docstring $prefixname
@inline $(esc(:qubit_kernel))(::$prefixname, x1, z1, x2, z2) = $kernel
@inline $(esc(:qubit_kernel))(::$prefixname, x1, z1, x2, z2) = $kernel
end
end

Expand All @@ -266,7 +266,7 @@ function CliffordOperator(op::AbstractTwoQubitOperator, n; compact=false)
for (i,q) in ((1,op.q1),(2,op.q2))
c[q,q] = _c[i,i] # TODO define an `embed` helper function
c[n+q,q] = _c[n+i,i]
c.tab.phases[q] = _c.tab.phases[i] # TODO define a `phasesview` or `phases` helper function
c.tab.phases[q] = _c.tab.phases[i] # TODO define a `phasesview` or `phases` helper function
c.tab.phases[n+q] = _c.tab.phases[n+i]
end
return c
Expand Down Expand Up @@ -374,4 +374,4 @@ project!(state::AbstractStabilizer, m::sMY) = projectY!(state, m.qubit)
project!(state::AbstractStabilizer, m::sMZ) = projectZ!(state, m.qubit)
projectrand!(state::AbstractStabilizer, m::sMX) = projectXrand!(state, m.qubit)
projectrand!(state::AbstractStabilizer, m::sMY) = projectYrand!(state, m.qubit)
projectrand!(state::AbstractStabilizer, m::sMZ) = projectZrand!(state, m.qubit)
projectrand!(state::AbstractStabilizer, m::sMZ) = projectZrand!(state, m.qubit)
Loading

2 comments on commit 55dad95

@Krastanov
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release Notes:

  • (fix) Bug-fixes to PauliMeasurement, Reset, and Register, detected by JET.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/64627

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.6 -m "<description of version>" 55dad95a346e0988a993f33f069418b73056e318
git push origin v0.5.6

Please sign in to comment.