BraketProgramContext

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

Bases: AbstractProgramContext

Inits a BraketProgramContext.

Parameters:

circuit (Circuit | None) – 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)[source]

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

Parameters:

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

Return type:

bool

Returns:

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

add_phase_instruction(target, phase_value)[source]

Add a global phase to the circuit.

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

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

Return type:

None

add_gate_instruction(gate_name, target, *params, ctrl_modifiers, power)[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.

Return type:

None

add_custom_unitary(unitary, target)[source]

Add a custom Unitary instruction to the circuit

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

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

Return type:

None

add_noise_instruction(noise_instruction, target, probabilities)[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.

Return type:

None

add_kraus_instruction(matrices, target)[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.

Return type:

None

add_result(result)[source]

Abstract method to add result type to the circuit

Parameters:

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

Return type:

None

handle_parameter_value(value)[source]

Convert parameter value to required format.

Parameters:

value (float | Expr) – Value of the parameter

Return type:

float | FreeParameterExpression

Returns:

float | FreeParameterExpression] – Returns the value directly if numeric, otherwise wraps the symbolic expression as a FreeParameterExpression.

add_measure(target, classical_targets=None)[source]

Add a measure instruction to the circuit

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

  • classical_targets (Iterable[int] | None) – the classical registers to use in the qubit measurement.

Return type:

None

add_verbatim_marker(marker)[source]

Add verbatim markers

Parameters:

marker (VerbatimBoxDelimiter)

Return type:

None

add_barrier(target=None)[source]

Add a barrier instruction to the circuit.

Parameters:

target (QubitSetInput | None) – Target qubits for the barrier. If None or empty, applies barrier to all qubits in the circuit.

Return type:

None