13
13
# limitations under the License.
14
14
"""A combination of several optimizations targeting XmonDevice."""
15
15
from functools import lru_cache
16
- from typing import Callable , cast , List , Optional , TYPE_CHECKING
16
+ from typing import Callable , cast , Optional , TYPE_CHECKING
17
17
18
18
import numpy as np
19
19
20
20
import cirq
21
21
from cirq_google import ops as cg_ops
22
- from cirq_google .optimizers import (
23
- convert_to_xmon_gates ,
24
- )
25
22
from cirq_google .transformers .target_gatesets import sycamore_gateset
26
23
27
24
if TYPE_CHECKING :
28
25
import cirq_google
29
26
30
27
31
- def _get_xmon_optimizers (
32
- tolerance : float , tabulation : Optional [cirq .TwoQubitGateTabulation ]
33
- ) -> List [Callable [[cirq .Circuit ], None ]]:
34
- if tabulation is not None :
35
- # coverage: ignore
36
- raise ValueError ("Gate tabulation not supported for xmon" )
37
-
38
- return [
39
- convert_to_xmon_gates .ConvertToXmonGates ().optimize_circuit ,
40
- ]
41
-
42
-
43
- def _get_xmon_optimizers_part_cz (
44
- tolerance : float , tabulation : Optional [cirq .TwoQubitGateTabulation ]
45
- ) -> List [Callable [[cirq .Circuit ], None ]]:
46
- if tabulation is not None :
47
- # coverage: ignore
48
- raise ValueError ("Gate tabulation not supported for xmon" )
49
- return [
50
- convert_to_xmon_gates .ConvertToXmonGates ().optimize_circuit ,
51
- ]
52
-
53
-
54
- _OPTIMIZER_TYPES = {
55
- 'xmon' : _get_xmon_optimizers ,
56
- 'xmon_partial_cz' : _get_xmon_optimizers_part_cz ,
57
- }
58
-
59
28
_TARGET_GATESETS = {
60
29
'sqrt_iswap' : lambda atol , _ : cirq .SqrtIswapTargetGateset (atol = atol ),
61
30
'sycamore' : lambda atol , tabulation : sycamore_gateset .SycamoreTargetGateset (
@@ -122,10 +91,10 @@ def optimized_for_sycamore(
122
91
ValueError: If the `optimizer_type` is not a supported type.
123
92
"""
124
93
copy = circuit .copy ()
125
- if optimizer_type not in _OPTIMIZER_TYPES and optimizer_type not in _TARGET_GATESETS :
94
+ if optimizer_type not in _TARGET_GATESETS :
126
95
raise ValueError (
127
96
f'{ optimizer_type } is not an allowed type. Allowed '
128
- f'types are: { _OPTIMIZER_TYPES .keys ()} '
97
+ f'types are: { _TARGET_GATESETS .keys ()} '
129
98
)
130
99
131
100
tabulation : Optional [cirq .TwoQubitGateTabulation ] = None
@@ -137,10 +106,6 @@ def optimized_for_sycamore(
137
106
circuit ,
138
107
gateset = _TARGET_GATESETS [optimizer_type ](tolerance , tabulation ),
139
108
)
140
- if optimizer_type in _OPTIMIZER_TYPES :
141
- opts = _OPTIMIZER_TYPES [optimizer_type ](tolerance = tolerance , tabulation = tabulation )
142
- for optimizer in opts :
143
- optimizer (copy )
144
109
copy = cirq .merge_single_qubit_gates_to_phxz (copy , atol = tolerance )
145
110
copy = cirq .eject_phased_paulis (copy , atol = tolerance )
146
111
copy = cirq .eject_z (copy , atol = tolerance )
0 commit comments