cirq-core 1.6.0.dev20250702182429__py3-none-any.whl → 1.6.0.dev20250704055727__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/circuits/circuit.py +4 -2
- cirq/circuits/circuit_operation.py +2 -2
- cirq/circuits/circuit_test.py +157 -148
- cirq/circuits/moment_test.py +61 -51
- cirq/circuits/optimization_pass.py +1 -1
- cirq/circuits/text_diagram_drawer.py +6 -6
- cirq/conftest.py +4 -3
- cirq/contrib/acquaintance/bipartite_test.py +10 -8
- cirq/contrib/acquaintance/devices_test.py +3 -3
- cirq/contrib/acquaintance/executor_test.py +8 -6
- cirq/contrib/acquaintance/gates.py +1 -1
- cirq/contrib/acquaintance/gates_test.py +18 -16
- cirq/contrib/acquaintance/inspection_utils.py +7 -3
- cirq/contrib/acquaintance/permutation_test.py +24 -17
- cirq/contrib/acquaintance/shift_swap_network_test.py +7 -6
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +8 -6
- cirq/contrib/bayesian_network/bayesian_network_gate.py +2 -2
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +10 -8
- cirq/contrib/circuitdag/circuit_dag.py +2 -2
- cirq/contrib/circuitdag/circuit_dag_test.py +15 -15
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +7 -3
- cirq/contrib/graph_device/graph_device.py +6 -5
- cirq/contrib/graph_device/graph_device_test.py +16 -14
- cirq/contrib/graph_device/hypergraph.py +2 -2
- cirq/contrib/graph_device/hypergraph_test.py +11 -11
- cirq/contrib/graph_device/uniform_graph_device_test.py +9 -3
- cirq/contrib/hacks/disable_validation.py +4 -1
- cirq/contrib/json.py +2 -2
- cirq/contrib/noise_models/noise_models.py +5 -5
- cirq/contrib/noise_models/noise_models_test.py +4 -0
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +1 -1
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +2 -1
- cirq/contrib/qcircuit/qcircuit_pdf.py +1 -1
- cirq/contrib/quantum_volume/quantum_volume_test.py +17 -16
- cirq/contrib/quimb/density_matrix.py +1 -1
- cirq/contrib/quimb/density_matrix_test.py +7 -7
- cirq/devices/noise_model_test.py +16 -14
- cirq/transformers/align.py +2 -2
- cirq/transformers/dynamical_decoupling.py +4 -4
- cirq/transformers/dynamical_decoupling_test.py +1 -1
- cirq/transformers/expand_composite_test.py +1 -1
- cirq/transformers/measurement_transformers.py +1 -1
- cirq/transformers/merge_single_qubit_gates.py +3 -3
- cirq/transformers/merge_single_qubit_gates_test.py +2 -2
- cirq/transformers/noise_adding.py +2 -2
- cirq/transformers/optimize_for_target_gateset.py +3 -3
- cirq/transformers/qubit_management_transformers.py +2 -2
- cirq/transformers/randomized_measurements.py +7 -7
- cirq/transformers/stratify.py +1 -1
- cirq/transformers/symbolize.py +1 -1
- cirq/transformers/tag_transformers.py +3 -3
- cirq/transformers/transformer_api.py +2 -2
- cirq/transformers/transformer_primitives.py +6 -6
- {cirq_core-1.6.0.dev20250702182429.dist-info → cirq_core-1.6.0.dev20250704055727.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250702182429.dist-info → cirq_core-1.6.0.dev20250704055727.dist-info}/RECORD +60 -60
- {cirq_core-1.6.0.dev20250702182429.dist-info → cirq_core-1.6.0.dev20250704055727.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250702182429.dist-info → cirq_core-1.6.0.dev20250704055727.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250702182429.dist-info → cirq_core-1.6.0.dev20250704055727.dist-info}/top_level.txt +0 -0
cirq/circuits/circuit_test.py
CHANGED
|
@@ -19,7 +19,7 @@ import os
|
|
|
19
19
|
import time
|
|
20
20
|
from collections import defaultdict
|
|
21
21
|
from random import randint, random, randrange, sample
|
|
22
|
-
from typing import Iterator
|
|
22
|
+
from typing import Iterator, Sequence
|
|
23
23
|
|
|
24
24
|
import numpy as np
|
|
25
25
|
import pytest
|
|
@@ -55,7 +55,7 @@ BCONE = ValidatingTestDevice(
|
|
|
55
55
|
q0, q1, q2, q3 = cirq.LineQubit.range(4)
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
def test_from_moments():
|
|
58
|
+
def test_from_moments() -> None:
|
|
59
59
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
60
60
|
moment = cirq.Moment(cirq.Z(a), cirq.Z(b))
|
|
61
61
|
subcircuit = cirq.FrozenCircuit.from_moments(cirq.X(c), cirq.Y(d))
|
|
@@ -83,15 +83,16 @@ def test_from_moments():
|
|
|
83
83
|
cirq.Moment(cirq.measure(a, b, key='ab'), cirq.measure(c, d, key='cd')),
|
|
84
84
|
)
|
|
85
85
|
assert circuit[0] is moment
|
|
86
|
+
assert isinstance(circuit[1].operations[0], cirq.CircuitOperation)
|
|
86
87
|
assert circuit[1].operations[0].circuit is subcircuit
|
|
87
88
|
|
|
88
89
|
|
|
89
|
-
def test_alignment():
|
|
90
|
+
def test_alignment() -> None:
|
|
90
91
|
assert repr(cirq.Alignment.LEFT) == 'cirq.Alignment.LEFT'
|
|
91
92
|
assert repr(cirq.Alignment.RIGHT) == 'cirq.Alignment.RIGHT'
|
|
92
93
|
|
|
93
94
|
|
|
94
|
-
def test_setitem():
|
|
95
|
+
def test_setitem() -> None:
|
|
95
96
|
circuit = cirq.Circuit([cirq.Moment(), cirq.Moment()])
|
|
96
97
|
|
|
97
98
|
circuit[1] = cirq.Moment([cirq.X(cirq.LineQubit(0))])
|
|
@@ -112,7 +113,7 @@ def test_setitem():
|
|
|
112
113
|
|
|
113
114
|
|
|
114
115
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
115
|
-
def test_equality(circuit_cls):
|
|
116
|
+
def test_equality(circuit_cls) -> None:
|
|
116
117
|
a = cirq.NamedQubit('a')
|
|
117
118
|
b = cirq.NamedQubit('b')
|
|
118
119
|
|
|
@@ -142,7 +143,7 @@ def test_equality(circuit_cls):
|
|
|
142
143
|
|
|
143
144
|
|
|
144
145
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
145
|
-
def test_approx_eq(circuit_cls):
|
|
146
|
+
def test_approx_eq(circuit_cls) -> None:
|
|
146
147
|
a = cirq.NamedQubit('a')
|
|
147
148
|
b = cirq.NamedQubit('b')
|
|
148
149
|
|
|
@@ -171,7 +172,7 @@ def test_approx_eq(circuit_cls):
|
|
|
171
172
|
)
|
|
172
173
|
|
|
173
174
|
|
|
174
|
-
def test_append_single():
|
|
175
|
+
def test_append_single() -> None:
|
|
175
176
|
a = cirq.NamedQubit('a')
|
|
176
177
|
|
|
177
178
|
c = cirq.Circuit()
|
|
@@ -193,7 +194,7 @@ def test_append_single():
|
|
|
193
194
|
)
|
|
194
195
|
|
|
195
196
|
|
|
196
|
-
def test_append_control_key():
|
|
197
|
+
def test_append_control_key() -> None:
|
|
197
198
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
198
199
|
c = cirq.Circuit()
|
|
199
200
|
c.append(cirq.measure(q0, key='a'))
|
|
@@ -207,7 +208,7 @@ def test_append_control_key():
|
|
|
207
208
|
assert len(c) == 1
|
|
208
209
|
|
|
209
210
|
|
|
210
|
-
def test_append_multiple():
|
|
211
|
+
def test_append_multiple() -> None:
|
|
211
212
|
a = cirq.NamedQubit('a')
|
|
212
213
|
b = cirq.NamedQubit('b')
|
|
213
214
|
|
|
@@ -225,7 +226,7 @@ def test_append_multiple():
|
|
|
225
226
|
assert c == cirq.Circuit([cirq.Moment([cirq.X(a), cirq.X(b)])])
|
|
226
227
|
|
|
227
228
|
|
|
228
|
-
def test_append_control_key_subcircuit():
|
|
229
|
+
def test_append_control_key_subcircuit() -> None:
|
|
229
230
|
q0, q1 = cirq.LineQubit.range(2)
|
|
230
231
|
|
|
231
232
|
c = cirq.Circuit()
|
|
@@ -291,7 +292,7 @@ def test_append_control_key_subcircuit():
|
|
|
291
292
|
assert len(c) == 1
|
|
292
293
|
|
|
293
294
|
|
|
294
|
-
def test_measurement_key_paths():
|
|
295
|
+
def test_measurement_key_paths() -> None:
|
|
295
296
|
a = cirq.LineQubit(0)
|
|
296
297
|
circuit1 = cirq.Circuit(cirq.measure(a, key='A'))
|
|
297
298
|
assert cirq.measurement_key_names(circuit1) == {'A'}
|
|
@@ -301,7 +302,7 @@ def test_measurement_key_paths():
|
|
|
301
302
|
assert cirq.measurement_key_names(circuit3) == {'C:B:A'}
|
|
302
303
|
|
|
303
304
|
|
|
304
|
-
def test_append_moments():
|
|
305
|
+
def test_append_moments() -> None:
|
|
305
306
|
a = cirq.NamedQubit('a')
|
|
306
307
|
b = cirq.NamedQubit('b')
|
|
307
308
|
|
|
@@ -320,7 +321,7 @@ def test_append_moments():
|
|
|
320
321
|
|
|
321
322
|
|
|
322
323
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
323
|
-
def test_add_op_tree(circuit_cls):
|
|
324
|
+
def test_add_op_tree(circuit_cls) -> None:
|
|
324
325
|
a = cirq.NamedQubit('a')
|
|
325
326
|
b = cirq.NamedQubit('b')
|
|
326
327
|
|
|
@@ -337,7 +338,7 @@ def test_add_op_tree(circuit_cls):
|
|
|
337
338
|
|
|
338
339
|
|
|
339
340
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
340
|
-
def test_radd_op_tree(circuit_cls):
|
|
341
|
+
def test_radd_op_tree(circuit_cls) -> None:
|
|
341
342
|
a = cirq.NamedQubit('a')
|
|
342
343
|
b = cirq.NamedQubit('b')
|
|
343
344
|
|
|
@@ -355,6 +356,7 @@ def test_radd_op_tree(circuit_cls):
|
|
|
355
356
|
_ = 0 + c
|
|
356
357
|
|
|
357
358
|
# non-empty circuit addition
|
|
359
|
+
d: cirq.AbstractCircuit
|
|
358
360
|
if circuit_cls == cirq.FrozenCircuit:
|
|
359
361
|
d = cirq.FrozenCircuit(cirq.Y(b))
|
|
360
362
|
else:
|
|
@@ -366,7 +368,7 @@ def test_radd_op_tree(circuit_cls):
|
|
|
366
368
|
)
|
|
367
369
|
|
|
368
370
|
|
|
369
|
-
def test_add_iadd_equivalence():
|
|
371
|
+
def test_add_iadd_equivalence() -> None:
|
|
370
372
|
q0, q1 = cirq.LineQubit.range(2)
|
|
371
373
|
iadd_circuit = cirq.Circuit(cirq.X(q0))
|
|
372
374
|
iadd_circuit += cirq.H(q1)
|
|
@@ -376,13 +378,13 @@ def test_add_iadd_equivalence():
|
|
|
376
378
|
|
|
377
379
|
|
|
378
380
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
379
|
-
def test_bool(circuit_cls):
|
|
381
|
+
def test_bool(circuit_cls) -> None:
|
|
380
382
|
assert not circuit_cls()
|
|
381
383
|
assert circuit_cls(cirq.X(cirq.NamedQubit('a')))
|
|
382
384
|
|
|
383
385
|
|
|
384
386
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
385
|
-
def test_repr(circuit_cls):
|
|
387
|
+
def test_repr(circuit_cls) -> None:
|
|
386
388
|
assert repr(circuit_cls()) == f'cirq.{circuit_cls.__name__}()'
|
|
387
389
|
|
|
388
390
|
a = cirq.NamedQubit('a')
|
|
@@ -407,7 +409,7 @@ def test_repr(circuit_cls):
|
|
|
407
409
|
|
|
408
410
|
|
|
409
411
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
410
|
-
def test_empty_moments(circuit_cls):
|
|
412
|
+
def test_empty_moments(circuit_cls) -> None:
|
|
411
413
|
# 1-qubit test
|
|
412
414
|
op = cirq.X(cirq.NamedQubit('a'))
|
|
413
415
|
op_moment = cirq.Moment([op])
|
|
@@ -512,7 +514,7 @@ a b
|
|
|
512
514
|
|
|
513
515
|
|
|
514
516
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
515
|
-
def test_symbol_addition_in_gate_exponent(circuit_cls):
|
|
517
|
+
def test_symbol_addition_in_gate_exponent(circuit_cls) -> None:
|
|
516
518
|
# 1-qubit test
|
|
517
519
|
qubit = cirq.NamedQubit('a')
|
|
518
520
|
circuit = circuit_cls(
|
|
@@ -558,7 +560,7 @@ Y^(a + b)
|
|
|
558
560
|
|
|
559
561
|
|
|
560
562
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
561
|
-
def test_slice(circuit_cls):
|
|
563
|
+
def test_slice(circuit_cls) -> None:
|
|
562
564
|
a = cirq.NamedQubit('a')
|
|
563
565
|
b = cirq.NamedQubit('b')
|
|
564
566
|
c = circuit_cls(
|
|
@@ -583,7 +585,7 @@ def test_slice(circuit_cls):
|
|
|
583
585
|
assert c[0:2:-1] == circuit_cls()
|
|
584
586
|
|
|
585
587
|
|
|
586
|
-
def test_concatenate():
|
|
588
|
+
def test_concatenate() -> None:
|
|
587
589
|
a = cirq.NamedQubit('a')
|
|
588
590
|
b = cirq.NamedQubit('b')
|
|
589
591
|
|
|
@@ -616,7 +618,7 @@ def test_concatenate():
|
|
|
616
618
|
|
|
617
619
|
|
|
618
620
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
619
|
-
def test_multiply(circuit_cls):
|
|
621
|
+
def test_multiply(circuit_cls) -> None:
|
|
620
622
|
a = cirq.NamedQubit('a')
|
|
621
623
|
|
|
622
624
|
c = circuit_cls()
|
|
@@ -650,7 +652,7 @@ def test_multiply(circuit_cls):
|
|
|
650
652
|
|
|
651
653
|
|
|
652
654
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
653
|
-
def test_container_methods(circuit_cls):
|
|
655
|
+
def test_container_methods(circuit_cls) -> None:
|
|
654
656
|
a = cirq.NamedQubit('a')
|
|
655
657
|
b = cirq.NamedQubit('b')
|
|
656
658
|
c = circuit_cls(
|
|
@@ -672,7 +674,7 @@ def test_container_methods(circuit_cls):
|
|
|
672
674
|
|
|
673
675
|
|
|
674
676
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
675
|
-
def test_bad_index(circuit_cls):
|
|
677
|
+
def test_bad_index(circuit_cls) -> None:
|
|
676
678
|
a = cirq.NamedQubit('a')
|
|
677
679
|
b = cirq.NamedQubit('b')
|
|
678
680
|
c = circuit_cls([cirq.Moment([cirq.H(a), cirq.H(b)])])
|
|
@@ -680,7 +682,7 @@ def test_bad_index(circuit_cls):
|
|
|
680
682
|
_ = c['string']
|
|
681
683
|
|
|
682
684
|
|
|
683
|
-
def test_append_strategies():
|
|
685
|
+
def test_append_strategies() -> None:
|
|
684
686
|
a = cirq.NamedQubit('a')
|
|
685
687
|
b = cirq.NamedQubit('b')
|
|
686
688
|
stream = [cirq.X(a), cirq.CZ(a, b), cirq.X(b), cirq.X(b), cirq.X(a)]
|
|
@@ -720,7 +722,7 @@ def test_append_strategies():
|
|
|
720
722
|
)
|
|
721
723
|
|
|
722
724
|
|
|
723
|
-
def test_insert_op_tree_new():
|
|
725
|
+
def test_insert_op_tree_new() -> None:
|
|
724
726
|
a = cirq.NamedQubit('alice')
|
|
725
727
|
b = cirq.NamedQubit('bob')
|
|
726
728
|
c = cirq.Circuit()
|
|
@@ -753,7 +755,7 @@ def test_insert_op_tree_new():
|
|
|
753
755
|
c.insert(1, cirq.X(a), BAD_INSERT)
|
|
754
756
|
|
|
755
757
|
|
|
756
|
-
def test_insert_op_tree_newinline():
|
|
758
|
+
def test_insert_op_tree_newinline() -> None:
|
|
757
759
|
a = cirq.NamedQubit('alice')
|
|
758
760
|
b = cirq.NamedQubit('bob')
|
|
759
761
|
c = cirq.Circuit()
|
|
@@ -778,7 +780,7 @@ def test_insert_op_tree_newinline():
|
|
|
778
780
|
assert c == c2
|
|
779
781
|
|
|
780
782
|
|
|
781
|
-
def test_insert_op_tree_inline():
|
|
783
|
+
def test_insert_op_tree_inline() -> None:
|
|
782
784
|
a = cirq.NamedQubit('alice')
|
|
783
785
|
b = cirq.NamedQubit('bob')
|
|
784
786
|
c = cirq.Circuit([cirq.Moment([cirq.H(a)])])
|
|
@@ -798,7 +800,7 @@ def test_insert_op_tree_inline():
|
|
|
798
800
|
assert c.operation_at(qubits[i], actual_index) == op_list[i]
|
|
799
801
|
|
|
800
802
|
|
|
801
|
-
def test_insert_op_tree_earliest():
|
|
803
|
+
def test_insert_op_tree_earliest() -> None:
|
|
802
804
|
a = cirq.NamedQubit('alice')
|
|
803
805
|
b = cirq.NamedQubit('bob')
|
|
804
806
|
c = cirq.Circuit([cirq.Moment([cirq.H(a)])])
|
|
@@ -815,7 +817,7 @@ def test_insert_op_tree_earliest():
|
|
|
815
817
|
assert c.operation_at(qubits[i], actual_index[i]) == op_list[i]
|
|
816
818
|
|
|
817
819
|
|
|
818
|
-
def test_insert_moment():
|
|
820
|
+
def test_insert_moment() -> None:
|
|
819
821
|
a = cirq.NamedQubit('alice')
|
|
820
822
|
b = cirq.NamedQubit('bob')
|
|
821
823
|
c = cirq.Circuit()
|
|
@@ -833,18 +835,18 @@ def test_insert_moment():
|
|
|
833
835
|
assert c.operation_at(qubit, actual_index) == operation[0]
|
|
834
836
|
|
|
835
837
|
|
|
836
|
-
def test_circuit_length_inference():
|
|
838
|
+
def test_circuit_length_inference() -> None:
|
|
837
839
|
# tests that `get_earliest_accommodating_moment_index` properly computes circuit length
|
|
838
840
|
circuit = cirq.Circuit(cirq.X(cirq.q(0)))
|
|
839
|
-
qubit_indices = {cirq.q(0): 0}
|
|
840
|
-
mkey_indices = {}
|
|
841
|
-
ckey_indices = {}
|
|
841
|
+
qubit_indices: dict[cirq.Qid, int] = {cirq.q(0): 0}
|
|
842
|
+
mkey_indices: dict[cirq.MeasurementKey, int] = {}
|
|
843
|
+
ckey_indices: dict[cirq.MeasurementKey, int] = {}
|
|
842
844
|
assert circuits.circuit.get_earliest_accommodating_moment_index(
|
|
843
845
|
cirq.Moment(), qubit_indices, mkey_indices, ckey_indices
|
|
844
846
|
) == len(circuit)
|
|
845
847
|
|
|
846
848
|
|
|
847
|
-
def test_insert_inline_near_start():
|
|
849
|
+
def test_insert_inline_near_start() -> None:
|
|
848
850
|
a = cirq.NamedQubit('a')
|
|
849
851
|
b = cirq.NamedQubit('b')
|
|
850
852
|
|
|
@@ -867,7 +869,7 @@ def test_insert_inline_near_start():
|
|
|
867
869
|
)
|
|
868
870
|
|
|
869
871
|
|
|
870
|
-
def test_insert_at_frontier_init():
|
|
872
|
+
def test_insert_at_frontier_init() -> None:
|
|
871
873
|
x = cirq.NamedQubit('x')
|
|
872
874
|
op = cirq.X(x)
|
|
873
875
|
circuit = cirq.Circuit(op)
|
|
@@ -882,11 +884,11 @@ def test_insert_at_frontier_init():
|
|
|
882
884
|
|
|
883
885
|
with pytest.raises(ValueError):
|
|
884
886
|
circuit = cirq.Circuit([cirq.Moment(), cirq.Moment([op])])
|
|
885
|
-
frontier = {x: 2}
|
|
887
|
+
frontier: dict[cirq.Qid, int] = {x: 2}
|
|
886
888
|
circuit.insert_at_frontier(op, 0, frontier)
|
|
887
889
|
|
|
888
890
|
|
|
889
|
-
def test_insert_at_frontier():
|
|
891
|
+
def test_insert_at_frontier() -> None:
|
|
890
892
|
class Replacer(cirq.PointOptimizer):
|
|
891
893
|
def __init__(self, replacer=(lambda x: x)):
|
|
892
894
|
super().__init__()
|
|
@@ -991,7 +993,7 @@ d: ───@───────@───────
|
|
|
991
993
|
)
|
|
992
994
|
|
|
993
995
|
|
|
994
|
-
def test_insert_into_range():
|
|
996
|
+
def test_insert_into_range() -> None:
|
|
995
997
|
x = cirq.NamedQubit('x')
|
|
996
998
|
y = cirq.NamedQubit('y')
|
|
997
999
|
c = cirq.Circuit([cirq.Moment([cirq.X(x)])] * 4)
|
|
@@ -1040,7 +1042,7 @@ y: ───T───Y───Y───@───Y───@───H──
|
|
|
1040
1042
|
|
|
1041
1043
|
|
|
1042
1044
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1043
|
-
def test_next_moment_operating_on(circuit_cls):
|
|
1045
|
+
def test_next_moment_operating_on(circuit_cls) -> None:
|
|
1044
1046
|
a = cirq.NamedQubit('a')
|
|
1045
1047
|
b = cirq.NamedQubit('b')
|
|
1046
1048
|
|
|
@@ -1080,7 +1082,7 @@ def test_next_moment_operating_on(circuit_cls):
|
|
|
1080
1082
|
|
|
1081
1083
|
|
|
1082
1084
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1083
|
-
def test_next_moment_operating_on_distance(circuit_cls):
|
|
1085
|
+
def test_next_moment_operating_on_distance(circuit_cls) -> None:
|
|
1084
1086
|
a = cirq.NamedQubit('a')
|
|
1085
1087
|
|
|
1086
1088
|
c = circuit_cls(
|
|
@@ -1119,7 +1121,7 @@ def test_next_moment_operating_on_distance(circuit_cls):
|
|
|
1119
1121
|
|
|
1120
1122
|
|
|
1121
1123
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1122
|
-
def test_prev_moment_operating_on(circuit_cls):
|
|
1124
|
+
def test_prev_moment_operating_on(circuit_cls) -> None:
|
|
1123
1125
|
a = cirq.NamedQubit('a')
|
|
1124
1126
|
b = cirq.NamedQubit('b')
|
|
1125
1127
|
|
|
@@ -1162,7 +1164,7 @@ def test_prev_moment_operating_on(circuit_cls):
|
|
|
1162
1164
|
|
|
1163
1165
|
|
|
1164
1166
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1165
|
-
def test_prev_moment_operating_on_distance(circuit_cls):
|
|
1167
|
+
def test_prev_moment_operating_on_distance(circuit_cls) -> None:
|
|
1166
1168
|
a = cirq.NamedQubit('a')
|
|
1167
1169
|
|
|
1168
1170
|
c = circuit_cls(
|
|
@@ -1202,7 +1204,7 @@ def test_prev_moment_operating_on_distance(circuit_cls):
|
|
|
1202
1204
|
c.prev_moment_operating_on([a], 6, max_distance=-1)
|
|
1203
1205
|
|
|
1204
1206
|
|
|
1205
|
-
def test_earliest_available_moment():
|
|
1207
|
+
def test_earliest_available_moment() -> None:
|
|
1206
1208
|
q = cirq.LineQubit.range(3)
|
|
1207
1209
|
c = cirq.Circuit(
|
|
1208
1210
|
cirq.Moment(cirq.measure(q[0], key="m")),
|
|
@@ -1225,7 +1227,7 @@ def test_earliest_available_moment():
|
|
|
1225
1227
|
|
|
1226
1228
|
|
|
1227
1229
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1228
|
-
def test_operation_at(circuit_cls):
|
|
1230
|
+
def test_operation_at(circuit_cls) -> None:
|
|
1229
1231
|
a = cirq.NamedQubit('a')
|
|
1230
1232
|
b = cirq.NamedQubit('b')
|
|
1231
1233
|
|
|
@@ -1248,7 +1250,7 @@ def test_operation_at(circuit_cls):
|
|
|
1248
1250
|
|
|
1249
1251
|
|
|
1250
1252
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1251
|
-
def test_findall_operations(circuit_cls):
|
|
1253
|
+
def test_findall_operations(circuit_cls) -> None:
|
|
1252
1254
|
a = cirq.NamedQubit('a')
|
|
1253
1255
|
b = cirq.NamedQubit('b')
|
|
1254
1256
|
|
|
@@ -1292,7 +1294,7 @@ def test_findall_operations(circuit_cls):
|
|
|
1292
1294
|
|
|
1293
1295
|
|
|
1294
1296
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1295
|
-
def test_findall_operations_with_gate(circuit_cls):
|
|
1297
|
+
def test_findall_operations_with_gate(circuit_cls) -> None:
|
|
1296
1298
|
a = cirq.NamedQubit('a')
|
|
1297
1299
|
b = cirq.NamedQubit('b')
|
|
1298
1300
|
c = circuit_cls(
|
|
@@ -1320,7 +1322,7 @@ def test_findall_operations_with_gate(circuit_cls):
|
|
|
1320
1322
|
|
|
1321
1323
|
def assert_findall_operations_until_blocked_as_expected(
|
|
1322
1324
|
circuit=None, start_frontier=None, is_blocker=None, expected_ops=None
|
|
1323
|
-
):
|
|
1325
|
+
) -> None:
|
|
1324
1326
|
if circuit is None:
|
|
1325
1327
|
circuit = cirq.Circuit()
|
|
1326
1328
|
if start_frontier is None:
|
|
@@ -1338,7 +1340,7 @@ def assert_findall_operations_until_blocked_as_expected(
|
|
|
1338
1340
|
|
|
1339
1341
|
|
|
1340
1342
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1341
|
-
def test_findall_operations_until_blocked(circuit_cls):
|
|
1343
|
+
def test_findall_operations_until_blocked(circuit_cls) -> None:
|
|
1342
1344
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
1343
1345
|
|
|
1344
1346
|
assert_findall_operations_until_blocked_as_expected()
|
|
@@ -1505,7 +1507,7 @@ def test_findall_operations_until_blocked(circuit_cls):
|
|
|
1505
1507
|
|
|
1506
1508
|
@pytest.mark.parametrize('seed', [randint(0, 2**31)])
|
|
1507
1509
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1508
|
-
def test_findall_operations_until_blocked_docstring_examples(seed, circuit_cls):
|
|
1510
|
+
def test_findall_operations_until_blocked_docstring_examples(seed, circuit_cls) -> None:
|
|
1509
1511
|
prng = np.random.RandomState(seed)
|
|
1510
1512
|
|
|
1511
1513
|
class ExampleGate(cirq.Gate):
|
|
@@ -1618,7 +1620,7 @@ def test_findall_operations_until_blocked_docstring_examples(seed, circuit_cls):
|
|
|
1618
1620
|
|
|
1619
1621
|
|
|
1620
1622
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1621
|
-
def test_has_measurements(circuit_cls):
|
|
1623
|
+
def test_has_measurements(circuit_cls) -> None:
|
|
1622
1624
|
a = cirq.NamedQubit('a')
|
|
1623
1625
|
b = cirq.NamedQubit('b')
|
|
1624
1626
|
|
|
@@ -1663,7 +1665,7 @@ def test_has_measurements(circuit_cls):
|
|
|
1663
1665
|
|
|
1664
1666
|
|
|
1665
1667
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1666
|
-
def test_are_all_or_any_measurements_terminal(circuit_cls):
|
|
1668
|
+
def test_are_all_or_any_measurements_terminal(circuit_cls) -> None:
|
|
1667
1669
|
a = cirq.NamedQubit('a')
|
|
1668
1670
|
b = cirq.NamedQubit('b')
|
|
1669
1671
|
|
|
@@ -1719,7 +1721,7 @@ def test_are_all_or_any_measurements_terminal(circuit_cls):
|
|
|
1719
1721
|
|
|
1720
1722
|
|
|
1721
1723
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1722
|
-
def test_all_or_any_terminal(circuit_cls):
|
|
1724
|
+
def test_all_or_any_terminal(circuit_cls) -> None:
|
|
1723
1725
|
def is_x_pow_gate(op):
|
|
1724
1726
|
return isinstance(op.gate, cirq.XPowGate)
|
|
1725
1727
|
|
|
@@ -1787,7 +1789,7 @@ def test_all_or_any_terminal(circuit_cls):
|
|
|
1787
1789
|
assert not c.are_any_matches_terminal(is_circuit_op)
|
|
1788
1790
|
|
|
1789
1791
|
|
|
1790
|
-
def test_clear_operations_touching():
|
|
1792
|
+
def test_clear_operations_touching() -> None:
|
|
1791
1793
|
a = cirq.NamedQubit('a')
|
|
1792
1794
|
b = cirq.NamedQubit('b')
|
|
1793
1795
|
|
|
@@ -1849,7 +1851,7 @@ def test_clear_operations_touching():
|
|
|
1849
1851
|
|
|
1850
1852
|
|
|
1851
1853
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1852
|
-
def test_all_qubits(circuit_cls):
|
|
1854
|
+
def test_all_qubits(circuit_cls) -> None:
|
|
1853
1855
|
a = cirq.NamedQubit('a')
|
|
1854
1856
|
b = cirq.NamedQubit('b')
|
|
1855
1857
|
|
|
@@ -1867,7 +1869,7 @@ def test_all_qubits(circuit_cls):
|
|
|
1867
1869
|
|
|
1868
1870
|
|
|
1869
1871
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1870
|
-
def test_all_operations(circuit_cls):
|
|
1872
|
+
def test_all_operations(circuit_cls) -> None:
|
|
1871
1873
|
a = cirq.NamedQubit('a')
|
|
1872
1874
|
b = cirq.NamedQubit('b')
|
|
1873
1875
|
|
|
@@ -1901,7 +1903,7 @@ def test_all_operations(circuit_cls):
|
|
|
1901
1903
|
|
|
1902
1904
|
|
|
1903
1905
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1904
|
-
def test_qid_shape_qubit(circuit_cls):
|
|
1906
|
+
def test_qid_shape_qubit(circuit_cls) -> None:
|
|
1905
1907
|
a = cirq.NamedQubit('a')
|
|
1906
1908
|
b = cirq.NamedQubit('b')
|
|
1907
1909
|
c = cirq.NamedQubit('c')
|
|
@@ -1917,7 +1919,7 @@ def test_qid_shape_qubit(circuit_cls):
|
|
|
1917
1919
|
|
|
1918
1920
|
|
|
1919
1921
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1920
|
-
def test_qid_shape_qudit(circuit_cls):
|
|
1922
|
+
def test_qid_shape_qudit(circuit_cls) -> None:
|
|
1921
1923
|
class PlusOneMod3Gate(cirq.testing.SingleQubitGate):
|
|
1922
1924
|
def _qid_shape_(self):
|
|
1923
1925
|
return (3,)
|
|
@@ -1943,7 +1945,7 @@ def test_qid_shape_qudit(circuit_cls):
|
|
|
1943
1945
|
|
|
1944
1946
|
|
|
1945
1947
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
1946
|
-
def test_to_text_diagram_teleportation_to_diagram(circuit_cls):
|
|
1948
|
+
def test_to_text_diagram_teleportation_to_diagram(circuit_cls) -> None:
|
|
1947
1949
|
ali = cirq.NamedQubit('(0, 0)')
|
|
1948
1950
|
bob = cirq.NamedQubit('(0, 1)')
|
|
1949
1951
|
msg = cirq.NamedQubit('(1, 0)')
|
|
@@ -2020,7 +2022,7 @@ M | M |
|
|
|
2020
2022
|
|
|
2021
2023
|
|
|
2022
2024
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2023
|
-
def test_diagram_with_unknown_exponent(circuit_cls):
|
|
2025
|
+
def test_diagram_with_unknown_exponent(circuit_cls) -> None:
|
|
2024
2026
|
class WeirdGate(cirq.testing.SingleQubitGate):
|
|
2025
2027
|
def _circuit_diagram_info_(
|
|
2026
2028
|
self, args: cirq.CircuitDiagramInfoArgs
|
|
@@ -2040,7 +2042,7 @@ def test_diagram_with_unknown_exponent(circuit_cls):
|
|
|
2040
2042
|
|
|
2041
2043
|
|
|
2042
2044
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2043
|
-
def test_circuit_diagram_on_gate_without_info(circuit_cls):
|
|
2045
|
+
def test_circuit_diagram_on_gate_without_info(circuit_cls) -> None:
|
|
2044
2046
|
q = cirq.NamedQubit('(0, 0)')
|
|
2045
2047
|
q2 = cirq.NamedQubit('(0, 1)')
|
|
2046
2048
|
q3 = cirq.NamedQubit('(0, 2)')
|
|
@@ -2081,7 +2083,7 @@ def test_circuit_diagram_on_gate_without_info(circuit_cls):
|
|
|
2081
2083
|
|
|
2082
2084
|
|
|
2083
2085
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2084
|
-
def test_to_text_diagram_multi_qubit_gate(circuit_cls):
|
|
2086
|
+
def test_to_text_diagram_multi_qubit_gate(circuit_cls) -> None:
|
|
2085
2087
|
q1 = cirq.NamedQubit('(0, 0)')
|
|
2086
2088
|
q2 = cirq.NamedQubit('(0, 1)')
|
|
2087
2089
|
q3 = cirq.NamedQubit('(0, 2)')
|
|
@@ -2120,7 +2122,7 @@ M('msg')─M──────M
|
|
|
2120
2122
|
|
|
2121
2123
|
|
|
2122
2124
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2123
|
-
def test_to_text_diagram_many_qubits_gate_but_multiple_wire_symbols(circuit_cls):
|
|
2125
|
+
def test_to_text_diagram_many_qubits_gate_but_multiple_wire_symbols(circuit_cls) -> None:
|
|
2124
2126
|
class BadGate(cirq.testing.ThreeQubitGate):
|
|
2125
2127
|
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, str]:
|
|
2126
2128
|
return 'a', 'a'
|
|
@@ -2134,7 +2136,7 @@ def test_to_text_diagram_many_qubits_gate_but_multiple_wire_symbols(circuit_cls)
|
|
|
2134
2136
|
|
|
2135
2137
|
|
|
2136
2138
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2137
|
-
def test_to_text_diagram_parameterized_value(circuit_cls):
|
|
2139
|
+
def test_to_text_diagram_parameterized_value(circuit_cls) -> None:
|
|
2138
2140
|
q = cirq.NamedQubit('cube')
|
|
2139
2141
|
|
|
2140
2142
|
class PGate(cirq.testing.SingleQubitGate):
|
|
@@ -2156,7 +2158,7 @@ def test_to_text_diagram_parameterized_value(circuit_cls):
|
|
|
2156
2158
|
|
|
2157
2159
|
|
|
2158
2160
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2159
|
-
def test_to_text_diagram_custom_order(circuit_cls):
|
|
2161
|
+
def test_to_text_diagram_custom_order(circuit_cls) -> None:
|
|
2160
2162
|
qa = cirq.NamedQubit('2')
|
|
2161
2163
|
qb = cirq.NamedQubit('3')
|
|
2162
2164
|
qc = cirq.NamedQubit('4')
|
|
@@ -2177,7 +2179,7 @@ def test_to_text_diagram_custom_order(circuit_cls):
|
|
|
2177
2179
|
|
|
2178
2180
|
|
|
2179
2181
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2180
|
-
def test_overly_precise_diagram(circuit_cls):
|
|
2182
|
+
def test_overly_precise_diagram(circuit_cls) -> None:
|
|
2181
2183
|
# Test default precision of 3
|
|
2182
2184
|
qa = cirq.NamedQubit('a')
|
|
2183
2185
|
c = circuit_cls([cirq.Moment([cirq.X(qa) ** 0.12345678])])
|
|
@@ -2191,7 +2193,7 @@ a: ---X^0.123---
|
|
|
2191
2193
|
|
|
2192
2194
|
|
|
2193
2195
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2194
|
-
def test_none_precision_diagram(circuit_cls):
|
|
2196
|
+
def test_none_precision_diagram(circuit_cls) -> None:
|
|
2195
2197
|
# Test default precision of 3
|
|
2196
2198
|
qa = cirq.NamedQubit('a')
|
|
2197
2199
|
c = circuit_cls([cirq.Moment([cirq.X(qa) ** 0.4921875])])
|
|
@@ -2206,7 +2208,7 @@ a: ---X^0.4921875---
|
|
|
2206
2208
|
|
|
2207
2209
|
|
|
2208
2210
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2209
|
-
def test_diagram_custom_precision(circuit_cls):
|
|
2211
|
+
def test_diagram_custom_precision(circuit_cls) -> None:
|
|
2210
2212
|
qa = cirq.NamedQubit('a')
|
|
2211
2213
|
c = circuit_cls([cirq.Moment([cirq.X(qa) ** 0.12341234])])
|
|
2212
2214
|
cirq.testing.assert_has_diagram(
|
|
@@ -2220,7 +2222,7 @@ a: ---X^0.12341---
|
|
|
2220
2222
|
|
|
2221
2223
|
|
|
2222
2224
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2223
|
-
def test_diagram_wgate(circuit_cls):
|
|
2225
|
+
def test_diagram_wgate(circuit_cls) -> None:
|
|
2224
2226
|
qa = cirq.NamedQubit('a')
|
|
2225
2227
|
test_wgate = cirq.PhasedXPowGate(exponent=0.12341234, phase_exponent=0.43214321)
|
|
2226
2228
|
c = circuit_cls([cirq.Moment([test_wgate.on(qa)])])
|
|
@@ -2235,7 +2237,7 @@ a: ---PhX(0.43)^(1/8)---
|
|
|
2235
2237
|
|
|
2236
2238
|
|
|
2237
2239
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2238
|
-
def test_diagram_wgate_none_precision(circuit_cls):
|
|
2240
|
+
def test_diagram_wgate_none_precision(circuit_cls) -> None:
|
|
2239
2241
|
qa = cirq.NamedQubit('a')
|
|
2240
2242
|
test_wgate = cirq.PhasedXPowGate(exponent=0.12341234, phase_exponent=0.43214321)
|
|
2241
2243
|
c = circuit_cls([cirq.Moment([test_wgate.on(qa)])])
|
|
@@ -2250,7 +2252,7 @@ a: ---PhX(0.43214321)^0.12341234---
|
|
|
2250
2252
|
|
|
2251
2253
|
|
|
2252
2254
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2253
|
-
def test_diagram_global_phase(circuit_cls):
|
|
2255
|
+
def test_diagram_global_phase(circuit_cls) -> None:
|
|
2254
2256
|
qa = cirq.NamedQubit('a')
|
|
2255
2257
|
global_phase = cirq.global_phase_operation(coefficient=1j)
|
|
2256
2258
|
c = circuit_cls([global_phase])
|
|
@@ -2299,7 +2301,7 @@ global phase: 0.5π 0.5π
|
|
|
2299
2301
|
|
|
2300
2302
|
|
|
2301
2303
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2302
|
-
def test_has_unitary(circuit_cls):
|
|
2304
|
+
def test_has_unitary(circuit_cls) -> None:
|
|
2303
2305
|
class NonUnitary(cirq.testing.SingleQubitGate):
|
|
2304
2306
|
pass
|
|
2305
2307
|
|
|
@@ -2322,7 +2324,7 @@ def test_has_unitary(circuit_cls):
|
|
|
2322
2324
|
|
|
2323
2325
|
|
|
2324
2326
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2325
|
-
def test_text_diagram_jupyter(circuit_cls):
|
|
2327
|
+
def test_text_diagram_jupyter(circuit_cls) -> None:
|
|
2326
2328
|
a = cirq.NamedQubit('a')
|
|
2327
2329
|
b = cirq.NamedQubit('b')
|
|
2328
2330
|
c = cirq.NamedQubit('c')
|
|
@@ -2353,7 +2355,7 @@ def test_text_diagram_jupyter(circuit_cls):
|
|
|
2353
2355
|
|
|
2354
2356
|
|
|
2355
2357
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2356
|
-
def test_circuit_to_unitary_matrix(circuit_cls):
|
|
2358
|
+
def test_circuit_to_unitary_matrix(circuit_cls) -> None:
|
|
2357
2359
|
a = cirq.NamedQubit('a')
|
|
2358
2360
|
b = cirq.NamedQubit('b')
|
|
2359
2361
|
|
|
@@ -2477,7 +2479,7 @@ def test_circuit_to_unitary_matrix(circuit_cls):
|
|
|
2477
2479
|
|
|
2478
2480
|
|
|
2479
2481
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2480
|
-
def test_circuit_unitary(circuit_cls):
|
|
2482
|
+
def test_circuit_unitary(circuit_cls) -> None:
|
|
2481
2483
|
q = cirq.NamedQubit('q')
|
|
2482
2484
|
|
|
2483
2485
|
with_inner_measure = circuit_cls(cirq.H(q), cirq.measure(q), cirq.H(q))
|
|
@@ -2485,14 +2487,14 @@ def test_circuit_unitary(circuit_cls):
|
|
|
2485
2487
|
assert cirq.unitary(with_inner_measure, None) is None
|
|
2486
2488
|
|
|
2487
2489
|
cirq.testing.assert_allclose_up_to_global_phase(
|
|
2488
|
-
cirq.unitary(circuit_cls(cirq.X(q) ** 0.5
|
|
2490
|
+
cirq.unitary(circuit_cls(cirq.X(q) ** 0.5, cirq.measure(q))),
|
|
2489
2491
|
np.array([[1j, 1], [1, 1j]]) * np.sqrt(0.5),
|
|
2490
2492
|
atol=1e-8,
|
|
2491
2493
|
)
|
|
2492
2494
|
|
|
2493
2495
|
|
|
2494
2496
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2495
|
-
def test_simple_circuits_to_unitary_matrix(circuit_cls):
|
|
2497
|
+
def test_simple_circuits_to_unitary_matrix(circuit_cls) -> None:
|
|
2496
2498
|
a = cirq.NamedQubit('a')
|
|
2497
2499
|
b = cirq.NamedQubit('b')
|
|
2498
2500
|
|
|
@@ -2528,7 +2530,7 @@ def test_simple_circuits_to_unitary_matrix(circuit_cls):
|
|
|
2528
2530
|
|
|
2529
2531
|
|
|
2530
2532
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2531
|
-
def test_composite_gate_to_unitary_matrix(circuit_cls):
|
|
2533
|
+
def test_composite_gate_to_unitary_matrix(circuit_cls) -> None:
|
|
2532
2534
|
class CnotComposite(cirq.testing.TwoQubitGate):
|
|
2533
2535
|
def _decompose_(self, qubits):
|
|
2534
2536
|
q0, q1 = qubits
|
|
@@ -2547,7 +2549,7 @@ def test_composite_gate_to_unitary_matrix(circuit_cls):
|
|
|
2547
2549
|
cirq.testing.assert_allclose_up_to_global_phase(mat, mat_expected, atol=1e-8)
|
|
2548
2550
|
|
|
2549
2551
|
|
|
2550
|
-
def test_circuit_superoperator_too_many_qubits():
|
|
2552
|
+
def test_circuit_superoperator_too_many_qubits() -> None:
|
|
2551
2553
|
circuit = cirq.Circuit(cirq.IdentityGate(num_qubits=11).on(*cirq.LineQubit.range(11)))
|
|
2552
2554
|
assert not circuit._has_superoperator_()
|
|
2553
2555
|
with pytest.raises(ValueError, match="too many"):
|
|
@@ -2597,7 +2599,7 @@ def test_circuit_superoperator_too_many_qubits():
|
|
|
2597
2599
|
),
|
|
2598
2600
|
),
|
|
2599
2601
|
)
|
|
2600
|
-
def test_circuit_superoperator_fixed_values(circuit, expected_superoperator):
|
|
2602
|
+
def test_circuit_superoperator_fixed_values(circuit, expected_superoperator) -> None:
|
|
2601
2603
|
"""Tests Circuit._superoperator_() on a few simple circuits."""
|
|
2602
2604
|
assert circuit._has_superoperator_()
|
|
2603
2605
|
assert np.allclose(circuit._superoperator_(), expected_superoperator)
|
|
@@ -2615,7 +2617,7 @@ def test_circuit_superoperator_fixed_values(circuit, expected_superoperator):
|
|
|
2615
2617
|
([0.1, 0.2, 0.3], 3),
|
|
2616
2618
|
),
|
|
2617
2619
|
)
|
|
2618
|
-
def test_circuit_superoperator_depolarizing_channel_compositions(rs, n_qubits):
|
|
2620
|
+
def test_circuit_superoperator_depolarizing_channel_compositions(rs, n_qubits) -> None:
|
|
2619
2621
|
"""Tests Circuit._superoperator_() on compositions of depolarizing channels."""
|
|
2620
2622
|
|
|
2621
2623
|
def pauli_error_probability(r: float, n_qubits: int) -> float:
|
|
@@ -2701,7 +2703,7 @@ def density_operator_basis(n_qubits: int) -> Iterator[np.ndarray]:
|
|
|
2701
2703
|
),
|
|
2702
2704
|
),
|
|
2703
2705
|
)
|
|
2704
|
-
def test_compare_circuits_superoperator_to_simulation(circuit, initial_state):
|
|
2706
|
+
def test_compare_circuits_superoperator_to_simulation(circuit, initial_state) -> None:
|
|
2705
2707
|
"""Compares action of circuit superoperator and circuit simulation."""
|
|
2706
2708
|
assert circuit._has_superoperator_()
|
|
2707
2709
|
superoperator = circuit._superoperator_()
|
|
@@ -2716,7 +2718,7 @@ def test_compare_circuits_superoperator_to_simulation(circuit, initial_state):
|
|
|
2716
2718
|
|
|
2717
2719
|
|
|
2718
2720
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2719
|
-
def test_expanding_gate_symbols(circuit_cls):
|
|
2721
|
+
def test_expanding_gate_symbols(circuit_cls) -> None:
|
|
2720
2722
|
class MultiTargetCZ(cirq.Gate):
|
|
2721
2723
|
def __init__(self, num_qubits):
|
|
2722
2724
|
self._num_qubits = num_qubits
|
|
@@ -2764,7 +2766,7 @@ c: ───@───
|
|
|
2764
2766
|
|
|
2765
2767
|
|
|
2766
2768
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2767
|
-
def test_transposed_diagram_exponent_order(circuit_cls):
|
|
2769
|
+
def test_transposed_diagram_exponent_order(circuit_cls) -> None:
|
|
2768
2770
|
a, b, c = cirq.LineQubit.range(3)
|
|
2769
2771
|
circuit = circuit_cls(cirq.CZ(a, b) ** -0.5, cirq.CZ(a, c) ** 0.5, cirq.CZ(b, c) ** 0.125)
|
|
2770
2772
|
cirq.testing.assert_has_diagram(
|
|
@@ -2784,7 +2786,7 @@ def test_transposed_diagram_exponent_order(circuit_cls):
|
|
|
2784
2786
|
|
|
2785
2787
|
|
|
2786
2788
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2787
|
-
def test_transposed_diagram_can_depend_on_transpose(circuit_cls):
|
|
2789
|
+
def test_transposed_diagram_can_depend_on_transpose(circuit_cls) -> None:
|
|
2788
2790
|
class TestGate(cirq.Gate):
|
|
2789
2791
|
def num_qubits(self):
|
|
2790
2792
|
return 1
|
|
@@ -2807,7 +2809,7 @@ t
|
|
|
2807
2809
|
)
|
|
2808
2810
|
|
|
2809
2811
|
|
|
2810
|
-
def test_insert_moments():
|
|
2812
|
+
def test_insert_moments() -> None:
|
|
2811
2813
|
q = cirq.NamedQubit('q')
|
|
2812
2814
|
c = cirq.Circuit()
|
|
2813
2815
|
|
|
@@ -2831,7 +2833,7 @@ def test_insert_moments():
|
|
|
2831
2833
|
|
|
2832
2834
|
|
|
2833
2835
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
2834
|
-
def test_final_state_vector(circuit_cls):
|
|
2836
|
+
def test_final_state_vector(circuit_cls) -> None:
|
|
2835
2837
|
a = cirq.NamedQubit('a')
|
|
2836
2838
|
b = cirq.NamedQubit('b')
|
|
2837
2839
|
|
|
@@ -3003,7 +3005,7 @@ def test_final_state_vector(circuit_cls):
|
|
|
3003
3005
|
|
|
3004
3006
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3005
3007
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
3006
|
-
def test_is_parameterized(circuit_cls, resolve_fn):
|
|
3008
|
+
def test_is_parameterized(circuit_cls, resolve_fn) -> None:
|
|
3007
3009
|
a, b = cirq.LineQubit.range(2)
|
|
3008
3010
|
circuit = circuit_cls(
|
|
3009
3011
|
cirq.CZ(a, b) ** sympy.Symbol('u'),
|
|
@@ -3021,7 +3023,7 @@ def test_is_parameterized(circuit_cls, resolve_fn):
|
|
|
3021
3023
|
|
|
3022
3024
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3023
3025
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
3024
|
-
def test_resolve_parameters(circuit_cls, resolve_fn):
|
|
3026
|
+
def test_resolve_parameters(circuit_cls, resolve_fn) -> None:
|
|
3025
3027
|
a, b = cirq.LineQubit.range(2)
|
|
3026
3028
|
circuit = circuit_cls(
|
|
3027
3029
|
cirq.CZ(a, b) ** sympy.Symbol('u'),
|
|
@@ -3051,7 +3053,7 @@ def test_resolve_parameters(circuit_cls, resolve_fn):
|
|
|
3051
3053
|
|
|
3052
3054
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3053
3055
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
3054
|
-
def test_resolve_parameters_no_change(circuit_cls, resolve_fn):
|
|
3056
|
+
def test_resolve_parameters_no_change(circuit_cls, resolve_fn) -> None:
|
|
3055
3057
|
a, b = cirq.LineQubit.range(2)
|
|
3056
3058
|
circuit = circuit_cls(cirq.CZ(a, b), cirq.X(a), cirq.Y(b))
|
|
3057
3059
|
resolved_circuit = resolve_fn(circuit, cirq.ParamResolver({'u': 0.1, 'v': 0.3, 'w': 0.2}))
|
|
@@ -3068,7 +3070,7 @@ def test_resolve_parameters_no_change(circuit_cls, resolve_fn):
|
|
|
3068
3070
|
|
|
3069
3071
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3070
3072
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
3071
|
-
def test_parameter_names(circuit_cls, resolve_fn):
|
|
3073
|
+
def test_parameter_names(circuit_cls, resolve_fn) -> None:
|
|
3072
3074
|
a, b = cirq.LineQubit.range(2)
|
|
3073
3075
|
circuit = circuit_cls(
|
|
3074
3076
|
cirq.CZ(a, b) ** sympy.Symbol('u'),
|
|
@@ -3080,7 +3082,7 @@ def test_parameter_names(circuit_cls, resolve_fn):
|
|
|
3080
3082
|
assert cirq.parameter_names(resolved_circuit) == set()
|
|
3081
3083
|
|
|
3082
3084
|
|
|
3083
|
-
def test_items():
|
|
3085
|
+
def test_items() -> None:
|
|
3084
3086
|
a = cirq.NamedQubit('a')
|
|
3085
3087
|
b = cirq.NamedQubit('b')
|
|
3086
3088
|
c = cirq.Circuit()
|
|
@@ -3108,12 +3110,12 @@ def test_items():
|
|
|
3108
3110
|
cirq.testing.assert_same_circuits(c, cirq.Circuit([m1]))
|
|
3109
3111
|
|
|
3110
3112
|
with pytest.raises(TypeError):
|
|
3111
|
-
c[:] = [m1, 1]
|
|
3113
|
+
c[:] = [m1, 1] # type: ignore
|
|
3112
3114
|
with pytest.raises(TypeError):
|
|
3113
|
-
c[0] = 1
|
|
3115
|
+
c[0] = 1 # type: ignore[call-overload]
|
|
3114
3116
|
|
|
3115
3117
|
|
|
3116
|
-
def test_copy():
|
|
3118
|
+
def test_copy() -> None:
|
|
3117
3119
|
a = cirq.NamedQubit('a')
|
|
3118
3120
|
b = cirq.NamedQubit('b')
|
|
3119
3121
|
c = cirq.Circuit(cirq.X(a), cirq.CZ(a, b), cirq.Z(a), cirq.Z(b))
|
|
@@ -3124,7 +3126,7 @@ def test_copy():
|
|
|
3124
3126
|
assert c2 != c
|
|
3125
3127
|
|
|
3126
3128
|
|
|
3127
|
-
def test_batch_remove():
|
|
3129
|
+
def test_batch_remove() -> None:
|
|
3128
3130
|
a = cirq.NamedQubit('a')
|
|
3129
3131
|
b = cirq.NamedQubit('b')
|
|
3130
3132
|
original = cirq.Circuit(
|
|
@@ -3203,7 +3205,7 @@ def test_batch_remove():
|
|
|
3203
3205
|
assert after == original
|
|
3204
3206
|
|
|
3205
3207
|
|
|
3206
|
-
def test_batch_replace():
|
|
3208
|
+
def test_batch_replace() -> None:
|
|
3207
3209
|
a = cirq.NamedQubit('a')
|
|
3208
3210
|
b = cirq.NamedQubit('b')
|
|
3209
3211
|
original = cirq.Circuit(
|
|
@@ -3257,7 +3259,7 @@ def test_batch_replace():
|
|
|
3257
3259
|
)
|
|
3258
3260
|
|
|
3259
3261
|
|
|
3260
|
-
def test_batch_insert_into():
|
|
3262
|
+
def test_batch_insert_into() -> None:
|
|
3261
3263
|
a = cirq.NamedQubit('a')
|
|
3262
3264
|
b = cirq.NamedQubit('b')
|
|
3263
3265
|
c = cirq.NamedQubit('c')
|
|
@@ -3360,7 +3362,7 @@ def test_batch_insert_into():
|
|
|
3360
3362
|
assert after == original
|
|
3361
3363
|
|
|
3362
3364
|
|
|
3363
|
-
def test_batch_insert():
|
|
3365
|
+
def test_batch_insert() -> None:
|
|
3364
3366
|
a = cirq.NamedQubit('a')
|
|
3365
3367
|
b = cirq.NamedQubit('b')
|
|
3366
3368
|
original = cirq.Circuit(
|
|
@@ -3392,7 +3394,7 @@ def test_batch_insert():
|
|
|
3392
3394
|
)
|
|
3393
3395
|
|
|
3394
3396
|
|
|
3395
|
-
def test_batch_insert_multiple_same_index():
|
|
3397
|
+
def test_batch_insert_multiple_same_index() -> None:
|
|
3396
3398
|
a, b = cirq.LineQubit.range(2)
|
|
3397
3399
|
c = cirq.Circuit()
|
|
3398
3400
|
c.batch_insert([(0, cirq.Z(a)), (0, cirq.Z(b)), (0, cirq.Z(a))])
|
|
@@ -3401,21 +3403,21 @@ def test_batch_insert_multiple_same_index():
|
|
|
3401
3403
|
)
|
|
3402
3404
|
|
|
3403
3405
|
|
|
3404
|
-
def test_batch_insert_reverses_order_for_same_index_inserts():
|
|
3406
|
+
def test_batch_insert_reverses_order_for_same_index_inserts() -> None:
|
|
3405
3407
|
a, b = cirq.LineQubit.range(2)
|
|
3406
3408
|
c = cirq.Circuit()
|
|
3407
3409
|
c.batch_insert([(0, cirq.Z(a)), (0, cirq.CZ(a, b)), (0, cirq.Z(b))])
|
|
3408
3410
|
assert c == cirq.Circuit(cirq.Z(b), cirq.CZ(a, b), cirq.Z(a))
|
|
3409
3411
|
|
|
3410
3412
|
|
|
3411
|
-
def test_batch_insert_maintains_order_despite_multiple_previous_inserts():
|
|
3413
|
+
def test_batch_insert_maintains_order_despite_multiple_previous_inserts() -> None:
|
|
3412
3414
|
a, b = cirq.LineQubit.range(2)
|
|
3413
3415
|
c = cirq.Circuit(cirq.H(a))
|
|
3414
3416
|
c.batch_insert([(0, cirq.Z(a)), (0, cirq.Z(a)), (0, cirq.Z(a)), (1, cirq.CZ(a, b))])
|
|
3415
3417
|
assert c == cirq.Circuit([cirq.Z(a)] * 3, cirq.H(a), cirq.CZ(a, b))
|
|
3416
3418
|
|
|
3417
3419
|
|
|
3418
|
-
def test_batch_insert_doesnt_overshift_due_to_previous_shifts():
|
|
3420
|
+
def test_batch_insert_doesnt_overshift_due_to_previous_shifts() -> None:
|
|
3419
3421
|
a = cirq.NamedQubit('a')
|
|
3420
3422
|
c = cirq.Circuit([cirq.H(a)] * 3)
|
|
3421
3423
|
c.batch_insert([(0, cirq.Z(a)), (0, cirq.Z(a)), (1, cirq.X(a)), (2, cirq.Y(a))])
|
|
@@ -3424,7 +3426,7 @@ def test_batch_insert_doesnt_overshift_due_to_previous_shifts():
|
|
|
3424
3426
|
)
|
|
3425
3427
|
|
|
3426
3428
|
|
|
3427
|
-
def test_batch_insert_doesnt_overshift_due_to_inline_inserts():
|
|
3429
|
+
def test_batch_insert_doesnt_overshift_due_to_inline_inserts() -> None:
|
|
3428
3430
|
a, b = cirq.LineQubit.range(2)
|
|
3429
3431
|
c = cirq.Circuit(cirq.SWAP(a, b), cirq.SWAP(a, b), cirq.H(a), cirq.SWAP(a, b), cirq.SWAP(a, b))
|
|
3430
3432
|
c.batch_insert([(0, cirq.X(a)), (3, cirq.X(b)), (4, cirq.Y(a))])
|
|
@@ -3441,7 +3443,7 @@ def test_batch_insert_doesnt_overshift_due_to_inline_inserts():
|
|
|
3441
3443
|
|
|
3442
3444
|
|
|
3443
3445
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3444
|
-
def test_next_moments_operating_on(circuit_cls):
|
|
3446
|
+
def test_next_moments_operating_on(circuit_cls) -> None:
|
|
3445
3447
|
for _ in range(20):
|
|
3446
3448
|
n_moments = randint(1, 10)
|
|
3447
3449
|
circuit = cirq.testing.random_circuit(randint(1, 20), n_moments, random())
|
|
@@ -3458,7 +3460,7 @@ def test_next_moments_operating_on(circuit_cls):
|
|
|
3458
3460
|
assert (not p) or (p < start)
|
|
3459
3461
|
|
|
3460
3462
|
|
|
3461
|
-
def test_pick_inserted_ops_moment_indices():
|
|
3463
|
+
def test_pick_inserted_ops_moment_indices() -> None:
|
|
3462
3464
|
for _ in range(20):
|
|
3463
3465
|
n_moments = randint(1, 10)
|
|
3464
3466
|
n_qubits = randint(1, 20)
|
|
@@ -3484,7 +3486,7 @@ def test_pick_inserted_ops_moment_indices():
|
|
|
3484
3486
|
assert actual_circuit == expected_circuit
|
|
3485
3487
|
|
|
3486
3488
|
|
|
3487
|
-
def test_push_frontier_new_moments():
|
|
3489
|
+
def test_push_frontier_new_moments() -> None:
|
|
3488
3490
|
operation = cirq.X(cirq.NamedQubit('q'))
|
|
3489
3491
|
insertion_index = 3
|
|
3490
3492
|
circuit = cirq.Circuit()
|
|
@@ -3494,7 +3496,7 @@ def test_push_frontier_new_moments():
|
|
|
3494
3496
|
)
|
|
3495
3497
|
|
|
3496
3498
|
|
|
3497
|
-
def test_push_frontier_random_circuit():
|
|
3499
|
+
def test_push_frontier_random_circuit() -> None:
|
|
3498
3500
|
for _ in range(20):
|
|
3499
3501
|
n_moments = randint(1, 10)
|
|
3500
3502
|
circuit = cirq.testing.random_circuit(randint(1, 20), n_moments, random())
|
|
@@ -3529,7 +3531,7 @@ def test_push_frontier_random_circuit():
|
|
|
3529
3531
|
@pytest.mark.parametrize(
|
|
3530
3532
|
'circuit', [cirq.testing.random_circuit(cirq.LineQubit.range(10), 10, 0.5) for _ in range(20)]
|
|
3531
3533
|
)
|
|
3532
|
-
def test_insert_operations_random_circuits(circuit):
|
|
3534
|
+
def test_insert_operations_random_circuits(circuit) -> None:
|
|
3533
3535
|
n_moments = len(circuit)
|
|
3534
3536
|
operations, insert_indices = [], []
|
|
3535
3537
|
for moment_index, moment in enumerate(circuit):
|
|
@@ -3541,7 +3543,7 @@ def test_insert_operations_random_circuits(circuit):
|
|
|
3541
3543
|
assert circuit == other_circuit
|
|
3542
3544
|
|
|
3543
3545
|
|
|
3544
|
-
def test_insert_zero_index():
|
|
3546
|
+
def test_insert_zero_index() -> None:
|
|
3545
3547
|
# Should always go to moment[0], independent of qubit order or earliest/inline strategy.
|
|
3546
3548
|
q0, q1 = cirq.LineQubit.range(2)
|
|
3547
3549
|
c0 = cirq.Circuit(cirq.X(q0))
|
|
@@ -3559,7 +3561,7 @@ def test_insert_zero_index():
|
|
|
3559
3561
|
assert c3 == expected
|
|
3560
3562
|
|
|
3561
3563
|
|
|
3562
|
-
def test_insert_earliest_on_previous_moment():
|
|
3564
|
+
def test_insert_earliest_on_previous_moment() -> None:
|
|
3563
3565
|
q = cirq.LineQubit(0)
|
|
3564
3566
|
c = cirq.Circuit(cirq.Moment(cirq.X(q)), cirq.Moment(), cirq.Moment(), cirq.Moment(cirq.Z(q)))
|
|
3565
3567
|
c.insert(3, cirq.Y(q), strategy=cirq.InsertStrategy.EARLIEST)
|
|
@@ -3569,7 +3571,7 @@ def test_insert_earliest_on_previous_moment():
|
|
|
3569
3571
|
)
|
|
3570
3572
|
|
|
3571
3573
|
|
|
3572
|
-
def test_insert_inline_end_of_circuit():
|
|
3574
|
+
def test_insert_inline_end_of_circuit() -> None:
|
|
3573
3575
|
# If end index is specified, INLINE should place all ops there independent of qubit order.
|
|
3574
3576
|
q0, q1 = cirq.LineQubit.range(2)
|
|
3575
3577
|
c0 = cirq.Circuit(cirq.X(q0))
|
|
@@ -3587,7 +3589,7 @@ def test_insert_inline_end_of_circuit():
|
|
|
3587
3589
|
assert c3 == expected
|
|
3588
3590
|
|
|
3589
3591
|
|
|
3590
|
-
def test_insert_operations_errors():
|
|
3592
|
+
def test_insert_operations_errors() -> None:
|
|
3591
3593
|
a, b, c = (cirq.NamedQubit(s) for s in 'abc')
|
|
3592
3594
|
with pytest.raises(ValueError):
|
|
3593
3595
|
circuit = cirq.Circuit([cirq.Moment([cirq.Z(c)])])
|
|
@@ -3609,7 +3611,7 @@ def test_insert_operations_errors():
|
|
|
3609
3611
|
|
|
3610
3612
|
|
|
3611
3613
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3612
|
-
def test_to_qasm(circuit_cls):
|
|
3614
|
+
def test_to_qasm(circuit_cls) -> None:
|
|
3613
3615
|
q0 = cirq.NamedQubit('q0')
|
|
3614
3616
|
circuit = circuit_cls(cirq.X(q0), cirq.measure(q0, key='mmm'))
|
|
3615
3617
|
assert circuit.to_qasm() == cirq.qasm(circuit)
|
|
@@ -3651,7 +3653,7 @@ m_mmm[0] = measure q[0];
|
|
|
3651
3653
|
|
|
3652
3654
|
|
|
3653
3655
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3654
|
-
def test_save_qasm(tmpdir, circuit_cls):
|
|
3656
|
+
def test_save_qasm(tmpdir, circuit_cls) -> None:
|
|
3655
3657
|
file_path = os.path.join(tmpdir, 'test.qasm')
|
|
3656
3658
|
q0 = cirq.NamedQubit('q0')
|
|
3657
3659
|
circuit = circuit_cls(cirq.X(q0))
|
|
@@ -3677,7 +3679,7 @@ x q[0];
|
|
|
3677
3679
|
|
|
3678
3680
|
|
|
3679
3681
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3680
|
-
def test_findall_operations_between(circuit_cls):
|
|
3682
|
+
def test_findall_operations_between(circuit_cls) -> None:
|
|
3681
3683
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
3682
3684
|
|
|
3683
3685
|
# 0: ───H───@───────────────────────────────────────@───H───
|
|
@@ -3757,7 +3759,7 @@ def test_findall_operations_between(circuit_cls):
|
|
|
3757
3759
|
|
|
3758
3760
|
|
|
3759
3761
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3760
|
-
def test_reachable_frontier_from(circuit_cls):
|
|
3762
|
+
def test_reachable_frontier_from(circuit_cls) -> None:
|
|
3761
3763
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
3762
3764
|
|
|
3763
3765
|
# 0: ───H───@───────────────────────────────────────@───H───
|
|
@@ -3827,7 +3829,7 @@ def test_reachable_frontier_from(circuit_cls):
|
|
|
3827
3829
|
|
|
3828
3830
|
|
|
3829
3831
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3830
|
-
def test_submoments(circuit_cls):
|
|
3832
|
+
def test_submoments(circuit_cls) -> None:
|
|
3831
3833
|
a, b, c, d, e, f = cirq.LineQubit.range(6)
|
|
3832
3834
|
circuit = circuit_cls(
|
|
3833
3835
|
cirq.H.on(a),
|
|
@@ -3927,7 +3929,7 @@ def test_submoments(circuit_cls):
|
|
|
3927
3929
|
|
|
3928
3930
|
|
|
3929
3931
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3930
|
-
def test_decompose(circuit_cls):
|
|
3932
|
+
def test_decompose(circuit_cls) -> None:
|
|
3931
3933
|
a, b = cirq.LineQubit.range(2)
|
|
3932
3934
|
assert cirq.decompose(circuit_cls(cirq.X(a), cirq.Y(b), cirq.CZ(a, b))) == [
|
|
3933
3935
|
cirq.X(a),
|
|
@@ -3937,7 +3939,7 @@ def test_decompose(circuit_cls):
|
|
|
3937
3939
|
|
|
3938
3940
|
|
|
3939
3941
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3940
|
-
def test_measurement_key_mapping(circuit_cls):
|
|
3942
|
+
def test_measurement_key_mapping(circuit_cls) -> None:
|
|
3941
3943
|
a, b = cirq.LineQubit.range(2)
|
|
3942
3944
|
c = circuit_cls(cirq.X(a), cirq.measure(a, key='m1'), cirq.measure(b, key='m2'))
|
|
3943
3945
|
assert c.all_measurement_key_names() == {'m1', 'm2'}
|
|
@@ -3966,7 +3968,7 @@ def test_measurement_key_mapping(circuit_cls):
|
|
|
3966
3968
|
|
|
3967
3969
|
|
|
3968
3970
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3969
|
-
def test_measurement_key_mapping_preserves_moments(circuit_cls):
|
|
3971
|
+
def test_measurement_key_mapping_preserves_moments(circuit_cls) -> None:
|
|
3970
3972
|
a, b = cirq.LineQubit.range(2)
|
|
3971
3973
|
c = circuit_cls(
|
|
3972
3974
|
cirq.Moment(cirq.X(a)),
|
|
@@ -3983,7 +3985,7 @@ def test_measurement_key_mapping_preserves_moments(circuit_cls):
|
|
|
3983
3985
|
|
|
3984
3986
|
|
|
3985
3987
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
3986
|
-
def test_inverse(circuit_cls):
|
|
3988
|
+
def test_inverse(circuit_cls) -> None:
|
|
3987
3989
|
a, b = cirq.LineQubit.range(2)
|
|
3988
3990
|
forward = circuit_cls((cirq.X**0.5)(a), (cirq.Y**-0.2)(b), cirq.CZ(a, b))
|
|
3989
3991
|
backward = circuit_cls((cirq.CZ ** (-1.0))(a, b), (cirq.X ** (-0.5))(a), (cirq.Y ** (0.2))(b))
|
|
@@ -4002,7 +4004,7 @@ def test_inverse(circuit_cls):
|
|
|
4002
4004
|
|
|
4003
4005
|
|
|
4004
4006
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4005
|
-
def test_pow_valid_only_for_minus_1(circuit_cls):
|
|
4007
|
+
def test_pow_valid_only_for_minus_1(circuit_cls) -> None:
|
|
4006
4008
|
a, b = cirq.LineQubit.range(2)
|
|
4007
4009
|
forward = circuit_cls((cirq.X**0.5)(a), (cirq.Y**-0.2)(b), cirq.CZ(a, b))
|
|
4008
4010
|
|
|
@@ -4017,7 +4019,7 @@ def test_pow_valid_only_for_minus_1(circuit_cls):
|
|
|
4017
4019
|
|
|
4018
4020
|
|
|
4019
4021
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4020
|
-
def test_moment_groups(circuit_cls):
|
|
4022
|
+
def test_moment_groups(circuit_cls) -> None:
|
|
4021
4023
|
qubits = [cirq.GridQubit(x, y) for x in range(8) for y in range(8)]
|
|
4022
4024
|
c0 = cirq.H(qubits[0])
|
|
4023
4025
|
c7 = cirq.H(qubits[7])
|
|
@@ -4055,7 +4057,7 @@ def test_moment_groups(circuit_cls):
|
|
|
4055
4057
|
|
|
4056
4058
|
|
|
4057
4059
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4058
|
-
def test_moments_property(circuit_cls):
|
|
4060
|
+
def test_moments_property(circuit_cls) -> None:
|
|
4059
4061
|
q = cirq.NamedQubit('q')
|
|
4060
4062
|
c = circuit_cls(cirq.X(q), cirq.Y(q))
|
|
4061
4063
|
assert c.moments[0] == cirq.Moment([cirq.X(q)])
|
|
@@ -4063,16 +4065,17 @@ def test_moments_property(circuit_cls):
|
|
|
4063
4065
|
|
|
4064
4066
|
|
|
4065
4067
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4066
|
-
def test_json_dict(circuit_cls):
|
|
4068
|
+
def test_json_dict(circuit_cls) -> None:
|
|
4067
4069
|
q0, q1 = cirq.LineQubit.range(2)
|
|
4068
4070
|
c = circuit_cls(cirq.CNOT(q0, q1))
|
|
4071
|
+
moments: Sequence[cirq.Moment]
|
|
4069
4072
|
moments = [cirq.Moment([cirq.CNOT(q0, q1)])]
|
|
4070
4073
|
if circuit_cls == cirq.FrozenCircuit:
|
|
4071
4074
|
moments = tuple(moments)
|
|
4072
4075
|
assert c._json_dict_() == {'moments': moments}
|
|
4073
4076
|
|
|
4074
4077
|
|
|
4075
|
-
def test_with_noise():
|
|
4078
|
+
def test_with_noise() -> None:
|
|
4076
4079
|
class Noise(cirq.NoiseModel):
|
|
4077
4080
|
def noisy_operation(self, operation):
|
|
4078
4081
|
yield operation
|
|
@@ -4107,7 +4110,7 @@ def test_with_noise():
|
|
|
4107
4110
|
|
|
4108
4111
|
|
|
4109
4112
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4110
|
-
def test_init_contents(circuit_cls):
|
|
4113
|
+
def test_init_contents(circuit_cls) -> None:
|
|
4111
4114
|
a, b = cirq.LineQubit.range(2)
|
|
4112
4115
|
|
|
4113
4116
|
# Moments are not subject to insertion rules.
|
|
@@ -4129,7 +4132,7 @@ def test_init_contents(circuit_cls):
|
|
|
4129
4132
|
circuit_cls()
|
|
4130
4133
|
|
|
4131
4134
|
|
|
4132
|
-
def test_transform_qubits():
|
|
4135
|
+
def test_transform_qubits() -> None:
|
|
4133
4136
|
a, b, c = cirq.LineQubit.range(3)
|
|
4134
4137
|
original = cirq.Circuit(
|
|
4135
4138
|
cirq.X(a), cirq.CNOT(a, b), cirq.Moment(), cirq.Moment([cirq.CNOT(b, c)])
|
|
@@ -4138,7 +4141,12 @@ def test_transform_qubits():
|
|
|
4138
4141
|
desired = cirq.Circuit(
|
|
4139
4142
|
cirq.X(x), cirq.CNOT(x, y), cirq.Moment(), cirq.Moment([cirq.CNOT(y, z)])
|
|
4140
4143
|
)
|
|
4141
|
-
assert
|
|
4144
|
+
assert (
|
|
4145
|
+
original.transform_qubits(
|
|
4146
|
+
lambda q: cirq.GridQubit(10 + q.x, 20) # type: ignore[attr-defined]
|
|
4147
|
+
)
|
|
4148
|
+
== desired
|
|
4149
|
+
)
|
|
4142
4150
|
assert (
|
|
4143
4151
|
original.transform_qubits(
|
|
4144
4152
|
{
|
|
@@ -4150,11 +4158,11 @@ def test_transform_qubits():
|
|
|
4150
4158
|
== desired
|
|
4151
4159
|
)
|
|
4152
4160
|
with pytest.raises(TypeError, match='must be a function or dict'):
|
|
4153
|
-
_ = original.transform_qubits('bad arg')
|
|
4161
|
+
_ = original.transform_qubits('bad arg') # type: ignore[arg-type]
|
|
4154
4162
|
|
|
4155
4163
|
|
|
4156
4164
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4157
|
-
def test_indexing_by_pair(circuit_cls):
|
|
4165
|
+
def test_indexing_by_pair(circuit_cls) -> None:
|
|
4158
4166
|
# 0: ───H───@───X───@───
|
|
4159
4167
|
# │ │
|
|
4160
4168
|
# 1: ───────H───@───@───
|
|
@@ -4256,7 +4264,7 @@ def test_indexing_by_pair(circuit_cls):
|
|
|
4256
4264
|
|
|
4257
4265
|
|
|
4258
4266
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4259
|
-
def test_indexing_by_numpy_integer(circuit_cls):
|
|
4267
|
+
def test_indexing_by_numpy_integer(circuit_cls) -> None:
|
|
4260
4268
|
q = cirq.NamedQubit('q')
|
|
4261
4269
|
c = circuit_cls(cirq.X(q), cirq.Y(q))
|
|
4262
4270
|
|
|
@@ -4265,7 +4273,7 @@ def test_indexing_by_numpy_integer(circuit_cls):
|
|
|
4265
4273
|
|
|
4266
4274
|
|
|
4267
4275
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4268
|
-
def test_all_measurement_key_names(circuit_cls):
|
|
4276
|
+
def test_all_measurement_key_names(circuit_cls) -> None:
|
|
4269
4277
|
class Unknown(cirq.testing.SingleQubitGate):
|
|
4270
4278
|
def _measurement_key_name_(self):
|
|
4271
4279
|
return 'test'
|
|
@@ -4298,7 +4306,7 @@ def test_all_measurement_key_names(circuit_cls):
|
|
|
4298
4306
|
).all_measurement_key_names() == {'x', 'y'}
|
|
4299
4307
|
|
|
4300
4308
|
|
|
4301
|
-
def test_zip():
|
|
4309
|
+
def test_zip() -> None:
|
|
4302
4310
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
4303
4311
|
|
|
4304
4312
|
circuit1 = cirq.Circuit(cirq.H(a), cirq.CNOT(a, b))
|
|
@@ -4340,7 +4348,7 @@ def test_zip():
|
|
|
4340
4348
|
|
|
4341
4349
|
|
|
4342
4350
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4343
|
-
def test_zip_alignment(circuit_cls):
|
|
4351
|
+
def test_zip_alignment(circuit_cls) -> None:
|
|
4344
4352
|
a, b, c = cirq.LineQubit.range(3)
|
|
4345
4353
|
|
|
4346
4354
|
circuit1 = circuit_cls([cirq.H(a)] * 5)
|
|
@@ -4367,7 +4375,7 @@ def test_zip_alignment(circuit_cls):
|
|
|
4367
4375
|
|
|
4368
4376
|
|
|
4369
4377
|
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
|
|
4370
|
-
def test_repr_html_escaping(circuit_cls):
|
|
4378
|
+
def test_repr_html_escaping(circuit_cls) -> None:
|
|
4371
4379
|
class TestGate(cirq.Gate):
|
|
4372
4380
|
def num_qubits(self):
|
|
4373
4381
|
return 2
|
|
@@ -4388,7 +4396,7 @@ def test_repr_html_escaping(circuit_cls):
|
|
|
4388
4396
|
assert '|c>' in circuit._repr_html_()
|
|
4389
4397
|
|
|
4390
4398
|
|
|
4391
|
-
def test_concat_ragged():
|
|
4399
|
+
def test_concat_ragged() -> None:
|
|
4392
4400
|
a, b = cirq.LineQubit.range(2)
|
|
4393
4401
|
empty = cirq.Circuit()
|
|
4394
4402
|
|
|
@@ -4535,6 +4543,7 @@ def test_concat_ragged():
|
|
|
4535
4543
|
)
|
|
4536
4544
|
|
|
4537
4545
|
# Types.
|
|
4546
|
+
v: cirq.AbstractCircuit
|
|
4538
4547
|
v = ha.freeze().concat_ragged(empty)
|
|
4539
4548
|
assert type(v) is cirq.FrozenCircuit and v == ha.freeze()
|
|
4540
4549
|
v = ha.concat_ragged(empty.freeze())
|
|
@@ -4547,7 +4556,7 @@ def test_concat_ragged():
|
|
|
4547
4556
|
assert type(v) is cirq.FrozenCircuit and v == ha.freeze()
|
|
4548
4557
|
|
|
4549
4558
|
|
|
4550
|
-
def test_concat_ragged_alignment():
|
|
4559
|
+
def test_concat_ragged_alignment() -> None:
|
|
4551
4560
|
a, b = cirq.LineQubit.range(2)
|
|
4552
4561
|
|
|
4553
4562
|
assert cirq.Circuit.concat_ragged(
|
|
@@ -4579,14 +4588,14 @@ def test_concat_ragged_alignment():
|
|
|
4579
4588
|
)
|
|
4580
4589
|
|
|
4581
4590
|
|
|
4582
|
-
def test_freeze_not_relocate_moments():
|
|
4591
|
+
def test_freeze_not_relocate_moments() -> None:
|
|
4583
4592
|
q = cirq.q(0)
|
|
4584
4593
|
c = cirq.Circuit(cirq.X(q), cirq.measure(q))
|
|
4585
4594
|
f = c.freeze()
|
|
4586
4595
|
assert [mc is fc for mc, fc in zip(c, f)] == [True, True]
|
|
4587
4596
|
|
|
4588
4597
|
|
|
4589
|
-
def test_freeze_is_cached():
|
|
4598
|
+
def test_freeze_is_cached() -> None:
|
|
4590
4599
|
q = cirq.q(0)
|
|
4591
4600
|
c = cirq.Circuit(cirq.X(q), cirq.measure(q))
|
|
4592
4601
|
f0 = c.freeze()
|
|
@@ -4645,7 +4654,7 @@ def test_freeze_is_cached():
|
|
|
4645
4654
|
),
|
|
4646
4655
|
],
|
|
4647
4656
|
)
|
|
4648
|
-
def test_mutation_clears_cached_attributes(circuit, mutate):
|
|
4657
|
+
def test_mutation_clears_cached_attributes(circuit, mutate) -> None:
|
|
4649
4658
|
cached_attributes = [
|
|
4650
4659
|
"_all_qubits",
|
|
4651
4660
|
"_frozen",
|
|
@@ -4680,7 +4689,7 @@ def test_mutation_clears_cached_attributes(circuit, mutate):
|
|
|
4680
4689
|
assert getattr(circuit, attr) is None, f"{attr=} is not None"
|
|
4681
4690
|
|
|
4682
4691
|
|
|
4683
|
-
def test_factorize_one_factor():
|
|
4692
|
+
def test_factorize_one_factor() -> None:
|
|
4684
4693
|
circuit = cirq.Circuit()
|
|
4685
4694
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
4686
4695
|
circuit.append(
|
|
@@ -4699,7 +4708,7 @@ def test_factorize_one_factor():
|
|
|
4699
4708
|
cirq.testing.assert_has_diagram(factors[0], desired)
|
|
4700
4709
|
|
|
4701
4710
|
|
|
4702
|
-
def test_factorize_simple_circuit_two_factors():
|
|
4711
|
+
def test_factorize_simple_circuit_two_factors() -> None:
|
|
4703
4712
|
circuit = cirq.Circuit()
|
|
4704
4713
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
4705
4714
|
circuit.append([cirq.H(q1), cirq.CZ(q0, q1), cirq.H(q2), cirq.H(q0), cirq.H(q0)])
|
|
@@ -4719,7 +4728,7 @@ def test_factorize_simple_circuit_two_factors():
|
|
|
4719
4728
|
cirq.testing.assert_has_diagram(f, d)
|
|
4720
4729
|
|
|
4721
4730
|
|
|
4722
|
-
def test_factorize_large_circuit():
|
|
4731
|
+
def test_factorize_large_circuit() -> None:
|
|
4723
4732
|
circuit = cirq.Circuit()
|
|
4724
4733
|
qubits = cirq.GridQubit.rect(3, 3)
|
|
4725
4734
|
circuit.append(cirq.Moment(cirq.X(q) for q in qubits))
|
|
@@ -4759,7 +4768,7 @@ def test_factorize_large_circuit():
|
|
|
4759
4768
|
cirq.testing.assert_has_diagram(f, d)
|
|
4760
4769
|
|
|
4761
4770
|
|
|
4762
|
-
def test_zero_target_operations_go_below_diagram():
|
|
4771
|
+
def test_zero_target_operations_go_below_diagram() -> None:
|
|
4763
4772
|
class CustomOperationAnnotation(cirq.Operation):
|
|
4764
4773
|
def __init__(self, text: str):
|
|
4765
4774
|
self.text = text
|
|
@@ -4874,7 +4883,7 @@ global phase: 0.5π
|
|
|
4874
4883
|
)
|
|
4875
4884
|
|
|
4876
4885
|
|
|
4877
|
-
def test_create_speed():
|
|
4886
|
+
def test_create_speed() -> None:
|
|
4878
4887
|
# Added in https://github.com/quantumlib/Cirq/pull/5332
|
|
4879
4888
|
# Previously this took ~30s to run. Now it should take ~150ms. However the coverage test can
|
|
4880
4889
|
# run this slowly, so allowing 4 sec to account for things like that. Feel free to increase the
|
|
@@ -4890,7 +4899,7 @@ def test_create_speed():
|
|
|
4890
4899
|
assert duration < 4
|
|
4891
4900
|
|
|
4892
4901
|
|
|
4893
|
-
def test_append_speed():
|
|
4902
|
+
def test_append_speed() -> None:
|
|
4894
4903
|
# Previously this took ~17s to run. Now it should take ~150ms. However the coverage test can
|
|
4895
4904
|
# run this slowly, so allowing 5 sec to account for things like that. Feel free to increase the
|
|
4896
4905
|
# buffer time or delete the test entirely if it ends up causing flakes.
|