def _apply_kraus(kraus: tuple[np.ndarray] | Sequence[Any], args: ApplyChannelArgs) -> np.ndarray:
    """Directly apply the kraus operators to the target tensor."""
    # Initialize output.
    args.out_buffer[:] = 0
    # Stash initial state into buffer0.
    np.copyto(dst=args.auxiliary_buffer0, src=args.target_tensor)

    # Special case for single-qubit operations.
    if len(args.left_axes) == 1 and kraus[0].shape == (2, 2):
        return _apply_kraus_single_qubit(kraus, args)
    # Fallback to np.einsum for the general case.
    return _apply_kraus_multi_qubit(kraus, args)
Directly apply the kraus operators to the target tensor.
cirq-core/cirq/protocols/apply_channel_protocol.py