def _analyze_readout_results(
    unshuffled_readout_measurements: list[ResultDict],
    random_bitstrings: np.ndarray,
    readout_repetitions: int,
    qubits: list[ops.Qid],
    timestamp: float,
) -> SingleQubitReadoutCalibrationResult:
    """Analyzes the readout error rates from the unshuffled measurements.

    Args:
        readout_measurements: A list of dictionaries containing the measurement results
                              for each readout calibration circuit.
        random_bitstrings: A numpy array of random bitstrings used for measuring readout.
        readout_repetitions: The number of repetitions for each readout bitstring.
        qubits: The list of qubits for which the readout error rates are to be calculated.

    Returns:
        A dictionary mapping each qubit to a tuple of readout error rates(e0 and e1),
        where e0 is the 0->1 readout error rate and e1 is the 1->0 readout error rate.
    """

    zero_state_trials = np.zeros((1, len(qubits)), dtype=np.int64)
    one_state_trials = np.zeros((1, len(qubits)), dtype=np.int64)
    zero_state_totals = np.zeros((1, len(qubits)), dtype=np.int64)
    one_state_totals = np.zeros((1, len(qubits)), dtype=np.int64)
    for measurement_result, bitstr in zip(unshuffled_readout_measurements, random_bitstrings):
        for _, trial_result in measurement_result.measurements.items():
            trial_result = trial_result.astype(np.int64)  # Cast to int64
            sample_counts = np.sum(trial_result, axis=0)

            zero_state_trials += sample_counts * (1 - bitstr)
            zero_state_totals += readout_repetitions * (1 - bitstr)
            one_state_trials += (readout_repetitions - sample_counts) * bitstr
            one_state_totals += readout_repetitions * bitstr

    zero_state_errors = {
        q: (
            zero_state_trials[0][qubit_idx] / zero_state_totals[0][qubit_idx]
            if zero_state_totals[0][qubit_idx] > 0
            else np.nan
        )
        for qubit_idx, q in enumerate(qubits)
    }

    one_state_errors = {
        q: (
            one_state_trials[0][qubit_idx] / one_state_totals[0][qubit_idx]
            if one_state_totals[0][qubit_idx] > 0
            else np.nan
        )
        for qubit_idx, q in enumerate(qubits)
    }
    return SingleQubitReadoutCalibrationResult(
        zero_state_errors=zero_state_errors,
        one_state_errors=one_state_errors,
        repetitions=readout_repetitions,
        timestamp=timestamp,
    )
Analyzes the readout error rates from the unshuffled measurements.

    Args:
        readout_measurements: A list of dictionaries containing the measurement results
                              for each readout calibration circuit.
        random_bitstrings: A numpy array of random bitstrings used for measuring readout.
        readout_repetitions: The number of repetitions for each readout bitstring.
        qubits: The list of qubits for which the readout error rates are to be calculated.

    Returns:
        A dictionary mapping each qubit to a tuple of readout error rates(e0 and e1),
        where e0 is the 0->1 readout error rate and e1 is the 1->0 readout error rate.
    
cirq-core/cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py