Measurement Helpers#
Every node’s Measurement class derives from
BaseMeasurement, which is much more than
an interface: it is a toolbox of schedule-building helpers that take care of
the repetitive (and easy-to-get-wrong) parts of a multiplexed experiment —
reading out all qubits, resetting them, and sweeping parameters in hardware
loops. A concrete measurement class typically only has to describe the pulses
that make its experiment unique and delegate everything else to these helpers.
This guide explains each helper from the source. For the rendered API
signatures see the bragi_quantum.experiments API; for where the
Measurement sits inside a node see Core Concepts.
Construction and qubit ordering#
A measurement is constructed with the dictionaries of device elements it acts on:
measurement = RabiOscillationsMeasurement(transmons) # couplers optional
transmonsmaps qubit names toExtendedTransmonobjects from the live device model;couplers(optional) maps coupler names to their device objects;self.qubitsis the list of qubit names.
Important
The transmons property
does not return the dictionary as given — it returns an OrderedDict
sorted by each transmon’s acquisition channel (measure.acq_channel).
Every helper that produces per-qubit lists (linear domains, stagger times,
device overrides) indexes them in this order, so “the i-th entry” always
means “the qubit on acquisition channel i”, regardless of the order in which
qubits were passed in.
The measure gate#
The only abstract member is the property
measure_gate_class: the
gate class used to read a qubit out. Concrete measurements choose it based on
what they are measuring — for example the Rabi measurement returns the plain
Measure gate when driving the 0→1 transition, and the datalayer package’s Measure_RO1
(readout optimized for state 1) when driving 1→2:
@property
def measure_gate_class(self) -> Measure:
match self.qubit_state:
case 1:
return Measure
case 2:
return Measure_RO1
Individual calls to measure_system may still override the gate class with
their measure_gate_class= keyword (the active-reset helper does exactly
that, see below).
Reading out all qubits: measure_system#
measure_system() builds the
sub-schedule that reads out every qubit of the measurement, and is the
single place where multiplexed-readout details live. What it produces:
an
IdlePulseas the common time anchor;one measure gate per transmon, scheduled relative to that anchor at the qubit’s stagger time;
optionally, a conditional single-qubit operation right after each measurement (used for active reset);
a trailing
IdlePulseper qubit whose duration is the reversed stagger time, so that every qubit’s branch has the same total duration and the schedule stays aligned no matter the stagger pattern.
Staggering#
stagger controls when each qubit’s readout starts, relative to
the idle pulse anchor:
0.0(default) — all qubits are read out simultaneously;a
float— each qubit starts that many seconds after the previous one; the start times are the cumulative sum computed bycompute_stagger_times()(the first qubit always starts at 0);a
list[float]— explicit start times, one per qubit in acquisition-channel order.
Coordinates#
coords attaches coordinate labels to each acquisition so the resulting
xarray dataset is self-describing. Keys are automatically prefixed with the
qubit name ("mw_amplitudes" becomes "q01_mw_amplitudes"), and values
follow a broadcast rule: a list/array is indexed per qubit (entry i goes to
qubit i), while a scalar or a single hardware Variable is attached to all
qubits unchanged.
Acquisition options#
bin_mode—"average_append"(hardware-averaged over repetitions) or"append"(keep every shot; combine with a shot index, see Shot indices below).acq_protocol— the Qblox acquisition protocol; defaults to"SSBIntegrationComplex"(single-sideband integration returning one complex point per acquisition)."ThresholdedAcquisition"returns discriminated 0/1 outcomes and is what active reset uses.acq_channel_prefix— by default a qubit’s data lands on its integer acquisition channel; a prefix turns the channel into a string like"AR_3". This keeps special acquisitions (e.g. the active-reset measurements) separate from the experiment data in the returned dataset.
Conditional operations#
conditional_operation accepts any callable that maps a qubit name to a gate
or sub-schedule (the SingleQubitGate protocol). When given, each
measurement registers a feedback trigger under the qubit’s name, and the
callable’s result is wrapped in a
ConditionalOperation
scheduled one trigger-delay after the measurement — i.e. “if this qubit
measured 1, play this”.
Device overrides#
acq_delay, pulse_amp, pulse_duration and freq are per-qubit
lists of hardware Variable s that override the corresponding readout
parameter of the device model inside the schedule. They are what make
readout-parameter sweeps (punchout, readout optimization) expressible as
hardware loops: the swept variable is handed straight to the measure gate
instead of recompiling the schedule per point.
Resetting the system: reset_system#
reset_system() returns the
sub-schedule that brings all qubits back to the ground state between points.
Two methods:
method="passive"— a plainReseton all qubits: idle long enough (several \(T_1\)) for the excited-state population to decay thermally. Simple and robust, but slow.method="active"— measure every qubit and conditionally flip it back with anXgate if it was found in \(|1\rangle\).
Active reset is assembled entirely from measure_system and is still work
in progress — see issue
#264.
Hardware sweeps: point schedules and generic loops#
Sweeps run as hardware loops: instead of unrolling one copy of the pulse
sequence per sweep point, the schedule contains a single parametrized point
schedule inside a loop over hardware Variable s. Three helpers make this
mechanical:
make_linear_domains#
make_linear_domains() turns
the per-qubit setpoint arrays of the samplespace (e.g.
{"q01": np.linspace(...), "q02": np.linspace(...)}) into one
LinearDomain per qubit, taking the start, stop and number of points from
each array. The returned list is in acquisition-channel order (see above), and
because a linear domain is described only by start/stop/num, the
setpoints of each qubit must be evenly spaced — arbitrary point lists cannot
be swept in a hardware loop.
generic_1d_sweep and generic_2d_sweep#
generic_1d_sweep() wraps a
point schedule — a callable receiving the list of loop variables (one per
qubit) and returning the schedule for a single sweep point — in a hardware loop
over the linear domains. All per-qubit domains advance together in one loop, so
qubit i always receives the i-th domain’s current value.
generic_2d_sweep() nests two
such loops (outer then inner) for two-dimensional sweeps, calling
point_schedule(setpoint_outer, setpoint_inner) in the innermost body.
The default point_schedule method raises NotImplementedError — a
measurement that wants to use the generic loop helpers overrides it. The Rabi
measurement is the canonical example: a 1-D sweep of the drive amplitude,
applied to every qubit in parallel:
def point_schedule(self, amplitude: list[Variable], /) -> TimeableSchedule:
"""
Build the schedule for a single point of the amplitude sweep.
Parameters
----------
amplitude : list[qblox_scheduler.operations.variables.Variable]
One loop variable per qubit, in acquisition-channel order (see
:attr:`~bragi_quantum.experiments.abstract.measurement.BaseMeasurement.transmons`).
``amplitude[qubit_idx]`` is the current setpoint for the qubit on
acquisition channel ``qubit_idx``.
Returns
-------
qblox_scheduler.schedule.TimeableSchedule
Drive, measure and reset for this sweep point.
"""
schedule = TimeableSchedule("point_schedule")
# Common time anchor: every qubit's X gate below is scheduled
# relative to this op (ref_op=start_ref) instead of one after
# another, so all qubits are driven *simultaneously* rather than in
# series. This is what makes the sweep "parallel across qubits".
start_ref = schedule.add(IdlePulse(duration=0.0))
for qubit_idx, transmon in enumerate(self.transmons.values()):
# amplitude[qubit_idx] isolates this one qubit's Variable out of
# the N-long vector generic_1d_sweep handed to point_schedule.
schedule.add(X(transmon.name, amp180=amplitude[qubit_idx]), ref_op=start_ref)
schedule.add(self.measure_system(
# measure_system wants the *list* of per-qubit Variables here,
# not one at a time, so it can reshape the dataset per qubit;
# a scalar would instead be broadcast unchanged to every qubit.
coords={"mw_amplitudes": amplitude}, bin_mode="average_append",
))
schedule.add(self.reset_system(method="passive"))
return schedule
def schedule_function(self, *, mw_amplitudes, repetitions, **kw) -> TimeableSchedule:
"""
Build the full multiplexed Rabi schedule.
Parameters
----------
mw_amplitudes : dict[str, numpy.ndarray]
Per-qubit amplitude setpoints (evenly spaced), keyed by qubit
name.
repetitions : int
Number of hardware repetitions of the schedule.
Returns
-------
qblox_scheduler.schedule.TimeableSchedule
The compiled hardware-loop schedule, ready for the node lifecycle
to run.
"""
schedule = TimeableSchedule("multiplexed_rabi_01", repetitions)
amplitude_domains = self.make_linear_domains(mw_amplitudes, DType.AMPLITUDE)
schedule.add(self.generic_1d_sweep(
linear_domains=amplitude_domains, point_schedule=self.point_schedule,
))
return schedule
Drive at the swept amplitude, measure, reset — the three helpers supply the
loop, the multiplexed readout and the reset. Note that the parallelism across
qubits is entirely a point_schedule concern: generic_1d_sweep only runs
the loop over amplitude and doesn’t know or care how many qubits are involved
— it hands point_schedule an N-long Variable vector each iteration and
lets it decide what to do with each entry.
Shot indices#
For single-shot experiments (bin_mode="append") the repetition itself must
become a schedule dimension, so it needs its own hardware loop and its own
loop variable.
make_shot_indices() builds
that domain: an integer
LinearDomain running
0 … repetitions-1.
shot_index is a keyword-only argument of generic_1d_sweep and
generic_2d_sweep:
left as
None(the default) — the average case, no shot dimension;point_scheduleis called aspoint_schedule(setpoint, ...).given a
Variable— obtained by looping overmake_shot_indices’s domain yourself (see the example below) — it is forwarded as the schedule builds each point, as the first positional argument:point_schedule(shot_index, setpoint, ...). Crucially, it is the sameVariableinstance passed to every point of the amplitude/frequency sweep — one shared loop variable, not one created per point — so every acquisition taken during a given repetition carries that repetition’s index, no matter which sweep point it belongs to.
The name shot_index is significant: configure_dataset (on
BaseNode) recognizes it by name. When pruning
coordinates that are not part of the schedule samplespace it explicitly keeps
any coordinate ending in shot_index, and when unstacking the flat
acquisition index it appends shot_index as an extra dataset dimension. A
shot index therefore never needs to be declared in the samplespace — tagging
the acquisition with a shot_index coordinate is enough for it to survive
into the final dataset as its own dimension.
Example: shots × amplitude × frequency (append)#
The readout combined-optimization node sweeps single shots against a 2-D
readout amplitude/frequency grid, for each of the qubit states being
distinguished. It combines everything above: generic_2d_sweep for the
amplitude/frequency grid, shot_index for the repetition dimension, and
both list and scalar/Variable coords broadcasting:
def point_schedule(
self,
shot_index: Variable,
ro_amplitude: list[Variable],
ro_frequency: list[Variable],
/,
) -> TimeableSchedule:
"""
Build the schedule for one (amplitude, frequency) point, for one shot.
Parameters
----------
shot_index : qblox_scheduler.operations.variables.Variable
This repetition's loop variable, shared by every point of the
amplitude/frequency sweep (see :ref:`shot-indices`). Attached as
a ``coords`` entry so it survives into the dataset unchanged.
ro_amplitude : list[qblox_scheduler.operations.variables.Variable]
One loop variable per qubit for the current readout amplitude
(outer loop), in acquisition-channel order.
ro_frequency : list[qblox_scheduler.operations.variables.Variable]
One loop variable per qubit for the current readout frequency
(inner loop), in acquisition-channel order.
Returns
-------
qblox_scheduler.schedule.TimeableSchedule
Reset, prepare and measure for this point, once per requested
qubit state.
"""
schedule = TimeableSchedule("point_schedule")
for state in self.states: # e.g. [0, 1] or [0, 1, 2]
# Fresh ground state before preparing each candidate qubit state.
prep_ref = schedule.add(self.reset_system(method="passive"))
for transmon in self.transmons.values():
if state >= 1:
schedule.add(X(transmon.name), ref_op=prep_ref)
schedule.add(
self.measure_system(
coords={
# scalar -> broadcast unchanged to every qubit
"qubit_states": int(state),
# Variable (not a list) -> also broadcast: every
# qubit's acquisition at this point shares the same
# shot index
"shot_index": shot_index,
# lists -> indexed per qubit by measure_system,
# entry i goes to the qubit on acquisition channel i
"ro_amplitudes": ro_amplitude,
"ro_frequencies": ro_frequency,
},
bin_mode="append",
# device overrides: also per-qubit lists of Variables
pulse_amp=ro_amplitude,
freq=ro_frequency,
)
)
schedule.add(self.reset_system(method="passive"))
return schedule
def schedule_function(
self,
*,
ro_amplitudes: dict[str, np.ndarray],
ro_frequencies: dict[str, np.ndarray],
repetitions: int,
**kw,
) -> TimeableSchedule:
"""
Build the full single-shot amplitude x frequency schedule.
Parameters
----------
ro_amplitudes : dict[str, numpy.ndarray]
Per-qubit readout amplitude setpoints (evenly spaced), outer loop.
ro_frequencies : dict[str, numpy.ndarray]
Per-qubit readout frequency setpoints (evenly spaced), inner loop.
repetitions : int
Number of single shots taken at each (amplitude, frequency) point.
Returns
-------
qblox_scheduler.schedule.TimeableSchedule
The compiled-loop schedule: shots x amplitudes x frequencies.
"""
schedule = TimeableSchedule("ro_combined_optimization", repetitions)
amplitude_domains = self.make_linear_domains(ro_amplitudes, DType.AMPLITUDE)
frequency_domains = self.make_linear_domains(ro_frequencies, DType.FREQUENCY)
shot_index_domain = self.make_shot_indices(repetitions)
# The shot loop wraps generic_2d_sweep: one shot_index Variable is
# created per repetition, and that same Variable is threaded through
# every point of the amplitude/frequency sweep below.
with schedule.loop(shot_index_domain) as shot_loop:
schedule.add(self.generic_2d_sweep(
outer_linear_domains=amplitude_domains,
inner_linear_domains=frequency_domains,
point_schedule=self.point_schedule,
shot_index=shot_loop,
))
return schedule
(Simplified from
ROCombinedOptimizationMeasurement;
see the source for the full three-state variant.)
External sweeps: reduce_samplespace#
Not every parameter can live inside a pulse schedule — DC coupler currents from
the SPI DAC, for instance. Those sweeps are driven by
ExternalParameterNode
(see Core Concepts), which loops in software: at each iteration it calls
bragi_quantum.experiments.utils.measurement_utils.reduce_samplespace() to slice the full
external samplespace down to the current iteration’s value per element,
external_samplespace = {"dc_currents": {"q1": np.array([1e-3, 2e-3, 3e-3]), ...}}
reduce_samplespace(1, external_samplespace)
# -> {"dc_currents": {"q1": 2e-3, ...}}
hands that reduced slice to the node’s pre_measurement_operation (which
sets the physical hardware, e.g. ramps the DAC), executes the — typically
pre-compiled — schedule, and finally stacks the resulting datasets along the
external dimension.
Note
An external sweep is not the only software-driven loop. A
ScheduleQubitNode also accepts an
outer_schedule_samplespace
(see Core Concepts), and the two differ on a technical level:
with
outer_schedule_samplespacethe swept parameter is still a schedule parameter — at every iterationreduce_samplespaceslices the outer samplespace, the slice is merged into the schedule samplespace, and the schedule is recompiled with the point passed as an argument to the schedule builder. This is how measurements whose acquisition count exceeds the QRM_RF memory (e.g. large single-shot runs) are split into multiple hardware executions;with
external_samplespacethe parameter never enters the schedule at all — the schedule is compiled once, and each iteration only callspre_measurement_operationto set the physical hardware before re-running the same compiled schedule.
Frequency samplespace helpers#
Two functions in bragi_quantum.experiments.utils.samplespace generate the frequency sweep
arrays used by the spectroscopy nodes, reading their center frequency from the
device model of the active session rather than requiring it as input:
resonator_samples()— a linear sweep centered on the qubit’s readout frequency (clock_freqs.readout), shifted down by 200 kHz per excited state probed, with a default half-width of 1 MHz.qubit_samples()— a linear sweep centered on the qubit drive frequency. For the"01"transition it is centered onclock_freqs.f01(default half-width 5 MHz); for"12"it estimates the center asf01minus a parity-dependent anharmonicity guess (150 MHz for even-numbered qubits, 250 MHz for odd, default half-width 12 MHz), unlessuse_freq_12_from_config=Trueand an explicitf12exists in the device.
Executing a compiled schedule#
bragi_quantum.experiments.utils.schedule_execution.execute_schedule() is the low-level
runner the node lifecycle uses for each compiled schedule. It prepares the
instrument coordinator, starts the run in a background thread (with a progress
bar tracking the expected schedule duration), retrieves the acquisition as a
raw xarray.Dataset and stops the coordinator.
With save_cluster_metadata_to_disk=True it additionally documents the
hardware state of the run under
<data_path>/cluster_metadata/measurement_<N>/:
a full QCoDeS snapshot of every cluster before and after the run (
before.json/after.json) plus a unifiedsnapshot.diffbetween them — invaluable when debugging what the run changed on the instruments;the compiled Q1ASM programs of every sequencer (
sequencerX.jsonwith the full serialized sequencer data andsequencerX.q1asmwith the assembly text), organized by cluster and module;a
waveforms.jpgper module plotting the waveforms uploaded to each sequencer.