Skip to content

Infer qubit number from STIM program#162

Open
david-pl wants to merge 4 commits into
mainfrom
david/stim-no-qubit
Open

Infer qubit number from STIM program#162
david-pl wants to merge 4 commits into
mainfrom
david/stim-no-qubit

Conversation

@david-pl

Copy link
Copy Markdown
Collaborator

One more nice convenience thing when running STIM programs.

  • Passing in n_qubits in the python wrapper (sample_stim and GeneralizedTableau.sample) is now optional and inferred from the program if omitted.
  • The rust side and GeneralizedTableau.do still require it (even though the inference is exposed, so you could construct the stim program first and infer from that), because of the compile-time values that depend on the qubit number.

FYI, @rafaelha: is this okay or should we somehow have GeneralizedTableau.do also omit the qubit number? It's a little trickier, but I guess we could just add a hack.

Copilot AI review requested due to automatic review settings June 25, 2026 13:09

Copilot AI 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.

Pull request overview

Adds a qubit-count inference path for running validated Stim programs from the Python API, so callers can omit n_qubits in common cases while keeping the Rust backend’s explicit sizing requirements.

Changes:

  • Added StimProgram.num_qubits (Python-visible) backed by a new ExtendedProgram::num_qubits() AST helper in stim-parser.
  • Made n_qubits optional in ppvm.sample_stim and GeneralizedTableau.sample, inferring it from prog.num_qubits when omitted.
  • Added Python and Rust tests covering qubit-count inference and edge cases (annotations ignored, repeats handled).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ppvm-python/test/generalized_tableau/test_stim.py Adds tests for StimProgram.num_qubits and for omitting n_qubits in sampling APIs.
ppvm-python/src/ppvm/generalized_tableau.py Makes n_qubits optional for sampling and infers from prog.num_qubits.
ppvm-python/src/ppvm/_core.pyi Exposes the new StimProgram.num_qubits property in type stubs.
crates/stim-parser/src/ast/extended.rs Implements ExtendedProgram::num_qubits() via a recursive max-qubit walk, with unit tests.
crates/ppvm-python-native/src/stim_program.rs Exposes num_qubits via a PyO3 #[getter] on StimProgram.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ppvm-python/src/ppvm/generalized_tableau.py
Comment thread crates/ppvm-python-native/src/stim_program.rs
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://QuEraComputing.github.io/ppvm/pr-preview/pr-162/

Built to branch gh-pages at 2026-06-26 09:04 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copilot AI review requested due to automatic review settings June 25, 2026 13:52

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread ppvm-python/src/ppvm/generalized_tableau.py
Comment thread crates/stim-parser/src/ast/extended.rs
@david-pl david-pl force-pushed the david/stim-no-qubit branch from 67f289e to 8e4fa52 Compare June 25, 2026 14:18
Copilot AI review requested due to automatic review settings June 26, 2026 08:30

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread crates/stim-parser/src/ast/extended.rs
Comment thread crates/ppvm-python-native/src/stim_program.rs
Comment thread crates/stim-parser/src/ast/extended.rs
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.

2 participants