qiskit/releasenotes/notes/2.0/stretch-variables-076070c3f...

44 lines
1.8 KiB
YAML

---
prelude: >
This release adds support for ``stretch`` variables to :class:`.QuantumCircuit`
which are used to express relationships between instruction durations. For
example, in order to ensure a sequence of gates between two barriers will be
left-aligned, whatever their actual durations may be, we can do the following::
from qiskit import QuantumCircuit
from numpy import pi
qc = QuantumCircuit(5)
qc.barrier()
qc.cx(0, 1)
qc.u(pi/4, 0, pi/2, 2)
qc.cx(3, 4)
a = qc.add_stretch("a")
b = qc.add_stretch("b")
c = qc.add_stretch("c")
# Use the stretches as Delay duration.
qc.delay(a, [0, 1])
qc.delay(b, 2)
qc.delay(c, [3, 4])
qc.barrier()
For additional context and examples, refer to the
`OpenQASM 3 language specification. <https://openqasm.com/language/delays.html#duration-and-stretch-types>`__
features_circuits:
- |
A new expression node :class:`~.expr.Stretch` has been added to the classical expression
system to represent ``stretch`` variables. To create a new ``stretch` variable, you can
use :meth:`.QuantumCircuit.add_stretch`. The resulting expression is a constant
expression of type :class:`~.types.Duration`, which can currently be used as the ``duration``
argument of a :meth:`~.QuantumCircuit.delay`.
The :class:`~.expr.Stretch` expression is most similar to the existing :class:`~.expr.Var`
expression used to represent classical variables in a circuit, except it is constant and
is always of type :class:`~.types.Duration`. It can be used in other expressions (e.g.
you can multiply it by a numeric constant) and :class:`.QuantumCircuit` provides full
scoping support for it (e.g. it can be captured by or declared within a control flow
scope).