Skip to content

add random Clifford circuit codes #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions docs/src/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,17 @@ @article{grassl2002algorithmic

% Examples of results that employ the tableaux formalism

@article{gullans2020quantum,
title={Quantum coding with low-depth random circuits},
author={Gullans, Michael J and Krastanov, Stefan and Huse, David A and Jiang, Liang and Flammia, Steven T},
journal={arXiv preprint arXiv:2010.09775},
year={2020}
@article{gullans2021quantum,
title = {Quantum {{Coding}} with {{Low-Depth Random Circuits}}},
author = {Gullans, Michael J. and Krastanov, Stefan and Huse, David A. and Jiang, Liang and Flammia, Steven T.},
year = {2021},
month = sep,
journal = {Physical Review X},
volume = {11},
number = {3},
pages = {031066},
issn = {2160-3308},
doi = {10.1103/PhysRevX.11.031066}
}

@article{krastanov2020heterogeneous,
Expand Down Expand Up @@ -386,3 +392,13 @@ @article{knill1996concatenated
journal={arXiv preprint quant-ph/9608012},
year={1996}
}

@inproceedings{brown2013short,
title = {Short Random Circuits Define Good Quantum Error Correcting Codes},
booktitle = {2013 {{IEEE International Symposium}} on {{Information Theory}}},
author = {Brown, Winton and Fawzi, Omar},
year = {2013},
month = jul,
pages = {346--350},
doi = {10.1109/ISIT.2013.6620245}
}
2 changes: 1 addition & 1 deletion docs/src/tutandpub.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This list has a number of notebooks with tutorials, examples, and reproduction o

## On the topic of explicit use of the Tableaux formalism for Stabilizer states

- [Quantum coding with low-depth random circuits](https://github.com/QuantumSavory/QuantumClifford.jl/blob/master/docs/src/notebooks/Stabilizer_Codes_Based_on_Random_Circuits.ipynb) reproducing results from [gullans2020quantum](@cite). [view on nbviewer.jupyter.org](https://nbviewer.jupyter.org/github/QuantumSavory/QuantumClifford.jl/blob/master/docs/src/notebooks/Stabilizer_Codes_Based_on_Random_Circuits.ipynb)
- [Quantum coding with low-depth random circuits](https://github.com/QuantumSavory/QuantumClifford.jl/blob/master/docs/src/notebooks/Stabilizer_Codes_Based_on_Random_Circuits.ipynb) reproducing results from [gullans2021quantum](@cite). [view on nbviewer.jupyter.org](https://nbviewer.jupyter.org/github/QuantumSavory/QuantumClifford.jl/blob/master/docs/src/notebooks/Stabilizer_Codes_Based_on_Random_Circuits.ipynb)


## On the Monte Carlo and Perturbative Expansions for **Noisy** Clifford circuits
Expand Down
1 change: 1 addition & 0 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export
random_invertible_gf2,
random_pauli, random_pauli!,
random_stabilizer, random_destabilizer, random_clifford,
random_brickwork_clifford_circuit, random_all_to_all_clifford_circuit,
# Noise
applynoise!, UnbiasedUncorrelatedNoise, NoiseOp, NoiseOpAll, NoisyGate,
PauliNoise, PauliError,
Expand Down
4 changes: 3 additions & 1 deletion src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export parity_checks, parity_checks_x, parity_checks_z, iscss,
RepCode,
CSS,
Shor9, Steane7, Cleve8, Perfect5, Bitflip3,
Toric, Gottesman, Surface, Concat,
Toric, Gottesman, Surface, Concat, CircuitCode,
random_circuit_code,
evaluate_decoder,
CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup,
TableDecoder,
Expand Down Expand Up @@ -359,6 +360,7 @@ include("codes/toric.jl")
include("codes/gottesman.jl")
include("codes/surface.jl")
include("codes/concat.jl")
include("codes/random_circuit.jl")
include("codes/classical/reedmuller.jl")
include("codes/classical/bch.jl")
end #module
74 changes: 74 additions & 0 deletions src/ecc/codes/random_circuit.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Random: AbstractRNG, GLOBAL_RNG


"""
`CircuitCode` is defined by a given encoding circuit `circ`.

- `arrange`: the spatial arrangement of qubits
- `connect`: the gate connectivity, can be `alltoall` or `brickwork`
- `circ`: the encoding circuit
- `encode_qubits`: the qubits to be encoded

Qubit arrangement for different connectivity types:

- For `all-to-all` connectivity, `arrange` is a one-element tuple containing the number of qubits.
- For `brickwork` connectivity, the qubits are arranged as a lattice, and `arrange` contains side length in each dimension.
For example, a 5×5 lattice will have `arrange = (5, 5)`.

TODO it would be nicer if we can use CartesianIndex for `encode_qubits` in brickworks,
but its conversion to LinearIndex is limited, not supporting non-one step.
"""
struct CircuitCode <: AbstractECC
arrange::NTuple{N,Int} where {N}
connect::Union{Val{:alltoall},Val{:brickwork}}
circ::Vector{QuantumClifford.AbstractOperation}
encode_qubits::AbstractArray
end

iscss(::Type{CircuitCode}) = nothing

code_n(c::CircuitCode) = prod(c.arrange)

code_k(c::CircuitCode) = length(c.encode_qubits)

function parity_checks(c::CircuitCode)
n = code_n(c)
checks = one(Stabilizer, n)[setdiff(1:n, c.encode_qubits)]
for op in c.circ
apply!(checks, op)
end
checks
end

"""
Random Clifford circuit code.

The code is generated by a random Clifford circuit `circ` that encode a subset of qubits `encode_qubits` into logical qubits.
The connectivity of the random circuit can be either all-to-all [brown2013short](@cite) or brickwork in some dimensions [gullans2021quantum](@cite).
Each gate in the random circuit is a random 2-qubit Clifford gate.
"""
function random_circuit_code end

function random_circuit_code(rng::AbstractRNG, n::Int, connect::Val{:alltoall}, ngates::Int, k::Int)
CircuitCode((n,), connect, random_all_to_all_clifford_circuit(rng, n, ngates), collect(1:k))

Check warning on line 53 in src/ecc/codes/random_circuit.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/codes/random_circuit.jl#L52-L53

Added lines #L52 - L53 were not covered by tests
end

function random_circuit_code(n::Int, connect::Val{:alltoall}, ngates::Int, k::Int)
CircuitCode((n,), connect, random_all_to_all_clifford_circuit(n, ngates), collect(1:k))
end

function random_circuit_code(rng::AbstractRNG, n::Int, connect::Val{:alltoall}, ngates::Int, encode_qubits::AbstractArray)
CircuitCode((n,), connect, random_all_to_all_clifford_circuit(rng, n, ngates), encode_qubits)

Check warning on line 61 in src/ecc/codes/random_circuit.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/codes/random_circuit.jl#L60-L61

Added lines #L60 - L61 were not covered by tests
end

function random_circuit_code(n::Int, connect::Val{:alltoall}, ngates::Int, encode_qubits::AbstractArray)
CircuitCode((n,), connect, random_all_to_all_clifford_circuit(n, ngates), encode_qubits)
end

function random_circuit_code(rng::AbstractRNG, arrange::NTuple{N,Int} where {N}, connect::Val{:brickwork}, nlayers::Int, encode_qubits::AbstractArray)
CircuitCode(arrange, connect, random_brickwork_clifford_circuit(rng, arrange, nlayers), encode_qubits)

Check warning on line 69 in src/ecc/codes/random_circuit.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/codes/random_circuit.jl#L68-L69

Added lines #L68 - L69 were not covered by tests
end

function random_circuit_code(arrange::NTuple{N,Int} where {N}, connect::Val{:brickwork}, nlayers::Int, encode_qubits::AbstractArray)
CircuitCode(arrange, connect, random_brickwork_clifford_circuit(arrange, nlayers), encode_qubits)
end
4 changes: 2 additions & 2 deletions src/entanglement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ It is the list of endpoints of a tableau in the clipped gauge.
If `clip=true` (the default) the tableau is converted to the clipped gauge in-place before calculating the bigram.
Otherwise, the clip gauge conversion is skipped (for cases where the input is already known to be in the correct gauge).

Introduced in [nahum2017quantum](@cite), with a more detailed explanation of the algorithm in [li2019measurement](@cite) and [gullans2020quantum](@cite).
Introduced in [nahum2017quantum](@cite), with a more detailed explanation of the algorithm in [li2019measurement](@cite) and [gullans2021quantum](@cite).

See also: [`canonicalize_clip!`](@ref)
"""
Expand Down Expand Up @@ -186,7 +186,7 @@ function entanglement_entropy(state::AbstractStabilizer, subsystem_range::UnitRa
# JET-XXX The ::Matrix{Int} should not be necessary, but they help with inference
bg = bigram(state; clip=clip)::Matrix{Int}
# If the state is mixed, this formula is valid only for contiguous regions that don't wrap around.
# See Eq. E7 of gullans2020quantum.
# See Eq. E7 of gullans2021quantum.
# As subsystem_range is UnitRange, we know the formula will be valid.
length(subsystem_range) - count(r->(r[1] in subsystem_range && r[2] in subsystem_range), eachrow(bg))
end
Expand Down
40 changes: 40 additions & 0 deletions src/randoms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,43 @@ function fill_tril(rng, matrix, n; symmetric::Bool=false)
end
matrix
end

##############################
# Random circuit
##############################

function random_brickwork_clifford_circuit(rng::AbstractRNG, arrange::NTuple{N,Int} where {N}, nlayers::Int)
circ = QuantumClifford.AbstractOperation[]
cartesian = CartesianIndices(arrange)
dim = length(arrange)
nqubits = prod(arrange)
for i in 1:nlayers
gate_direction = (i - 1) % dim + 1
l = arrange[gate_direction]
brickwise_parity = dim == 1 ? i % 2 : 1 - (i ÷ dim) % 2
for j in 1:nqubits
cardj = collect(cartesian[j].I)
if cardj[gate_direction] % 2 == brickwise_parity && cardj[gate_direction] != l # open boundary
cardk = cardj
cardk[gate_direction] = cardk[gate_direction] + 1
k = LinearIndices(cartesian)[cardk...]
push!(circ, SparseGate(random_clifford(rng, 2), [j, k]))
end
end
end
circ
end

random_brickwork_clifford_circuit(arrange::NTuple{N,Int} where {N}, nlayers::Int) = random_brickwork_clifford_circuit(GLOBAL_RNG, arrange, nlayers)

function random_all_to_all_clifford_circuit(rng::AbstractRNG, nqubits::Int, ngates::Int)
circ = QuantumClifford.AbstractOperation[]
for i in 1:ngates
j = rand(1:nqubits)
k = rand(1:nqubits-1)
push!(circ, SparseGate(random_clifford(rng, 2), [j, (j + k - 1) % nqubits + 1]))
end
circ
end

random_all_to_all_clifford_circuit(nqubits::Int, ngates::Int) = random_all_to_all_clifford_circuit(GLOBAL_RNG, nqubits, ngates)
19 changes: 15 additions & 4 deletions test/test_ecc_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ using InteractiveUtils

# generate instances of all implemented codes to make sure nothing skips being checked

# we does not include smaller random circuit code, because some of them has a bad distance and fails the TableDecoder test
const random_circuit_args = repeat([
(20, Val(:alltoall), 200, 1), (40, Val(:alltoall), 200, [1, 20]),
((20,), Val(:brickwork), 50, [1]), ((20,), Val(:brickwork), 50, 1:2:20),
((5, 5), Val(:brickwork), 50, [1]), ((3, 3, 3), Val(:brickwork), 50, [1])
], 10) # repeat for more randomness


random_circuit_code_args = [map(f -> getfield(random_circuit_code(c...), f), fieldnames(CircuitCode)) for c in random_circuit_args]

const code_instance_args = Dict(
Toric => [(3,3), (4,4), (3,6), (4,3), (5,5)],
Surface => [(3,3), (4,4), (3,6), (4,3), (5,5)],
Toric => [(3, 3), (4, 4), (3, 6), (4, 3), (5, 5)],
Surface => [(3, 3), (4, 4), (3, 6), (4, 3), (5, 5)],
Gottesman => [3, 4, 5],
CSS => (c -> (parity_checks_x(c), parity_checks_z(c))).([Shor9(), Steane7(), Toric(4,4)]),
Concat => [(Perfect5(), Perfect5()), (Perfect5(), Steane7()), (Steane7(), Cleve8()), (Toric(2,2), Shor9())],
CSS => (c -> (parity_checks_x(c), parity_checks_z(c))).([Shor9(), Steane7(), Toric(4, 4)]),
Concat => [(Perfect5(), Perfect5()), (Perfect5(), Steane7()), (Steane7(), Cleve8()), (Toric(2, 2), Shor9())],
CircuitCode => random_circuit_code_args
)

function all_testablable_code_instances(;maxn=nothing)
Expand Down
Loading