-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Combining readout circuits for QWC pauli strings in the measure_pauli_strings method
#7416
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e7958e0
Make the readout qubits consistent with the measurement qubits
ddddddanni be11ec4
Format
ddddddanni 0cd202a
remote unnecessary file
ddddddanni 02717e1
Fix dependency
ddddddanni 624b309
Merge branch 'main' into readout-qubits
ddddddanni 145038c
Fix format and type check
ddddddanni 61215b2
Move SingleQubitReadoutCalibrationResult out of type check
ddddddanni aba7de3
fix format again :)
ddddddanni f6cda49
Make changes based on @Nour's suggestions.
ddddddanni 0b48d9b
Fix lint
ddddddanni 27fa0ed
Fix format
ddddddanni a3d705e
Merge branch 'main' into readout-qubits
ddddddanni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
|
|
||
| from cirq import circuits, ops, work | ||
| from cirq.contrib.shuffle_circuits import run_shuffled_with_readout_benchmarking | ||
| from cirq.experiments.single_qubit_readout_calibration import SingleQubitReadoutCalibrationResult | ||
| from cirq.experiments.readout_confusion_matrix import TensoredConfusionMatrices | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -217,6 +218,31 @@ def _normalize_input_paulis( | |
| return cast(dict[circuits.FrozenCircuit, list[list[ops.PauliString]]], circuits_to_pauli) | ||
|
|
||
|
|
||
| def _extract_readout_qubits(pauli_strings: list[ops.PauliString]) -> list[ops.Qid]: | ||
| """Extracts unique qubits from a list of QWC Pauli strings.""" | ||
| qubits = set() | ||
| for pauli_str in pauli_strings: | ||
| for qubit in pauli_str.qubits: | ||
| qubits.add(qubit) | ||
| return sorted(qubits) | ||
|
|
||
|
|
||
| def _build_pauli_string_calibration_result( | ||
| qubits_to_error: SingleQubitReadoutCalibrationResult, readout_qubits: list[ops.Qid] | ||
| ) -> SingleQubitReadoutCalibrationResult: | ||
| """Builds a calibration result for the specific readout qubits.""" | ||
| return SingleQubitReadoutCalibrationResult( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this should be a SingleQubitReadoutCalibrationResult method class SingleQubitReadoutCalibrationResult:
...
def readout_result_for_qubits(self, qubits) -> 'SingleQubitReadoutCalibrationResult':
...
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! Moved the method to under SingleQubitReadoutCalibrationResult |
||
| zero_state_errors={ | ||
| qubit: qubits_to_error.zero_state_errors[qubit] for qubit in readout_qubits | ||
| }, | ||
| one_state_errors={ | ||
| qubit: qubits_to_error.one_state_errors[qubit] for qubit in readout_qubits | ||
| }, | ||
| timestamp=qubits_to_error.timestamp, | ||
| repetitions=qubits_to_error.repetitions, | ||
| ) | ||
|
|
||
|
|
||
| def _pauli_strings_to_basis_change_ops( | ||
| pauli_strings: list[ops.PauliString], qid_list: list[ops.Qid] | ||
| ): | ||
|
|
@@ -315,13 +341,25 @@ def _process_pauli_measurement_results( | |
| for pauli_group_index, circuit_result in enumerate(circuit_results): | ||
| measurement_results = circuit_result.measurements["m"] | ||
| pauli_strs = pauli_string_groups[pauli_group_index] | ||
| pauli_readout_qubits = _extract_readout_qubits(pauli_strs) | ||
|
|
||
| calibration_result = ( | ||
| calibration_results[tuple(pauli_readout_qubits)] | ||
| if disable_readout_mitigation is False | ||
| else None | ||
| ) | ||
|
|
||
| for pauli_str in pauli_strs: | ||
| qubits_sorted = sorted(pauli_str.qubits) | ||
| qubit_indices = [qubits.index(q) for q in qubits_sorted] | ||
|
|
||
| pauli_str_calibration_result = ( | ||
| _build_pauli_string_calibration_result(calibration_result, qubits_sorted) | ||
| if disable_readout_mitigation is False | ||
| else None | ||
| ) | ||
| confusion_matrices = ( | ||
| _build_many_one_qubits_confusion_matrix(calibration_results[tuple(qubits_sorted)]) | ||
| _build_many_one_qubits_confusion_matrix(pauli_str_calibration_result) | ||
| if disable_readout_mitigation is False | ||
| else _build_many_one_qubits_empty_confusion_matrix(len(qubits_sorted)) | ||
| ) | ||
|
|
@@ -356,11 +394,7 @@ def _process_pauli_measurement_results( | |
| mitigated_stddev=d_m_with_coefficient, | ||
| unmitigated_expectation=unmitigated_value_with_coefficient, | ||
| unmitigated_stddev=d_unmit_with_coefficient, | ||
| calibration_result=( | ||
| calibration_results[tuple(qubits_sorted)] | ||
| if disable_readout_mitigation is False | ||
| else None | ||
| ), | ||
| calibration_result=(pauli_str_calibration_result), | ||
| ) | ||
| ) | ||
|
|
||
|
|
@@ -428,8 +462,7 @@ def measure_pauli_strings( | |
| unique_qubit_tuples = set() | ||
| for pauli_string_groups in normalized_circuits_to_pauli.values(): | ||
| for pauli_strings in pauli_string_groups: | ||
| for pauli_string in pauli_strings: | ||
| unique_qubit_tuples.add(tuple(sorted(pauli_string.qubits))) | ||
| unique_qubit_tuples.add(tuple(_extract_readout_qubits(pauli_strings))) | ||
| # qubits_list is a list of qubit tuples | ||
| qubits_list = sorted(unique_qubit_tuples) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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!