Sweep Program API¶
Import paths¶
from qm.qua import (
declare_with_stream,
NativeIterable,
NativeIterableRange,
QuaIterable,
QuaIterableRange,
QuaProduct,
QuaZip,
)
Automatic streaming¶
qm.qua.declare_with_stream ¶
declare_with_stream(
t: type[NumberT],
stream_name: str,
value: Optional[NumberT] = None,
auto_buffer: bool = True,
average_axes: Optional[list[str]] = None,
) -> DirectStreamSource[NumberT]
Declare a QUA variable that is automatically saved to a result stream.
The returned object can be used anywhere the declared QUA variable can be
used, including assignments and measurement processes. During
stream_processing, the saved values are emitted
to stream_name.
When auto_buffer=True, buffering is derived from the enclosing named
QUA loops. Native iterables are not buffered; their current values are
appended to the saved stream name instead. When no averaging is requested,
the outermost buffered QUA axis is left unbuffered so live plotting can
consume the stream progressively, and the generated stream-processing step
stores the result with save_all(). When average_axes is provided,
the named axes are reduced during generated stream processing and the final
averaged result is stored with save().
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Type of the declared variable, for example
TYPE:
|
stream_name
|
Base name of the result stream.
TYPE:
|
value
|
Optional initial value for the declared variable.
TYPE:
|
auto_buffer
|
If
TYPE:
|
average_axes
|
Names of QUA loop axes to average when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DirectStreamSource[NumberT]
|
A stream-backed QUA variable. |
| RAISES | DESCRIPTION |
|---|---|
QmQuaException
|
If |
Iterator helpers¶
NativeIterable ¶
Python-side iterable over explicit values.
Use this helper for loops that choose Python values such as element names, labels, or configuration variants. No QUA variable is declared; the yielded value is a Python value.
Use NativeIterable instead of a plain Python iterator when the
Python-side axis should still participate in Sweep Program composition. The
iterable name is preserved, so the axis can be combined inside
QuaProduct or
QuaZip, and its current value can
be reflected in generated stream names by
declare_with_stream.
Example
with program() as prog:
for element in NativeIterable("element", ["q1", "q2"]):
play("x180", element)
This is equivalent to:
NativeIterableRange ¶
Python-side range iterator.
Use this helper for sweep dimensions that should stay in Python, for example when choosing configuration variants or element names around QUA code. No QUA variable is declared; the yielded value is a Python value.
Use NativeIterableRange instead of a plain Python iterator when the
Python-side axis should still participate in Sweep Program composition. The
iterable name is preserved, so the axis can be combined inside
QuaProduct or
QuaZip, and its current value can
be reflected in generated stream names by
declare_with_stream.
NativeIterableRange(name, stop) behaves like range(stop).
NativeIterableRange(name, start, stop, step) behaves like
range(start, stop, step) for integers and like
numpy.arange(start, stop, step) for floats. stop is exclusive.
Example
with program() as prog:
for amp_scale in NativeIterableRange("amp_scale", 0.1, 1.0, 0.05):
play("pulse" * amp(amp_scale), "element")
This is equivalent to:
QuaIterable ¶
QUA-side iterable over an explicit sequence of numeric values.
Use this helper when a sweep axis should execute on the QOP rather than in Python.
If the values are uniformly spaced, the iterator may be optimized to a
for_ loop. Otherwise it is compiled as a
for_each_ loop.
Integer sequences produce integer QUA variables. Any non-integer values are converted to float.
The yielded value is a QUA variable, not a Python scalar.
QuaIterableRange ¶
QUA-side range iterator.
Use this helper when a sweep axis should execute on the QOP as a
for_ loop rather than in Python.
QuaIterableRange(name, stop) behaves like range(stop).
QuaIterableRange(name, start, stop, step) behaves like
range(start, stop, step) for integers and like
numpy.arange(start, stop, step) for floats. stop is exclusive.
The yielded value is a QUA variable, not a Python scalar.
For floating-point ranges, the internal stop value may be adjusted slightly to avoid fixed-point boundary issues in the generated loop.
Example
with program() as prog:
for amp_scale in QuaIterableRange("amp_scale", 0.1, 1.0, 0.05):
play("pulse" * amp(amp_scale), "element")
This is equivalent to:
values
property
¶
Return the Python values represented by this iterable.
QuaProduct ¶
Combine iterables into nested loops, similarly to Python's
itertools.product.
QuaProduct expands a sequence of iterable helpers into nested loops.
The first iterable becomes the outermost loop and the last iterable becomes
the innermost loop, so reordering the list changes the loop nesting order.
A product can mix QUA iterables and native iterables. The yielded value is a named tuple whose field names match the iterable names.
Note
Use QuaProduct as the outer combinator. Do not pass a
QuaProduct instance into another iterable helper such as
QuaZip.
Example
QuaZip ¶
Combine iterables position-by-position, similarly to Python's built-in
zip.
QuaZip advances multiple iterables together and yields one named tuple
per position.
It can zip either QUA iterables or native iterables, but not both in the
same call. When zipping QUA iterables, the zip is compiled as a single
for_each_ loop. When zipping native iterables,
iteration happens in Python and stops at the shortest iterable.
Note
Provide iterables with matching lengths so that the zipped values represent the same sweep positions.
Example
values
property
¶
Return the underlying values of the zipped iterables.
For usage examples and behavior details, see the Sweep Program guide.