braket.circuits.braket_program_context module

class braket.circuits.braket_program_context.BraketProgramContext(circuit: Circuit | None = None)[source]

Bases: AbstractProgramContext

Inits a BraketProgramContext.

Parameters:

circuit (Optional[Circuit]) – A partially-built circuit to continue building with this context. Default: None.

property circuit: Circuit

The circuit being built in this context.

is_builtin_gate(name: str) bool[source]

Whether the gate is currently in scope as a built-in Braket gate.

Parameters:

name (str) – name of the built-in Braket gate

Returns:

bool – return TRUE if it is a built-in gate else FALSE.

add_phase_instruction(target: tuple[int], phase_value: float) None[source]

Add a global phase to the circuit.

Parameters:
  • target (tuple[int]) – Unused

  • phase_value (float) – The phase value to be applied

add_gate_instruction(gate_name: str, target: tuple[int], *params, ctrl_modifiers: list[int], power: float) None[source]

Add Braket gate to the circuit.

Parameters:
  • gate_name (str) – name of the built-in Braket gate.

  • target (tuple[int]) – control_qubits + target_qubits.

  • ctrl_modifiers (list[int]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in control-qubits in target. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the |0⟩ state and qubits 1 and 3 being in the |1⟩ state.

  • power (float) – Integer or fractional power to raise the gate to.

add_custom_unitary(unitary: ndarray, target: tuple[int]) None[source]

Add a custom Unitary instruction to the circuit

Parameters:
  • unitary (np.ndarray) – unitary matrix

  • target (tuple[int]) – control_qubits + target_qubits

add_noise_instruction(noise_instruction: str, target: list[int], probabilities: list[float]) None[source]

Method to add a noise instruction to the circuit

Parameters:
  • noise_instruction (str) – The name of the noise operation

  • target (list[int]) – The target qubit or qubits to which the noise operation is applied.

  • probabilities (list[float]) – The probabilities associated with each possible outcome of the noise operation.

add_kraus_instruction(matrices: list[ndarray], target: list[int]) None[source]

Method to add a Kraus instruction to the circuit

Parameters:
  • matrices (list[ndarray]) – The matrices defining the Kraus operation

  • target (list[int]) – The target qubit or qubits to which the Kraus operation is applied.

add_result(result: Amplitude | Expectation | Probability | Sample | StateVector | DensityMatrix | Variance | AdjointGradient) None[source]

Abstract method to add result type to the circuit

Parameters:

result (Results) – The result object representing the measurement results

handle_parameter_value(value: float | Expr) float | FreeParameterExpression[source]

Convert parameter value to required format.

Parameters:

value (Union[float, Expr]) – Value of the parameter

Returns:

Union[float, FreeParameterExpression] – Return the value directly if numeric, otherwise wraps the symbolic expression as a FreeParameterExpression.

add_measure(target: tuple[int]) None[source]

Add a measure instruction to the circuit

Parameters:

target (tuple[int]) – the target qubits to be measured.