async def estimate_characteristic_function(
    circuit: cirq.Circuit,
    pauli_string: cirq.PauliString,
    sampler: cirq.Sampler,
    samples_per_term: int,
) -> float:
    """Estimates the characteristic function using a (noisy) circuit simulator.

    Args:
        circuit: The circuit to run the simulation on.
        pauli_string: The Pauli string.
        sampler: Either a noisy simulator or an engine.
        samples_per_term: An integer greater than 0, the number of samples.

    Returns:
        The estimated characteristic function.
    """
    p = cirq.PauliSumCollector(
        circuit=circuit, observable=pauli_string, samples_per_term=samples_per_term
    )

    await p.collect_async(sampler=sampler)

    sigma_i = p.estimated_energy()
    assert np.isclose(sigma_i.imag, 0.0, atol=1e-6)
    sigma_i = sigma_i.real

    return sigma_i
Estimates the characteristic function using a (noisy) circuit simulator.

    Args:
        circuit: The circuit to run the simulation on.
        pauli_string: The Pauli string.
        sampler: Either a noisy simulator or an engine.
        samples_per_term: An integer greater than 0, the number of samples.

    Returns:
        The estimated characteristic function.
    
examples/direct_fidelity_estimation.py