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 andtarget_gates
contain gates with the number of qubits is the same asnoise.qubit_count
.
- 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 intarget_qubits
.When
noise.qubit_count
> 1,noise.qubit_count
must be the same as the length oftarget_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 aftertarget_gates
.When
noise.qubit_count
> 1, all elements intarget_gates
, if is given, must have the same number of qubits asnoise.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 intarget_qubits
or in the whole circuit whentarget_qubits
is not given. If notarget_gates
exist intarget_qubits
or in the whole circuit whentarget_qubits
is not given.