Parallel XEB: Add option to specify pairs#6787
Merged
NoureldinYosri merged 7 commits intomainfrom Nov 8, 2024
Merged
Conversation
NoureldinYosri
approved these changes
Nov 7, 2024
| if qubits is None: | ||
| raise ValueError("Couldn't determine qubits from sampler. Please specify them.") | ||
| else: | ||
| qubits_set = set() |
Collaborator
There was a problem hiding this comment.
Suggested change
| qubits_set = set() | |
| qubit_set = set(itertools.chain(*pairs)) |
| def parallel_xeb_workflow( | ||
| sampler: 'cirq.Sampler', | ||
| qubits: Optional[Sequence['cirq.GridQubit']] = None, | ||
| pairs: Optional[Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]] = None, |
Collaborator
There was a problem hiding this comment.
usually new arguments go to the end
NoureldinYosri
requested changes
Nov 7, 2024
Collaborator
NoureldinYosri
left a comment
There was a problem hiding this comment.
lets move the new argument pairs to the end of the list
| graph = nx.Graph( | ||
| pair for pair in itertools.combinations(qubits, 2) if _manhattan_distance(*pair) == 1 | ||
| ) | ||
| if pairs is None: |
Collaborator
There was a problem hiding this comment.
extract this logic into a method and use it here and in the other methods
def qubits_and_pairs(
sampler: 'cirq.Sampler',
qubits: Optional[Sequence['cirq.GridQubit']] = None,
pairs: Optional[Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]] = None,
) -> Tuple[Sequence['cirq.GridQubit'], Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]]:
"""Extract qubits and pairs from sampler.
If qubits are not provided, then they are extracted from the pairs (if given) or the sampler.
If pairs are not provided then all pairs of adjacent qubits are used.
Args:
sampler: The quantum engine or simulator to run the circuits.
qubits: Optional list of qubits.
pairs: Optional list of pair to use.
Returns:
- Qubits to use.
- Pairs of qubits to use.
Raises:
ValueError: If qubits are not specified and can't be deduced from other arguments.
"""
if qubits is None:
if pairs is None:
qubits = _grid_qubits_for_sampler(sampler)
if qubits is None:
raise ValueError("Couldn't determine qubits from sampler. Please specify them.")
else:
qubits_set = set(itertools.chain(*pairs))
qubits = list(qubits_set)
if pairs is None:
pairs = [
pair for pair in itertools.combinations(qubits, 2) if _manhattan_distance(*pair) == 1
]
return qubits, pairs
NoureldinYosri
approved these changes
Nov 8, 2024
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6787 +/- ##
========================================
Coverage 97.85% 97.85%
========================================
Files 1081 1083 +2
Lines 93370 93537 +167
========================================
+ Hits 91364 91528 +164
- Misses 2006 2009 +3 ☔ View full report in Codecov by Sentry. |
BichengYing
pushed a commit
to BichengYing/Cirq
that referenced
this pull request
Jun 20, 2025
Co-authored-by: Noureldin <noureldinyosri@google.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.