CircuitBinding
- class braket.program_sets.circuit_binding.CircuitBinding(circuit, input_sets=None, observables=None)[source]
Bases:
objectA single parametrized circuit and multiple parameter sets and observables.
In other words, running a circuit binding means running the circuit with each set of input parameters specified. Furthermore, observables are encoded as input parameters by way of Euler angle representation.
If both input parameters and observables are provided, then each combination is executed, resulting in a total number of runs equal to the product of the two. For example, if there are 3 input sets and 4 parameters (or a Hamiltonian with 4 terms), the circuit will be run 12 times.
Note: Circuits cannot have result types attached.
- Parameters:
circuit (Circuit) – The parametrized circuit
input_sets (ParameterSetsLike | None) – The inputs to the circuit, if specified.
observables (Sequence[Observable | PauliString | str] | Sum | None) – The observables or Hamiltonian to measure, if specified.
Examples
>>> circuit = Circuit().rx(0, FreeParameter("theta")).cnot(0, 1) >>> observable = 2.1 * X(0) @ Z(1) - 4.5 * Z(0) @ Y(1) # Sum Hamiltonian >>> # observable = [X(0) @ Z(1), Z(0) @ Y(1)] # Or a list of single-term observables >>> binding = CircuitBinding(circuit, {"theta": [1.23, 1.73, 0.73]}, observable)
- property input_sets: ParameterSets | None
The inputs to the circuit, if specified.
- Type:
ParameterSets | None
- property observables: Sequence[Observable] | Sum | None
The observables or qubit Hamiltonian to measure, if specified.
- Type:
Sequence[Observable] | Sum | None
- to_ir(*, gate_definitions=None)[source]
Serializes the circuit binding into a form that can run on a Braket device.
Observables are treated as input parameters via conversion to Euler angles.
- Parameters:
gate_definitions (dict[tuple[Gate, QubitSet], PulseSequence] | None) – The calibration data for the device. default: None.
- Return type:
Program- Returns:
Program – An OpenQASM program containing the serialized circuit and input parameters.
- bind_observables_to_inputs(inplace=True, add_measure=True)[source]
Bind observables to input sets of parameters.
Translates observables in a CircuitBinding to local measurement bases via a parameterized quantum circuit. The resulting composite input_set will be indexed to the same index in the CompositeEntry. entry.expectation will no longer work, and data will have to be processed as from a distribution. If using a Sum, information on the coefficients will be lost, as well as CompositeEntry.expectation.
- Kwargs:
inplace (bool): whether or not to return a new circuit binding or use the same one add_measure (bool): whether or not to apply Measure instructions to the circuit
- Return type:
- Returns:
CircuitBinding – A new circuit binding with the observables bound.
- Parameters:
inplace (
bool)add_measure (
bool)