Infer qubit number from STIM program#162
Open
david-pl wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
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 newExtendedProgram::num_qubits()AST helper instim-parser. - Made
n_qubitsoptional inppvm.sample_stimandGeneralizedTableau.sample, inferring it fromprog.num_qubitswhen 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.
|
67f289e to
8e4fa52
Compare
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.
One more nice convenience thing when running STIM programs.
n_qubitsin the python wrapper (sample_stimandGeneralizedTableau.sample) is now optional and inferred from the program if omitted.GeneralizedTableau.dostill 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.doalso omit the qubit number? It's a little trickier, but I guess we could just add a hack.