1818 from cirq import RouteCQC
1919except ImportError :
2020 RouteCQC = NotImplemented
21+
22+ try :
23+ # Set the 'RECIRQ_IMPORT_FAILSAFE' environment variable to treat PyTket as an optional
24+ # dependency. We do this for CI testing against the next, pre-release Cirq version.
25+ import pytket
26+ import pytket .extensions .cirq
27+ from pytket .circuit import Node , Qubit
28+ from pytket .passes import SequencePass , RoutingPass , PlacementPass
29+ from pytket .predicates import CompilationUnit , ConnectivityPredicate
2130 try :
22- # Set the 'RECIRQ_IMPORT_FAILSAFE' environment variable to treat PyTket as an optional
23- # dependency. We do this for CI testing against the next, pre-release Cirq version.
24- import pytket
25- import pytket .extensions .cirq
26- from pytket .circuit import Node , Qubit
27- from pytket .passes import SequencePass , RoutingPass , PlacementPass
28- from pytket .predicates import CompilationUnit , ConnectivityPredicate
29- try :
30- from pytket .placement import GraphPlacement
31- except ImportError :
32- from pytket .routing import GraphPlacement
33-
34- try :
35- from pytket .architecture import Architecture
36- except ImportError :
37- from pytket .routing import Architecture
31+ from pytket .placement import GraphPlacement
3832 except ImportError :
39- if 'RECIRQ_IMPORT_FAILSAFE' in os .environ :
40- pytket = NotImplemented
41- else :
42- raise ImportError (
43- "Routing utilities don't exist in this version of Cirq and PyTket is not installed."
44- )
33+ from pytket .routing import GraphPlacement
34+
35+ try :
36+ from pytket .architecture import Architecture
37+ except ImportError :
38+ from pytket .routing import Architecture
39+ except ImportError :
40+ pytket = NotImplemented
41+ Node = NotImplemented
42+ Qubit = NotImplemented
43+ SequencePass = NotImplemented
44+ RoutingPass = NotImplemented
45+ PlacementPass = NotImplemented
46+ CompilationUnit = NotImplemented
47+ ConnectivityPredicate = NotImplemented
48+ GraphPlacement = NotImplemented
49+ Architecture = NotImplemented
50+ if 'RECIRQ_IMPORT_FAILSAFE' not in os .environ and RouteCQC is NotImplemented :
51+ raise ImportError (
52+ "Routing utilities don't exist in this version of Cirq and PyTket is not installed."
53+ )
4554
4655import recirq
4756
@@ -69,6 +78,10 @@ def calibration_data_to_graph(calib_dict: cg.Calibration) -> nx.Graph:
6978
7079def _qubit_index_edges (device : cirq .Device ):
7180 """Helper function in `_device_to_tket_device`."""
81+ if Node is NotImplemented :
82+ raise ImportError (
83+ "pytket-cirq is required for this function but not installed."
84+ )
7285 qubits = device .metadata .qubit_set if device .metadata else ()
7386 dev_graph = ccr .gridqubits_to_graph_device (qubits )
7487 for n1 , n2 in dev_graph .edges :
@@ -80,6 +93,10 @@ def _device_to_tket_device(device: cirq.Device):
8093
8194 This supports any device that supports `ccr.xmon_device_to_graph`.
8295 """
96+ if Architecture is NotImplemented :
97+ raise ImportError (
98+ "pytket-cirq is required for this function but not installed."
99+ )
83100 return Architecture (
84101 list (_qubit_index_edges (device ))
85102 )
0 commit comments