-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[runtime] QubitPlacer 2 - RandomDevicePlacer (#4719)
As part of the cirqflow runtime, add `RandomDevicePlacer` which uses `cirq.get_placements` to map from a `NamedTopology` graph to a device graph. This requires shimming over the ability to get a device graph from a `cirq.Device`. @tanujkhattar @MichaelBroughton feel free to browse while I add tests
- Loading branch information
1 parent
bce3002
commit 7ffc77c
Showing
9 changed files
with
253 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
3 changes: 3 additions & 0 deletions
3
cirq-google/cirq_google/json_test_data/cirq.google.RandomDevicePlacer.json
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"cirq_type": "cirq.google.RandomDevicePlacer" | ||
} |
1 change: 1 addition & 0 deletions
1
cirq-google/cirq_google/json_test_data/cirq.google.RandomDevicePlacer.repr
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
cirq_google.RandomDevicePlacer() |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2021 The Cirq Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import itertools | ||
from typing import Iterable, cast | ||
|
||
import cirq | ||
import networkx as nx | ||
|
||
|
||
def _gridqubits_to_graph_device(qubits: Iterable[cirq.GridQubit]): | ||
return nx.Graph( | ||
pair for pair in itertools.combinations(qubits, 2) if pair[0].is_adjacent(pair[1]) | ||
) | ||
|
||
|
||
def _Device_dot_get_nx_graph(device: 'cirq.Device') -> nx.Graph: | ||
"""Shim over future `cirq.Device` method to get a NetworkX graph.""" | ||
return _gridqubits_to_graph_device(cast(Iterable[cirq.GridQubit], device.qubit_set())) |
This file contains 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
This file contains 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