Conversation
…es and fail loudly on unknown gate types
ciaranra
force-pushed
the
python-gate-wildcards-fail-loud
branch
from
September 20, 2026 05:58
d15b5b0 to
2f5d9b9
Compare
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 #802.
Problem
Two Python-facing gate classifiers ended in a wildcard that silently ignored any gate type not on a hand-written list:
TickCircuit.with_noise(dag_circuit_bindings.rs) gave no two-qubit noise toRXYXY2Q,RXXRYYRZZ,U2q,CH, and no preparation noise toPX.tick_circuit_to_stimdropped unknown gates from the exported Stim circuit, so the Stim DEM described a different circuit from the one simulated. ExportingRXYXY2Q(pi, 0)produced an empty program.Change
GateNoiseKindandgate_noise_kindinpecos-qec'spropagator.rs, next to the predicates they read (is_supported_prep_gate,is_supported_noop_or_metadata_gate,GateType::is_single_qubit/is_two_qubit,consumes_measurement_record). Buckets: Prep, Single, Two, Measurement, Transparent, Error.IandIdlekeep their single-qubit noise;CustomandCCXare Error.with_noiseclassifies through it and raisesValueErroron an Error gate whenever any rate is non-zero.PXpreparation noise is a Z flip (Dephasing), matchingmem_builder.rs;PZ/QAllockeepBitFlip.is_supported_noop_or_metadata_gateis exposed to Python, and_gate_to_stimuses it for its transparent set, raises on anything else unknown, and lowers CliffordRXYXY2Q(SQRT_XX/SQRT_YY, their daggers, andX X/Y Yattheta = pi, all with one two-qubit noise channel).u8test overGateTypepins every variant to exactly one bucket, so a future variant that fits none fails. It lives inpecos-qecbecausepecos-rslibunit tests are excluded from CI (pecos-rslib Rust unit tests are excluded from CI and 11 of them fail on dev #806).Behaviour changes for existing circuits, all intended:
PXgains Z preparation noise;CH,RXXRYYRZZ,U2q,RXYXY2Qgain two-qubit noise;CCXandCustomraise when noise is active (with all rates zero they still pass through). The core rule that a circuit already containing channel operations is rejected bywith_noiseis unchanged.Tests
39 new Python tests in
tests/qec/test_tick_circuit_gate_classification.pyplus the exhaustive Rust guard. Mutation-checked: restoring either wildcard, routingCCXto Two, swapping the Stim axis or SQRT/DAG, and accepting a non-Cliffordphieach fail a test.Verification
cargo test -p pecos-qec(1101 passed),cargo clippy --locked -p pecos-qec -p pecos-rslib --all-targets -- -D warnings,cargo fmt --check,just python-ci-build-test, the new test file (39 passed) plus the wider-k "stim or with_noise or tick_circuit or rxyxy2q"selection (237 passed), andjust python-ci-lint, all clean.How this was produced
Implemented by OpenAI
gpt-6-astra(Codex CLI 0.154.0) from a task packet written by Claude Fable 5.1 in Claude Code; Claude reviewed every hunk, re-ran all verification itself, and sent findings back for fix rounds. An independent Codex review arm with no access to the implementation session also reviewed the diff. Posted at the maintainer's request.