-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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
qubits_to_measure = [sorted(qubits_set)] | |
qubits_to_measure = [sorted(set(q for circuit in input_circuits for q in circuit.all_qubits())] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
cirq-core/cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py
Show resolved
Hide resolved
cirq-core/cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py
Show resolved
Hide resolved
There was a problem hiding this 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( |
There was a problem hiding this comment.
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__
There was a problem hiding this comment.
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 ( |
There was a problem hiding this comment.
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]]], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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
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).