Extract Pauli flow from XZ-corrections (closes #432)#526
Open
Vinny010 wants to merge 2 commits into
Open
Conversation
Implement `XZCorrections.to_pauli_flow` and the convenience method `Pattern.extract_pauli_flow`, reconstructing a Pauli flow directly from a pattern's XZ-corrections (Theorem 4 of Browne et al. 2007) rather than from the underlying open graph (whose Pauli flow is not unique and need not generate the pattern). The difficulty is the anachronical corrections: corrections targeting X/Y Pauli-measured nodes in the present or past of the corrected node. These are dropped by `PauliFlow.to_corrections` (the `& future` filter) and so never appear in the pattern, so they must be reconstructed. For each measured node this is cast as a GF(2) linear system: the future membership of the correction set is pinned by the observed X-corrections; the free variables are the anachronical (non-future, X/Y-measured) candidates and, where allowed, the node itself; and the equations encode the odd-neighbourhood constraints (Z-corrections on future nodes, P2 on past non-(Y/Z) nodes, the P3 coupling on past Y nodes, and the local proposition P4-P9 on the node). The system is solved over GF(2) with `_solve_gf2`. Tests verify, on the three worked examples of the issue, on a Pauli-measured open graph, and on a randomized family of open graphs that admit a Pauli flow, that the reconstructed flow is well formed and that `to_corrections()` reproduces the pattern's corrections exactly (the decisive round-trip criterion). Passes ruff, mypy --strict, pyright, and pytest locally. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #526 +/- ##
==========================================
+ Coverage 88.85% 89.08% +0.23%
==========================================
Files 49 49
Lines 7135 7240 +105
==========================================
+ Hits 6340 6450 +110
+ Misses 795 790 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Cover the branches where no Pauli flow is compatible with the XZ-corrections: a measured input node that must correct itself, and an isolated XY-measured node whose proposition P4 cannot be satisfied (unsolvable GF(2) system). Addresses the patch-coverage gap reported on the PR. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #432.
Implements
XZCorrections.to_pauli_flowand the convenience methodPattern.extract_pauli_flow(analogous toextract_causal_flow/extract_gflow), reconstructing a Pauli flow directly from the pattern's XZ-corrections (Theorem 4 of Browne et al. 2007) rather than from the underlying open graph — whose Pauli flow is not unique and is not guaranteed to generate the pattern.How the anachronical corrections were tackled (the crux of the issue)
The hard part, as the issue notes, is that a Pauli flow's correction sets may contain anachronical corrections: corrections targeting X/Y Pauli-measured nodes that lie in the present or past of the corrected node.
PauliFlow.to_correctionsdiscards these (thecorrecting_set & futurefilter), so they never appear in the pattern and cannot be read off the corrections — they must be reconstructed.For each measured node
i, reconstruction is cast as a linear system over GF(2):i, membership in the correction setp(i)is fixed by the observed X-corrections ofi(and must reproduce the Z-corrections via the odd neighbourhood). These become constants of the system.p(i)by P1) — and, where the local proposition allows it,iitself.i(P4–P9, handling the XY/XZ/YZ planes and the X/Y/Z axes).The system is solved with a small GF(2) Gaussian-elimination helper (
_solve_gf2); failure to solve at any node means no Pauli flow is compatible with the corrections. The resulting flow is then validated byPauliFlow.check_well_formed.Correctness
The decisive check is the round trip: for the reconstructed
pf,pf.to_corrections()must reproduce the pattern's X- and Z-corrections exactly (this is what guarantees it generates this pattern). Tests verify well-formedness and the round trip on:p(0) = {1, 3}, p(1) = {2}, p(2) = {3}etc., including the anachronical node1),There are also unit tests for the GF(2) solver. Passes
ruff,mypy --strict,pyright, andpytestlocally (new tests plus the existing flow / open-graph / pattern suites).Developed with LLM assistance, reviewed and tested by me.