Take Deltakit’s RotatedPlanarCode(11, 11) and an 11-round -basis memory experiment built
by css_code_memory_circuit.
How many data qubits, ancilla qubits and qubits in all does it use?
How many checks have weight 4, and how many weight 2?
How many two-qubit gates does one round use? How many does the whole experiment use?
How many measurements does the experiment make, counting the final data readout?
How many detectors sit in the first round (), in each round of the bulk, and in the
last ()? What is the total?
Then confirm every answer with Deltakit.
Solution
There are data qubits and one ancilla per check, , so
qubits in all.
The interior of the grid has plaquettes, all of weight 4. Each
of the four sides carries weight-2 checks, in all. As a check,
.
A check needs one CX or CZ per data qubit: per round,
which is . Eleven rounds use .
Each round measures all 120 ancillas, and the end reads out the 121 data qubits:
.
In a -basis memory only the checks have a known value in the first round, because
the data start in : 60 detectors. Each later round compares every check with its
previous value: 120 detectors in each of rounds . The final readout gives
every check a value computed from the data, which is compared with its last ancilla
outcome: 60 more. The total is .
import numpy as npfrom deltakit.circuit.gates import PauliBasisfrom deltakit.explorer.codes import RotatedPlanarCode, css_code_memory_circuitcode = RotatedPlanarCode(11, 11)w = [len([p for p in s.paulis if p is not None]) for s in code.stabilisers[0]]print("weight-4 checks:", w.count(4), " weight-2 checks:", w.count(2))circ = css_code_memory_circuit( code, num_rounds=11, logical_basis=PauliBasis.Z).as_stim_circuit()ops = list(circ.flattened())n2q = sum(len(i.targets_copy()) // 2 for i in ops if i.name in ("CX", "CZ"))print("qubits", circ.num_qubits, " two-qubit gates", n2q, " measurements", circ.num_measurements)coords = circ.get_detector_coordinates()t = np.array([coords[i][2] for i in range(circ.num_detectors)])per_round = [int(np.sum(t == r)) for r in np.unique(t)]print("detectors", circ.num_detectors, " first round", per_round[0], " bulk rounds", sorted(set(per_round[1:-1])), " last", per_round[-1])
The toric code on an torus puts a qubit on each of the edges, an check
on each vertex (the four edges that meet there) and a check on each face (its four edges).
Show that the product of all checks is the identity, and that no other non-empty set
of checks multiplies to the identity. Conclude that . The same
argument gives .
Deduce . Why does it not depend on ?
The planar code of Lecture 3 cuts the torus open. It has data qubits and
checks of each type, all independent. Find .
Check both answers at with UnrotatedToricCode(6, 6) and
UnrotatedPlanarCode(6, 6), computing the ranks over .
Solution
Every edge has two endpoints, so every qubit appears in exactly two checks. In the
product of all of them each appears twice and cancels. Now take any non-empty set
of vertices whose checks multiply to the identity. Every edge must then have an even
number of endpoints in : both or none. If missed some vertex, then, because the
torus is connected, some edge would join a vertex in to one outside it. So is all
vertices, the rows of satisfy exactly one relation, and
. Faces that share edges give the same argument for .
. The two logical qubits belong to
the two independent loops around the torus, which exist at every size. The count is
topological; only the distance grows.
.
A short Gaussian elimination over gives the ranks:
from deltakit.explorer.codes import UnrotatedPlanarCode, UnrotatedToricCodedef gf2_rank(m): """Rank of a 0/1 matrix over GF(2), by Gaussian elimination.""" m = np.array(m, dtype=np.uint8) % 2 rank = 0 for col in range(m.shape[1]): rows = np.nonzero(m[rank:, col])[0] if len(rows) == 0: continue piv = rank + rows[0] m[[rank, piv]] = m[[piv, rank]] for r in np.nonzero(m[:, col])[0]: if r != rank: m[r] ^= m[rank] rank += 1 if rank == m.shape[0]: break return rankfor cls in (UnrotatedToricCode, UnrotatedPlanarCode): code = cls(6, 6) hx, hz = (np.asarray(m) for m in code.parity_check_matrices) n, rx, rz = len(code.data_qubits), gf2_rank(hx), gf2_rank(hz) print(f"{cls.__name__}: n={n} checks={hx.shape[0]}+{hz.shape[0]}" f" ranks={rx}+{rz} k={n - rx - rz}")
An check is measured with an ancilla prepared in , four CX gates from the
ancilla to its data qubits, and an -basis measurement of the ancilla. The gates follow the
order TL, TR, BL, BR (the “Z order”; points up).
An error hits the ancilla just after the first, the second or the third CX. Which
data qubits carry an error at the end of the round? Which of the three cases is
equivalent, up to the check itself, to an error on a single qubit?
In Deltakit’s layout is a column of operators, so an undetectable string that
flips it runs along a row. Which memory experiment does the Z order hurt, and what does its
circuit distance become for odd ? Why does the default N order (TL, BL, TR, BR) not have
this problem?
Predict the circuit distance of a 9-round, memory with checks in Z order, in
both bases. Check it with the reorder helper of Notebook 3 and Stim’s
shortest_graphlike_error under SD6 noise.
Solution
A CX copies an on its control onto its target. An on the ancilla after the first
gate reaches TR, BL and BR. After the second it reaches BL and BR, and after the third only
BR. The ancilla’s own does not change its -basis outcome. The first case,
, is times the check, so it acts
like one error. The third case is one error. The second case leaves the pair BL, BR: a
weight-2 error from a single fault, the hook.
The pair BL, BR lies along a row, the direction of an string that flips . Each
hook fault extends such a string by two qubits, so faults complete
one. The -basis memory, which protects , drops from distance to
. The -basis memory protects , which errors cannot flip, so
it keeps distance . In N order the last two qubits are TR and BR, a vertical pair. That
pair crosses each row only once, so a hook adds just one qubit to any row and the distance
stays .
The prediction is for the memory and 9 for the memory:
from deltakit.explorer.codes import CSSCodefrom deltakit.explorer.qpu import QPU, SD6NoiseTL, TR, BL, BR = (-1, 1), (1, 1), (-1, -1), (1, -1)N_ORDER, Z_ORDER = (TL, BL, TR, BR), (TL, TR, BL, BR)def offset(stab, pauli): a = stab.ancilla_qubit.unique_identifier q = pauli.qubit.unique_identifier return (int(q[0] - a[0]), int(q[1] - a[1]))def reorder(code, x_order, z_order): Stabiliser = type(code.stabilisers[0][0]) # not exported in 0.10.2 checks = [] for s in code.stabilisers[0]: terms = [p for p in s.paulis if p is not None] is_x = type(terms[0]).__name__.endswith("X") by_offset = {offset(s, p): p for p in terms} order = x_order if is_x else z_order checks.append(Stabiliser(paulis=[by_offset.get(o) for o in order], ancilla_qubit=s.ancilla_qubit)) return CSSCode(stabilisers=[checks], x_logical_operators=code.x_logical_operators, z_logical_operators=code.z_logical_operators)def circuit_distance(code, basis, rounds): circ = css_code_memory_circuit(code, num_rounds=rounds, logical_basis=basis) qpu = QPU(circ.qubits, noise_model=SD6Noise(p=1e-3)) noisy = qpu.compile_and_add_noise_to_circuit(circ) return len(noisy.as_stim_circuit().shortest_graphlike_error())for name, x_order in (("N (default)", N_ORDER), ("Z", Z_ORDER)): code = reorder(RotatedPlanarCode(9, 9), x_order, Z_ORDER) dz = circuit_distance(code, PauliBasis.Z, 9) dx = circuit_distance(code, PauliBasis.X, 9) print(f"X checks in {name} order: Z memory {dz}, X memory {dx}")
X checks in N (default) order: Z memory 9, X memory 9X checks in Z order: Z memory 5, X memory 9
Problem 4 (Merging error mechanisms).
Two independent mechanisms flip the same pair of detectors, with probabilities and
. Show that the pair is flipped with probability .
Show that for independent mechanisms the pair is flipped with probability
. (Hint: compute the mean of ,
where if mechanism fires.)
With SI1000 noise at , a -check ancilla’s measurement is flipped with
probability , and its reset with probability . Explain why both flip the same two
detectors. Merge them, find the edge weight , and find the relative
error you would make by simply adding the probabilities.
In the decoding graph of the , three-round SI1000 memory, detectors 0 and 5 belong
to the same check in rounds 0 and 1. Find their edge’s probability and weight with
Deltakit. Confirm that every edge’s probability is the merge of the decomposed DEM pieces
with the same endpoints. Why is the probability larger than your answer to part 3?
Solution
The pair flips when exactly one mechanism fires:
.
Let . Its mean is . The pair is flipped
exactly when , so . By
independence the left side is . Solving gives
. For this is part 1.
Both faults flip the ancilla’s recorded outcome in one round : the measurement flip
directly, the reset flip by starting the ancilla in the wrong state. The detector of round
compares rounds and , and the detector of round compares rounds
and . Both contain the flipped outcome, so both fire. The merged probability is
, with weight
. Adding gives , which is 0.29% too high. At such
small rates the correction hardly matters, but the merge rule never exceeds ,
while the sum can exceed 1.
The graph gives the edge, and the pieces of the decomposed DEM rebuild every edge:
from deltakit.core.decoding_graphs import dem_to_decoding_graph_and_logicalsfrom deltakit.explorer.qpu import SI1000Noisecirc3 = css_code_memory_circuit( RotatedPlanarCode(3, 3), num_rounds=3, logical_basis=PauliBasis.Z)qpu = QPU(circ3.qubits, noise_model=SI1000Noise(p=1e-3))sc3 = qpu.compile_and_add_noise_to_circuit(circ3).as_stim_circuit()dem = sc3.detector_error_model(decompose_errors=True)graph, _ = dem_to_decoding_graph_and_logicals(dem)print("detector 0:", graph.detector_records[0])print("detector 5:", graph.detector_records[5])edge = next(e for e in graph.edges if set(e) == {0, 5})rec = graph.edge_records[edge]print(f"edge (0, 5): p = {rec.p_err:.7f}, weight = {rec.weight:.4f}")boundary = next(iter(graph.boundaries))merged = {}for row in dem.flattened(): if row.type != "error": continue p = row.args_copy()[0] piece = [] for t in row.targets_copy() + [None]: if t is None or t.is_separator(): dets = [x.val for x in piece if x.is_relative_detector_id()] key = frozenset(dets if len(dets) == 2 else dets + [boundary]) q = merged.get(key, 0.0) merged[key] = q + p - 2 * q * p piece = [] else: piece.append(t)match = all(abs(merged[frozenset(e)] - graph.edge_records[e].p_err) < 1e-12 * graph.edge_records[e].p_err for e in graph.edges)print(len(graph.edges), "edges, all equal to the merged pieces:", match)
detector 0: {'spatial_coord': (4.0, 0.0), 'time': 0}detector 5: {'spatial_coord': (4.0, 0.0), 'time': 1}edge (0, 5): p = 0.0075058, weight = 4.884578 edges, all equal to the merged pieces: True
The edge has and weight . It is larger than because the
depolarizing noise after each of the ancilla’s two two-qubit gates can also flip only its
outcome: in the compiled circuit the ancilla is the CX target and is read with M, so an
or on it carries through to the measurement. Stim has already merged all such faults into
one DEM row before the graph is built.
Problem 5 (When a bigger code stops helping).
Lecture 4 and Notebook 4 ran -round SI1000 memories at with leakage
probability . Each point used 200,000 shots, decoded by PyMatching built from the DEM.
fails
fails
0
730
177
1008
411
3819
3910
At the decomposed DEM has 290 rows, the same rows whether is 0 or .
Why? What does that mean for the decoder?
Compute the ratio of failures, over , at each .
At , is significantly worse than ? Treat each count as
binomial, find the standard deviation of the difference of the two counts, and the
-score.
Name two ways to win back the benefit of a larger code.
Reproduce the last row of the table with Deltakit.
Solution
Stim builds the DEM by propagating Pauli faults through the circuit. LEAKAGE and
RELAX are not Pauli channels, so they contribute no rows, and the DEM text is identical
for both values of (the checker compares it). The decoder is therefore the same with
leakage on or off. It still treats every detection event as an independent Pauli fault
with the leakage-free weights, while a leaked qubit fires its detectors at random, round
after round.
, and . Leakage at already
cuts the gain from to from 4.1 to 2.5; at the gain is gone.
The two error rates are and
. A binomial count has variance :
3746 and 3834. The difference of two independent counts has standard deviation
, and the counts differ by 91, so . That is not
significant. The honest statement is “no better”, not “worse”.
Any two of: leakage-reduction units, operations that return a leaked qubit to the qubit
subspace every round (for example by swapping the roles of data and ancilla qubits, or by
a reset designed to remove ); readout that distinguishes and so
heralds leakage; and a decoder that uses those heralds to discount the detectors near a
leaked qubit, as Riverlane’s local clustering decoder does (Lecture 4).
Same seed, same code as the notebook:
from deltakit.decode import PyMatchingDecoderfrom deltakit.decode.analysis import StimDecoderManagerSEED = 2026for d in (3, 5): circ = css_code_memory_circuit( RotatedPlanarCode(d, d), num_rounds=d, logical_basis=PauliBasis.Z ) qpu = QPU(circ.qubits, noise_model=SI1000Noise(p=1e-3, pL=1e-3)) noisy = qpu.compile_and_add_noise_to_circuit(circ) dec, dcirc = PyMatchingDecoder.construct_decoder_and_stim_circuit(noisy) manager = StimDecoderManager(dcirc, dec, seed=SEED, batch_size=100_000) n, f = manager.run_batch_shots(200_000) print(f"d={d}, pL=1e-3: {int(f)} fails in {int(n)} shots")
d=3, pL=1e-3: 3819 fails in 200000 shotsd=5, pL=1e-3: 3910 fails in 200000 shots