def check_noise_target_gates()

in src/braket/circuits/noise_helpers.py [0:0]


def check_noise_target_gates(noise: Noise, target_gates: Iterable[Type[Gate]]):
    """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`.
    Args:
        noise (Noise): A Noise class object to be applied to the circuit.
        target_gates (Union[Type[Gate], Iterable[Type[Gate]]]): Gate class or
            List of Gate classes which `noise` is applied to.
    """

    if not all(isinstance(g, type) and issubclass(g, Gate) for g in target_gates):
        raise TypeError("All elements in target_gates must be an instance of the Gate class")

    if noise.qubit_count > 1:
        for g in target_gates:
            fixed_qubit_count = g.fixed_qubit_count()
            if fixed_qubit_count is NotImplemented:
                raise ValueError(
                    f"Target gate {g} can be instantiated on a variable number of qubits,"
                    " but noise can only target gates with fixed qubit counts."
                )
            if fixed_qubit_count != noise.qubit_count:
                raise ValueError(
                    f"Target gate {g} acts on {fixed_qubit_count} qubits,"
                    f" but {noise} acts on {noise.qubit_count} qubits."
                )