def _strat_distance_from_unitary(val: Any) -> float | None:
    """Attempts to compute a value's trace_distance_bound from its unitary."""
    u = unitary_protocol.unitary(val, default=None)

    if u is None:
        return NotImplemented

    if u.shape == (2, 2):
        squared = 1 - (0.5 * abs(u[0][0] + u[1][1])) ** 2
        if squared <= 0:
            return 0.0
        return squared**0.5

    return trace_distance_from_angle_list(np.angle(np.linalg.eigvals(u)))
Attempts to compute a value's trace_distance_bound from its unitary.
cirq-core/cirq/protocols/trace_distance_bound.py