Repository navigation
[Parser] Do not split numbers in scientific notation at the exponent's sign - #233
Merged
xumingkuan merged 2 commits intoNov 1, 2026
Merged
Conversation
…s sign ParamParser::parse_expr splits an expression into terms at the last + or -, skipping only a sign right after '*'. A literal such as 9.58737992428526e-05 was therefore split into "9.58737992428526e" and "-05" and parsed as about 4.59 rad, without a warning. Also skip a sign that follows 'e'/'E' preceded by a digit or '.'. test_parser_exponent checks that angles in scientific notation parse to the same circuit as the same angles written as plain decimals. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YFXDzXihmK8D9bNxsBNotC
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the scientific-notation parsing change.
No open issues 🎉
What changed in this PR
This PR fixes QASM parameter parsing so signs in scientific-notation exponents are not mistaken for addition or subtraction, preventing incorrect rotation angles in parsed circuits.
Changes:
- Preserve exponent signs following
eorEwhen preceded by a digit or decimal point. - Add seven matrix-equivalence regression cases covering scientific notation, subtraction, and existing negative-factor handling.
- Add a CMake executable target for the new regression test.
| File | Description |
|---|---|
src/test/test_parser_exponent.cpp |
Compares circuits parsed from scientific-notation angles and equivalent expressions. |
src/test/CMakeLists.txt |
Adds the test_parser_exponent executable target. |
src/quartz/parser/qasm_parser.cpp |
Skips exponent signs when splitting expressions into terms. |
Review effort: Balanced
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.
ParamParser::parse_exprsplits an expression into terms at the last+/-, skipping only a sign right after*(as inpi*-0.25). A literal in scientific notation is therefore split at the sign of its exponent:rz(9.58737992428526e-05)is parsed as9.58737992428526eminus05, i.e. about 4.59 rad, without a warning. Likewise-4.79e-05becomes about -9.79 and3.451511e-09about -5.55.Such literals are common in generated circuits. For example, 15 circuits of the GUOQ benchmark suite (
TFIM_step_*_4,TFIM_step_100_{8,16,32},qft_20,vqe_4; 766 literals) contain them, so Quartz optimized a different circuit than the input.Fix: also skip a
+/-that followse/Epreceded by a digit or..Test:
src/test/test_parser_exponent.cppparsesrzangles in scientific notation and the same angles written as plain decimals, and checks that the two circuits have the same matrix. On master 6 of the 7 cases fail; with the fix all pass. The changed files are clean under clang-format 21.1.0 (the pre-commit version).Not changed here: with
USE_RATIONAL(the default),string_to_param_without_pistores a decimal angle asstd::to_string(angle / pi), i.e. with 6 decimals, so small angles are still rounded (e.g. 9.587e-05 rad becomes 3.1e-05·π ≈ 9.74e-05 rad); the existing warning covers this.🤖 Generated with Claude Code
https://claude.ai/code/session_01YFXDzXihmK8D9bNxsBNotC