Skip to content

Add Stim MPP stabilizer import#217

Merged
masa10-f merged 11 commits into
masterfrom
feat/qec-helper
Jul 15, 2026
Merged

Add Stim MPP stabilizer import#217
masa10-f merged 11 commits into
masterfrom
feat/qec-helper

Conversation

@masa10-f

@masa10-f masa10-f commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add graphqomb.qec helpers for building Type I and Type II graph states from stabilizer matrices.
  • Add graphqomb.qec.stim_mpp utilities for extracting unsigned Stim MPP products, sparse qubit mappings, coordinates, detectors, and logical observables.
  • Reject signed MPP products explicitly because stabilizer signs are not retained.
  • Keep stim as the optional graphqomb[stim] extra and use the existing development extra for type stubs.
  • Add Sphinx references and usage documentation for the QEC builder and Stim MPP importer.

Review follow-up

  • Add a coordinate type alias and support retaining higher-dimensional coordinate tuples.
  • Remove partial matrix-shape and coordinate-dimensionality validation.
  • Document every field returned by StabilizerGraphStateBuildResult.
  • Simplify the logical-observable record default factory.
  • Add regression coverage for signed MPP rejection and higher-dimensional coordinates.

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.

@masa10-f masa10-f marked this pull request as ready for review July 8, 2026 12:15

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread graphqomb/qec/stim_mpp.py


def _target_pauli(target: stim.GateTarget) -> str:
if target.is_x_target:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread graphqomb/qec/qeccode.py Outdated
self,
stabilizer_matrix: csr_array,
*,
stabilizer_coords: Mapping[int, tuple[float, ...]] | None = None,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using type alias for tuple[float, ...] for better readability.

Comment thread graphqomb/qec/qeccode.py Outdated
Comment on lines +40 to +43
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")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not always expect 3 because higher dimensional code can be considered here. I feel this validation is meaningless.

Comment thread graphqomb/qec/qeccode.py Outdated
Comment on lines +37 to +39
if stabilizer_matrix.shape[1] % 2 != 0:
msg = "Stabilizer matrix must have an even number of columns."
raise ValueError(msg)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this check because it is not a complete check

Comment thread graphqomb/qec/qeccode.py
Comment on lines +62 to +67
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]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detailed doc is necessary for each variables.

Comment thread graphqomb/qec/stim_mpp.py Outdated
Comment on lines +27 to +28
def _empty_logical_observable_record_indices() -> dict[int, frozenset[int]]:
return {}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems unnecessary to define

Comment thread graphqomb/qec/stim_mpp.py Outdated
Comment on lines +161 to +163
if coord_dims not in {2, 3}:
msg = "coord_dims must be 2 or 3."
raise ValueError(msg)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary

@masa10-f masa10-f self-assigned this Jul 15, 2026
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.76454% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.55%. Comparing base (7a5cfa4) to head (114de49).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@masa10-f masa10-f merged commit c4f600f into master Jul 15, 2026
24 checks passed
@masa10-f masa10-f deleted the feat/qec-helper branch July 15, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant