From bcaf49ca6883de0b2019b8a55b493014e7486c97 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 30 Apr 2026 14:02:05 +0200 Subject: [PATCH 1/4] Fix issue #16097 --- crates/qasm3/src/ast.rs | 2 +- crates/qasm3/src/exporter.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/qasm3/src/ast.rs b/crates/qasm3/src/ast.rs index 01abda24753a..1dfc06db652f 100644 --- a/crates/qasm3/src/ast.rs +++ b/crates/qasm3/src/ast.rs @@ -138,7 +138,7 @@ impl Display for DurationUnit { let unit_str = match self { DurationUnit::Nanosecond => "ns", DurationUnit::Microsecond => "us", - DurationUnit::Millisecond => "us", + DurationUnit::Millisecond => "ms", DurationUnit::Second => "s", DurationUnit::Sample => "dt", }; diff --git a/crates/qasm3/src/exporter.rs b/crates/qasm3/src/exporter.rs index 83393ed87cc3..1673df2006a2 100644 --- a/crates/qasm3/src/exporter.rs +++ b/crates/qasm3/src/exporter.rs @@ -1213,7 +1213,7 @@ impl<'a> QASM3Builder { None => { if delay_unit == DelayUnit::PS { DurationLiteral { - value: duration * 1000.0, + value: duration / 1000.0, unit: DurationUnit::Nanosecond, } } else { From 5d766055123b8d509b0f57e027b0fa50d386a0d6 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 5 May 2026 14:20:30 +0200 Subject: [PATCH 2/4] add test --- test/python/qasm3/test_export.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/python/qasm3/test_export.py b/test/python/qasm3/test_export.py index e20c80bb3bc4..b94bd73139c0 100644 --- a/test/python/qasm3/test_export.py +++ b/test/python/qasm3/test_export.py @@ -2769,6 +2769,7 @@ def test_circuit_with_unitary(self): self.assertEqual(test, expected) + @ddt class TestQASM3ExporterFailurePaths(QiskitTestCase): """Tests of the failure paths for the exporter.""" @@ -3504,3 +3505,23 @@ def dump(self, annotation): ) self.assertEqual(prog.strip(), expected.strip()) self.assertTrue(skip_triggered) + + def test_experimental_delay_units(self): + """Test that the `dumps_experimental` function correctly handles delay units.""" + + def emit(unit): + qc = QuantumCircuit(1) + qc.delay(1, 0, unit=unit) + out = dumps_experimental(qc) + line = next(l for l in out.splitlines() if "delay" in l) + return line.strip() + + units = ["ns", "us", "ms", "s", "dt","ps"] + expected = "\n".join(['delay[1ns] q[0];', + 'delay[1us] q[0];', + 'delay[1ms] q[0];', + 'delay[1s] q[0];', + 'delay[1dt] q[0];', + 'delay[0.001ns] q[0];']) + + self.assertEqual("\n".join(emit(u) for u in units), expected) From 8444c35106c492cac774662f6d7c8d759d08d173 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 5 May 2026 14:24:26 +0200 Subject: [PATCH 3/4] change name test --- test/python/qasm3/test_export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/python/qasm3/test_export.py b/test/python/qasm3/test_export.py index b94bd73139c0..bdfd8f2532ba 100644 --- a/test/python/qasm3/test_export.py +++ b/test/python/qasm3/test_export.py @@ -3506,7 +3506,7 @@ def dump(self, annotation): self.assertEqual(prog.strip(), expected.strip()) self.assertTrue(skip_triggered) - def test_experimental_delay_units(self): + def test_delay_units(self): """Test that the `dumps_experimental` function correctly handles delay units.""" def emit(unit): From 9adcf63fb9732442dfd8ac7954b73b224e8971f5 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 5 May 2026 14:35:18 +0200 Subject: [PATCH 4/4] release note --- ...rimental-delay-units-ac8bd64fb2c79f7d.yaml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 releasenotes/notes/fix-qasm3-dumps-experimental-delay-units-ac8bd64fb2c79f7d.yaml diff --git a/releasenotes/notes/fix-qasm3-dumps-experimental-delay-units-ac8bd64fb2c79f7d.yaml b/releasenotes/notes/fix-qasm3-dumps-experimental-delay-units-ac8bd64fb2c79f7d.yaml new file mode 100644 index 000000000000..7ec958cac4ca --- /dev/null +++ b/releasenotes/notes/fix-qasm3-dumps-experimental-delay-units-ac8bd64fb2c79f7d.yaml @@ -0,0 +1,25 @@ +--- +# Delete all sections that you do not need. You can have more than one section in a file, and +# more than one bullet point per section. This is a regular YAML file, and all text should use +# Sphinx's flavor of rST (restructured text). Each bullet point is a separate "release note". +# +# Each public bug fix, feature, deprecation, and behavior change needs a release note. +# Documentation- or internal-only changes do not need release notes. +# +# Each bullet point appears without any context, so make sure each can be read in isolation. The +# reader will not see your code change, the issue, or any other bullet points in this file. You +# might need to repeat yourself between bullets. +# +# Use Sphinx cross-references like :meth:`.YourClass.your_method` whenever mentioning a +# function/class/method by name. +# +# Use `- |` for multiline YAML strings (like in the "fixes" example in this template) to preserve +# newlines, which you need for Sphinx syntax. +# +# There are some rare additional sections listed in `releasenotes/config.yaml` not included here. + +fixes: + - | + Fix qasm3.dump_experimental delay units + + See ` #16097 `__. \ No newline at end of file