Skip to content

Allow users to run readout benchmarking with sweep #7435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ddddddanni
Copy link
Contributor

Requested by @NoureldinYosri, this pr is splited from #7358.

The pr adds a new function run_sweep_with_readout_benchmarking which runs the sweep circuits with readout error benchmarking (without shuffling).

@github-actions github-actions bot added the size: L 250< lines changed <1000 label Jun 24, 2025
Copy link

codecov bot commented Jun 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.69%. Comparing base (9a58a8b) to head (e7e0077).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7435    +/-   ##
========================================
  Coverage   98.69%   98.69%            
========================================
  Files        1112     1112            
  Lines       98076    98199   +123     
========================================
+ Hits        96798    96921   +123     
  Misses       1278     1278            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ddddddanni
Copy link
Contributor Author

cc: @eliottrosenberg this is a smaller RP I split from #7358. This one only touches the readout benchmarking but not pauli expectation calculation.

@@ -84,6 +101,79 @@ def _generate_readout_calibration_circuits(
return readout_calibration_circuits, random_bitstrings


def _generate_parameterized_readout_calibration_circuit_with_sweep(
qubits: list[ops.Qid], rng: np.random.Generator, num_random_bitstrings: int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

traditionally rng should be the last input, same below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

qubits_set: set[ops.Qid] = set()
for circuit in input_circuits:
qubits_set.update(circuit.all_qubits())
qubits_to_measure = [sorted(qubits_set)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this can be a single line

Suggested change
qubits_to_measure = [sorted(qubits_set)]
qubits_to_measure = [sorted(set(q for circuit in input_circuits for q in circuit.all_qubits())]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ddddddanni overall LGTM%nits

# Check readout_repetitions is bigger than 0
if readout_repetitions <= 0:
raise ValueError("Must provide non-zero readout_repetitions for readout calibration.")
def _validate_experiment_input_with_sweep(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move this logic inside __attrs_post_init__

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this one could be moved to the attrs_post_init under ReadoutBenchmarkingParams? The reason is this is a specific validation if the experiment input is with sweep. However, the ReadoutBenchmarkingParams can be used by both sweep/non sweep functions.

@@ -24,7 +24,10 @@
import numpy as np

from cirq import circuits, ops, work
from cirq.contrib.shuffle_circuits import run_shuffled_with_readout_benchmarking
from cirq.contrib.shuffle_circuits import run_shuffled_circuits_with_readout_benchmarking
from cirq.contrib.shuffle_circuits.shuffle_circuits_with_readout_benchmarking import (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: lets use the Google convention here and import the modules


def _determine_qubits_to_measure(
input_circuits: Sequence[circuits.Circuit],
qubits: Optional[Sequence[ops.Qid] | Sequence[Sequence[ops.Qid]]],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type annotation for qubits is strange, why is a nested sequence?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because each input circuit can have a corresponding qubit list to be measured. And since the function can accept a list of circuits, so it has a corresponding list[list[qid]], where each list[qid] matches a circuit.

circuit_repetitions: int | list[int]
num_random_bitstrings: int = 100
readout_repetitions: int = 1000
qubits: Optional[Sequence[ops.Qid] | Sequence[Sequence[ops.Qid]]] = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it was my suggestion, but thinking again about it I think qubits shouldn't be part of the ReadoutBenchmarkingParams class

)

for measurement in measurements:
assert isinstance(measurement, ResultDict)
if mode == "shuffled":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move these two logic parts into two functions _circuits_with_readout_benchmarking_errors_with_noise_shuffled and _circuits_with_readout_benchmarking_errors_with_noise_sweep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants