Setting the file. One moment.
Subchapter 101.4
references/program-sets.mdMarkdown4 KBView on GitHub
Program sets run on the local simulator and on all gate-based QPUs. Support is one entry in the device’s action map — read it, never guess:
from braket.aws import AwsDevice
from braket.device_schema import DeviceActionType
device = AwsDevice("<device-arn>")
supported = DeviceActionType.OPENQASM_PROGRAM_SET in device.properties.actionfrom braket.circuits import Circuit, FreeParameter, Observable
from braket.devices import LocalSimulator
from braket.program_sets import CircuitBinding, ProgramSet
bell = Circuit().h(0).cnot(0, 1)
rotation = Circuit().rx(0, FreeParameter("a")).cnot(0, 1)
entangler = Circuit().h(0).cz(0, 1).ry(1, FreeParameter("phi"))
sweep = CircuitBinding(
circuit=rotation,
input_sets={"a": (0.1, 0.2, 0.3)},
)
program_set = ProgramSet([bell, sweep])
# Cartesian product of every circuit under every observable (3 circuits x 2 observables = 6 executables)
# https://amazon-braket-sdk-python.readthedocs.io/en/latest/_apidoc/braket.program_sets.program_set.html#braket.program_sets.program_set.ProgramSet.product
ProgramSet.product([bell, bell, bell], [Observable.Z() @ Observable.I(), Observable.I() @ Observable.X()])
# zip — the nth circuit in circuits list is bound by the nth input_set and the nth observable
# https://amazon-braket-sdk-python.readthedocs.io/en/latest/_apidoc/braket.program_sets.program_set.html#braket.program_sets.program_set.ProgramSet.zip
ProgramSet.zip([rotation, entangler], input_sets=[{"a": 0.1}, {"phi": 0.5}],
observables=[Observable.Z() @ Observable.I(), Observable.I() @ Observable.X()])
# shots is the TOTAL and must be divisible by program_set.total_executables
task = LocalSimulator().run(program_set, shots=300)
counts = [[r.counts for r in entry] for entry in task.result()] # indexed result[program][executable]AwsQuantumTaskBatch (opens in a new tab) (device.run_batch([...], shots=...)) — many independent tasks dispatched in parallel by the SDK, each billed its own per-task fee. Does not require device support.Always prefer a program set when the device supports it; fall back to run_batch if and only if the device doesn’t support program sets, as program sets supersede batches in most cases.