Limitation
Duration and stretch types defines
durationof(), which takes a block of quantum instructions and returns its duration. It is
how a program expresses a delay relative to the length of some other operation rather than as
an absolute time.
pyqasm does not evaluate it.
Example QASM failure
OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;
duration a = durationof({x q[0];});
ValidationError: Invalid initialization value for variable 'a'
Plain duration declarations, unit arithmetic, delay[...] and box[...] all work today, so
durationof is the isolated gap in the timing surface.
Change Requested
- Evaluate
durationof({ ... }) to a duration value usable anywhere a duration literal is,
in particular in delay[...] and box[...].
- Where the enclosed block's length is known — because the module was loaded with
device_cycle_time / calibration information, or the block contains only explicit delay
instructions — return the concrete value.
- Where it is not known, keep it symbolic and emit
durationof({ ... }) unchanged through
dumps(). Rejecting a valid program because a backend duration is unknown would be worse
than passing it through.
- Validate the block itself: the enclosed statements must be legal quantum instructions, and
any qubit they reference must be declared.
Implementation Details
openqasm3 parses this as a DurationOf expression whose target is a statement list.
Qasm3ExprEvaluator (src/pyqasm/expressions.py) has no branch for it, which is why the
value reaches the declaration check as unresolved.
pyqasm already tracks per-qubit depth via QubitDepthNode in src/pyqasm/elements.py. The
duration of a block is the same walk over a smaller statement list, so the existing
bookkeeping is largely reusable.
loads() already accepts device_cycle_time, and dt units are handled in
DURATION_UNITS (src/pyqasm/maps/expressions.py). A cycle-count result converts to a
concrete duration through that path when a cycle time is available.
- This composes with the symbolic representation proposed in the
stretch arithmetic issue —
both need a duration value that is not necessarily a concrete number. Landing a single
representation that serves both is preferable to two partial ones.
- The block must be visited in a child scope so that any temporary state it creates does not
leak, and its instructions must not be emitted into the unrolled output — durationof
measures the block, it does not execute it.
- Tests:
tests/qasm3/test_timing.py — durationof of a single gate, of a multi-gate block,
of a block containing an explicit delay, its use inside delay[...], a dumps()
round-trip of the symbolic form, and an undeclared qubit inside the block raising a
ValidationError.
Limitation
Duration and stretch types defines
durationof(), which takes a block of quantum instructions and returns itsduration. It ishow a program expresses a delay relative to the length of some other operation rather than as
an absolute time.
pyqasmdoes not evaluate it.Example QASM failure
Plain duration declarations, unit arithmetic,
delay[...]andbox[...]all work today, sodurationofis the isolated gap in the timing surface.Change Requested
durationof({ ... })to adurationvalue usable anywhere a duration literal is,in particular in
delay[...]andbox[...].device_cycle_time/ calibration information, or the block contains only explicitdelayinstructions — return the concrete value.
durationof({ ... })unchanged throughdumps(). Rejecting a valid program because a backend duration is unknown would be worsethan passing it through.
any qubit they reference must be declared.
Implementation Details
openqasm3parses this as aDurationOfexpression whosetargetis a statement list.Qasm3ExprEvaluator(src/pyqasm/expressions.py) has no branch for it, which is why thevalue reaches the declaration check as unresolved.
pyqasmalready tracks per-qubit depth viaQubitDepthNodeinsrc/pyqasm/elements.py. Theduration of a block is the same walk over a smaller statement list, so the existing
bookkeeping is largely reusable.
loads()already acceptsdevice_cycle_time, anddtunits are handled inDURATION_UNITS(src/pyqasm/maps/expressions.py). A cycle-count result converts to aconcrete duration through that path when a cycle time is available.
stretcharithmetic issue —both need a duration value that is not necessarily a concrete number. Landing a single
representation that serves both is preferable to two partial ones.
leak, and its instructions must not be emitted into the unrolled output —
durationofmeasures the block, it does not execute it.
tests/qasm3/test_timing.py—durationofof a single gate, of a multi-gate block,of a block containing an explicit
delay, its use insidedelay[...], adumps()round-trip of the symbolic form, and an undeclared qubit inside the block raising a
ValidationError.