Skip to content
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

Add isolated qubit functionality for gridmetadata. #5001

Merged
merged 4 commits into from
Feb 18, 2022

Conversation

MichaelBroughton
Copy link
Collaborator

Adds isolated qubit property to GridDeviceMetadata. Also adds error checking for self loops. cc: @verult .

@MichaelBroughton MichaelBroughton requested review from a team, vtomole and cduck as code owners February 16, 2022 23:06
@CirqBot CirqBot added the size: M 50< lines changed <250 label Feb 16, 2022
@mpharrigan
Copy link
Collaborator

did you consider having the arguments be qubit_paris, all_qubits and have union semantics rather than the current intersection semantics? Networkx has more of the former when you can

g = nx.Graph()
g.add_edges_from(edgelist)
g.add_nodes_from(nodelist that may or may not include nodes in edges)

if (b, a) not in edge_set:
edge_set.add((a, b))

if isolated_qubits is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if we default isolated_qubits to an empty collection instead of None?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using empty collections is a dangerous default.

Here's a simplified example:

def f(value, key, store={}):
    store[value] = key
    return store

print(f('a', 1))
print(f('b', 2))

prints:

{'a': 1}
{'a': 1, 'b': 2}

Using it as None and then promoting it is a safer route that's recommended in the style guide.

@@ -39,12 +39,14 @@ def __init__(
qubit_pairs: Iterable[Tuple['cirq.Qid', 'cirq.Qid']],
gateset: 'cirq.Gateset',
gate_durations: Optional[Dict['cirq.GateFamily', 'cirq.Duration']] = None,
isolated_qubits: Optional[Iterable['cirq.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.

WDYT about using all_qubits instead?

Pros

  • DeviceSpecification keeps a full list of qubits, so the translation is easier. Current design plans to keep this field. This will minimize changes on Pyle side.
  • It will simplify the logic of computing the node set a bit, and also computing all_qubits for the super class constructor.

Cons

  • If we want to expose an isolated_qubits property, still need to calculate that separately. This somewhat voids the benefit of reducing code for computing all_qubits.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just saw @mpharrigan 's comment :P

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed over to all_qubits approach. PTAL.

Copy link
Collaborator

@verult verult left a comment

Choose a reason for hiding this comment

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

Thanks for explaining the None default! LGTM

for q in isolated_qubits:
if q in node_set:
all_qubits = frozenset(all_qubits)
for q in node_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: can be in the else block of if all_qubits is None.

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Feb 18, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Feb 18, 2022
@MichaelBroughton
Copy link
Collaborator Author

Oops looks like @verult isn't a code owner for cirq-core. We should probably fix that. In the meantime, would @95-martin-orion you mind approving as well ?

@CirqBot CirqBot merged commit 3517306 into quantumlib:master Feb 18, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Feb 18, 2022
@MichaelBroughton MichaelBroughton deleted the isolated_metadata branch February 22, 2022 23:09
95-martin-orion pushed a commit to 95-martin-orion/Cirq that referenced this pull request Mar 2, 2022
Adds isolated qubit property to GridDeviceMetadata. Also adds error checking for self loops. cc: @verult .
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Adds isolated qubit property to GridDeviceMetadata. Also adds error checking for self loops. cc: @verult .
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Adds isolated qubit property to GridDeviceMetadata. Also adds error checking for self loops. cc: @verult .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants