Skip to content

Commit

Permalink
project*rand! for Register
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Aug 17, 2022
1 parent c04c01c commit 7c47653
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# News

## v0.5.8
## v0.5.9 - 2022-08-17

- `Register` now works with `traceout!` and `project*rand!`.

## v0.5.8 - 2022-08-15

- Implement `projectremoverand!` which besides performing a projective measurement like `projectrand!` also removes the measured qubit from the tableau, returning a smaller tableau. Not yet exported in public API.

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumClifford"
uuid = "0525e862-1e90-11e9-3e4d-1b39d7109de1"
authors = ["Stefan Krastanov <stefan@krastanov.org>"]
version = "0.5.8"
version = "0.5.9"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
21 changes: 21 additions & 0 deletions src/classical_register.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,29 @@ function apply!(r::Register, m::PauliMeasurement{A,B,T}) where {A,B,T}
T==Int && (bitview(r)[m.storagebit] = iszero(res))
r
end
function projectXrand!(r::Register, m)
q = quantumstate(r)
_, res = projectXrand!(q,m)
r, res
end
function projectYrand!(r::Register, m)
q = quantumstate(r)
_, res = projectYrand!(q,m)
r, res
end
function projectZrand!(r::Register, m)
q = quantumstate(r)
_, res = projectZrand!(q,m)
r, res
end
function projectrand!(r::Register, m)
q = quantumstate(r)
_, res = projectrand!(q,m)
r, res
end

function traceout!(r::Register, arg)
q = quantumstate(r)
traceout!(q,arg)
q
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ doset("cliffords") && include("./test_cliff.jl")
doset("symbolic cliffords") && include("./test_symcliff.jl")
doset("random") && include("./test_random.jl")
doset("noisy circuits") && include("./test_noisycircuits.jl")
doset("syndrome measure") && include("./test_syndromemeas.jl")
doset("bitpack") && include("./test_bitpack.jl")
doset("graphs") && include("./test_graphs.jl")
doset("hash") && include("./test_hash.jl")
Expand Down
57 changes: 57 additions & 0 deletions test/test_syndromemeas.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using QuantumClifford.Experimental.NoisyCircuits

function test_syndromemeas()
@testset "Syndrome Measurements" begin
codeˢᵗᵉᵃⁿᵉ = S"Z__Z_ZZ
_Z_ZZ_Z
__Z_ZZZ
X__X_XX
_X_XX_X
__X_XXX";
function get_check(code,index) # TODO a fairly ugly piece of code that should just be part of the library
s,n = size(code)
@assert index<=s
op = code[index]
anc = n+1
circuit = AbstractOperation[]
measurement = nothing
resetgate = nothing
for qubit in 1:n
if op[qubit] == (false, true) # it is a Z
if isnothing(measurement) || measurement==sMZ
resetgate = Reset(S"-Z",[anc])
measurement = sMZ
else
error("can not do mixed syndromes")
end
push!(circuit, sCNOT(qubit, anc))
elseif op[qubit] == (true, false) # it is a X
if isnothing(measurement) || measurement==sMX
resetgate = Reset(S"-X",[anc])
measurement = sMX
else
error("can not do mixed syndromes")
end
push!(circuit, sCNOT(anc, qubit))
elseif op[qubit] == (true, true) # it is a Y
error("can not do Y syndromes")
end
end
push!(circuit,measurement(anc,index))
circuit = AbstractOperation[resetgate,circuit...]
end
function get_all_checks(code)
s,n = size(code)
vcat([get_check(code,i) for i in 1:s]...)
end
# test the code is correct
state = Register(MixedDestabilizer(codeˢᵗᵉᵃⁿᵉ S"Z"),zeros(Bool,6))
full_circuit = get_all_checks(codeˢᵗᵉᵃⁿᵉ)
for _ in 1:100
err = random_pauli(7;realphase=true)
@test mctrajectory!(apply!(copy(state),(err P"I")),full_circuit)[1].bits == comm(err*codeˢᵗᵉᵃⁿᵉ, err)
end
end
end

test_syndromemeas()

2 comments on commit 7c47653

@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:

  • Register now works with traceout! and project*rand!.

@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/66438

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.9 -m "<description of version>" 7c47653f3e653b3a90d2bce5a97b36472a21e304
git push origin v0.5.9

Please sign in to comment.