Fix qasm3 experimental exporter delay units for ms and ps#16233
Fix qasm3 experimental exporter delay units for ms and ps#16233gkneighb wants to merge 1 commit into
Conversation
Two independent bugs caused `qasm3.dumps_experimental` to produce incorrect output for `Delay` instructions with `unit="ms"` or `unit="ps"`: * `DurationUnit::Millisecond` was serialised with the suffix `"us"` instead of `"ms"` (a copy-paste in `ast.rs`), making the emitted duration read as 1000x smaller than intended. * The picosecond-to-nanosecond conversion in `exporter.rs` multiplied by 1000 instead of dividing. Since 1 ps = 0.001 ns, `Delay(1, 'ps')` was emitted as `delay[1000ns]` rather than `delay[0.001ns]`, a factor of 10^6 too large. The existing Python exporter (`Exporter.dumps`) was already correct; only the Rust-backed experimental path was affected. Adds `TestQASM3ExporterRust.test_delay_units` covering every unit (`ns`, `us`, `ms`, `s`, `dt`, `ps`). Fixes Qiskit#16097
|
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the following people are relevant to this code:
|
|
|
Summary
Fixes two independent bugs in
qiskit.qasm3.dumps_experimental(anddump_experimental) whereDelayinstructions were serialised with the wrong unit or numeric value.Fixes #16097.
What was wrong
mswas emitted asus—crates/qasm3/src/ast.rs'sDisplayimpl forDurationUnitmappedMillisecondto"us"(copy-paste from the previous arm). The emitted duration was 1000x smaller than intended.ps → nsconversion was inverted —crates/qasm3/src/exporter.rsmultiplied by 1000 instead of dividing. Since 1 ps = 0.001 ns,Delay(1, 'ps')was emitted asdelay[1000ns], a factor of 10^6 too large.OpenQASM 3 has no
psliteral, so the exporter must convert tons— that part is correct; only the conversion factor was wrong.The non-experimental Python exporter (
Exporter.dumps) was unaffected and already covered byTestCircuitQASM3.test_delay_statement.Reproduction (from the issue)
Test plan
TestQASM3ExporterRust.test_delay_unitsexercises every unit (ns,us,ms,s,dt,ps) with asubTestper case.TestQASM3ExporterRustclass (19 tests) still passes.test/python/qasm3/suite (127 passed, 8 skipped) still passes.cargo check,cargo clippy -p qiskit-qasm3 -- -D warnings, andcargo fmt --checkare clean.ruff checkandblack --checkontest_export.pyare clean.AI tool disclosure
Per the Qiskit contribution policy: this change was prepared with assistance from Claude Opus 4.7 (1M context, via Claude Code). I reviewed every diff and verified all results locally; the model did not introduce any change I did not validate.
(Noting also that the originating issue #16097 was filed by @ihincks in collaboration with Claude 4.6.)