def assert_consistent_channel(gate: Any, rtol: float = 1e-5, atol: float = 1e-8):
    """Asserts that a given gate has Kraus operators and that they are properly normalized."""
    assert cirq.has_kraus(gate), f"Given gate {gate!r} does not return True for cirq.has_kraus."
    kraus_ops = cirq.kraus(gate)
    assert cirq.is_cptp(kraus_ops=kraus_ops, rtol=rtol, atol=atol), (
        f"Kraus operators for {gate!r} did not sum to identity up to expected tolerances. "
        f"Summed to {sum(m.T.conj() @ m for m in kraus_ops)}"
    )
Asserts that a given gate has Kraus operators and that they are properly normalized.
cirq-core/cirq/testing/consistent_channels.py