Merged
Conversation
Contributor
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
Contributor
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves error reporting and robustness around parsing tsim shorthand/Stim program text, and adjusts sampler behavior to warn (instead of error) on small normalization deviations.
Changes:
- Add scientific-notation support for parametric angles in shorthand parsing and tag parsing, with new unit tests.
- Enrich Stim parse errors to surface the problematic unconverted shorthand snippet in
Circuitconstruction/append paths. - Change sampler normalization handling from raising to warning for small deviations, and update integration expectations; also refactor transversal encoder behavior (gate expansion removal).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/tsim/utils/program_text.py |
Adds scientific-notation parsing and introduces enriched Stim error extraction helpers. |
src/tsim/circuit.py |
Uses enriched parsing errors when constructing/appending circuits; replaces asserts with ValueError for invalid parametric usage. |
src/tsim/core/parse.py |
Extends parametric tag parsing regex to allow scientific notation. |
src/tsim/sampler.py |
Switches normalization failures from exception to warning (and introduces a new underflow ValueError path). |
src/tsim/utils/encoder.py |
Removes logical gate expansion behavior from transversal encoding logic and constructor surface. |
test/unit/utils/test_program_text.py |
Adds tests for scientific notation and for enriched parse-error snippets. |
test/integration/test_sampler.py |
Updates expectations to warning (instead of raising) on normalization deviation. |
Comments suppressed due to low confidence (1)
src/tsim/core/parse.py:58
parse_parametric_tagnow accepts scientific notation via regex, but still doesFraction(param_match.group(2)).fractions.Fractiondoes not accept strings like"1e-2", so tags produced with scientific notation (e.g.theta=1e-6*pi) will raise instead of parsing. Convert viaDecimal(e.g.Fraction(Decimal(value_str))) or viaFraction.from_float(float(value_str)).limit_denominator(...)to actually support the new accepted formats.
# Match param=value*pi (value can be negative/decimal/scientific)
param_match = re.match(
r"^(\w+)=([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\*pi$", param
)
if not param_match:
return None
param_name = param_match.group(1)
value = Fraction(param_match.group(2))
params[param_name] = value
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Slight normalization issues no longer raise an error but a warning. These can occur for circuits with arbitrary rotation gates, where fp32 is used instead of an exact representation.
Parsing errors for invalid Stim circuits now raise useful exceptions.