Skip to content

Commit b631919

Browse files
dstrain115BichengYing
authored andcommitted
Move Coupler to cirq_gooogle.ops (quantumlib#6697)
* Move Coupler to cirq_gooogle.ops - Noticed when adding code that there were circular imports due to Couplers api codes needing code from devices. - Moved this to ops directory instead, which avoids the circular import. - Note that, although GridQubit is in cirq.devices, LineQubit and NamedQubit are in cirq.ops, so this also seems to be a good place to put this class.
1 parent 3c34181 commit b631919

File tree

8 files changed

+7
-15
lines changed

8 files changed

+7
-15
lines changed

cirq-google/cirq_google/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from cirq_google._version import __version__
2121

2222
from cirq_google.devices import (
23-
Coupler,
2423
GoogleNoiseProperties,
2524
GridDevice,
2625
NoiseModelFromGoogleNoiseProperties,
@@ -56,6 +55,7 @@
5655

5756
from cirq_google.ops import (
5857
CalibrationTag,
58+
Coupler,
5959
FSimGateFamily,
6060
FSimViaModelTag,
6161
InternalGate,

cirq-google/cirq_google/api/v2/program.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import re
15-
from typing import TYPE_CHECKING
1615

1716
import cirq
1817

19-
if TYPE_CHECKING:
20-
import cirq
18+
from cirq_google.ops.coupler import Coupler
2119

2220
GRID_QUBIT_ID_PATTERN = r'^q?(-?\d+)_(-?\d+)$'
2321

@@ -35,9 +33,6 @@ def qubit_to_proto_id(q: cirq.Qid) -> str:
3533
For `cirq_google.Coupler`s, this id is `c_{qubit0}_{qubit1}` where
3634
qubit0 and qubit1 are the ids for the two Qid in the Coupler.
3735
"""
38-
# Avoid circular import
39-
from cirq_google.devices.coupler import Coupler
40-
4136
if isinstance(q, cirq.GridQubit):
4237
return f'{q.row}_{q.col}'
4338
elif isinstance(q, cirq.NamedQubit):
@@ -76,9 +71,6 @@ def qubit_from_proto_id(proto_id: str) -> cirq.Qid:
7671
Returns:
7772
A `cirq.Qid` corresponding to the proto id.
7873
"""
79-
# Avoid circular import
80-
from cirq_google.devices.coupler import Coupler
81-
8274
qubit_field = proto_id.split('_')
8375
num_coords = len(qubit_field)
8476
if proto_id[:2] == 'c_':

cirq-google/cirq_google/devices/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@
2121

2222
from cirq_google.devices.known_devices import Sycamore, Sycamore23
2323

24-
from cirq_google.devices.coupler import Coupler
25-
2624
from cirq_google.devices.grid_device import GridDevice

cirq-google/cirq_google/devices/grid_device.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from cirq_google import transformers
3838
from cirq_google.api import v2
3939
from cirq_google.devices import known_devices
40-
from cirq_google.devices.coupler import Coupler
4140
from cirq_google.experimental import ops as experimental_ops
4241

4342

@@ -623,7 +622,7 @@ def validate_operation(self, operation: cirq.Operation) -> None:
623622
raise ValueError(f'Operation {operation} contains a gate which is not supported.')
624623

625624
for q in operation.qubits:
626-
if isinstance(q, Coupler):
625+
if isinstance(q, ops.Coupler):
627626
if any(qc not in self._metadata.qubit_set for qc in q.qubits):
628627
raise ValueError(f'Qubits on coupler not on device: {q.qubits}.')
629628
if frozenset(q.qubits) not in self._metadata.qubit_pairs:

cirq-google/cirq_google/devices/grid_device_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import cirq
2222
import cirq_google
2323
from cirq_google.api import v2
24-
from cirq_google.devices import Coupler, grid_device
24+
from cirq_google.devices import grid_device
25+
from cirq_google.ops import Coupler
2526

2627

2728
GRID_HEIGHT = 5

cirq-google/cirq_google/ops/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
from cirq_google.ops.calibration_tag import CalibrationTag
2020

21+
from cirq_google.ops.coupler import Coupler
22+
2123
from cirq_google.ops.fsim_gate_family import FSimGateFamily
2224

2325
from cirq_google.ops.fsim_via_model_tag import FSimViaModelTag

0 commit comments

Comments
 (0)