def _estimate_std_devs_clifford(fidelity: float, n: int) -> tuple[float | None, float]:
    """Estimates the standard deviation of the measurement for Clifford circuits.

    Args:
        fidelity: The measured fidelity
        n: the number of measurements

    Returns:
        The standard deviation (estimated from the fidelity and a maximum bound
        on the variance regardless of what the true fidelity is)
    """

    # We use the Bhatia Davis inequality to estimate the variance of the
    # fidelity. This gives that:
    # Var[\hat{F}] <= (1 - F) . F / N
    # StdDev[\hat{F}] <= \sqrt{(1 - F) . F / N}
    #
    # By further using the fact that 0 <= F <= 1 we get:
    # StdDev[\hat{F}] <= \frac{1}{2 \sqrt{N}}

    # Because of the noisiness of the simulation, the estimated fidelity can be
    # outside the [0, 1] range. If that is the case, we just do not use it to
    # compute the estimate.
    in_range = fidelity >= 0 and fidelity <= 1.0
    std_dev_estimate = math.sqrt((1.0 - fidelity) * fidelity / n) if in_range else None

    std_dev_bound = 0.5 / math.sqrt(n)
    return std_dev_estimate, std_dev_bound
Estimates the standard deviation of the measurement for Clifford circuits.

    Args:
        fidelity: The measured fidelity
        n: the number of measurements

    Returns:
        The standard deviation (estimated from the fidelity and a maximum bound
        on the variance regardless of what the true fidelity is)
    
examples/direct_fidelity_estimation.py