def _check_and_get_real_coef(observable: cirq.PauliString, atol: float):
    """Assert that a PauliString has a real coefficient and return it."""
    coef = observable.coefficient
    if isinstance(coef, sympy.Expr) or not np.isclose(coef.imag, 0, atol=atol):
        raise ValueError(f"{observable} has a complex or symbolic coefficient.")
    return coef.real
Assert that a PauliString has a real coefficient and return it.
cirq-core/cirq/work/observable_measurement_data.py