batched_measurement#

batched_measurement(variables, backend, shots=None)[source]#

Measure multiple QuantumVariables in a single batched execution using a BatchedBackend.

All get_measurement calls are collected first (returning lazy results immediately), then dispatch() is called once to execute every circuit and populate all results together.

Deprecated since version 0.8: batched_measurement is deprecated. You can call get_measurement() on each variable with a BatchedBackend, then call dispatch() directly instead:

bb = backend.batched()
r1 = qv1.get_measurement(backend=bb)
r2 = qv2.get_measurement(backend=bb)
bb.dispatch()
Parameters:
variableslist[QuantumVariable]

A list of QuantumVariables to measure.

backendBatchedBackend

A batched backend obtained via Backend.batched().

shotsint, optional

Number of shots. Defaults to the backend’s shots option.

Returns:
resultslist[DecodedMeasurementResult]

One decoded result per variable, in the same order as variables.

Examples

from qrisp import QuantumFloat, batched_measurement
from qrisp.default_backend import QrispSimulatorBackend

bb = QrispSimulatorBackend().batched()

a = QuantumFloat(4)
b = QuantumFloat(3)
a[:] = 1
b[:] = 2
c = a + b

d = QuantumFloat(4)
e = QuantumFloat(3)
d[:] = 2
e[:] = 3
f = d + e

batched_measurement([c, f], backend=bb)
# Yields: [{3: 1.0}, {5: 1.0}]