def test_shuffled_circuits_with_readout_benchmarking_errors_with_noise():
    """Test shuffled circuits with readout benchmarking with noise from sampler."""
    qubits = cirq.LineQubit.range(6)

    # Generate random input circuits
    input_circuits = _create_test_circuits(qubits, 6)

    sampler = NoisySingleQubitReadoutSampler(p0=0.1, p1=0.2, seed=1234)
    circuit_repetitions = 1
    rng = np.random.default_rng()
    readout_repetitions = 1000

    measurements, readout_calibration_results = (
        cirq.contrib.shuffle_circuits.run_shuffled_with_readout_benchmarking(
            input_circuits,
            sampler,
            circuit_repetitions,
            rng,
            num_random_bitstrings=100,
            readout_repetitions=readout_repetitions,
        )
    )

    for measurement in measurements:
        assert isinstance(measurement, ResultDict)

    for qlist, readout_calibration_result in readout_calibration_results.items():
        assert isinstance(qlist, tuple)
        assert all(isinstance(q, cirq.Qid) for q in qlist)
        assert isinstance(readout_calibration_result, SingleQubitReadoutCalibrationResult)

        for error in readout_calibration_result.zero_state_errors.values():
            assert 0.08 < error < 0.12
        for error in readout_calibration_result.one_state_errors.values():
            assert 0.18 < error < 0.22
        assert readout_calibration_result.repetitions == readout_repetitions
        assert isinstance(readout_calibration_result.timestamp, float)
Test shuffled circuits with readout benchmarking with noise from sampler.
cirq-core/cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py