cirq-core 1.6.0.dev20250609223500__py3-none-any.whl → 1.6.0.dev20250612013443__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cirq-core might be problematic. Click here for more details.
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/contrib/qasm_import/_parser.py +447 -6
- cirq/contrib/qasm_import/_parser_test.py +768 -35
- cirq/transformers/dynamical_decoupling.py +16 -6
- cirq/transformers/dynamical_decoupling_test.py +211 -193
- {cirq_core-1.6.0.dev20250609223500.dist-info → cirq_core-1.6.0.dev20250612013443.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250609223500.dist-info → cirq_core-1.6.0.dev20250612013443.dist-info}/RECORD +11 -11
- {cirq_core-1.6.0.dev20250609223500.dist-info → cirq_core-1.6.0.dev20250612013443.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250609223500.dist-info → cirq_core-1.6.0.dev20250612013443.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250609223500.dist-info → cirq_core-1.6.0.dev20250612013443.dist-info}/top_level.txt +0 -0
|
@@ -276,14 +276,24 @@ def add_dynamical_decoupling(
|
|
|
276
276
|
dd_iter_by_qubits[q] = cycle(base_dd_sequence)
|
|
277
277
|
# Need to insert a new moment before current moment
|
|
278
278
|
if new_moment_ops:
|
|
279
|
-
# Fill insertable idle moments in the new moment using dd sequence
|
|
280
|
-
for q in orig_circuit.all_qubits() - stop_pulling_through_qubits:
|
|
281
|
-
if busy_moment_range_by_qubit[q][0] < moment_id <= busy_moment_range_by_qubit[q][1]:
|
|
282
|
-
new_moment_ops.append(_update_pulled_through(q, next(dd_iter_by_qubits[q])))
|
|
283
279
|
moments_to_be_appended = _try_merge_single_qubit_ops_of_two_moments(
|
|
284
|
-
transformed_moments
|
|
280
|
+
transformed_moments[-1], circuits.Moment(new_moment_ops)
|
|
285
281
|
)
|
|
286
|
-
|
|
282
|
+
if len(moments_to_be_appended) == 1:
|
|
283
|
+
transformed_moments.pop()
|
|
284
|
+
transformed_moments.append(moments_to_be_appended[0])
|
|
285
|
+
else: # Fill insertable idle moments in the new moment using dd sequence
|
|
286
|
+
for q in orig_circuit.all_qubits() - stop_pulling_through_qubits:
|
|
287
|
+
if (
|
|
288
|
+
busy_moment_range_by_qubit[q][0]
|
|
289
|
+
< moment_id
|
|
290
|
+
<= busy_moment_range_by_qubit[q][1]
|
|
291
|
+
):
|
|
292
|
+
new_moment_ops.append(_update_pulled_through(q, next(dd_iter_by_qubits[q])))
|
|
293
|
+
moments_to_be_appended = _try_merge_single_qubit_ops_of_two_moments(
|
|
294
|
+
transformed_moments.pop(), circuits.Moment(new_moment_ops)
|
|
295
|
+
)
|
|
296
|
+
transformed_moments.extend(moments_to_be_appended)
|
|
287
297
|
|
|
288
298
|
# Step 2, calc updated_moment with insertions / merges.
|
|
289
299
|
updated_moment_ops: set[cirq.Operation] = set()
|
|
@@ -20,7 +20,7 @@ import numpy as np
|
|
|
20
20
|
import pytest
|
|
21
21
|
|
|
22
22
|
import cirq
|
|
23
|
-
from cirq import add_dynamical_decoupling
|
|
23
|
+
from cirq import add_dynamical_decoupling, CNOT, CZ, CZPowGate, H, X, Y, Z
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
def assert_sim_eq(circuit1: cirq.AbstractCircuit, circuit2: cirq.AbstractCircuit):
|
|
@@ -68,11 +68,9 @@ def test_no_insertion():
|
|
|
68
68
|
b = cirq.NamedQubit('b')
|
|
69
69
|
|
|
70
70
|
assert_dd(
|
|
71
|
-
input_circuit=cirq.Circuit(
|
|
72
|
-
cirq.Moment(cirq.H(a)), cirq.Moment(cirq.CNOT(a, b)), cirq.Moment(cirq.H(b))
|
|
73
|
-
),
|
|
71
|
+
input_circuit=cirq.Circuit(cirq.Moment(H(a)), cirq.Moment(CNOT(a, b)), cirq.Moment(H(b))),
|
|
74
72
|
expected_circuit=cirq.Circuit(
|
|
75
|
-
cirq.Moment(
|
|
73
|
+
cirq.Moment(H(a)), cirq.Moment(CNOT(a, b)), cirq.Moment(H(b))
|
|
76
74
|
),
|
|
77
75
|
schema='XX_PAIR',
|
|
78
76
|
single_qubit_gate_moments_only=False,
|
|
@@ -81,12 +79,7 @@ def test_no_insertion():
|
|
|
81
79
|
|
|
82
80
|
@pytest.mark.parametrize(
|
|
83
81
|
'schema,inserted_gates',
|
|
84
|
-
[
|
|
85
|
-
('XX_PAIR', (cirq.X, cirq.X)),
|
|
86
|
-
('X_XINV', (cirq.X, cirq.X**-1)),
|
|
87
|
-
('YY_PAIR', (cirq.Y, cirq.Y)),
|
|
88
|
-
('Y_YINV', (cirq.Y, cirq.Y**-1)),
|
|
89
|
-
],
|
|
82
|
+
[('XX_PAIR', (X, X)), ('X_XINV', (X, X**-1)), ('YY_PAIR', (Y, Y)), ('Y_YINV', (Y, Y**-1))],
|
|
90
83
|
)
|
|
91
84
|
def test_insert_provided_schema(schema: str, inserted_gates: Sequence[cirq.Gate]):
|
|
92
85
|
"""Test case diagrams.
|
|
@@ -102,17 +95,17 @@ def test_insert_provided_schema(schema: str, inserted_gates: Sequence[cirq.Gate]
|
|
|
102
95
|
c = cirq.NamedQubit('c')
|
|
103
96
|
|
|
104
97
|
input_circuit = cirq.Circuit(
|
|
105
|
-
cirq.Moment(
|
|
106
|
-
cirq.Moment(
|
|
107
|
-
cirq.Moment(
|
|
108
|
-
cirq.Moment(
|
|
98
|
+
cirq.Moment(H(a)),
|
|
99
|
+
cirq.Moment(CNOT(a, b)),
|
|
100
|
+
cirq.Moment(CNOT(b, c)),
|
|
101
|
+
cirq.Moment(CNOT(b, c)),
|
|
109
102
|
cirq.Moment([cirq.M(qubit) for qubit in [a, b, c]]),
|
|
110
103
|
)
|
|
111
104
|
expected_circuit = cirq.Circuit(
|
|
112
|
-
cirq.Moment(
|
|
113
|
-
cirq.Moment(
|
|
114
|
-
cirq.Moment(
|
|
115
|
-
cirq.Moment(
|
|
105
|
+
cirq.Moment(H(a)),
|
|
106
|
+
cirq.Moment(CNOT(a, b)),
|
|
107
|
+
cirq.Moment(CNOT(b, c), inserted_gates[0](a)),
|
|
108
|
+
cirq.Moment(CNOT(b, c), inserted_gates[1](a)),
|
|
116
109
|
cirq.Moment([cirq.M(qubit) for qubit in [a, b, c]]),
|
|
117
110
|
)
|
|
118
111
|
|
|
@@ -141,24 +134,24 @@ def test_insert_by_customized_dd_sequence():
|
|
|
141
134
|
|
|
142
135
|
assert_dd(
|
|
143
136
|
input_circuit=cirq.Circuit(
|
|
144
|
-
cirq.Moment(
|
|
145
|
-
cirq.Moment(
|
|
146
|
-
cirq.Moment(
|
|
147
|
-
cirq.Moment(
|
|
148
|
-
cirq.Moment(
|
|
149
|
-
cirq.Moment(
|
|
150
|
-
cirq.Moment([
|
|
137
|
+
cirq.Moment(H(a)),
|
|
138
|
+
cirq.Moment(CNOT(a, b)),
|
|
139
|
+
cirq.Moment(CNOT(b, c)),
|
|
140
|
+
cirq.Moment(CNOT(b, c)),
|
|
141
|
+
cirq.Moment(CNOT(b, c)),
|
|
142
|
+
cirq.Moment(CNOT(b, c)),
|
|
143
|
+
cirq.Moment([H(qubit) for qubit in [a, b, c]]),
|
|
151
144
|
),
|
|
152
145
|
expected_circuit=cirq.Circuit(
|
|
153
|
-
cirq.Moment(
|
|
154
|
-
cirq.Moment(
|
|
155
|
-
cirq.Moment(
|
|
156
|
-
cirq.Moment(
|
|
157
|
-
cirq.Moment(
|
|
158
|
-
cirq.Moment(
|
|
159
|
-
cirq.Moment([
|
|
160
|
-
),
|
|
161
|
-
schema=[
|
|
146
|
+
cirq.Moment(H(a)),
|
|
147
|
+
cirq.Moment(CNOT(a, b)),
|
|
148
|
+
cirq.Moment(CNOT(b, c), X(a)),
|
|
149
|
+
cirq.Moment(CNOT(b, c), X(a)),
|
|
150
|
+
cirq.Moment(CNOT(b, c), Y(a)),
|
|
151
|
+
cirq.Moment(CNOT(b, c), Y(a)),
|
|
152
|
+
cirq.Moment([H(qubit) for qubit in [a, b, c]]),
|
|
153
|
+
),
|
|
154
|
+
schema=[X, X, Y, Y],
|
|
162
155
|
single_qubit_gate_moments_only=False,
|
|
163
156
|
)
|
|
164
157
|
|
|
@@ -180,19 +173,19 @@ def test_pull_through_h_gate_case1(single_qubit_gate_moments_only: bool):
|
|
|
180
173
|
|
|
181
174
|
assert_dd(
|
|
182
175
|
input_circuit=cirq.Circuit(
|
|
183
|
-
cirq.Moment(
|
|
184
|
-
cirq.Moment(
|
|
185
|
-
cirq.Moment(
|
|
186
|
-
cirq.Moment(
|
|
187
|
-
cirq.Moment(
|
|
176
|
+
cirq.Moment(H(a), H(b)),
|
|
177
|
+
cirq.Moment(H(b)),
|
|
178
|
+
cirq.Moment(H(a), H(b)),
|
|
179
|
+
cirq.Moment(H(b)),
|
|
180
|
+
cirq.Moment(CNOT(a, b)),
|
|
188
181
|
),
|
|
189
182
|
expected_circuit=cirq.Circuit(
|
|
190
|
-
cirq.Moment(
|
|
191
|
-
cirq.Moment(
|
|
192
|
-
cirq.Moment(
|
|
193
|
-
cirq.Moment(
|
|
194
|
-
cirq.Moment(
|
|
195
|
-
cirq.Moment(
|
|
183
|
+
cirq.Moment(H(a), H(b)),
|
|
184
|
+
cirq.Moment(H(b), X(a)),
|
|
185
|
+
cirq.Moment(H(a), H(b)),
|
|
186
|
+
cirq.Moment(H(b), X(a)),
|
|
187
|
+
cirq.Moment(CNOT(a, b)),
|
|
188
|
+
cirq.Moment(Y(a), X(b)),
|
|
196
189
|
),
|
|
197
190
|
schema="XX_PAIR",
|
|
198
191
|
single_qubit_gate_moments_only=single_qubit_gate_moments_only,
|
|
@@ -216,20 +209,19 @@ def test_pull_through_h_gate_case2(single_qubit_gate_moments_only: bool):
|
|
|
216
209
|
|
|
217
210
|
assert_dd(
|
|
218
211
|
input_circuit=cirq.Circuit(
|
|
219
|
-
cirq.Moment(
|
|
220
|
-
cirq.Moment(
|
|
221
|
-
cirq.Moment(
|
|
222
|
-
cirq.Moment(
|
|
223
|
-
cirq.Moment(
|
|
212
|
+
cirq.Moment(H(a), H(b)),
|
|
213
|
+
cirq.Moment(H(b)),
|
|
214
|
+
cirq.Moment(H(a), H(b)),
|
|
215
|
+
cirq.Moment(H(b)),
|
|
216
|
+
cirq.Moment(H(a), H(b)),
|
|
224
217
|
),
|
|
225
218
|
expected_circuit=cirq.Circuit(
|
|
226
|
-
cirq.Moment(
|
|
227
|
-
cirq.Moment(
|
|
228
|
-
cirq.Moment(
|
|
229
|
-
cirq.Moment(
|
|
219
|
+
cirq.Moment(H(a), H(b)),
|
|
220
|
+
cirq.Moment(H(b), X(a)),
|
|
221
|
+
cirq.Moment(H(a), H(b)),
|
|
222
|
+
cirq.Moment(H(b), X(a)),
|
|
230
223
|
cirq.Moment(
|
|
231
|
-
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=1).on(a),
|
|
232
|
-
cirq.H(b),
|
|
224
|
+
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=1).on(a), H(b)
|
|
233
225
|
),
|
|
234
226
|
),
|
|
235
227
|
schema="XX_PAIR",
|
|
@@ -241,14 +233,14 @@ def test_pull_through_h_gate_case2(single_qubit_gate_moments_only: bool):
|
|
|
241
233
|
'schema,error_msg_regex',
|
|
242
234
|
[
|
|
243
235
|
('INVALID_SCHEMA', 'Invalid schema name.'),
|
|
244
|
-
([
|
|
236
|
+
([X], 'Invalid dynamical decoupling sequence. Expect more than one gates.'),
|
|
245
237
|
(
|
|
246
|
-
[
|
|
238
|
+
[X, Y],
|
|
247
239
|
'Invalid dynamical decoupling sequence. Expect sequence production equals identity'
|
|
248
240
|
' up to a global phase, got',
|
|
249
241
|
),
|
|
250
242
|
(
|
|
251
|
-
[
|
|
243
|
+
[H, H],
|
|
252
244
|
'Dynamical decoupling sequence should only contain gates that are essentially'
|
|
253
245
|
' Pauli gates.',
|
|
254
246
|
),
|
|
@@ -256,7 +248,7 @@ def test_pull_through_h_gate_case2(single_qubit_gate_moments_only: bool):
|
|
|
256
248
|
)
|
|
257
249
|
def test_invalid_dd_schema(schema: str | tuple[cirq.Gate, ...], error_msg_regex):
|
|
258
250
|
a = cirq.NamedQubit('a')
|
|
259
|
-
input_circuit = cirq.Circuit(
|
|
251
|
+
input_circuit = cirq.Circuit(H(a))
|
|
260
252
|
with pytest.raises(ValueError, match=error_msg_regex):
|
|
261
253
|
add_dynamical_decoupling(input_circuit, schema=schema, single_qubit_gate_moments_only=False)
|
|
262
254
|
|
|
@@ -264,15 +256,15 @@ def test_invalid_dd_schema(schema: str | tuple[cirq.Gate, ...], error_msg_regex)
|
|
|
264
256
|
def test_single_qubit_gate_moments_only_no_updates_succeeds():
|
|
265
257
|
qubits = cirq.LineQubit.range(9)
|
|
266
258
|
input_circuit = cirq.Circuit(
|
|
267
|
-
cirq.Moment([
|
|
268
|
-
cirq.Moment(
|
|
269
|
-
cirq.Moment(
|
|
270
|
-
cirq.Moment([
|
|
271
|
-
cirq.Moment(
|
|
272
|
-
cirq.Moment([
|
|
273
|
-
cirq.Moment(
|
|
274
|
-
cirq.Moment([
|
|
275
|
-
cirq.Moment(
|
|
259
|
+
cirq.Moment([H(qubits[i]) for i in [3, 4, 5]]),
|
|
260
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
261
|
+
cirq.Moment(CZ(*qubits[3:5])),
|
|
262
|
+
cirq.Moment([H(qubits[i]) for i in [2, 3, 5, 6]]),
|
|
263
|
+
cirq.Moment(CZ(*qubits[2:4]), CNOT(*qubits[5:7])),
|
|
264
|
+
cirq.Moment([H(qubits[i]) for i in [1, 2, 6, 7]]),
|
|
265
|
+
cirq.Moment(CZ(*qubits[1:3]), CNOT(*qubits[6:8])),
|
|
266
|
+
cirq.Moment([H(qubits[i]) for i in [0, 1, 7, 8]]),
|
|
267
|
+
cirq.Moment(CZ(*qubits[0:2]), CNOT(*qubits[7:])),
|
|
276
268
|
)
|
|
277
269
|
add_dynamical_decoupling(input_circuit, schema='X_XINV', single_qubit_gate_moments_only=True)
|
|
278
270
|
|
|
@@ -338,37 +330,35 @@ def test_scattered_circuit():
|
|
|
338
330
|
"""
|
|
339
331
|
qubits = cirq.LineQubit.range(9)
|
|
340
332
|
input_circuit = cirq.Circuit(
|
|
341
|
-
cirq.Moment([
|
|
342
|
-
cirq.Moment(
|
|
343
|
-
cirq.Moment(
|
|
344
|
-
cirq.Moment([
|
|
345
|
-
cirq.Moment(
|
|
346
|
-
cirq.Moment([
|
|
347
|
-
cirq.Moment(
|
|
348
|
-
cirq.Moment([
|
|
349
|
-
cirq.Moment(
|
|
350
|
-
cirq.Moment([
|
|
333
|
+
cirq.Moment([H(qubits[i]) for i in [3, 4, 5]]),
|
|
334
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
335
|
+
cirq.Moment(CZ(*qubits[3:5])),
|
|
336
|
+
cirq.Moment([H(qubits[i]) for i in [2, 3, 5, 6]]),
|
|
337
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7])),
|
|
338
|
+
cirq.Moment([H(qubits[i]) for i in [1, 2, 6, 7]]),
|
|
339
|
+
cirq.Moment(CZ(*qubits[1:3]), CZ(*qubits[6:8])),
|
|
340
|
+
cirq.Moment([H(qubits[i]) for i in [0, 1, 7, 8]]),
|
|
341
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[7:])),
|
|
342
|
+
cirq.Moment([H(q) for q in qubits]),
|
|
351
343
|
)
|
|
352
344
|
expected_circuit_single_qubit_gate_on = cirq.Circuit(
|
|
353
|
-
cirq.Moment([
|
|
354
|
-
cirq.Moment(
|
|
355
|
-
cirq.Moment(
|
|
356
|
-
cirq.Moment([
|
|
357
|
-
cirq.Moment(
|
|
345
|
+
cirq.Moment([H(qubits[i]) for i in [3, 4, 5]]),
|
|
346
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
347
|
+
cirq.Moment(CZ(*qubits[3:5])),
|
|
348
|
+
cirq.Moment([H(qubits[i]) for i in [2, 3, 5, 6]] + [X(qubits[4])]),
|
|
349
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7])),
|
|
358
350
|
cirq.Moment(
|
|
359
|
-
[
|
|
360
|
-
+ [cirq.X(qubits[i]) for i in [3, 5]]
|
|
361
|
-
+ [cirq.Y(qubits[4])]
|
|
351
|
+
[H(qubits[i]) for i in [1, 2, 6, 7]] + [X(qubits[i]) for i in [3, 5]] + [Y(qubits[4])]
|
|
362
352
|
),
|
|
363
|
-
cirq.Moment(
|
|
353
|
+
cirq.Moment(CZ(*qubits[1:3]), CZ(*qubits[6:8])),
|
|
364
354
|
cirq.Moment(
|
|
365
|
-
[
|
|
366
|
-
+ [
|
|
367
|
-
+ [
|
|
355
|
+
[H(qubits[i]) for i in [0, 1, 7, 8]]
|
|
356
|
+
+ [X(qubits[i]) for i in [2, 4, 6]]
|
|
357
|
+
+ [Y(qubits[i]) for i in [3, 5]]
|
|
368
358
|
),
|
|
369
|
-
cirq.Moment(
|
|
359
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[7:])),
|
|
370
360
|
cirq.Moment(
|
|
371
|
-
[
|
|
361
|
+
[H(qubits[i]) for i in [0, 1, 7, 8]]
|
|
372
362
|
+ [
|
|
373
363
|
cirq.PhasedXZGate(axis_phase_exponent=-0.5, x_exponent=0.5, z_exponent=0).on(
|
|
374
364
|
qubits[2]
|
|
@@ -389,33 +379,29 @@ def test_scattered_circuit():
|
|
|
389
379
|
),
|
|
390
380
|
)
|
|
391
381
|
expected_circuit_single_qubit_gates_off = cirq.Circuit(
|
|
392
|
-
cirq.Moment([
|
|
393
|
-
cirq.Moment(
|
|
394
|
-
cirq.Moment(
|
|
395
|
-
cirq.Moment([
|
|
396
|
-
cirq.Moment(
|
|
382
|
+
cirq.Moment([H(qubits[i]) for i in [3, 4, 5]]),
|
|
383
|
+
cirq.Moment(CZ(*qubits[4:6]), X(qubits[3])),
|
|
384
|
+
cirq.Moment(CZ(*qubits[3:5]), X(qubits[5])),
|
|
385
|
+
cirq.Moment([H(qubits[i]) for i in [2, 3, 5, 6]] + [X(qubits[i]) for i in [4]]),
|
|
386
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7]), Y(qubits[4])),
|
|
397
387
|
cirq.Moment(
|
|
398
|
-
[
|
|
399
|
-
+ [cirq.Y(qubits[i]) for i in [3, 5]]
|
|
400
|
-
+ [cirq.X(qubits[4])]
|
|
388
|
+
[H(qubits[i]) for i in [1, 2, 6, 7]] + [Y(qubits[i]) for i in [3, 5]] + [X(qubits[4])]
|
|
401
389
|
),
|
|
402
390
|
cirq.Moment(
|
|
403
|
-
[
|
|
404
|
-
+ [cirq.X(qubits[i]) for i in [3, 5]]
|
|
405
|
-
+ [cirq.Y(qubits[4])]
|
|
391
|
+
[CZ(*qubits[1:3]), CZ(*qubits[6:8])] + [X(qubits[i]) for i in [3, 5]] + [Y(qubits[4])]
|
|
406
392
|
),
|
|
407
393
|
cirq.Moment(
|
|
408
|
-
[
|
|
409
|
-
+ [
|
|
410
|
-
+ [
|
|
394
|
+
[H(qubits[i]) for i in [0, 1, 7, 8]]
|
|
395
|
+
+ [X(qubits[i]) for i in [2, 4, 6]]
|
|
396
|
+
+ [Y(qubits[i]) for i in [3, 5]]
|
|
411
397
|
),
|
|
412
398
|
cirq.Moment(
|
|
413
|
-
[
|
|
414
|
-
+ [
|
|
415
|
-
+ [
|
|
399
|
+
[CZ(*qubits[0:2]), CZ(*qubits[7:])]
|
|
400
|
+
+ [X(qubits[i]) for i in [3, 5]]
|
|
401
|
+
+ [Y(qubits[i]) for i in [2, 4, 6]]
|
|
416
402
|
),
|
|
417
403
|
cirq.Moment(
|
|
418
|
-
[
|
|
404
|
+
[H(qubits[i]) for i in [0, 1, 4, 7, 8]]
|
|
419
405
|
+ [
|
|
420
406
|
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=0).on(
|
|
421
407
|
qubits[i]
|
|
@@ -480,18 +466,18 @@ def test_scattered_circuit2():
|
|
|
480
466
|
qubits = cirq.LineQubit.range(9)
|
|
481
467
|
assert_dd(
|
|
482
468
|
input_circuit=cirq.Circuit(
|
|
483
|
-
cirq.Moment(
|
|
484
|
-
cirq.Moment(
|
|
485
|
-
cirq.Moment(
|
|
486
|
-
cirq.Moment(
|
|
487
|
-
cirq.Moment(
|
|
469
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
470
|
+
cirq.Moment(CZ(*qubits[3:5])),
|
|
471
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7])),
|
|
472
|
+
cirq.Moment(CZ(*qubits[1:3]), CZ(*qubits[6:8])),
|
|
473
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[7:])),
|
|
488
474
|
),
|
|
489
475
|
expected_circuit=cirq.Circuit(
|
|
490
|
-
cirq.Moment(
|
|
491
|
-
cirq.Moment(
|
|
492
|
-
cirq.Moment(
|
|
493
|
-
cirq.Moment(
|
|
494
|
-
cirq.Moment(
|
|
476
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
477
|
+
cirq.Moment(CZ(*qubits[3:5]), X(qubits[5])),
|
|
478
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7])),
|
|
479
|
+
cirq.Moment(CZ(*qubits[1:3]), CZ(*qubits[6:8]), X(qubits[5])),
|
|
480
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[7:]), Z(qubits[6])),
|
|
495
481
|
),
|
|
496
482
|
schema="XX_PAIR",
|
|
497
483
|
single_qubit_gate_moments_only=False,
|
|
@@ -520,20 +506,20 @@ def test_pull_through_chain():
|
|
|
520
506
|
qubits = cirq.LineQubit.range(4)
|
|
521
507
|
assert_dd(
|
|
522
508
|
input_circuit=cirq.Circuit(
|
|
523
|
-
cirq.Moment(
|
|
524
|
-
cirq.Moment(
|
|
509
|
+
cirq.Moment(X(qubits[0])),
|
|
510
|
+
cirq.Moment(Y(qubits[1])),
|
|
525
511
|
cirq.Moment(cirq.SWAP(*qubits[0:2])),
|
|
526
512
|
cirq.Moment(cirq.SWAP(*qubits[1:3])),
|
|
527
513
|
cirq.Moment(cirq.SWAP(*qubits[2:4])),
|
|
528
|
-
cirq.Moment([
|
|
514
|
+
cirq.Moment([X(qubits[i]) for i in range(4)]),
|
|
529
515
|
),
|
|
530
516
|
expected_circuit=cirq.Circuit(
|
|
531
|
-
cirq.Moment(
|
|
532
|
-
cirq.Moment(
|
|
517
|
+
cirq.Moment(X(qubits[0])),
|
|
518
|
+
cirq.Moment(Y(qubits[1]), X(qubits[0])),
|
|
533
519
|
cirq.Moment(cirq.SWAP(*qubits[0:2])),
|
|
534
|
-
cirq.Moment([cirq.SWAP(*qubits[1:3])] + [
|
|
535
|
-
cirq.Moment([cirq.SWAP(*qubits[2:4])] + [
|
|
536
|
-
cirq.Moment(
|
|
520
|
+
cirq.Moment([cirq.SWAP(*qubits[1:3])] + [X(qubits[0])]),
|
|
521
|
+
cirq.Moment([cirq.SWAP(*qubits[2:4])] + [X(qubits[0]), X(qubits[1])]),
|
|
522
|
+
cirq.Moment(X(qubits[0]), cirq.I(qubits[1]), X(qubits[2]), cirq.I(qubits[3])),
|
|
537
523
|
),
|
|
538
524
|
schema='XX_PAIR',
|
|
539
525
|
single_qubit_gate_moments_only=False,
|
|
@@ -555,30 +541,29 @@ def test_multiple_clifford_pieces_case1():
|
|
|
555
541
|
b = cirq.NamedQubit('b')
|
|
556
542
|
assert_dd(
|
|
557
543
|
input_circuit=cirq.Circuit(
|
|
558
|
-
cirq.Moment(
|
|
559
|
-
cirq.Moment(
|
|
560
|
-
cirq.Moment(
|
|
561
|
-
cirq.Moment(
|
|
562
|
-
cirq.Moment(
|
|
563
|
-
cirq.Moment(
|
|
564
|
-
cirq.Moment(
|
|
565
|
-
cirq.Moment(
|
|
566
|
-
cirq.Moment(
|
|
544
|
+
cirq.Moment(H(a), H(b)),
|
|
545
|
+
cirq.Moment(H(b)),
|
|
546
|
+
cirq.Moment(H(a), H(b)),
|
|
547
|
+
cirq.Moment(H(b)),
|
|
548
|
+
cirq.Moment(CZPowGate(exponent=0.5).on(a, b)),
|
|
549
|
+
cirq.Moment(H(b)),
|
|
550
|
+
cirq.Moment(H(a), H(b)),
|
|
551
|
+
cirq.Moment(H(b)),
|
|
552
|
+
cirq.Moment(H(a), H(b)),
|
|
567
553
|
),
|
|
568
554
|
expected_circuit=cirq.Circuit(
|
|
569
|
-
cirq.Moment(
|
|
570
|
-
cirq.Moment(
|
|
571
|
-
cirq.Moment(
|
|
555
|
+
cirq.Moment(H(a), H(b)),
|
|
556
|
+
cirq.Moment(H(b), X(a)),
|
|
557
|
+
cirq.Moment(H(a), H(b)),
|
|
572
558
|
cirq.Moment(
|
|
573
|
-
|
|
574
|
-
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0, z_exponent=-1).on(a),
|
|
559
|
+
H(b), cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0, z_exponent=-1).on(a)
|
|
575
560
|
),
|
|
576
|
-
cirq.Moment(
|
|
577
|
-
cirq.Moment(
|
|
578
|
-
cirq.Moment(
|
|
579
|
-
cirq.Moment(
|
|
561
|
+
cirq.Moment(CZPowGate(exponent=0.5).on(a, b)),
|
|
562
|
+
cirq.Moment(H(b), X(a)),
|
|
563
|
+
cirq.Moment(H(a), H(b)),
|
|
564
|
+
cirq.Moment(H(b), X(a)),
|
|
580
565
|
cirq.Moment(
|
|
581
|
-
|
|
566
|
+
H(b),
|
|
582
567
|
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=-1).on(a),
|
|
583
568
|
),
|
|
584
569
|
),
|
|
@@ -603,19 +588,19 @@ def test_multiple_clifford_pieces_case2():
|
|
|
603
588
|
|
|
604
589
|
assert_dd(
|
|
605
590
|
input_circuit=cirq.Circuit(
|
|
606
|
-
cirq.Moment(
|
|
591
|
+
cirq.Moment(CZ(a, b)),
|
|
607
592
|
cirq.Moment(phased_xz_gate.on(a)),
|
|
608
593
|
cirq.Moment(phased_xz_gate.on(a)),
|
|
609
594
|
cirq.Moment(phased_xz_gate.on(a)),
|
|
610
|
-
cirq.Moment(
|
|
595
|
+
cirq.Moment(CZ(a, b)),
|
|
611
596
|
),
|
|
612
597
|
expected_circuit=cirq.Circuit(
|
|
613
|
-
cirq.Moment(
|
|
614
|
-
cirq.Moment(phased_xz_gate.on(a),
|
|
615
|
-
cirq.Moment(phased_xz_gate.on(a),
|
|
616
|
-
cirq.Moment(phased_xz_gate.on(a),
|
|
617
|
-
cirq.Moment(
|
|
618
|
-
cirq.Moment(
|
|
598
|
+
cirq.Moment(CZ(a, b)),
|
|
599
|
+
cirq.Moment(phased_xz_gate.on(a), X(b)),
|
|
600
|
+
cirq.Moment(phased_xz_gate.on(a), X(b)),
|
|
601
|
+
cirq.Moment(phased_xz_gate.on(a), X(b)),
|
|
602
|
+
cirq.Moment(CZ(a, b)),
|
|
603
|
+
cirq.Moment(Z(a), X(b)),
|
|
619
604
|
),
|
|
620
605
|
schema='XX_PAIR',
|
|
621
606
|
single_qubit_gate_moments_only=False,
|
|
@@ -642,20 +627,20 @@ def test_insert_new_moment():
|
|
|
642
627
|
c = cirq.NamedQubit('c')
|
|
643
628
|
assert_dd(
|
|
644
629
|
input_circuit=cirq.Circuit(
|
|
645
|
-
cirq.Moment(
|
|
646
|
-
cirq.Moment(
|
|
647
|
-
cirq.Moment(
|
|
648
|
-
cirq.Moment(
|
|
649
|
-
cirq.Moment(
|
|
630
|
+
cirq.Moment(H(a), H(b), H(c)),
|
|
631
|
+
cirq.Moment(H(b)),
|
|
632
|
+
cirq.Moment(H(b), H(a)),
|
|
633
|
+
cirq.Moment(CNOT(a, b)),
|
|
634
|
+
cirq.Moment(CZPowGate(exponent=0.5).on(a, b), H(c)),
|
|
650
635
|
),
|
|
651
636
|
expected_circuit=cirq.Circuit(
|
|
652
|
-
cirq.Moment(
|
|
653
|
-
cirq.Moment(
|
|
654
|
-
cirq.Moment(
|
|
655
|
-
cirq.Moment(
|
|
656
|
-
cirq.Moment(
|
|
637
|
+
cirq.Moment(H(a), H(b), H(c)),
|
|
638
|
+
cirq.Moment(H(b), X(a), X(c)),
|
|
639
|
+
cirq.Moment(H(a), H(b), X(c)),
|
|
640
|
+
cirq.Moment(CNOT(a, b)),
|
|
641
|
+
cirq.Moment(Z(a), X(c)),
|
|
657
642
|
cirq.Moment(
|
|
658
|
-
|
|
643
|
+
CZPowGate(exponent=0.5).on(a, b),
|
|
659
644
|
cirq.PhasedXZGate(axis_phase_exponent=-0.5, x_exponent=0.5, z_exponent=0).on(c),
|
|
660
645
|
),
|
|
661
646
|
),
|
|
@@ -685,22 +670,22 @@ def test_with_non_clifford_measurements():
|
|
|
685
670
|
qubits = cirq.LineQubit.range(4)
|
|
686
671
|
assert_dd(
|
|
687
672
|
input_circuit=cirq.Circuit(
|
|
688
|
-
cirq.Moment([
|
|
689
|
-
cirq.Moment(
|
|
690
|
-
cirq.Moment([
|
|
691
|
-
cirq.Moment(
|
|
692
|
-
cirq.Moment([
|
|
673
|
+
cirq.Moment([H(qubits[i]) for i in [1, 2]]),
|
|
674
|
+
cirq.Moment(CZ(*qubits[1:3])),
|
|
675
|
+
cirq.Moment([H(qubits[i]) for i in [0, 2, 3]]),
|
|
676
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[2:])),
|
|
677
|
+
cirq.Moment([H(qubits[i]) for i in [0, 3]]),
|
|
693
678
|
cirq.Moment([cirq.M(qubits[i]) for i in [0, 1, 2, 3]]),
|
|
694
679
|
),
|
|
695
680
|
expected_circuit=cirq.Circuit(
|
|
696
|
-
cirq.Moment([
|
|
697
|
-
cirq.Moment(
|
|
698
|
-
cirq.Moment([
|
|
699
|
-
cirq.Moment(
|
|
681
|
+
cirq.Moment([H(qubits[i]) for i in [1, 2]]),
|
|
682
|
+
cirq.Moment(CZ(*qubits[1:3])),
|
|
683
|
+
cirq.Moment([H(qubits[i]) for i in [0, 2, 3]] + [X(qubits[1])]),
|
|
684
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[2:])),
|
|
700
685
|
cirq.Moment(
|
|
701
|
-
|
|
686
|
+
H(qubits[3]),
|
|
702
687
|
cirq.I(qubits[2]),
|
|
703
|
-
|
|
688
|
+
X(qubits[1]),
|
|
704
689
|
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=0).on(
|
|
705
690
|
qubits[0]
|
|
706
691
|
),
|
|
@@ -751,16 +736,16 @@ def test_cross_clifford_pieces_filling_merge():
|
|
|
751
736
|
assert_dd(
|
|
752
737
|
input_circuit=cirq.Circuit(
|
|
753
738
|
cirq.Moment([phased_xz_gate.on(qubits[i]) for i in [2, 5]]),
|
|
754
|
-
cirq.Moment(
|
|
739
|
+
cirq.Moment(CZ(qubits[2], qubits[5])),
|
|
755
740
|
cirq.Moment([phased_xz_gate.on(qubits[i]) for i in [0, 1, 2, 3, 5]]),
|
|
756
741
|
cirq.Moment(
|
|
757
|
-
[
|
|
742
|
+
[CZ(qubits[i0], qubits[i1]) for i0, i1 in [(0, 1), (2, 3), (4, 5)]]
|
|
758
743
|
+ [phased_xz_gate.on(qubits[6])]
|
|
759
744
|
),
|
|
760
745
|
cirq.Moment([phased_xz_gate.on(qubits[i]) for i in [0, 1, 2, 5]]),
|
|
761
|
-
cirq.Moment([
|
|
746
|
+
cirq.Moment([CZ(qubits[i0], qubits[i1]) for i0, i1 in [(0, 1), (2, 3), (5, 6)]]),
|
|
762
747
|
cirq.Moment([phased_xz_gate.on(qubits[i]) for i in [0, 1, 5, 6]]),
|
|
763
|
-
cirq.Moment([
|
|
748
|
+
cirq.Moment([H.on(q) for q in qubits]),
|
|
764
749
|
),
|
|
765
750
|
expected_circuit="""
|
|
766
751
|
0: ─────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@─────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)─────H────────────────────────
|
|
@@ -794,11 +779,11 @@ def test_pull_through_phxz_gate_case1():
|
|
|
794
779
|
phxz = cirq.PhasedXZGate(axis_phase_exponent=0.25, x_exponent=-1, z_exponent=0)
|
|
795
780
|
assert_dd(
|
|
796
781
|
input_circuit=cirq.Circuit(
|
|
797
|
-
cirq.Moment(
|
|
798
|
-
cirq.Moment(
|
|
799
|
-
cirq.Moment(phxz(a),
|
|
800
|
-
cirq.Moment(
|
|
801
|
-
cirq.Moment(
|
|
782
|
+
cirq.Moment(H(a), H(b)),
|
|
783
|
+
cirq.Moment(H(b)),
|
|
784
|
+
cirq.Moment(phxz(a), H(b)),
|
|
785
|
+
cirq.Moment(H(b)),
|
|
786
|
+
cirq.Moment(CNOT(a, b)),
|
|
802
787
|
),
|
|
803
788
|
expected_circuit="""
|
|
804
789
|
a: ───H───X───PhXZ(a=0.25,x=-1,z=0)───X───@───Z───
|
|
@@ -823,11 +808,11 @@ def test_pull_through_phxz_gate_case2():
|
|
|
823
808
|
phxz = cirq.PhasedXZGate(axis_phase_exponent=0.2, x_exponent=-1, z_exponent=0)
|
|
824
809
|
assert_dd(
|
|
825
810
|
input_circuit=cirq.Circuit(
|
|
826
|
-
cirq.Moment(
|
|
827
|
-
cirq.Moment(
|
|
828
|
-
cirq.Moment(phxz(a),
|
|
829
|
-
cirq.Moment(
|
|
830
|
-
cirq.Moment(
|
|
811
|
+
cirq.Moment(H(a), H(b)),
|
|
812
|
+
cirq.Moment(H(b)),
|
|
813
|
+
cirq.Moment(phxz(a), H(b)),
|
|
814
|
+
cirq.Moment(H(b)),
|
|
815
|
+
cirq.Moment(CNOT(a, b)),
|
|
831
816
|
),
|
|
832
817
|
expected_circuit="""
|
|
833
818
|
a: ───H───X───PhXZ(a=0.1,x=0,z=0.4)───X───@───X───
|
|
@@ -836,3 +821,36 @@ b: ───H───H───H───────────────
|
|
|
836
821
|
""",
|
|
837
822
|
schema="XX_PAIR",
|
|
838
823
|
)
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
def test_merge_before_non_cliffords():
|
|
827
|
+
"""Test case diagrams.
|
|
828
|
+
Input circuit:
|
|
829
|
+
0: ───X──────────────────────────────────────────────────M───
|
|
830
|
+
|
|
831
|
+
1: ───X───────PhXZ(a=-1,x=0,z=-0.5)───FSim(0, 0.0637π)───M───
|
|
832
|
+
│
|
|
833
|
+
2: ───X───X───S───────────────────────FSim(0, 0.0637π)───M───
|
|
834
|
+
"""
|
|
835
|
+
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
836
|
+
input_circuit = cirq.Circuit(
|
|
837
|
+
cirq.Moment([X(q) for q in [q0, q1, q2]]),
|
|
838
|
+
cirq.Moment(X(q2)),
|
|
839
|
+
cirq.Moment(
|
|
840
|
+
cirq.PhasedXZGate(axis_phase_exponent=-1, x_exponent=0, z_exponent=-0.5).on(q1),
|
|
841
|
+
(Z**0.5).on(q2),
|
|
842
|
+
),
|
|
843
|
+
cirq.Moment(cirq.FSimGate(theta=0, phi=0.2).on(q1, q2)),
|
|
844
|
+
cirq.Moment([cirq.M(q) for q in [q0, q1, q2]]),
|
|
845
|
+
)
|
|
846
|
+
assert_dd(
|
|
847
|
+
input_circuit=input_circuit,
|
|
848
|
+
expected_circuit="""
|
|
849
|
+
0: ───X───X───X──────────────────────────────────────────M───
|
|
850
|
+
|
|
851
|
+
1: ───X───X───PhXZ(a=-1.25,x=1,z=0)───FSim(0, 0.0637π)───M───
|
|
852
|
+
│
|
|
853
|
+
2: ───X───X───S───────────────────────FSim(0, 0.0637π)───M───
|
|
854
|
+
""",
|
|
855
|
+
schema="XX_PAIR",
|
|
856
|
+
)
|
{cirq_core-1.6.0.dev20250609223500.dist-info → cirq_core-1.6.0.dev20250612013443.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.6.0.
|
|
3
|
+
Version: 1.6.0.dev20250612013443
|
|
4
4
|
Summary: A framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
|
|
5
5
|
Home-page: http://github.com/quantumlib/cirq
|
|
6
6
|
Author: The Cirq Developers
|