Skip to content

Commit 6d0d0bc

Browse files
committed
partial cleanup of codebase
1 parent 9705a2b commit 6d0d0bc

7 files changed

Lines changed: 105 additions & 313 deletions

File tree

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,68 @@
1-
# CircuitCompilation2xn
1+
# CircuitCompilation2xn
2+
CircuitCompilation2xn offers some tools to manipulate syndrome extracting circuits for better use on 2xn quantum dot hardwares. For more information please refer to the [paper](https://arxiv.org/abs/2501.09061) , and if one would desire to cite this tool, please cite the paper.
3+
## How to use this?
4+
First, we state that this work is closely integrated with [QuantumClifford.jl](https://github.com/QuantumSavory/QuantumClifford.jl)
5+
6+
To begin, we will need either a parity check matrix (or stabilizer tableau), or a `Vector{QuantumClifford.AbstractOperation}` containing the syndrome extracting circuit. Currently, we enforce the constraint that syndrome extracting circuit will always be of a form where the two qubit gates act one one qubit in the data qubit region and one in the ancilla region (i.e. there are two qubit gates that go between data or ancilla qubits).
7+
8+
`QuantumClifford.jl` as of present (v0.10.0), contains two functions for generating syndrome extracting circuits for any provided stabilizer tableau, one for naive syndrome extraction (a single ancillary qubit is used per parity check), and one for Shor-style fault tolerant syndrome extraction (each parity check requires a w-body GHZ state, where w is weight of the parity check at hand). This is shown in Figure 3, of the [paper](https://arxiv.org/abs/2501.09061):
9+
10+
![Figure 3 from paper:](assets/images/syndrome_circuits.png)
11+
12+
### Naive syndrome circuits example
13+
First we will need a error correction code, and while any will do, let's use one that's already defined within `QuantumClifford.jl`, and is quite pedagogical. Furthermore, one might want to consider the X and Z checks seperately to guarantee commutativity, however for this first example and for simplicity, we will consider them together. (This is addressed later in this README)
14+
15+
```
16+
using QuantumClifford
17+
using QuantumClifford.ECC
18+
19+
code = Steane7()
20+
scirc, _ = QuantumClifford.ECC.naive_syndrome_circuit(code)
21+
```
22+
23+
`scirc` will now be in the style of the required input to the functions of `CircuitCompilation2xn`:
24+
```
25+
julia> scirc
26+
30-element Vector{QuantumClifford.AbstractOperation}:
27+
sXCX(4,8)
28+
sXCX(5,8)
29+
sXCX(6,8)
30+
sXCX(7,8)
31+
sMRZ(8, 1)
32+
sXCX(2,9)
33+
sXCX(3,9)
34+
sXCX(6,9)
35+
sXCX(7,9)
36+
sMRZ(9, 2)
37+
sXCX(1,10)
38+
sXCX(3,10)
39+
sXCX(5,10)
40+
sXCX(7,10)
41+
sMRZ(10, 3)
42+
sCNOT(4,11)
43+
sCNOT(5,11)
44+
sCNOT(6,11)
45+
sCNOT(7,11)
46+
sMRZ(11, 4)
47+
sCNOT(2,12)
48+
sCNOT(3,12)
49+
sCNOT(6,12)
50+
sCNOT(7,12)
51+
sMRZ(12, 5)
52+
sCNOT(1,13)
53+
sCNOT(3,13)
54+
sCNOT(5,13)
55+
sCNOT(7,13)
56+
sMRZ(13, 6)
57+
```
58+
59+
Visualizing this with [Quantikz.jl](https://github.com/QuantumSavory/Quantikz.jl):
60+
![Uncompiled naive Steane7 circuit](assets/images/naive_steane_uncompiled.png)
61+
62+
Now we can use CircuitCompilation2xn to compile this circuit in different ways, as well as to calculate the number of shifts it would take to run in its current form.
63+
64+
```
65+
using CircuitCompilation2xn
66+
```
67+
68+
README under construction....

src/CircuitCompilation2xn.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ end
273273

274274
"""Splits the provided circuit into two pieces. The first piece is the one on which we reindex. The second piece contains operations that would
275275
cause an error in the reordering."""
276-
function clifford_grouper(circuit)
276+
function two_qubit_sieve(circuit)
277277
non_mz = Vector{QuantumClifford.AbstractOperation}()
278278
mz = Vector{QuantumClifford.AbstractOperation}()
279279
for gate in circuit
@@ -322,7 +322,7 @@ end
322322

323323
"""Runs pipline on a circuit. If using a code, ECC.naive_syndrome_circuit should be run first. Returns new circuit and ordering"""
324324
function ancil_reindex_pipeline(circuit, inverted=false)
325-
circuit, measurement_circuit = clifford_grouper(circuit)
325+
circuit, measurement_circuit = two_qubit_sieve(circuit)
326326
blocks = create_blocks(circuit)
327327

328328
h1_order = ancil_sort_h1(blocks)
@@ -380,7 +380,7 @@ end
380380

381381
"""Special case of the reindexing pipeline that exploits the structure of Shor syndrome circuits"""
382382
function ancil_reindex_pipeline_shor_syndrome(scirc, extra_info=false)
383-
scirc, measurement_circuit = clifford_grouper(scirc)
383+
scirc, measurement_circuit = two_qubit_sieve(scirc)
384384
blocks = create_blocks(scirc)
385385

386386
if extra_info
@@ -428,15 +428,15 @@ end
428428

429429
"""Sorts by [`get_delta`](@ref) and then returns list of parallel batches via [`calculate_shifts`](@ref)"""
430430
function gate_Shuffle(circuit)
431-
non_mz, mz = clifford_grouper(circuit)
431+
non_mz, mz = two_qubit_sieve(circuit)
432432
circuit = sort(non_mz, by = x -> get_delta(x))
433433
calculate_shifts(circuit)
434434
end
435435

436436
# TODO Absolutely horrible name
437437
"""Sorts by [`get_delta`](@ref) and then returns the circuirt. One needs to do circ = gate_Shuffle!(circ)"""
438438
function gate_Shuffle!(circuit) # TODO
439-
non_mz, mz = clifford_grouper(circuit)
439+
non_mz, mz = two_qubit_sieve(circuit)
440440
new_circ = sort!(non_mz, by = x -> get_delta(x))
441441
return vcat(new_circ, mz)
442442
end
@@ -558,7 +558,7 @@ end
558558
"""
559559
function comp_numbers(circuit, total_qubits)
560560
shifts = []
561-
a, _ = clifford_grouper(circuit) # only need the two qubit gates
561+
a, _ = two_qubit_sieve(circuit) # only need the two qubit gates
562562
push!(shifts, length(calculate_shifts(a)))
563563
push!(shifts, length(gate_Shuffle(a)))
564564

@@ -701,7 +701,7 @@ end
701701

702702
function shorNumbers(circuit)
703703
shifts = []
704-
a, _ = clifford_grouper(circuit) # only need the two qubit gates
704+
a, _ = two_qubit_sieve(circuit) # only need the two qubit gates
705705
push!(shifts, length(calculate_shifts(a)))
706706
push!(shifts, length(gate_Shuffle(a)))
707707

src/LDPC_functions.jl

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ function stab_from_cxcz(Cx, Cz)
66
return stab
77
end
88

9-
function getGoodLDPC(n=1)
10-
# Absolute paths to Cx and Cz npz files:
11-
if n==1
12-
Cx = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/1_ra1_rb2_X_rankX120_rankZ179_minWtX2_minWtZ2.npz");
13-
Cz = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/1_ra1_rb2_Z_rankX120_rankZ179_minWtX2_minWtZ2.npz");
14-
stab = stab_from_cxcz(Cx,Cz);
15-
elseif n==2
16-
Cx = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/1_ra2_rb2_X_rankX226_rankZ120_minWtX2_minWtZ2.npz");
17-
Cz = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/1_ra2_rb2_Z_rankX226_rankZ120_minWtX2_minWtZ2.npz");
18-
stab = stab_from_cxcz(Cx,Cz);
19-
elseif n==3
20-
Cx = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/3_ra1_rb2_X_rankX120_rankZ179_minWtX2_minWtZ2.npz");
21-
Cz = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/3_ra1_rb2_Z_rankX120_rankZ179_minWtX2_minWtZ2.npz");
22-
stab = stab_from_cxcz(Cx,Cz);
23-
end
24-
return stab, Cx, Cz
25-
end
9+
# TODO delte this - these codes are not good at all
10+
# function getGoodLDPC(n=1)
11+
# # Absolute paths to Cx and Cz npz files:
12+
# if n==1
13+
# Cx = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/1_ra1_rb2_X_rankX120_rankZ179_minWtX2_minWtZ2.npz");
14+
# Cz = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/1_ra1_rb2_Z_rankX120_rankZ179_minWtX2_minWtZ2.npz");
15+
# stab = stab_from_cxcz(Cx,Cz);
16+
# elseif n==2
17+
# Cx = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/1_ra2_rb2_X_rankX226_rankZ120_minWtX2_minWtZ2.npz");
18+
# Cz = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/1_ra2_rb2_Z_rankX226_rankZ120_minWtX2_minWtZ2.npz");
19+
# stab = stab_from_cxcz(Cx,Cz);
20+
# elseif n==3
21+
# Cx = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/3_ra1_rb2_X_rankX120_rankZ179_minWtX2_minWtZ2.npz");
22+
# Cz = npzread("/Users/micciche/Research/QuantumInfo23/JuliaProjects/codes_for_hardware_test/3_ra1_rb2_Z_rankX120_rankZ179_minWtX2_minWtZ2.npz");
23+
# stab = stab_from_cxcz(Cx,Cz);
24+
# end
25+
# return stab, Cx, Cz
26+
# end
2627

2728
function real_LDPC_numbers()
2829
println("First one")
@@ -106,7 +107,7 @@ function test_LDPC_shift_reduction(n,k,w_r, samples=5)
106107
stab = Stabilizer(zeros(Bool,n-k, n), matrix)
107108
scirc, _ = naive_syndrome_circuit(stab)
108109

109-
circuit_wo_mz, measurement_circuit = CircuitCompilation2xn.clifford_grouper(scirc)
110+
circuit_wo_mz, measurement_circuit = CircuitCompilation2xn.two_qubit_sieve(scirc)
110111
push!(raw_shifts, length(CircuitCompilation2xn.calculate_shifts(circuit_wo_mz)))
111112

112113
push!(gate_shuffling_shifts, length((CircuitCompilation2xn.gate_Shuffle(circuit_wo_mz))))
@@ -134,7 +135,7 @@ function test_LDPC_shift_reduction_shor_syndrome(n,k,w_r, samples=5)
134135
stab = Stabilizer(zeros(Bool,n-k, n), matrix)
135136
cat, scirc, anc_qubits, bit_indices = shor_syndrome_circuit(stab)
136137

137-
circuit_wo_mz, measurement_circuit = CircuitCompilation2xn.clifford_grouper(scirc)
138+
circuit_wo_mz, measurement_circuit = CircuitCompilation2xn.two_qubit_sieve(scirc)
138139
push!(raw_shifts, length(CircuitCompilation2xn.calculate_shifts(circuit_wo_mz)))
139140

140141
push!(gate_shuffling_shifts, length((CircuitCompilation2xn.gate_Shuffle(circuit_wo_mz))))
@@ -165,7 +166,7 @@ function average_cooc(n,k,w_r, samples=5)
165166
stab = Stabilizer(zeros(Bool,n-k, n), matrix)
166167
scirc, _ = naive_syndrome_circuit(stab)
167168

168-
circuit_wo_mz, measurement_circuit = CircuitCompilation2xn.clifford_grouper(scirc)
169+
circuit_wo_mz, measurement_circuit = CircuitCompilation2xn.two_qubit_sieve(scirc)
169170
numGates = length(circuit_wo_mz)
170171
push!(raw_shifts, numGates/length(CircuitCompilation2xn.calculate_shifts(circuit_wo_mz)))
171172

src/nonpf_evalutation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function evaluate_code_decoder_w_ecirc_shifts(code::Stabilizer, ecirc, circuit,
9999
apply!(state, error)
100100
end
101101

102-
non_mz, mz = clifford_grouper(circuit)
102+
non_mz, mz = two_qubit_sieve(circuit)
103103
non_mz = calculate_shifts(non_mz)
104104

105105
decoded = 0 # Counts correct decodings

0 commit comments

Comments
 (0)