Skip to content
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

add random Clifford circuit codes #298

Merged
merged 15 commits into from
Jul 4, 2024
Merged
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`.

- `n`: qubit number
- `circ`: the encoding circuit
- `encode_qubits`: the qubits to be encoded

See also: [`random_circuit_code`](@ref)
"""
struct CircuitCode <: AbstractECC
n::Int
circ::Vector{QuantumClifford.AbstractOperation}
encode_qubits::AbstractArray
end

iscss(::Type{CircuitCode}) = nothing

code_n(c::CircuitCode) = prod(c.n)
royess marked this conversation as resolved.
Show resolved Hide resolved

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 encodes 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.

For `brickwork` connectivity, the qubits are arranged as a lattice, and `lattice_size` contains side length in each dimension.
For example, a chain of length five will have `lattice_size = (5,)`, and a 5×5 lattice will have `lattice_size = (5, 5)`.

In multi-dimensional cases, gate layers act alternatively along each direction.
The nearest two layers along the same direction are offset by one qubit, forming a so-called brickwork.
The boundary condition is chosen as open.
"""
royess marked this conversation as resolved.
Show resolved Hide resolved
function random_circuit_code end

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

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/codes/random_circuit.jl#L50-L51

Added lines #L50 - L51 were not covered by tests
end

function random_circuit_code(n::Int, connect::Val{:alltoall}, ngates::Int, k::Int)
CircuitCode(n, 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, random_all_to_all_clifford_circuit(rng, n, ngates), encode_qubits)

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/codes/random_circuit.jl#L58-L59

Added lines #L58 - L59 were not covered by tests
end

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

# 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.
function random_circuit_code(rng::AbstractRNG, lattice_size::NTuple{N,Int} where {N}, connect::Val{:brickwork}, nlayers::Int, encode_qubits::AbstractArray)
CircuitCode(prod(lattice_size), random_brickwork_clifford_circuit(rng, lattice_size, 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(lattice_size::NTuple{N,Int} where {N}, connect::Val{:brickwork}, nlayers::Int, encode_qubits::AbstractArray)
CircuitCode(prod(lattice_size), random_brickwork_clifford_circuit(lattice_size, nlayers), encode_qubits)
end
royess marked this conversation as resolved.
Show resolved Hide resolved
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)
royess marked this conversation as resolved.
Show resolved Hide resolved
circ = QuantumClifford.SparseGate[]
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)
royess marked this conversation as resolved.
Show resolved Hide resolved
circ = QuantumClifford.SparseGate[]
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)
15 changes: 13 additions & 2 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)],
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