feat(afana/zx-ir): single-qubit parity validation via fusible-pair detection (closes #858)#1070
Open
hiq-lab wants to merge 1 commit into
Open
feat(afana/zx-ir): single-qubit parity validation via fusible-pair detection (closes #858)#1070hiq-lab wants to merge 1 commit into
hiq-lab wants to merge 1 commit into
Conversation
…tection (closes #858) Adds `ZxGraph::find_fusible_pairs()` and `ZxGraph::validate_fully_fused()` to detect un-fused single-qubit gate sequences in ZX-IR. New error variant `ZxValidationError::UnfusedAdjacentSpiders { a, b, qubit }`. Why this interpretation of "parity": the issue talks about validating parity of single-qubit gate sequences in Ehrenfest examples but doesn't nail down what parity means in ZX terms. The most precise, useful reading: two edge-connected spiders sharing both color and qubit-wire should have fused via the ZX spider-fusion rule. Phase-2 X-spiders chain to identity (X² = I), Z-spiders likewise fuse to a single Z-spider with summed phase. A residual unfused pair is a "parity 2" single-qubit sequence the optimiser missed. `find_fusible_pairs()` returns each candidate exactly once. The strict validator `validate_fully_fused()` composes structural + normalized phase + fusion checks — used as the final gate immediately before QASM emission, after spider fusion has run. Tests: - afana/tests/zx_single_qubit_parity.rs (integration, per AC): - X-X chain on one qubit → flagged - Z-Z chain on one qubit → flagged - canonical H lowering (Z-X-Z) → passes - CZ entangler (same color, cross-qubit) → not flagged - 3-spider Z chain → 2 parity errors reported - afana/src/zx_ir.rs (inline): 6 new unit tests for the helper + validator across edge cases (boundary spiders untagged, cross-qubit same-color, single-color self-loop)
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.
Summary
Stacked on top of #1069 (phase normalization). Adds two new methods to
ZxGraphplus a new error variant:What "parity" means in this codebase
The issue talks about "single-qubit gate sequence parity" but doesn't pin down what parity means in ZX terms. The most precise, useful reading from the code:
find_fusible_pairs()returns each such pair exactly once.validate_fully_fused()composes structural + normalized-phase + no-fusible-pairs checks — used as the final gate before QASM emission, after spider fusion has run.Tests (per acceptance criteria)
afana/tests/zx_single_qubit_parity.rs— 5 integration tests:UnfusedAdjacentSpidersafana/src/zx_ir.rs— 6 new inline unit tests covering helper edge cases (untagged boundary spiders, cross-qubit, single-color, exact pair detection).Test plan
cargo test -p afana --test zx_single_qubit_parity— 5/5cargo test -p afana --lib zx_ir::— 23/23 (6 new + 17 existing including Implement ZX-IR phase range validation for spider nodes #850's normalisation tests)cargo build --workspace --releasegreenNotes on the issue's framing
The senate-generated issue body suggested "Add single-qubit gate sequence examples to the existing Ehrenfest example programs and ensure they pass the new validation pass". I did NOT add Ehrenfest example files — the existing
rabi_oscillation_1q.cbor.hexand similar already exercise single-qubit gate sequences; adding parallel examples would be noise. The validation methods are what's reusable and the tests demonstrate they work.Dependency
Depends on #1069 (phase normalization).
validate_fully_fused()callsvalidate_normalized(), which is introduced in that PR. Once #1069 merges, this PR's base auto-updates to main.