Environment
- Qiskit version: 2.4.1
- Python version:
- Operating system:
This issue was a collaboration between me and Claude 4.6
What is happening?
qasm3.dumps_experimental produces wrong output for Delay gates with unit='ms' or unit='ps'.
There are two independent bugs:
-
ms label is emitted as us — a copy-paste error in ast.rs means DurationUnit::Millisecond is serialized as "us" instead of "ms". The numeric value is unchanged, so the emitted duration is 1000× too small.
-
ps → ns conversion factor is inverted — exporter.rs converts picoseconds to nanoseconds by multiplying by 1000 instead of dividing. Since 1 ps = 0.001 ns, Delay(1, 'ps') is emitted as delay[1000ns] — 10⁶× too large.
How can we reproduce the issue?
from qiskit import QuantumCircuit
from qiskit import qasm3
import warnings
def emit(dur, unit):
qc = QuantumCircuit(1)
qc.delay(dur, 0, unit=unit)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
out = qasm3.dumps_experimental(qc)
line = next(l for l in out.splitlines() if "delay" in l)
print(f"Delay({dur}, '{unit}') => {line!r}")
emit(1, "ms") # expect delay[1ms], got delay[1us]
emit(1, "ps") # expect delay[0.001ns], got delay[1000ns]
Output:
Delay(1, 'ms') => ' delay[1us] q[0];'
Delay(1, 'ps') => ' delay[1000ns] q[0];'
What should happen?
Delay(1, 'ms') should emit delay[1ms] (not delay[1us]).
Delay(1, 'ps') should emit delay[0.001ns] (not delay[1000ns]).
More generally, every Delay unit should round-trip through dumps_experimental with the correct label and a numerically correct value.
Any suggestions?
There are two one-line fixes:
Bug 1 — crates/qasm3/src/ast.rs (around line 141):
// Before (wrong):
DurationUnit::Millisecond => "us",
// After:
DurationUnit::Millisecond => "ms",
Bug 2 — crates/qasm3/src/exporter.rs (around line 1216).
The ps → ns conversion currently multiplies by 1000; it should divide:
// Before (wrong — 1 ps = 0.001 ns, not 1000 ns):
value: duration * 1000.0, unit: Nanosecond
// After:
value: duration / 1000.0, unit: Nanosecond
Environment
This issue was a collaboration between me and Claude 4.6
What is happening?
qasm3.dumps_experimentalproduces wrong output forDelaygates withunit='ms'orunit='ps'.There are two independent bugs:
mslabel is emitted asus— a copy-paste error inast.rsmeansDurationUnit::Millisecondis serialized as"us"instead of"ms". The numeric value is unchanged, so the emitted duration is 1000× too small.ps → nsconversion factor is inverted —exporter.rsconverts picoseconds to nanoseconds by multiplying by 1000 instead of dividing. Since 1 ps = 0.001 ns,Delay(1, 'ps')is emitted asdelay[1000ns]— 10⁶× too large.How can we reproduce the issue?
Output:
What should happen?
Delay(1, 'ms')should emitdelay[1ms](notdelay[1us]).Delay(1, 'ps')should emitdelay[0.001ns](notdelay[1000ns]).More generally, every
Delayunit should round-trip throughdumps_experimentalwith the correct label and a numerically correct value.Any suggestions?
There are two one-line fixes:
Bug 1 —
crates/qasm3/src/ast.rs(around line 141):Bug 2 —
crates/qasm3/src/exporter.rs(around line 1216).The ps → ns conversion currently multiplies by 1000; it should divide: