-
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
Change GridDeviceMetadata qubit type to GridQubit #5633
Changes from 5 commits
18006b2
da9e55c
4ff386e
e4220cc
54e8a81
8c816be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,15 +101,22 @@ def __init__( | |
self.qubits = qubits | ||
self.gate_definitions = gate_definitions | ||
has_subcircuit_support: bool = cirq.FrozenCircuit in gate_definitions | ||
|
||
self._metadata = cirq.GridDeviceMetadata( | ||
qubit_pairs=[ | ||
(pair[0], pair[1]) | ||
for gate_defs in gate_definitions.values() | ||
for gate_def in gate_defs | ||
if gate_def.number_of_qubits == 2 | ||
for pair in gate_def.target_set | ||
if len(pair) == 2 and pair[0] < pair[1] | ||
], | ||
qubit_pairs=cast( | ||
List[Tuple[cirq.GridQubit, cirq.GridQubit]], | ||
[ | ||
(pair[0], pair[1]) | ||
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. put the cast here so you're casting less things? Like it still can infer the 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. I tried that at first, but mypy still complained (don't remember the exact error message, though) |
||
for gate_defs in gate_definitions.values() | ||
for gate_def in gate_defs | ||
if gate_def.number_of_qubits == 2 | ||
for pair in gate_def.target_set | ||
if len(pair) == 2 | ||
and pair[0] < pair[1] | ||
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. I know this was already here, but does this mean if you order your qubits "backwards" in target_set the metadata will report that there are no pairs? 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. Ah good catch. This was added when |
||
and isinstance(pair[0], cirq.GridQubit) | ||
and isinstance(pair[1], cirq.GridQubit) | ||
Comment on lines
+116
to
+117
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. doesn't this obviate the need for the cast? Usually mypy can use 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. I was hoping for that too, but unfortunately mypy complained (that the type is |
||
], | ||
), | ||
gateset=cirq.Gateset( | ||
*(g for g in gate_definitions.keys() if issubclass(g, cirq.Gate)), | ||
cirq.GlobalPhaseGate, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import cast, Dict, List, Optional, Set, TYPE_CHECKING | ||
from typing import Dict, List, Optional, Set, TYPE_CHECKING | ||
|
||
import abc | ||
import collections | ||
|
@@ -304,7 +304,7 @@ def place_line(self, device: 'cirq_google.GridDevice', length: int) -> GridQubit | |
if not device.metadata.qubit_set: | ||
return GridQubitLineTuple() | ||
|
||
start: GridQubit = cast(GridQubit, min(device.metadata.qubit_set)) | ||
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. nice |
||
start: GridQubit = min(device.metadata.qubit_set) | ||
sequences: List[LineSequence] = [] | ||
greedy_search: Dict[str, List[GreedySequenceSearch]] = { | ||
'minimal_connectivity': [_PickFewestNeighbors(device, start)], | ||
|
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.
wait, why do we need a cast here? Is it because you want to call
super()
instead of returningfrozenset(self.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.
Right.self.qubits
doesn't exist, and I wasn't sure about adding aself._qubits
attribute just for this when it's already accessible from the superclass but just with a more general type.edit: I tried it without the cast and actually mypy didn't complain locally. Will push it and see if it passes presubmits.
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.
Nope that didn't work, reverting back