|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -from typing import Collection, Dict, Optional, Iterable, List, Set, Tuple, cast |
| 15 | +from typing import Collection, Dict, Optional, List, Set, Tuple, cast |
16 | 16 |
|
17 | 17 | import cirq
|
18 |
| -from cirq import _compat |
19 | 18 | from cirq_google.api import v2
|
20 | 19 | from cirq_google.api.v2 import device_pb2
|
21 | 20 | from cirq_google.devices import grid_device
|
22 | 21 | from cirq_google.experimental.ops import coupler_pulse
|
23 | 22 | from cirq_google.ops import physical_z_tag, sycamore_gate
|
24 |
| -from cirq_google.serialization import op_serializer, serializable_gate_set |
25 | 23 |
|
26 | 24 | _2_QUBIT_TARGET_SET = "2_qubit_targets"
|
27 | 25 | _MEAS_TARGET_SET = "meas_targets"
|
@@ -55,42 +53,6 @@ def _parse_device(s: str) -> Tuple[List[cirq.GridQubit], Dict[str, Set[cirq.Grid
|
55 | 53 | return qubits, measurement_lines
|
56 | 54 |
|
57 | 55 |
|
58 |
| -@_compat.deprecated( |
59 |
| - deadline='v0.16', |
60 |
| - fix='This function will no longer be available.' |
61 |
| - ' `cirq_google.grid_device.create_device_specification_proto()` can be used' |
62 |
| - ' to generate a DeviceSpecification proto which matches the format expected' |
63 |
| - ' by GridDevice.', |
64 |
| -) |
65 |
| -def create_device_proto_from_diagram( |
66 |
| - ascii_grid: str, |
67 |
| - gate_sets: Optional[Iterable[serializable_gate_set.SerializableGateSet]] = None, |
68 |
| - durations_picos: Optional[Dict[str, int]] = None, |
69 |
| - out: Optional[device_pb2.DeviceSpecification] = None, |
70 |
| -) -> device_pb2.DeviceSpecification: |
71 |
| - """Parse ASCIIart device layout into DeviceSpecification proto. |
72 |
| - This function assumes that all pairs of adjacent qubits are valid targets |
73 |
| - for two-qubit gates. |
74 |
| - Args: |
75 |
| - ascii_grid: ASCII version of the grid (see _parse_device for details). |
76 |
| - gate_sets: Gate sets that define the translation between gate ids and |
77 |
| - cirq Gate objects. |
78 |
| - durations_picos: A map from gate ids to gate durations in picoseconds. |
79 |
| - out: If given, populate this proto, otherwise create a new proto. |
80 |
| - """ |
81 |
| - qubits, _ = _parse_device(ascii_grid) |
82 |
| - |
83 |
| - # Create a list of all adjacent pairs on the grid for two-qubit gates. |
84 |
| - qubit_set = frozenset(qubits) |
85 |
| - pairs: List[Tuple[cirq.Qid, cirq.Qid]] = [] |
86 |
| - for qubit in qubits: |
87 |
| - for neighbor in sorted(qubit.neighbors()): |
88 |
| - if neighbor > qubit and neighbor in qubit_set: |
89 |
| - pairs.append((qubit, neighbor)) |
90 |
| - |
91 |
| - return create_device_proto_for_qubits(qubits, pairs, gate_sets, durations_picos, out) |
92 |
| - |
93 |
| - |
94 | 56 | def _create_grid_device_from_diagram(
|
95 | 57 | ascii_grid: str,
|
96 | 58 | gateset: cirq.Gateset,
|
@@ -124,108 +86,6 @@ def _create_grid_device_from_diagram(
|
124 | 86 | return grid_device.GridDevice.from_proto(device_specification)
|
125 | 87 |
|
126 | 88 |
|
127 |
| -@_compat.deprecated( |
128 |
| - deadline='v0.16', |
129 |
| - fix='This function will no longer be available.' |
130 |
| - ' `cirq_google.grid_device.create_device_specification_proto()` can be used' |
131 |
| - ' to generate a DeviceSpecification proto which matches the format expected' |
132 |
| - ' by GridDevice.', |
133 |
| -) |
134 |
| -def create_device_proto_for_qubits( |
135 |
| - qubits: Collection[cirq.Qid], |
136 |
| - pairs: Collection[Tuple[cirq.Qid, cirq.Qid]], |
137 |
| - gate_sets: Optional[Iterable[serializable_gate_set.SerializableGateSet]] = None, |
138 |
| - durations_picos: Optional[Dict[str, int]] = None, |
139 |
| - out: Optional[device_pb2.DeviceSpecification] = None, |
140 |
| -) -> device_pb2.DeviceSpecification: |
141 |
| - """Create device spec for the given qubits and coupled pairs. |
142 |
| -
|
143 |
| - Args: |
144 |
| - qubits: Qubits that can perform single-qubit gates. |
145 |
| - pairs: Pairs of coupled qubits that can perform two-qubit gates. |
146 |
| - gate_sets: Gate sets that define the translation between gate ids and |
147 |
| - cirq Gate objects. |
148 |
| - durations_picos: A map from gate ids to gate durations in picoseconds. |
149 |
| - out: If given, populate this proto, otherwise create a new proto. |
150 |
| - """ |
151 |
| - if out is None: |
152 |
| - out = device_pb2.DeviceSpecification() |
153 |
| - |
154 |
| - # Create valid qubit list |
155 |
| - populate_qubits_in_device_proto(qubits, out) |
156 |
| - |
157 |
| - # Single qubit gates in this gateset |
158 |
| - single_qubit_gates = (cirq.PhasedXPowGate, cirq.PhasedXZGate, cirq.ZPowGate) |
159 |
| - |
160 |
| - # Set up a target set for measurement (any qubit permutation) |
161 |
| - meas_targets = out.valid_targets.add() |
162 |
| - meas_targets.name = _MEAS_TARGET_SET |
163 |
| - meas_targets.target_ordering = device_pb2.TargetSet.SUBSET_PERMUTATION |
164 |
| - |
165 |
| - # Set up a target set for 2 qubit gates (specified qubit pairs) |
166 |
| - populate_qubit_pairs_in_device_proto(pairs, out) |
167 |
| - |
168 |
| - # Create gate sets |
169 |
| - arg_def = device_pb2.ArgDefinition |
170 |
| - for gate_set in gate_sets or []: |
171 |
| - gs_proto = out.valid_gate_sets.add() |
172 |
| - gs_proto.name = gate_set.name |
173 |
| - gate_ids: Set[str] = set() |
174 |
| - for internal_type in gate_set.serializers: |
175 |
| - for serializer in gate_set.serializers[internal_type]: |
176 |
| - gate_id = serializer.serialized_id |
177 |
| - if gate_id in gate_ids: |
178 |
| - # Only add each type once |
179 |
| - continue |
180 |
| - |
181 |
| - gate_ids.add(gate_id) |
182 |
| - gate = gs_proto.valid_gates.add() |
183 |
| - gate.id = gate_id |
184 |
| - |
185 |
| - if not isinstance(serializer, op_serializer._GateOpSerializer): |
186 |
| - # This implies that 'serializer' handles non-gate ops, |
187 |
| - # such as CircuitOperations. No other properties apply. |
188 |
| - continue |
189 |
| - |
190 |
| - # Choose target set and number of qubits based on gate type. |
191 |
| - gate_type = internal_type |
192 |
| - |
193 |
| - # Note: if it is not a measurement gate and it's type |
194 |
| - # is not in the single_qubit_gates tuple, it's assumed to be a two qubit gate. |
195 |
| - if gate_type == cirq.MeasurementGate: |
196 |
| - gate.valid_targets.append(_MEAS_TARGET_SET) |
197 |
| - elif gate_type == cirq.WaitGate: |
198 |
| - # TODO: Refactor gate-sets / device to eliminate the need |
199 |
| - # to keep checking type here. |
200 |
| - # Github issue: |
201 |
| - # https://github.com/quantumlib/Cirq/issues/2537 |
202 |
| - gate.number_of_qubits = 1 |
203 |
| - elif gate_type in single_qubit_gates: |
204 |
| - gate.number_of_qubits = 1 |
205 |
| - else: |
206 |
| - # This must be a two-qubit gate |
207 |
| - gate.valid_targets.append(_2_QUBIT_TARGET_SET) |
208 |
| - gate.number_of_qubits = 2 |
209 |
| - |
210 |
| - # Add gate duration |
211 |
| - if durations_picos is not None and gate.id in durations_picos: |
212 |
| - gate.gate_duration_picos = durations_picos[gate.id] |
213 |
| - |
214 |
| - # Add argument names and types for each gate. |
215 |
| - for arg in serializer.args: |
216 |
| - new_arg = gate.valid_args.add() |
217 |
| - if arg.serialized_type == str: |
218 |
| - new_arg.type = arg_def.STRING |
219 |
| - if arg.serialized_type == float: |
220 |
| - new_arg.type = arg_def.FLOAT |
221 |
| - if arg.serialized_type == List[bool]: |
222 |
| - new_arg.type = arg_def.REPEATED_BOOLEAN |
223 |
| - new_arg.name = arg.serialized_name |
224 |
| - # Note: this does not yet support adding allowed_ranges |
225 |
| - |
226 |
| - return out |
227 |
| - |
228 |
| - |
229 | 89 | def populate_qubits_in_device_proto(
|
230 | 90 | qubits: Collection[cirq.Qid], out: device_pb2.DeviceSpecification
|
231 | 91 | ) -> None:
|
|
0 commit comments