Add Stim MPP stabilizer import#217
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be48e39c71
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
|
|
||
| def _target_pauli(target: stim.GateTarget) -> str: | ||
| if target.is_x_target: |
There was a problem hiding this comment.
Handle inverted MPP targets instead of dropping signs
When a Stim MPP product uses an inverted target such as MPP !Z5 or X2*!Y3*Z5, Stim flips the recorded measurement result, but this parser treats the target exactly like an uninverted Pauli target and loses that sign/constant offset. For circuits that use these valid MPP forms, the extracted stabilizer and any imported detector/logical parity rows no longer match the Stim circuit; if signs are not representable here, this should at least reject target.is_inverted_result_target instead of silently importing incorrect data.
Useful? React with 👍 / 👎.
| self, | ||
| stabilizer_matrix: csr_array, | ||
| *, | ||
| stabilizer_coords: Mapping[int, tuple[float, ...]] | None = None, |
There was a problem hiding this comment.
I recommend using type alias for tuple[float, ...] for better readability.
| if stabilizer_coords is not None: | ||
| _validate_coordinate_lengths(stabilizer_coords, expected_lengths={3}, label="stabilizer_coords") | ||
| if qubit_coords is not None: | ||
| _validate_coordinate_lengths(qubit_coords, expected_lengths={2, 3}, label="qubit_coords") |
There was a problem hiding this comment.
We should not always expect 3 because higher dimensional code can be considered here. I feel this validation is meaningless.
| if stabilizer_matrix.shape[1] % 2 != 0: | ||
| msg = "Stabilizer matrix must have an even number of columns." | ||
| raise ValueError(msg) |
There was a problem hiding this comment.
Please remove this check because it is not a complete check
| class StabilizerGraphStateBuildResult(NamedTuple): | ||
| """Result of building a graph state from a stabilizer code.""" | ||
|
|
||
| graph: GraphState | ||
| data_nodes: dict[tuple[int, int], int] | ||
| ancilla_nodes: dict[int, int] |
There was a problem hiding this comment.
Detailed doc is necessary for each variables.
| def _empty_logical_observable_record_indices() -> dict[int, frozenset[int]]: | ||
| return {} |
There was a problem hiding this comment.
It seems unnecessary to define
| if coord_dims not in {2, 3}: | ||
| msg = "coord_dims must be 2 or 3." | ||
| raise ValueError(msg) |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #217 +/- ##
==========================================
- Coverage 85.62% 85.55% -0.08%
==========================================
Files 25 27 +2
Lines 3674 4035 +361
Branches 638 703 +65
==========================================
+ Hits 3146 3452 +306
- Misses 379 413 +34
- Partials 149 170 +21 🚀 New features to boost your workflow:
|
Summary
graphqomb.qechelpers for building Type I and Type II graph states from stabilizer matrices.graphqomb.qec.stim_mpputilities for extracting unsigned StimMPPproducts, sparse qubit mappings, coordinates, detectors, and logical observables.stimas the optionalgraphqomb[stim]extra and use the existing development extra for type stubs.Review follow-up
StabilizerGraphStateBuildResult.Validation
uv run --no-sync pytest -q— 533 passed.uv run --no-sync mypy graphqomb tests examples.uv run --no-sync pyright graphqomb/qec tests/test_qec.py tests/test_stim_mpp.py.uv run --no-sync ruff check graphqomb/qec tests/test_qec.py tests/test_stim_mpp.py.uv run --no-sync ruff format --check graphqomb/qec tests/test_qec.py tests/test_stim_mpp.py.uv run --no-sync sphinx-build -W -E docs/source docs/build.uv lock --check.git diff --check.