Skip to content

Add Pauli input initialization#230

Open
masa10-f wants to merge 6 commits into
masterfrom
agent/pauli-input-initialization
Open

Add Pauli input initialization#230
masa10-f wants to merge 6 commits into
masterfrom
agent/pauli-input-initialization

Conversation

@masa10-f

@masa10-f masa10-f commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

#229 has been merged into master; this PR now targets master directly.

Summary

  • Add per-input positive Pauli eigenstate initialization (X+, Y+, Z+) through GraphState, Pattern, and qompile().
  • Compile input initialization to Stim reset instructions (RX, RY, R) and mirror the same states in PatternSimulator.
  • Import leading Stim reset instructions (R, RX, RY) as the corresponding input initialization states; reject mid-circuit resets explicitly.
  • Sample all pattern measurements from exact Born probabilities by default; retain the legacy non-output 50/50 assumption with calc_prob=False.
  • Bump exported .ptn files to format version 2 with .input_basis, while keeping version 1 files readable with X+ input defaults.
  • Document initial reset import, simulator sampling modes, and the .ptn version 2 format.
  • Add regression coverage for graph copying/composition, initialization validation, .ptn roundtrip, simulator behavior, and Stim import/export.

Rebase notes

Validation

  • uv run --no-sync pytest -q -s -m "not pyzx" — 622 passed, 13 deselected.
  • uv run --no-sync pytest -q -s -m pyzx — 13 passed, 622 deselected.
  • uv run --no-sync ruff check . and uv run --no-sync ruff format --check .
  • uv run --no-sync mypy graphqomb and uv run --no-sync pyright graphqomb
  • uv run --no-sync sphinx-build -W --keep-going -b html docs/source <output>
  • GitHub Actions matrix: triggered for the latest commit.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.67925% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.19%. Comparing base (133621a) to head (0291fd2).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #230      +/-   ##
==========================================
+ Coverage   86.09%   86.19%   +0.09%     
==========================================
  Files          29       29              
  Lines        4451     4577     +126     
  Branches      783      802      +19     
==========================================
+ Hits         3832     3945     +113     
- Misses        438      448      +10     
- Partials      181      184       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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: 5989bd7c53

ℹ️ 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/simulator.py
# Note: deterministic check skipped for now
self.state = StateVector.from_num_qubits(len(self.__pattern.input_node_indices))
input_states = [
_INPUT_STATE_VECTORS[self.__pattern.input_initialization_axes.get(node, Axis.X)]

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 Sample Pauli-initialized non-output measurements

When simulating a pattern where an input initialized with a new non-X basis is later measured as a non-output in the same basis (for example, a one-edge input/output graph with init_axis=Axis.Z and an MZ on the input), the state is now deterministic but apply_cmd(M) still samples all non-output measurements as 50/50. Half of those runs project onto an impossible branch and normalize a zero vector, producing NaNs or wrong downstream outputs; the simulator needs to sample these measurements from the current state when the Pauli input initialization can bias them.

Useful? React with 👍 / 👎.

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