Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/qasm3/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand Down
2 changes: 1 addition & 1 deletion crates/qasm3/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/Qiskit/qiskit/issues/16097>`__.
21 changes: 21 additions & 0 deletions test/python/qasm3/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -3504,3 +3505,23 @@ def dump(self, annotation):
)
self.assertEqual(prog.strip(), expected.strip())
self.assertTrue(skip_triggered)

def test_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)