-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Parallel XEB: Add option to specify pairs #6787
base: main
Are you sure you want to change the base?
Conversation
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.
LGTM%nit
if qubits is None: | ||
raise ValueError("Couldn't determine qubits from sampler. Please specify them.") | ||
else: | ||
qubits_set = 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.
qubits_set = set() | |
qubit_set = set(itertools.chain(*pairs)) |
@@ -351,6 +351,7 @@ def plot_histogram( | |||
def parallel_xeb_workflow( | |||
sampler: 'cirq.Sampler', | |||
qubits: Optional[Sequence['cirq.GridQubit']] = None, | |||
pairs: Optional[Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]] = 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.
usually new arguments go to the end
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 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: |
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.
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
No description provided.