49
49
_SQRT_ISWAP_FSIM_GATE_FAMILY = ops .FSimGateFamily (gates_to_accept = [cirq .SQRT_ISWAP ])
50
50
_SQRT_ISWAP_INV_FSIM_GATE_FAMILY = ops .FSimGateFamily (gates_to_accept = [cirq .SQRT_ISWAP_INV ])
51
51
_CZ_FSIM_GATE_FAMILY = ops .FSimGateFamily (gates_to_accept = [cirq .CZ ])
52
+ _SYC_GATE_FAMILY = cirq .GateFamily (ops .SYC )
53
+ _SQRT_ISWAP_GATE_FAMILY = cirq .GateFamily (cirq .SQRT_ISWAP )
54
+ _SQRT_ISWAP_INV_GATE_FAMILY = cirq .GateFamily (cirq .SQRT_ISWAP_INV )
55
+ _CZ_GATE_FAMILY = cirq .GateFamily (cirq .CZ )
52
56
53
57
54
58
# TODO(#5050) Add GlobalPhaseGate
55
59
# Target gates of `cirq_google.GoogleCZTargetGateset`.
56
- _CZ_TARGET_GATES = [_CZ_FSIM_GATE_FAMILY , _PHASED_XZ_GATE_FAMILY , _MEASUREMENT_GATE_FAMILY ]
60
+ _CZ_TARGET_GATES = [
61
+ _CZ_FSIM_GATE_FAMILY ,
62
+ _CZ_GATE_FAMILY ,
63
+ _PHASED_XZ_GATE_FAMILY ,
64
+ _MEASUREMENT_GATE_FAMILY ,
65
+ ]
57
66
# Target gates of `cirq_google.SycamoreTargetGateset`.
58
- _SYC_TARGET_GATES = [_SYC_FSIM_GATE_FAMILY , _PHASED_XZ_GATE_FAMILY , _MEASUREMENT_GATE_FAMILY ]
67
+ _SYC_TARGET_GATES = [
68
+ _SYC_FSIM_GATE_FAMILY ,
69
+ _SYC_GATE_FAMILY ,
70
+ _PHASED_XZ_GATE_FAMILY ,
71
+ _MEASUREMENT_GATE_FAMILY ,
72
+ ]
59
73
# Target gates of `cirq.SqrtIswapTargetGateset`
60
74
_SQRT_ISWAP_TARGET_GATES = [
61
75
_SQRT_ISWAP_FSIM_GATE_FAMILY ,
76
+ _SQRT_ISWAP_GATE_FAMILY ,
62
77
_PHASED_XZ_GATE_FAMILY ,
63
78
_MEASUREMENT_GATE_FAMILY ,
64
79
]
@@ -77,51 +92,44 @@ class _GateRepresentations:
77
92
78
93
Attributes:
79
94
gate_spec_name: The name of gate type in `GateSpecification`.
80
- deserialized_forms: Gate representations to be included when the corresponding
81
- `GateSpecification` gate type is deserialized into gatesets and gate durations.
82
- serializable_forms: GateFamilies used to check whether a given gate can be serialized to the
83
- gate type in this _GateRepresentation.
95
+ supported_gates: A list of gates that can be serialized into the `GateSpecification` with
96
+ the matching name.
84
97
"""
85
98
86
99
gate_spec_name : str
87
- deserialized_forms : List [GateOrFamily ]
88
- serializable_forms : List [ cirq . GateFamily ]
100
+ supported_gates : List [cirq . GateFamily ]
101
+
89
102
103
+ # Gates recognized by the GridDevice class. This controls the (de)serialization between
104
+ # `DeviceSpecification.valid_gates` and `cirq.Gateset`.
90
105
91
- """Valid gates for a GridDevice."""
106
+ # This is a superset of valid gates for a given `GridDevice` instance. The specific gateset depends
107
+ # on the underlying device.
108
+
109
+ # Edit this list to add support for new gates. If a new `_GateRepresentations` is added, add a new
110
+ # `GateSpecification` message in cirq-google/cirq_google/api/v2/device.proto.
111
+
112
+ # Update `_build_compilation_target_gatesets()` if the gate you are updating affects an existing
113
+ # CompilationTargetGateset there, or if you'd like to add another `CompilationTargetGateset` to
114
+ # allow users to transform their circuits that include your gate.
92
115
_GATES : List [_GateRepresentations ] = [
93
116
_GateRepresentations (
94
- gate_spec_name = 'syc' ,
95
- deserialized_forms = [_SYC_FSIM_GATE_FAMILY ],
96
- serializable_forms = [_SYC_FSIM_GATE_FAMILY , cirq .GateFamily (ops .SYC )],
117
+ gate_spec_name = 'syc' , supported_gates = [_SYC_FSIM_GATE_FAMILY , _SYC_GATE_FAMILY ]
97
118
),
98
119
_GateRepresentations (
99
120
gate_spec_name = 'sqrt_iswap' ,
100
- deserialized_forms = [_SQRT_ISWAP_FSIM_GATE_FAMILY ],
101
- serializable_forms = [_SQRT_ISWAP_FSIM_GATE_FAMILY , cirq .GateFamily (cirq .SQRT_ISWAP )],
121
+ supported_gates = [_SQRT_ISWAP_FSIM_GATE_FAMILY , _SQRT_ISWAP_GATE_FAMILY ],
102
122
),
103
123
_GateRepresentations (
104
124
gate_spec_name = 'sqrt_iswap_inv' ,
105
- deserialized_forms = [_SQRT_ISWAP_INV_FSIM_GATE_FAMILY ],
106
- serializable_forms = [_SQRT_ISWAP_INV_FSIM_GATE_FAMILY , cirq .GateFamily (cirq .SQRT_ISWAP_INV )],
125
+ supported_gates = [_SQRT_ISWAP_INV_FSIM_GATE_FAMILY , _SQRT_ISWAP_INV_GATE_FAMILY ],
107
126
),
108
127
_GateRepresentations (
109
- gate_spec_name = 'cz' ,
110
- deserialized_forms = [_CZ_FSIM_GATE_FAMILY ],
111
- serializable_forms = [_CZ_FSIM_GATE_FAMILY , cirq .GateFamily (cirq .CZ )],
128
+ gate_spec_name = 'cz' , supported_gates = [_CZ_FSIM_GATE_FAMILY , _CZ_GATE_FAMILY ]
112
129
),
113
130
_GateRepresentations (
114
131
gate_spec_name = 'phased_xz' ,
115
- deserialized_forms = [
116
- cirq .PhasedXZGate ,
117
- cirq .XPowGate ,
118
- cirq .YPowGate ,
119
- cirq .PhasedXPowGate ,
120
- cirq .HPowGate ,
121
- cirq .GateFamily (cirq .I ),
122
- cirq .ops .SingleQubitCliffordGate ,
123
- ],
124
- serializable_forms = [
132
+ supported_gates = [
125
133
# TODO: Extend support to cirq.IdentityGate.
126
134
cirq .GateFamily (cirq .I ),
127
135
cirq .GateFamily (cirq .PhasedXZGate ),
@@ -134,29 +142,20 @@ class _GateRepresentations:
134
142
),
135
143
_GateRepresentations (
136
144
gate_spec_name = 'virtual_zpow' ,
137
- deserialized_forms = [cirq .GateFamily (cirq .ZPowGate , tags_to_ignore = [ops .PhysicalZTag ()])],
138
- serializable_forms = [cirq .GateFamily (cirq .ZPowGate , tags_to_ignore = [ops .PhysicalZTag ()])],
145
+ supported_gates = [cirq .GateFamily (cirq .ZPowGate , tags_to_ignore = [ops .PhysicalZTag ()])],
139
146
),
140
147
_GateRepresentations (
141
148
gate_spec_name = 'physical_zpow' ,
142
- deserialized_forms = [cirq .GateFamily (cirq .ZPowGate , tags_to_accept = [ops .PhysicalZTag ()])],
143
- serializable_forms = [cirq .GateFamily (cirq .ZPowGate , tags_to_accept = [ops .PhysicalZTag ()])],
149
+ supported_gates = [cirq .GateFamily (cirq .ZPowGate , tags_to_accept = [ops .PhysicalZTag ()])],
144
150
),
145
151
_GateRepresentations (
146
152
gate_spec_name = 'coupler_pulse' ,
147
- deserialized_forms = [experimental_ops .CouplerPulse ],
148
- serializable_forms = [cirq .GateFamily (experimental_ops .CouplerPulse )],
149
- ),
150
- _GateRepresentations (
151
- gate_spec_name = 'meas' ,
152
- deserialized_forms = [cirq .MeasurementGate ],
153
- serializable_forms = [cirq .GateFamily (cirq .MeasurementGate )],
153
+ supported_gates = [cirq .GateFamily (experimental_ops .CouplerPulse )],
154
154
),
155
155
_GateRepresentations (
156
- gate_spec_name = 'wait' ,
157
- deserialized_forms = [cirq .WaitGate ],
158
- serializable_forms = [cirq .GateFamily (cirq .WaitGate )],
156
+ gate_spec_name = 'meas' , supported_gates = [cirq .GateFamily (cirq .MeasurementGate )]
159
157
),
158
+ _GateRepresentations (gate_spec_name = 'wait' , supported_gates = [cirq .GateFamily (cirq .WaitGate )]),
160
159
]
161
160
162
161
@@ -216,7 +215,7 @@ def _serialize_gateset_and_gate_durations(
216
215
for gate_family in gateset .gates :
217
216
gate_spec = v2 .device_pb2 .GateSpecification ()
218
217
gate_rep = next (
219
- (gr for gr in _GATES for gf in gr .serializable_forms if gf == gate_family ), None
218
+ (gr for gr in _GATES for gf in gr .supported_gates if gf == gate_family ), None
220
219
)
221
220
if gate_rep is None :
222
221
raise ValueError (f'Unrecognized gate: { gate_family } .' )
@@ -228,13 +227,13 @@ def _serialize_gateset_and_gate_durations(
228
227
# Set gate duration
229
228
gate_durations_picos = {
230
229
int (gate_durations [gf ].total_picos ())
231
- for gf in gate_rep .serializable_forms
230
+ for gf in gate_rep .supported_gates
232
231
if gf in gate_durations
233
232
}
234
233
if len (gate_durations_picos ) > 1 :
235
234
raise ValueError (
236
235
'Multiple gate families in the following list exist in the gate duration dict, and '
237
- f'they are expected to have the same duration value: { gate_rep .serializable_forms } '
236
+ f'they are expected to have the same duration value: { gate_rep .supported_gates } '
238
237
)
239
238
elif len (gate_durations_picos ) == 1 :
240
239
gate_spec .gate_duration_picos = gate_durations_picos .pop ()
@@ -269,10 +268,8 @@ def _deserialize_gateset_and_gate_durations(
269
268
)
270
269
continue
271
270
272
- gates_list .extend (gate_rep .deserialized_forms )
273
- for g in gate_rep .deserialized_forms :
274
- if not isinstance (g , cirq .GateFamily ):
275
- g = cirq .GateFamily (g )
271
+ gates_list .extend (gate_rep .supported_gates )
272
+ for g in gate_rep .supported_gates :
276
273
gate_durations [g ] = cirq .Duration (picos = gate_spec .gate_duration_picos )
277
274
278
275
# TODO(#5050) Add GlobalPhaseGate support
0 commit comments