braket.circuits.noise_helpers module

braket.circuits.noise_helpers.no_noise_applied_warning(noise_applied: bool) None[source]

Helper function to give a warning is noise is not applied.

Parameters:

noise_applied (bool) – True if the noise has been applied.

braket.circuits.noise_helpers.wrap_with_list(an_item: Any) list[Any][source]

Helper function to make the input parameter a list.

Parameters:

an_item (Any) – The item to wrap.

Returns:

list[Any] – The item wrapped in a list.

braket.circuits.noise_helpers.check_noise_target_gates(noise: Noise, target_gates: Iterable[type[Gate]]) None[source]

Helper function to check 1. whether all the elements in target_gates are a Gate type; 2. if noise is multi-qubit noise and target_gates contain gates with the number of qubits is the same as noise.qubit_count.

Parameters:
  • noise (Noise) – A Noise class object to be applied to the circuit.

  • target_gates (Iterable[type[Gate]]) – Gate class or List of Gate classes which noise is applied to.

braket.circuits.noise_helpers.check_noise_target_unitary(noise: Noise, target_unitary: ndarray) None[source]

Helper function to check 1. whether the input matrix is a np.ndarray type; 2. whether the target_unitary is a unitary;

Parameters:
  • noise (Noise) – A Noise class object to be applied to the circuit.

  • target_unitary (ndarray) – matrix of the target unitary gates

braket.circuits.noise_helpers.check_noise_target_qubits(circuit: Circuit, target_qubits: QubitSetInput | None = None) QubitSet[source]

Helper function to check whether all the target_qubits are positive integers.

Parameters:
  • circuit (Circuit) – A circuit where noise is to be checked.

  • target_qubits (Optional[QubitSetInput]) – Index or indices of qubit(s).

Returns:

QubitSet – The target qubits.

braket.circuits.noise_helpers.apply_noise_to_moments(circuit: Circuit, noise: Iterable[type[Noise]], target_qubits: QubitSet, position: str) Circuit[source]

Apply initialization/readout noise to the circuit.

When noise.qubit_count == 1, noise is added to all qubits in target_qubits.

When noise.qubit_count > 1, noise.qubit_count must be the same as the length of target_qubits.

Parameters:
  • circuit (Circuit) – A circuit to noise is applied to.

  • noise (Iterable[type[Noise]]) – Noise channel(s) to be applied to the circuit.

  • target_qubits (QubitSet) – Index or indices of qubits. noise is applied to.

  • position (str) – The position to add the noise to. May be ‘initialization’ or ‘readout_noise’.

Returns:

Circuit – modified circuit.

braket.circuits.noise_helpers.apply_noise_to_gates(circuit: Circuit, noise: Iterable[type[Noise]], target_gates: Iterable[type[Gate]] | np.ndarray, target_qubits: QubitSet) Circuit[source]

Apply noise after target gates in target qubits.

When noise.qubit_count == 1, noise is applied to target_qubits after target_gates.

When noise.qubit_count > 1, all elements in target_gates, if is given, must have the same number of qubits as noise.qubit_count.

Parameters:
  • circuit (Circuit) – A circuit where noise is applied to.

  • noise (Iterable[type[Noise]]) – Noise channel(s) to be applied to the circuit.

  • target_gates (Union[Iterable[type[Gate]], ndarray]) – List of gates, or a unitary matrix which noise is applied to.

  • target_qubits (QubitSet) – Index or indices of qubits which noise is applied to.

Returns:

Circuit – modified circuit.

Raises:

Warning – If noise is multi-qubit noise while there is no gate with the same number of qubits in target_qubits or in the whole circuit when target_qubits is not given. If no target_gates exist in target_qubits or in the whole circuit when target_qubits is not given.