def validate_mixture(supports_mixture: SupportsMixture):
    """Validates that the mixture's tuple are valid probabilities."""
    mixture_tuple = mixture(supports_mixture, None)
    if mixture_tuple is None:
        raise TypeError(f'{supports_mixture}_mixture did not have a _mixture_ method')

    def validate_probability(p, p_str):
        if p < 0:
            raise ValueError(f'{p_str} was less than 0.')
        elif p > 1:
            raise ValueError(f'{p_str} was greater than 1.')

    total = 0.0
    for p, val in mixture_tuple:
        validate_probability(p, f"{val}'s probability")
        total += p
    if not np.isclose(total, 1.0):
        raise ValueError('Sum of probabilities of a mixture was not 1.0')
Validates that the mixture's tuple are valid probabilities.
cirq-core/cirq/protocols/mixture_protocol.py