Skip to content
Closed
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
17 changes: 17 additions & 0 deletions test/python/qasm3/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3407,6 +3407,23 @@ def test_delay_qpy_roundtrip(self):
with_qpy = dumps_experimental(qpy_roundtrip)
self.assertEqual(no_qpy, with_qpy)

def test_delay_units(self):
"""Test duration-unit serialization in the experimental exporter."""
qc = QuantumCircuit(1)
qc.delay(1, 0, unit="ms")
qc.delay(1, 0, unit="ps")
expected_qasm = "\n".join(
[
"OPENQASM 3.0;",
'include "stdgates.inc";',
"qubit[1] q;",
"delay[1ms] q[0];",
"delay[0.001ns] q[0];",
"",
]
)
self.assertEqual(dumps_experimental(qc), expected_qasm)

def test_annotations(self):
"""Test that the annotation-serialisation framework works."""
assert_in = self.assertIn
Expand Down