def _validate_input(val: Any, args: ApplyMixtureArgs) -> tuple[Any, ApplyMixtureArgs, bool]:
    """Validate args input and determine if we are operating on a
    density matrix or a state vector.
    """

    is_density_matrix = False
    val_qid_shape = qid_shape_protocol.qid_shape(val, (2,) * len(args.left_axes))
    left_shape = tuple(args.target_tensor.shape[i] for i in args.left_axes)
    if val_qid_shape != left_shape:
        raise ValueError(
            'Invalid mixture qid shape is not equal to the '
            'selected left and right shape of target_tensor. '
            f'Got {val_qid_shape!r} but expected {left_shape!r}.'
        )

    if args.right_axes is not None:
        is_density_matrix = True

        right_shape = tuple(args.target_tensor.shape[i] for i in args.right_axes)
        if left_shape != right_shape:
            raise ValueError(
                'Invalid target_tensor shape or selected axes. '
                'The selected left and right shape of '
                f'target_tensor are not equal. Got {left_shape!r} and {right_shape!r}.'
            )

    return val, args, is_density_matrix
Validate args input and determine if we are operating on a
    density matrix or a state vector.
    
cirq-core/cirq/protocols/apply_mixture_protocol.py