TQEC: ZX Graphs and Lattice Surgery
Adrien Suau, Yiming Zhang, Purva Thakre, Sam Burdick, Yilun Zhao, Ricky Young, Arabella Schelpe, Ángela Elisa Álvarez, Victory Omole, Gian Giacomo Guerreschi, Kabir Dubey, Jose A Bolanos, Tianyi Hao, Reinhard Stahn, Jerome Lenssen, Moritz Schmidt, Mohammed Imaduddin, Brendan Reid, Milo Moses, Sean Collins, Mark Agib, Kwok Ho Wan, Austin Fowler
https://groups.google.com/g/tqec-design-automation
Program flow*
Qrisp/Jasp
Qiskit
Cirq
ProjectQ
Pytket
Qmod
Qualtran
Pandora
OpenQASM 2.0
PyZX
Topologiq
tqec
stim
* non-exhaustive examples
Central message: compiling an algorithm to lattice surgery should go via a ZX graph.
Where kind of hardware are we talking about?
Where kind of hardware are we talking about?
Performance data
arXiv:2408.13687, Nature 638 (2025) 920-926
Mean errors:
Bigger is better
Bigger arrays show exponentially slower growth of logical error.
Precisely describing the surface code: stabilizers
The simplest stabilizers are just operators that leave some useful state unchanged, eg:
Pauli matrices:
Since the eigenstates are uniquely specified by the stabilizers, we can write them instead of the states.
Simple example:
Consider
This state is stabilized by 3 independent stabilizers
For complex states, the list of independent stabilizers can be far more compact than the state itself. We’ll need stabilizers to talk about the surface code.
+XXX
+ZZI
+IZZ
What about errors?
Consider the effect of errors:
What does this do to our stabilizers?
To say the same thing another way: or:
Errors flip the sign of stabilizers they anticommute with (XZ = -ZX). If we can work out how to measure the sign of a stabilizer, we can detect errors.
+XXX
-ZZI
+IZZ
A zero measurement means the output is the +1 eigenstate of A, one means -1 eigenstate
H
controlled-A
H
Let’s specialize to the surface code
Measure X stabilizer
Measure Z stabilizer
And now let’s put it all together
This is the surface code memory circuit in full detail
Let’s go 3D
d rounds
d rounds
0 rounds
0 rounds
Logical operators stick to walls of the same color.
This is 2d rounds of memory.
Moving things around
RGB = XYZ mnemonic
This is also just memory
Slices of the structure tell you what the computer should be doing at every instant of time
Logical operators stick to walls of the same color.
What about junctions?
blue node
red node
Logical operators with opposite color to the node must propagate to all edges, same color logical operators must touch an even number of edges.
Let’s formalize these rules
Prep |0> or Z basis measurement
Logical operators with opposite color to the node must propagate to all edges, same color logical operators must touch an even number of edges.
CNOT gates copy X on control, and Z on target to both outputs.
Hadamard converts X into Z and vice versa.
Reminder: gates as maps of matrices
Any process that maps logical operators as shown also implements that gate.
Let’s use these rules
A lattice surgery CNOT is a blue node (control) connected to a red node (target)
These paths are called correlation surfaces, basically a set of measurements that gives you sign information.
Example CNOTs
Control = blue node
Target = red node
This is CNOT
This is also CNOT
Provided you get the nodes right, the rest is arbitrary noodles
One more logical gate
Logical operators that pass through a layer of Hadamard gates are interchanged X⟷Z.
Let’s convert this…
This circuit prepares a 7 qubit Steane code, but all that really matters is that it’s made of gates that we can realize in tqec.
…into this in PyZX
This is the canonical ZX graph version of the quantum circuit that prepares a 7 qubit Steane code.
Fun with structures
Nodes of the same color connected by an edge can be merged/unmerged.
This is the “spider rule”.
Follows from lattice surgery.
Summary of ZX graphs from lattice surgery
Spider rule: merge and split same color nodes
Hadamard rule: can change color of node with only H edges
Two edge spider rule gives the identity rule.
PyZX can use these rules to simplify the ZX graph to just
Which is equivalent* to this…
Q: How can we turn this into lattice surgery?
* Used the above, which is true because both structures support one red left + two reds right, and two blues left + one blue right. This is the “bialgebra-rule”.
Node by node…
1
1
Volume = 1
Node by node…
1
1
2
3
4
2
3
4
Volume = 4
Node by node…
1
2
3
4
2
3
4
1
5
6
7
5
6
7
8
8
Volume = 12, best so far
Or automatically using topologiq (Jose A Bolanos)…
Volume = 18, best so far
Topologiq step by step
Topologiq uses an edge by edge algorithm with a randomly determined starting point.
Vast scope for further research.
Now what?
We have a structure…
But just as with CNOT we also need correlation surfaces…
Revisiting PyZX
Back when our computation was in PyZX we actually had correlation surfaces, future work to use them.
These give us the time ordering of our non-Clifford nodes, more about this later…
Algorithm: Tianyi Hao
CS dept University of Wisconsin-Madison
Issue: currently slow to find correlation surfaces…
Algorithm: Tianyi Hao
Currently ~O(n4)
Have ideas to reduce this to O(n)
Graphs for universal quantum computation
A Z node is by default green in PyZX, but blue using our RGB convention
Let’s focus on one node
Graphs for universal quantum computation
Can always express a ZX graph using only non-overlapping horizontal and vertical edges with only single-edge nodes having non-zero angles
Graphs for universal quantum computation
Let’s dive into the details, circuits and lattice surgery
Magic state cultivation: growing T states as cheap as CNOT gates
Craig Gidney, Cody Jones, Noah Shutty
Can get O(p5) suppression.
Likely good enough for practical purposes at Lambda ~10.
How does a T state give us a T gate?
time
Achieving universal quantum computation
Data
T state
|0> |1>
Consume T states to implement T gates
Output
Why does this work?
Data
T state
|0> |1>
Output
This is teleportation.
T is a Z rotation and commutes through the Z control node
Why does this work?
Data
T state
|0> |1>
Output
This is teleportation.
T becomes T dagger if commuted through X, and this must be corrected with S.
Next missing piece: the S gate
The T gate requires an S gate 50% of the time.
|0> |1>
Data
Ancilla
Output
Next missing piece: Y-basis measurement
Data
Ancilla
Y-basis measurement
|0> |1>
time
Output
Don't want the S-gate? X-basis measurement
Data
Ancilla
X-basis measurement
|0> |1>
Top surface blue = transversal data qubit MX, red = MZ, this is logical measurement.
time
Let's put the full T-gate together
Data
Ancilla
Data
Data
Let’s focus up to here
Let's put the full T-gate together
Data
Ancilla
Data
Data
Parity of the blue correlation surface gives the measurement result
Both red and blue correlation surfaces can terminate on a T node
classical
Now the S-gate bit
Data
Ancilla
X- or Y-basis measurement
Data
Data
Ancilla
Want to be able to omit this
X- or Z-basis measurement
Now the S-gate bit
Data
Ancilla
X- or Y-basis measurement
Data
Data
Ancilla
Want to be able to omit this
X- or Z-basis measurement
Setting the indicated node to blue (X measurement) makes the structure a fancy identity gate. Z -> Z, X -> X
Now the S-gate bit
Data
Ancilla
X- or Y-basis measurement
Data
Data
Ancilla
Want to be able to omit this
X- or Z-basis measurement
Setting the indicated node to red (Z measurement) makes the structure an S gate. Z -> Z, Y -> X
Let's put the full T-gate together
Need enough time to process the results of the logical measurement and determine whether we apply a layer of data qubit Hadamard gates before measurement.
Let's put the full T-gate together
Need enough time to process the results of the logical measurement and determine whether we apply a layer of data qubit Hadamard gates before measurement.
Deform and simplify
Let's put the full T-gate together
Need enough time to process the results of the logical measurement and determine whether we apply a layer of data qubit Hadamard gates before measurement.
Deform and simplify
Let's put the full T-gate together
Need enough time to process the results of the logical measurement and determine whether we apply a layer of data qubit Hadamard gates before measurement.
Deform and simplify
Let's put the full T-gate together
Need enough time to process the results of the logical measurement and determine whether we apply a layer of data qubit Hadamard gates before measurement.
Deform and simplify
Let's put the full T-gate together
Need enough time to process the results of the logical measurement and determine whether we apply a layer of data qubit Hadamard gates before measurement.
Deform and simplify
Let's put the full T-gate together
Need enough time to process the results of the logical measurement and determine whether we apply a layer of data qubit Hadamard gates before measurement.
Deform and simplify
Let's put the full T-gate together
ZX graph version! Let’s study this!
Let's put the full T-gate together
This correlation surface controls the color of the white node. There will be a classical processing delay.
Let's put the full T-gate together
T gates are diagonal, so Z -> Z (TZ = ZT), an eigenstate of Z (|0> or |1>) stays an eigenstate of Z.
Let's put the full T-gate together
Suppose that the T gate succeeds and no S gate correction is required. The white node will be set to be an X basis measurement, meaning a blue node.
Let's put the full T-gate together
The X correlation surface now only interacts with the T state, no S gate is applied.
Let's put the full T-gate together
But wait! Haven’t I made an arbitrary choice? Couldn’t I have made the correlation surface go this way?
Let's put the full T-gate together
A blue correlation surface cannot terminate on a blue node, so this is not valid and is not supported.
Only Y correlation surfaces can terminate on Y (green) nodes.
Let's put the full T-gate together
Suppose that the T gate “fails” and an S gate correction is required. The white node will be set to be a Z basis measurement, meaning a red node.
Let's put the full T-gate together
Now the S gate (green node) is included.
Let's put the full T-gate together
Note that the exact measurements included in the continuing correlation surface depend on whether or not the S-gate is included, hence a time ordering.
Let's put a small algorithm together
Start with just the first T gate.
Need enough time to process the results of the logical measurement and determine whether we apply a layer of data qubit Hadamard gates before measurement.
At 1 µs per round, distance 30, and classical processing latency of 10 µs, could "complete" a T-gate in 10 µs given sufficient space-time volume.
What do you mean 10 µs?
At first glance this may seem like a more reasonable amount of time.
1) Execute most of the structure
2) After classical processing determine basis and measure
3) After classical processing determine basis and measure
1
1
2
3
Can’t do universal computations yet…
We have a structure…
Get a set of correlation surfaces (observables in stim)
Use stim to simulate or drive quantum computer
Summary
tqec is a group of enthusiasts working towards building an open source full stack fault-tolerant quantum compiler
There is much work to be done! Please join the community, all are welcome :-)
https://groups.google.com/g/tqec-design-automation