Implement Y basis initialization/measurement block#719
Conversation
…ation to the layer tree with metadata stored in `SequencedLayer`
…ts localized to single cycle
|
@KabirDubey When checking the test coverage for |
Yes! Sorry, I tried to come up with something that can systematically generate layers but I couldn't figure out how to specify the geometric constraints. What remained was a lot of dead code. You might be able to replace with simple helper functions taking |
|
The last layers of the Crumble example distance 5 Y basis initialization circuit are a particular pattern of MPPs. Gidney says "the measurement process is finished by destroying the patch by measuring all of its data qubits. To maximize code distance, each data qubit is measured in the basis of its closest boundary." I haven't figured out how that implies the exact pattern we see in the circuit but I see that your Crumble circuit does not do the same, right? Do we pay the price in code distance? |
No, it’s not that issue. The data qubit measurements you mentioned correspond to the final twist line, which is orthogonal to the one constructed by the stabilizer walking operation. My circuit already accounts for that by design. I haven’t started investigating the problem yet, but I’ll update once I have a more precise idea of its root cause. |
I'm asking generally, not as an explanation for the bug (I haven't looked into that yet either). Are you saying that your circuit implements an equivalent data qubit measurement? |
This is under the context of Y-basis measurement (the reverse of initialization). At the final layer of Y-basis measurement, we measure (near) half of data qubits in X basis and others in Z basis to form a twist line and preserve distance as well. You can see from the Crumble links in this PR that all the circuits have implemented the data qubit reset/measurements in a similar pattern at the first/last layer. |
|
|
A preview of bcad2d8 is uploaded and can be seen here: ✨ https://tqec.github.io/tqec/pull/719/ ✨ Changes may take a few minutes to propagate. |
|
Thanks Yiming, I will look into this tomorrow and this week.
where can I find your implementation of the "one-to-one match to the expected end stabilizers"? Is it here? It's not clear to me that this is fragile. The function
Wouldn't this call |
|
Looks like even the hybrid annotator is not working perfectly. Here's the LER for the "claw" plot from here.
Still better than pure
But not as good as the pure
I will next debug by modifying tqecd (starting with Tianyi's tqecd PR 45) and verifying if buggy circuit distances are preserved. |
Note this depicts |
Still not working. Will update tqecd issue 48, we can work on buffing tqecd up directly to get these circuits working there. |
|
@KabirDubey @inmzhang Do you still plan on finishing this? |
Hi Sam, I don’t have time to finish this PR at the moment. I’ve provided the necessary circuit here and hope someone can pick it up and explore a better way to integrate it into the TQEC framework. That said, I’ll try to catch up on the changes in the TQEC repo and get back to reviewing PRs later this week. |
Yes, but I'm too busy at the moment. The starting point is in the |















This PR implements the inplace Y-basis initialization and measurement block. Closes #548.
Circuit Construction
Craig’s original circuit is designed under the fixed-bulk convention with an X-top boundary. The memory round uses S-shaped CX ordering for X stabilizers and N-shaped ordering for Z stabilizers. At first, I thought we could simply rotate and reflect the circuit to obtain versions for all conventions and boundary orientations. However, it turns out that the CX ordering in the memory round before/after the Y-basis block matters: the interaction ordering within the Y-basis block must be adjusted accordingly to avoid tricky space/time/spacetime-like errors that would reduce the circuit distance.
The challenging part of the circuit is the transition round, which transforms the code patch between a normal surface code patch and a degenerate patch with no encoded qubit. Careful design of the diagonal twist line, the domain wall orientation, and the interaction ordering is needed to achieve good logical performance. I do not yet have a systematic method for designing such circuits, but by following the pattern of the original circuit, I have worked out correct versions for all conventions and boundary orientations (three variants in total, since two conventions share the same circuit with a Z-top boundary). Key points include:
MYoperation to avoid near-twist spacetime-like errors.Here are the final Crumble circuits for a Y-basis initialize-then-measure experiment:
Fixed-bulk X-top
Fixed-boundary X-top
Z-top
Implementation
Initially, I tried to use the existing
RawCircuitLayerto implement the Y-basis block within the current architecture. However, I found it difficult to align and merge layers with symbolic linear expressions ofk. For example, the Y-basis block has1 + k + 1layers, while regular cubes have1 + (2k - 1) + 1layers. To handle this, we would need to unroll the repetition layers depending on the value ofk, then align the layers at either the head or the tail for merging. On top of that, significant changes would be required to support detector annotations inRawCircuitLayer, since the current approach is based on template and plaquette concepts. While it still seems possible to implement the Y-basis block with this layered approach, it would require too much work.The current implementation of Y-basis blocks is spacetime-oriented. In this design, a
YHalfCubecan only connect temporally to other cubes and is spatially distinct from surrounding cubes. This makes it natural to construct the circuits for the main computation and the “temporally injected” Y-basis blocks separately, then align and merge them at the circuit level. The bulk of detectors is built independently for each circuit; we only need to add the missing detectors at the injection interface during merging. With this in mind, I introduced a new block type calledInjectedBlock, which includes a factory callable that generates both the Y-basis block circuit and its detector-flow interface. The injected blocks are attached to theLayerTree. After building the main circuit from theLayerTree, I iterate through the injected blocks, aligning and merging their circuits layer by layer. The missing detectors are then computed from the flow interface and added.Circuit alignment and merging is the most challenging part. We need to carefully track flows and measurement records to correctly update existing detector and observable definitions. I relied heavily on the
genpackage, which I used to convert stim circuits intogen.Layers (with layer type information) and to merge twogen.LayerCircuits using a simple merging strategy. The current implementation has only minimal checks on circuit structure and may not work reliably for more generic injected circuits. However, it works for the specific Y-basis block circuits tested so far.Since I used
genextensively during both construction and merging, I also ran into a few small issues with the package that required modifying its source code. For this reason, I created a local copy of the repository, clarifying the license and documenting my modifications in the README. In the long run, it would be preferable to re-implement the most useful functionality fromgendirectly in TQEC, but this was the fastest way to get things working.So far, I have only tested compilation with Y-basis blocks in a simple Y-memory experiment and in an S-gate teleportation experiment. A working example of the S-gate has been added to the gallery in the docs. There may still be bugs for more complex computational structures that I haven’t tested yet. We will also need more meaningful test cases involving Y-basis blocks. Additionally, the implementation is not optimized for performance, and there is plenty of room for speed improvements. For example, all the circuits are flattened (unloop) during circuit merging for simplicity while for a larger computation most layers require no flatten operation at all. That said, the feature is already usable under this feature branch.
References