Fix tests to account for QEC and box ops in transpilation#51
Open
conorfitzmaurice wants to merge 2 commits into
Open
Fix tests to account for QEC and box ops in transpilation#51conorfitzmaurice wants to merge 2 commits into
conorfitzmaurice wants to merge 2 commits into
Conversation
Member
|
A few notes that need to be addressed right away:
|
| fidelity = _logical_fidelity(lsv.logical_decomposition, sv_expected.data) | ||
|
|
||
| lqc_h.measure_all() | ||
| if np.isclose(fidelity, 1.0, atol=GATE_FIDELITY_ATOL): |
Member
There was a problem hiding this comment.
We're not sure how logging should be handled, we should discuss this
RasmitDevkota
requested changes
Apr 20, 2026
Added new LogicalQ/tests/__init__.py so fidelity tolerances are shared test configuration rather than global hardcoded variables:
- FIDELITY_ATOL: derived from inspect.signature(np.isclose).parameters["atol"].default, so it tracks numpy's own default instead of being hardcoded.
- sk_rotation_atol(recursion_degree, depth, basis_gates, thetas): measures the worst-case Solovay-Kitaev state infidelity for RXGate/RYGate/RZGate at the supplied parameters/angles and returns it as the tolerance. TestSingleQubitRotationGate passes recursion_degree, depth, and thetas through, so tolerance always matches the approximation regime of test being run. Overridable via atol kwarg.
No production (non-test) code was modified.
## Tests
Ran locally against qiskit==2.4.0, qiskit-aer==0.17.2, qiskit-addon-utils==0.3.1.
**Functional**
- [x] TestAllGates() with default implemented_codes: True
- [x] TestAllGates([steane_code]): True (every test, no warnings)
- [x] TestAllGates([five_qubit_code]): True (fidelity tests skipped with warnings, construction tests still execute)
**Cross-validation against demo tooling**
- [x] Single-qubit fidelity matches logical_state_fidelity(lsv, Statevector(qc)): the pattern for demos/RGateValidation.ipynb and demos/LogicalGateBenchmarking.ipynb: to 1e-8 for all 16 {X, Y, Z, H, S, Sdg, T, Tdg} x {0, 1} cases.
- [x] Rotation fidelity matches the same demo pattern to 1e-8 for all 15 {RX, RY, RZ} x {5 angles} cases; measured fidelities span 0.9921–1.0000, all passing the derived sk_rotation_atol bound (~0.006 for the 5-angle test sweep).
**Configuration override**
- [x] Overriding atol=0.0 via kwarg correctly makes non-identity rotation cases report False, confirming the inherited tolerance is actually honored (not silently ignored).
**Negative controls** (to confirm the suite catches regressions rather than always reporting True)
- [x] Claiming X = Z: returns False (fidelity 0.0 for both 0 and 1)
- [x] Claiming H = X: returns False (fidelity 0.5)
- [x] Claiming RX(theta) = RX(2*theta): returns False for all theta not equal to 0
- [x] Construction helper with a raising lqc_method: returns False for every QECC
## Tolerance derivation check
- At each test angle theta, the infidelity observed on the logical circuit matches the infidelity sk_rotation_atol measures on the physical SK decomposition (e.g. RX at θ=1.2566: 0.006000 in both).
## Known limitations (not regressions)
- Multi-qubit gate correctness (CX, RXX, RYY, RZZ) is not fidelity-tested: same intractability as the demo's caveat.
- Non-Steane QECCs are skipped for fidelity tests until LogicalStatevector supports them.
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.
Update:
Added new LogicalQ/tests/init.py so fidelity tolerances are shared test configuration rather than global hardcoded variables:
Tests
Ran locally against qiskit==2.4.0, qiskit-aer==0.17.2, qiskit-addon-utils==0.3.1.
Functional
Cross-validation against demo tooling
Configuration override
Negative controls (to confirm the suite catches regressions rather than always reporting True)
Tolerance derivation check
Known limitations (not regressions)