Implement logical hadamard transition for the fixed boundary convention
Logical Hadamard Transition
The logical Hadamard transition allows X(Z) type correlation surface to be changed to Z(X) type either in space or time. The necessary ingredients to implement the feature is ready in the codebase and it should be a good starting point for the new contributors to get themselves familiar with the project.
1. Temporal Hadamard Transition
1.1 Construction
The temporal Hadamard transition is simply a transversal layer of H gates applied to all data qubits. Note that the boundary conditions of the code patches before and after the transition are flipped, meaning the X(Z) boundary changes to Z(X), and the stabilizer types of the patch are also inverted.
1.2 Example
You can create a minimal example of a computation that includes the temporal Hadamard transition:
from tqec import BlockGraph, Cube, Position3D, ZXCube, SignedDirection3D, Direction3D
g = BlockGraph()
g.add_edge(
Cube(Position3D(0, 0, 0), ZXCube.from_str("ZXZ")),
Cube(Position3D(0, 0, 1), ZXCube.from_str("XZX")),
)
correlation_surfaces = g.to_zx_graph().find_correration_surfaces()
g.view_as_html(
pop_faces_at_direction=SignedDirection3D(Direction3D.Y, False),
show_correlation_surface=correlation_surfaces[0],
)
2. Spatial Hadamard Transition
2.1 Construction
The spatial Hadamard transition is more complex. It involves replacing plaquettes on the boundaries of connected cubes. Specifically, new plaquettes measuring ZXZX and XZXZ stabilizers must be introduced at the boundary.
2.2 Example
You can create a minimal example of a computation that includes the spatial Hadamard transition with the following code:
from tqec import BlockGraph, Cube, Position3D, ZXCube, SignedDirection3D, Direction3D
g = BlockGraph()
g.add_edge(
Cube(Position3D(0, 0, 0), ZXCube.from_str("ZXZ")),
Cube(Position3D(1, 0, 0), ZXCube.from_str("XZX")),
)
correlation_surfaces = g.to_zx_graph().find_correration_surfaces()
g.view_as_html(
pop_faces_at_direction=SignedDirection3D(Direction3D.Y, False),
show_correlation_surface=correlation_surfaces[0],
)
3. Implementation
To implement this feature, consider starting with the CSS-type surface code, which has a simpler circuit. The main changes will be in src/tqec/compile/specs/library/_utils particularly in the default_substitution_builder function. You will need to create new plaquettes that support the transition; existing plaquette builders can be found in src/tqec/plaquette/library, which you may modify as needed.
Regarding of temporal transition, there is an issue I'm aware of: if you implement a plaquette with a layer of H gates at the end of the circuit, i.e. after the measurements, then it will break the condition used by detector automation that there are no gates between measurements and resets. However, if you insert a layer of H gates before the measurements or after the resets, it will break the schedule of the circuits. @nelimee any idea on that? It seems reasonable to me that we should make some changes on the detector automation side to tolerate such cases.
For the boundary plaquette circuits that implement spatial transition, please refer to the figure above which includes both the stabilizer configuration and CNOTs order. If further guidance is needed, I can provide sample circuits in crumble.
Testing the implementation can be done using the example code above to generate a BlockGraph. Use the compilation pipeline from the README to create stim circuits, which you can then verify in Crumble.
These are just my initial thoughts on the issue; there may be some details I haven’t covered. If you run into any problems, please feel free to reach out here or via email :-)
This description is impressive, well done!
However, if you insert a layer of H gates before the measurements or after the resets, it will break the schedule of the circuits. @nelimee any idea on that? It seems reasonable to me that we should make some changes on the detector automation side to tolerate such cases.
There are two major issues here that I would like to discuss in the future (and probably not here):
- There are a few "things" in the code that are hard-coded and require to match across several places right now.
Plaquettesinstances needing to be hand-made for each template (because each template might have its own plaquette indexing), template instantiation indices on the spatial boundaries, plaquette scheduling, and I am pretty sure that there are a few more things. We should think about whether this is fine for us, or if we should make that less manual / error-prone. I will open an issue on that soon. - The detector computation part could very much be improved. It is lacking tests, it is not really performant, we might even benefit from more features (i.e., being able to only compute detectors involving at least one measurement from a given set of measurements instead of computing all the detectors and filtering them afterwards). #378 might be a good start. I will also open the issues (or discussions) I have in mind about that soon.
Please, add SignedDirection3D, Direction3D to «from tqec import BlockGraph, Cube, Position3D, ZXCube» to make it easier to run for beginners as me :)
Please, add SignedDirection3D, Direction3D to «from tqec import BlockGraph, Cube, Position3D, ZXCube» to make it easier to run for beginners as me :)
Thank you for the reminder! The code has been updated. Regarding the link mentioned in #436, I have removed the paragraph since the code snippets now work correctly with the latest branch.
@inmzhang do you know what's the actual link for https://qchackers.github.io/tqec/pull/322 ? It's mentioned in the intro videos, but it's also broken. Thanks :)
do you know what's the actual link for https://qchackers.github.io/tqec/pull/322 ?
This was the documentation preview page while the PR was still open, deployed via this method. Now please refer to the latest docs page at https://tqec.github.io/tqec/.
Will this issue be closed by #562?
Will this issue be closed by #562?
Yes, it should be. Not tested yet though.
@BSchelpe if I am right, that's the issue you are targeting. Could you comment here so that I can assign you to it?
Thanks! Yes when I'm done I think the last remaining piece of work on this will be finished. If you could assign me that would be great. I also think my PR (when I submit it :)) will close issue #631 .