cirq-core 1.6.0.dev20250529194600__py3-none-any.whl → 1.6.0.dev20250530203656__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/_bucket_priority_queue_test.py +20 -20
- cirq/circuits/circuit_operation_test.py +58 -56
- cirq/circuits/frozen_circuit_test.py +6 -5
- cirq/circuits/qasm_output_test.py +22 -22
- cirq/circuits/text_diagram_drawer_test.py +17 -17
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +11 -10
- cirq/contrib/qasm_import/_lexer_test.py +47 -13
- cirq/contrib/qasm_import/_parser_test.py +5 -5
- cirq/contrib/qasm_import/qasm_test.py +4 -4
- cirq/contrib/quirk/export_to_quirk_test.py +16 -16
- cirq/devices/insertion_noise_model.py +2 -2
- cirq/linalg/transformations_test.py +71 -43
- cirq/ops/boolean_hamiltonian_test.py +8 -8
- cirq/ops/classically_controlled_operation_test.py +51 -51
- cirq/ops/clifford_gate_test.py +58 -54
- cirq/ops/common_gate_families_test.py +9 -7
- cirq/ops/common_gates_test.py +81 -81
- cirq/ops/control_values_test.py +17 -17
- cirq/ops/controlled_gate_test.py +34 -32
- cirq/ops/diagonal_gate_test.py +11 -11
- cirq/ops/eigen_gate_test.py +28 -20
- cirq/ops/fourier_transform.py +1 -3
- cirq/ops/fourier_transform_test.py +13 -12
- cirq/ops/gate_operation_test.py +43 -42
- cirq/ops/global_phase_op_test.py +22 -20
- cirq/ops/identity_test.py +21 -20
- cirq/ops/kraus_channel_test.py +11 -11
- cirq/ops/named_qubit_test.py +13 -13
- cirq/ops/op_tree_test.py +19 -19
- cirq/ops/phased_x_gate_test.py +16 -16
- cirq/ops/phased_x_z_gate_test.py +14 -11
- cirq/ops/projector_test.py +16 -16
- cirq/ops/qubit_order_test.py +10 -10
- cirq/ops/raw_types.py +2 -2
- cirq/ops/raw_types_test.py +51 -49
- cirq/ops/wait_gate.py +1 -1
- cirq/ops/wait_gate_test.py +6 -6
- cirq/protocols/qasm.py +2 -2
- cirq/qis/entropy_test.py +1 -1
- cirq/testing/consistent_protocols.py +1 -3
- cirq/testing/consistent_protocols_test.py +3 -3
- cirq/value/digits.py +5 -0
- cirq/value/duration.py +1 -1
- {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/RECORD +50 -50
- {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/top_level.txt +0 -0
cirq/ops/clifford_gate_test.py
CHANGED
|
@@ -68,13 +68,13 @@ def _all_clifford_gates() -> tuple[cirq.SingleQubitCliffordGate, ...]:
|
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
@pytest.mark.parametrize('pauli,flip_x,flip_z', itertools.product(_paulis, _bools, _bools))
|
|
71
|
-
def test_init_value_error(pauli, flip_x, flip_z):
|
|
71
|
+
def test_init_value_error(pauli, flip_x, flip_z) -> None:
|
|
72
72
|
with pytest.raises(ValueError):
|
|
73
73
|
cirq.SingleQubitCliffordGate.from_xz_map((pauli, flip_x), (pauli, flip_z))
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
@pytest.mark.parametrize('trans_x,trans_z', _all_rotation_pairs())
|
|
77
|
-
def test_init_from_xz(trans_x, trans_z):
|
|
77
|
+
def test_init_from_xz(trans_x, trans_z) -> None:
|
|
78
78
|
gate = cirq.SingleQubitCliffordGate.from_xz_map(trans_x, trans_z)
|
|
79
79
|
assert gate.pauli_tuple(cirq.X) == trans_x
|
|
80
80
|
assert gate.pauli_tuple(cirq.Z) == trans_z
|
|
@@ -82,7 +82,7 @@ def test_init_from_xz(trans_x, trans_z):
|
|
|
82
82
|
_assert_no_collision(gate)
|
|
83
83
|
|
|
84
84
|
|
|
85
|
-
def test_dense_pauli_string():
|
|
85
|
+
def test_dense_pauli_string() -> None:
|
|
86
86
|
gate = cirq.SingleQubitCliffordGate.from_xz_map((cirq.X, True), (cirq.Y, False))
|
|
87
87
|
assert gate.dense_pauli_string(cirq.X) == cirq.DensePauliString('X', coefficient=-1)
|
|
88
88
|
assert gate.dense_pauli_string(cirq.Z) == cirq.DensePauliString('Y')
|
|
@@ -96,7 +96,7 @@ def test_dense_pauli_string():
|
|
|
96
96
|
if trans1[0] != trans2[0]
|
|
97
97
|
),
|
|
98
98
|
)
|
|
99
|
-
def test_init_from_double_map_vs_kwargs(trans1, trans2, from1):
|
|
99
|
+
def test_init_from_double_map_vs_kwargs(trans1, trans2, from1) -> None:
|
|
100
100
|
from2 = cirq.Pauli.by_relative_index(from1, 1)
|
|
101
101
|
from1_str, from2_str = (str(frm).lower() + '_to' for frm in (from1, from2))
|
|
102
102
|
gate_kw = cirq.SingleQubitCliffordGate.from_double_map(**{from1_str: trans1, from2_str: trans2})
|
|
@@ -115,7 +115,7 @@ def test_init_from_double_map_vs_kwargs(trans1, trans2, from1):
|
|
|
115
115
|
'trans1,from1',
|
|
116
116
|
((trans1, from1) for trans1, from1 in itertools.product(_all_rotations(), _paulis)),
|
|
117
117
|
)
|
|
118
|
-
def test_init_from_double_invalid(trans1, from1):
|
|
118
|
+
def test_init_from_double_invalid(trans1, from1) -> None:
|
|
119
119
|
from2 = cirq.Pauli.by_relative_index(from1, 1)
|
|
120
120
|
# Test throws on invalid arguments
|
|
121
121
|
with pytest.raises(ValueError):
|
|
@@ -123,7 +123,7 @@ def test_init_from_double_invalid(trans1, from1):
|
|
|
123
123
|
|
|
124
124
|
|
|
125
125
|
@pytest.mark.parametrize('trans,frm', itertools.product(_all_rotations(), _paulis))
|
|
126
|
-
def test_init_from_single_map_vs_kwargs(trans, frm):
|
|
126
|
+
def test_init_from_single_map_vs_kwargs(trans, frm) -> None:
|
|
127
127
|
from_str = str(frm).lower() + '_to'
|
|
128
128
|
# pylint: disable=unexpected-keyword-arg
|
|
129
129
|
gate_kw = cirq.SingleQubitCliffordGate.from_single_map(**{from_str: trans})
|
|
@@ -139,7 +139,7 @@ def test_init_from_single_map_vs_kwargs(trans, frm):
|
|
|
139
139
|
if trans[0] != frm
|
|
140
140
|
),
|
|
141
141
|
)
|
|
142
|
-
def test_init_90rot_from_single(trans, frm):
|
|
142
|
+
def test_init_90rot_from_single(trans, frm) -> None:
|
|
143
143
|
gate = cirq.SingleQubitCliffordGate.from_single_map({frm: trans})
|
|
144
144
|
assert gate.pauli_tuple(frm) == trans
|
|
145
145
|
_assert_not_mirror(gate)
|
|
@@ -164,7 +164,7 @@ def test_init_90rot_from_single(trans, frm):
|
|
|
164
164
|
if trans[0] == frm and trans[1]
|
|
165
165
|
),
|
|
166
166
|
)
|
|
167
|
-
def test_init_180rot_from_single(trans, frm):
|
|
167
|
+
def test_init_180rot_from_single(trans, frm) -> None:
|
|
168
168
|
gate = cirq.SingleQubitCliffordGate.from_single_map({frm: trans})
|
|
169
169
|
assert gate.pauli_tuple(frm) == trans
|
|
170
170
|
_assert_not_mirror(gate)
|
|
@@ -183,7 +183,7 @@ def test_init_180rot_from_single(trans, frm):
|
|
|
183
183
|
if trans[0] == frm and not trans[1]
|
|
184
184
|
),
|
|
185
185
|
)
|
|
186
|
-
def test_init_ident_from_single(trans, frm):
|
|
186
|
+
def test_init_ident_from_single(trans, frm) -> None:
|
|
187
187
|
gate = cirq.SingleQubitCliffordGate.from_single_map({frm: trans})
|
|
188
188
|
assert gate.pauli_tuple(frm) == trans
|
|
189
189
|
_assert_not_mirror(gate)
|
|
@@ -205,12 +205,12 @@ def test_init_ident_from_single(trans, frm):
|
|
|
205
205
|
(cirq.Z, True, cirq.SingleQubitCliffordGate.Z_sqrt),
|
|
206
206
|
),
|
|
207
207
|
)
|
|
208
|
-
def test_init_from_pauli(pauli, sqrt, expected):
|
|
208
|
+
def test_init_from_pauli(pauli, sqrt, expected) -> None:
|
|
209
209
|
gate = cirq.SingleQubitCliffordGate.from_pauli(pauli, sqrt=sqrt)
|
|
210
210
|
assert gate == expected
|
|
211
211
|
|
|
212
212
|
|
|
213
|
-
def test_pow():
|
|
213
|
+
def test_pow() -> None:
|
|
214
214
|
assert cirq.SingleQubitCliffordGate.X**-1 == cirq.SingleQubitCliffordGate.X
|
|
215
215
|
assert cirq.SingleQubitCliffordGate.H**-1 == cirq.SingleQubitCliffordGate.H
|
|
216
216
|
assert cirq.SingleQubitCliffordGate.X_sqrt == cirq.SingleQubitCliffordGate.X**0.5
|
|
@@ -229,7 +229,7 @@ def test_pow():
|
|
|
229
229
|
_ = cirq.SingleQubitCliffordGate.Z**0.25
|
|
230
230
|
|
|
231
231
|
|
|
232
|
-
def test_init_from_quarter_turns():
|
|
232
|
+
def test_init_from_quarter_turns() -> None:
|
|
233
233
|
eq = cirq.testing.EqualsTester()
|
|
234
234
|
eq.add_equality_group(
|
|
235
235
|
cirq.SingleQubitCliffordGate.from_quarter_turns(cirq.X, 0),
|
|
@@ -274,7 +274,7 @@ def test_init_from_quarter_turns():
|
|
|
274
274
|
|
|
275
275
|
|
|
276
276
|
@pytest.mark.parametrize('gate', _all_clifford_gates())
|
|
277
|
-
def test_init_from_quarter_turns_reconstruct(gate):
|
|
277
|
+
def test_init_from_quarter_turns_reconstruct(gate) -> None:
|
|
278
278
|
new_gate = functools.reduce(
|
|
279
279
|
cirq.SingleQubitCliffordGate.merged_with,
|
|
280
280
|
(
|
|
@@ -286,7 +286,7 @@ def test_init_from_quarter_turns_reconstruct(gate):
|
|
|
286
286
|
assert gate == new_gate
|
|
287
287
|
|
|
288
288
|
|
|
289
|
-
def test_init_invalid():
|
|
289
|
+
def test_init_invalid() -> None:
|
|
290
290
|
with pytest.raises(ValueError):
|
|
291
291
|
cirq.SingleQubitCliffordGate.from_single_map()
|
|
292
292
|
with pytest.raises(ValueError):
|
|
@@ -317,7 +317,7 @@ def test_init_invalid():
|
|
|
317
317
|
)
|
|
318
318
|
|
|
319
319
|
|
|
320
|
-
def test_eq_ne_and_hash():
|
|
320
|
+
def test_eq_ne_and_hash() -> None:
|
|
321
321
|
eq = EqualsTester()
|
|
322
322
|
for trans_x, trans_z in _all_rotation_pairs():
|
|
323
323
|
gate_gen = lambda: cirq.SingleQubitCliffordGate.from_xz_map(trans_x, trans_z)
|
|
@@ -333,11 +333,11 @@ def test_eq_ne_and_hash():
|
|
|
333
333
|
cirq.SingleQubitCliffordGate.X_sqrt,
|
|
334
334
|
),
|
|
335
335
|
)
|
|
336
|
-
def test_repr_gate(gate):
|
|
336
|
+
def test_repr_gate(gate) -> None:
|
|
337
337
|
cirq.testing.assert_equivalent_repr(gate)
|
|
338
338
|
|
|
339
339
|
|
|
340
|
-
def test_repr_operation():
|
|
340
|
+
def test_repr_operation() -> None:
|
|
341
341
|
cirq.testing.assert_equivalent_repr(
|
|
342
342
|
cirq.SingleQubitCliffordGate.from_pauli(cirq.Z).on(cirq.LineQubit(2))
|
|
343
343
|
)
|
|
@@ -359,7 +359,7 @@ def test_repr_operation():
|
|
|
359
359
|
(cirq.SingleQubitCliffordGate.Z_nsqrt, (cirq.X, False)),
|
|
360
360
|
),
|
|
361
361
|
)
|
|
362
|
-
def test_y_rotation(gate, trans_y):
|
|
362
|
+
def test_y_rotation(gate, trans_y) -> None:
|
|
363
363
|
assert gate.pauli_tuple(cirq.Y) == trans_y
|
|
364
364
|
|
|
365
365
|
|
|
@@ -379,7 +379,7 @@ def test_y_rotation(gate, trans_y):
|
|
|
379
379
|
(cirq.SingleQubitCliffordGate.Z_nsqrt, cirq.Z**-0.5),
|
|
380
380
|
),
|
|
381
381
|
)
|
|
382
|
-
def test_decompose(gate, gate_equiv):
|
|
382
|
+
def test_decompose(gate, gate_equiv) -> None:
|
|
383
383
|
q0 = cirq.NamedQubit('q0')
|
|
384
384
|
mat = cirq.Circuit(gate(q0)).unitary()
|
|
385
385
|
mat_check = cirq.Circuit(gate_equiv(q0)).unitary()
|
|
@@ -402,7 +402,7 @@ def test_decompose(gate, gate_equiv):
|
|
|
402
402
|
(cirq.SingleQubitCliffordGate.Z_nsqrt, cirq.Z**-0.5),
|
|
403
403
|
),
|
|
404
404
|
)
|
|
405
|
-
def test_known_matrix(gate, gate_equiv):
|
|
405
|
+
def test_known_matrix(gate, gate_equiv) -> None:
|
|
406
406
|
assert cirq.has_unitary(gate)
|
|
407
407
|
mat = cirq.unitary(gate)
|
|
408
408
|
mat_check = cirq.unitary(gate_equiv)
|
|
@@ -435,19 +435,19 @@ def test_common_clifford_types(name: str, expected_cls: type) -> None:
|
|
|
435
435
|
|
|
436
436
|
|
|
437
437
|
@pytest.mark.parametrize('gate', _all_clifford_gates())
|
|
438
|
-
def test_inverse(gate):
|
|
438
|
+
def test_inverse(gate) -> None:
|
|
439
439
|
assert gate == cirq.inverse(cirq.inverse(gate))
|
|
440
440
|
|
|
441
441
|
|
|
442
442
|
@pytest.mark.parametrize('gate', _all_clifford_gates())
|
|
443
|
-
def test_inverse_matrix(gate):
|
|
443
|
+
def test_inverse_matrix(gate) -> None:
|
|
444
444
|
q0 = cirq.NamedQubit('q0')
|
|
445
445
|
mat = cirq.Circuit(gate(q0)).unitary()
|
|
446
446
|
mat_inv = cirq.Circuit(cirq.inverse(gate)(q0)).unitary()
|
|
447
447
|
assert_allclose_up_to_global_phase(mat, mat_inv.T.conj(), rtol=1e-7, atol=1e-7)
|
|
448
448
|
|
|
449
449
|
|
|
450
|
-
def test_commutes_notimplemented_type():
|
|
450
|
+
def test_commutes_notimplemented_type() -> None:
|
|
451
451
|
with pytest.raises(TypeError):
|
|
452
452
|
cirq.commutes(cirq.SingleQubitCliffordGate.X, 'X')
|
|
453
453
|
assert cirq.commutes(cirq.SingleQubitCliffordGate.X, 'X', default='default') == 'default'
|
|
@@ -458,7 +458,7 @@ def test_commutes_notimplemented_type():
|
|
|
458
458
|
|
|
459
459
|
|
|
460
460
|
@pytest.mark.parametrize('gate,other', itertools.combinations(_all_clifford_gates(), r=2))
|
|
461
|
-
def test_commutes_single_qubit_gate(gate, other):
|
|
461
|
+
def test_commutes_single_qubit_gate(gate, other) -> None:
|
|
462
462
|
q0 = cirq.NamedQubit('q0')
|
|
463
463
|
gate_op = gate(q0)
|
|
464
464
|
other_op = other(q0)
|
|
@@ -474,7 +474,7 @@ def test_commutes_single_qubit_gate(gate, other):
|
|
|
474
474
|
|
|
475
475
|
|
|
476
476
|
@pytest.mark.parametrize('gate', _all_clifford_gates())
|
|
477
|
-
def test_parses_single_qubit_gate(gate):
|
|
477
|
+
def test_parses_single_qubit_gate(gate) -> None:
|
|
478
478
|
assert gate == cirq.read_json(json_text=(cirq.to_json(gate)))
|
|
479
479
|
|
|
480
480
|
|
|
@@ -482,7 +482,7 @@ def test_parses_single_qubit_gate(gate):
|
|
|
482
482
|
'gate,pauli,half_turns',
|
|
483
483
|
itertools.product(_all_clifford_gates(), _paulis, (1.0, 0.25, 0.5, -0.5)),
|
|
484
484
|
)
|
|
485
|
-
def test_commutes_pauli(gate, pauli, half_turns):
|
|
485
|
+
def test_commutes_pauli(gate, pauli, half_turns) -> None:
|
|
486
486
|
pauli_gate = pauli if half_turns == 1 else pauli**half_turns
|
|
487
487
|
q0 = cirq.NamedQubit('q0')
|
|
488
488
|
mat = cirq.Circuit(gate(q0), pauli_gate(q0)).unitary()
|
|
@@ -492,7 +492,7 @@ def test_commutes_pauli(gate, pauli, half_turns):
|
|
|
492
492
|
assert commutes == commutes_check, f"gate: {gate}, pauli {pauli}"
|
|
493
493
|
|
|
494
494
|
|
|
495
|
-
def test_to_clifford_tableau_util_function():
|
|
495
|
+
def test_to_clifford_tableau_util_function() -> None:
|
|
496
496
|
tableau = cirq.ops.clifford_gate._to_clifford_tableau(
|
|
497
497
|
x_to=(cirq.X, False), z_to=(cirq.Z, False)
|
|
498
498
|
)
|
|
@@ -530,35 +530,39 @@ def test_to_clifford_tableau_util_function():
|
|
|
530
530
|
),
|
|
531
531
|
),
|
|
532
532
|
)
|
|
533
|
-
def test_text_diagram_info(gate, sym, exp):
|
|
533
|
+
def test_text_diagram_info(gate, sym, exp) -> None:
|
|
534
534
|
assert cirq.circuit_diagram_info(gate) == cirq.CircuitDiagramInfo(
|
|
535
535
|
wire_symbols=(sym,), exponent=exp
|
|
536
536
|
)
|
|
537
537
|
|
|
538
538
|
|
|
539
539
|
@pytest.mark.parametrize("clifford_gate", cirq.SingleQubitCliffordGate.all_single_qubit_cliffords)
|
|
540
|
-
def test_from_unitary(clifford_gate):
|
|
540
|
+
def test_from_unitary(clifford_gate) -> None:
|
|
541
541
|
u = cirq.unitary(clifford_gate)
|
|
542
542
|
result_gate = cirq.SingleQubitCliffordGate.from_unitary(u)
|
|
543
543
|
assert result_gate == clifford_gate
|
|
544
544
|
|
|
545
|
-
|
|
545
|
+
result = cirq.SingleQubitCliffordGate.from_unitary_with_global_phase(u)
|
|
546
|
+
assert result is not None
|
|
547
|
+
result_gate2, global_phase = result
|
|
546
548
|
assert result_gate2 == result_gate
|
|
547
549
|
assert np.allclose(cirq.unitary(result_gate2) * global_phase, u)
|
|
548
550
|
|
|
549
551
|
|
|
550
|
-
def test_from_unitary_with_phase_shift():
|
|
552
|
+
def test_from_unitary_with_phase_shift() -> None:
|
|
551
553
|
u = np.exp(0.42j) * cirq.unitary(cirq.SingleQubitCliffordGate.Y_sqrt)
|
|
552
554
|
gate = cirq.SingleQubitCliffordGate.from_unitary(u)
|
|
553
555
|
|
|
554
556
|
assert gate == cirq.SingleQubitCliffordGate.Y_sqrt
|
|
555
557
|
|
|
556
|
-
|
|
558
|
+
result = cirq.SingleQubitCliffordGate.from_unitary_with_global_phase(u)
|
|
559
|
+
assert result is not None
|
|
560
|
+
gate2, global_phase = result
|
|
557
561
|
assert gate2 == gate
|
|
558
562
|
assert np.allclose(cirq.unitary(gate2) * global_phase, u)
|
|
559
563
|
|
|
560
564
|
|
|
561
|
-
def test_from_unitary_not_clifford():
|
|
565
|
+
def test_from_unitary_not_clifford() -> None:
|
|
562
566
|
# Not a single-qubit gate.
|
|
563
567
|
u = cirq.unitary(cirq.CNOT)
|
|
564
568
|
assert cirq.SingleQubitCliffordGate.from_unitary(u) is None
|
|
@@ -576,14 +580,14 @@ def test_from_unitary_not_clifford():
|
|
|
576
580
|
|
|
577
581
|
|
|
578
582
|
@pytest.mark.parametrize("clifford_gate", cirq.SingleQubitCliffordGate.all_single_qubit_cliffords)
|
|
579
|
-
def test_decompose_gate(clifford_gate):
|
|
583
|
+
def test_decompose_gate(clifford_gate) -> None:
|
|
580
584
|
gates = clifford_gate.decompose_gate()
|
|
581
585
|
u = functools.reduce(np.dot, [np.eye(2), *(cirq.unitary(gate) for gate in reversed(gates))])
|
|
582
586
|
assert np.allclose(u, cirq.unitary(clifford_gate)) # No global phase difference.
|
|
583
587
|
|
|
584
588
|
|
|
585
589
|
@pytest.mark.parametrize('trans_x,trans_z', _all_rotation_pairs())
|
|
586
|
-
def test_to_phased_xz_gate(trans_x, trans_z):
|
|
590
|
+
def test_to_phased_xz_gate(trans_x, trans_z) -> None:
|
|
587
591
|
gate = cirq.SingleQubitCliffordGate.from_xz_map(trans_x, trans_z)
|
|
588
592
|
actual_phased_xz_gate = gate.to_phased_xz_gate()._canonical()
|
|
589
593
|
expect_phased_xz_gates = cirq.PhasedXZGate.from_matrix(cirq.unitary(gate))
|
|
@@ -595,7 +599,7 @@ def test_to_phased_xz_gate(trans_x, trans_z):
|
|
|
595
599
|
)
|
|
596
600
|
|
|
597
601
|
|
|
598
|
-
def test_from_xz_to_clifford_tableau():
|
|
602
|
+
def test_from_xz_to_clifford_tableau() -> None:
|
|
599
603
|
seen_tableau = []
|
|
600
604
|
for trans_x, trans_z in _all_rotation_pairs():
|
|
601
605
|
tableau = cirq.SingleQubitCliffordGate.from_xz_map(trans_x, trans_z).clifford_tableau
|
|
@@ -623,7 +627,7 @@ def test_from_xz_to_clifford_tableau():
|
|
|
623
627
|
(cirq.CliffordGate.SWAP, cirq.SWAP),
|
|
624
628
|
],
|
|
625
629
|
)
|
|
626
|
-
def test_common_clifford_gate(clifford_gate, standard_gate):
|
|
630
|
+
def test_common_clifford_gate(clifford_gate, standard_gate) -> None:
|
|
627
631
|
# cirq.unitary is relied on the _decompose_ methods.
|
|
628
632
|
u_c = cirq.unitary(clifford_gate)
|
|
629
633
|
u_s = cirq.unitary(standard_gate)
|
|
@@ -631,7 +635,7 @@ def test_common_clifford_gate(clifford_gate, standard_gate):
|
|
|
631
635
|
|
|
632
636
|
|
|
633
637
|
@pytest.mark.parametrize('property_name', ("all_single_qubit_cliffords", "CNOT", "CZ", "SWAP"))
|
|
634
|
-
def test_common_clifford_gate_caching(property_name):
|
|
638
|
+
def test_common_clifford_gate_caching(property_name) -> None:
|
|
635
639
|
cache_name = f"_{property_name}"
|
|
636
640
|
delattr(cirq.CliffordGate, cache_name)
|
|
637
641
|
assert not hasattr(cirq.CliffordGate, cache_name)
|
|
@@ -639,7 +643,7 @@ def test_common_clifford_gate_caching(property_name):
|
|
|
639
643
|
assert hasattr(cirq.CliffordGate, cache_name)
|
|
640
644
|
|
|
641
645
|
|
|
642
|
-
def test_multi_qubit_clifford_pow():
|
|
646
|
+
def test_multi_qubit_clifford_pow() -> None:
|
|
643
647
|
assert cirq.CliffordGate.X**-1 == cirq.CliffordGate.X
|
|
644
648
|
assert cirq.CliffordGate.H**-1 == cirq.CliffordGate.H
|
|
645
649
|
assert cirq.CliffordGate.S**2 == cirq.CliffordGate.Z
|
|
@@ -651,7 +655,7 @@ def test_multi_qubit_clifford_pow():
|
|
|
651
655
|
_ = cirq.CliffordGate.Z**0.25
|
|
652
656
|
|
|
653
657
|
|
|
654
|
-
def test_stabilizer_effec():
|
|
658
|
+
def test_stabilizer_effec() -> None:
|
|
655
659
|
assert cirq.has_stabilizer_effect(cirq.CliffordGate.X)
|
|
656
660
|
assert cirq.has_stabilizer_effect(cirq.CliffordGate.H)
|
|
657
661
|
assert cirq.has_stabilizer_effect(cirq.CliffordGate.S)
|
|
@@ -664,7 +668,7 @@ def test_stabilizer_effec():
|
|
|
664
668
|
assert cirq.has_stabilizer_effect(gate)
|
|
665
669
|
|
|
666
670
|
|
|
667
|
-
def test_clifford_gate_from_op_list():
|
|
671
|
+
def test_clifford_gate_from_op_list() -> None:
|
|
668
672
|
# Since from_op_list() ==> _act_on_() ==> tableau.then() and then() has already covered
|
|
669
673
|
# lots of random circuit cases, here we just test a few well-known relationships.
|
|
670
674
|
qubit = cirq.NamedQubit('test')
|
|
@@ -709,7 +713,7 @@ def test_clifford_gate_from_op_list():
|
|
|
709
713
|
cirq.CliffordGate.from_op_list([cirq.T(qubit)], [qubit])
|
|
710
714
|
|
|
711
715
|
|
|
712
|
-
def test_clifford_gate_from_tableau():
|
|
716
|
+
def test_clifford_gate_from_tableau() -> None:
|
|
713
717
|
t = cirq.CliffordGate.X.clifford_tableau
|
|
714
718
|
assert cirq.CliffordGate.from_clifford_tableau(t) == cirq.CliffordGate.X
|
|
715
719
|
|
|
@@ -733,10 +737,10 @@ def test_clifford_gate_from_tableau():
|
|
|
733
737
|
cirq.CliffordGate.from_clifford_tableau(t)
|
|
734
738
|
|
|
735
739
|
with pytest.raises(ValueError, match="Input argument has to be a CliffordTableau instance."):
|
|
736
|
-
cirq.CliffordGate.from_clifford_tableau(1)
|
|
740
|
+
cirq.CliffordGate.from_clifford_tableau(1) # type: ignore[arg-type]
|
|
737
741
|
|
|
738
742
|
|
|
739
|
-
def test_multi_clifford_decompose_by_unitary():
|
|
743
|
+
def test_multi_clifford_decompose_by_unitary() -> None:
|
|
740
744
|
# Construct a random clifford gate:
|
|
741
745
|
n, num_ops = 5, 20 # because we relied on unitary cannot test large-scale qubits
|
|
742
746
|
gate_candidate = [cirq.X, cirq.Y, cirq.Z, cirq.H, cirq.S, cirq.CNOT, cirq.CZ]
|
|
@@ -756,7 +760,7 @@ def test_multi_clifford_decompose_by_unitary():
|
|
|
756
760
|
)
|
|
757
761
|
|
|
758
762
|
|
|
759
|
-
def test_pad_tableau_bad_input():
|
|
763
|
+
def test_pad_tableau_bad_input() -> None:
|
|
760
764
|
with pytest.raises(
|
|
761
765
|
ValueError, match="Input axes of padding should match with the number of qubits"
|
|
762
766
|
):
|
|
@@ -770,7 +774,7 @@ def test_pad_tableau_bad_input():
|
|
|
770
774
|
cirq.ops.clifford_gate._pad_tableau(tableau, num_qubits_after_padding=2, axes=[0, 1, 2])
|
|
771
775
|
|
|
772
776
|
|
|
773
|
-
def test_pad_tableau():
|
|
777
|
+
def test_pad_tableau() -> None:
|
|
774
778
|
tableau = cirq.CliffordTableau(num_qubits=1)
|
|
775
779
|
padded_tableau = cirq.ops.clifford_gate._pad_tableau(
|
|
776
780
|
tableau, num_qubits_after_padding=2, axes=[0]
|
|
@@ -811,7 +815,7 @@ def test_pad_tableau():
|
|
|
811
815
|
np.testing.assert_equal(padded_tableau.rs.astype(np.int64), np.zeros(4))
|
|
812
816
|
|
|
813
817
|
|
|
814
|
-
def test_clifford_gate_act_on_small_case():
|
|
818
|
+
def test_clifford_gate_act_on_small_case() -> None:
|
|
815
819
|
# Note this is also covered by the `from_op_list` one, etc.
|
|
816
820
|
|
|
817
821
|
qubits = cirq.LineQubit.range(5)
|
|
@@ -842,7 +846,7 @@ def test_clifford_gate_act_on_small_case():
|
|
|
842
846
|
assert args.tableau == expected_args.tableau
|
|
843
847
|
|
|
844
848
|
|
|
845
|
-
def test_clifford_gate_act_on_large_case():
|
|
849
|
+
def test_clifford_gate_act_on_large_case() -> None:
|
|
846
850
|
n, num_ops = 50, 1000 # because we don't need unitary, it is fast.
|
|
847
851
|
gate_candidate = [cirq.X, cirq.Y, cirq.Z, cirq.H, cirq.S, cirq.CNOT, cirq.CZ]
|
|
848
852
|
for seed in range(10):
|
|
@@ -866,7 +870,7 @@ def test_clifford_gate_act_on_large_case():
|
|
|
866
870
|
assert args1.tableau == args2.tableau
|
|
867
871
|
|
|
868
872
|
|
|
869
|
-
def test_clifford_gate_act_on_ch_form():
|
|
873
|
+
def test_clifford_gate_act_on_ch_form() -> None:
|
|
870
874
|
# Although we don't support CH_form from the _act_on_, it will fall back
|
|
871
875
|
# to the decomposititon method and apply it through decomposed ops.
|
|
872
876
|
# Here we run it for the coverage only.
|
|
@@ -879,12 +883,12 @@ def test_clifford_gate_act_on_ch_form():
|
|
|
879
883
|
np.testing.assert_allclose(args.state.state_vector(), np.array([0, 0, 0, 1]))
|
|
880
884
|
|
|
881
885
|
|
|
882
|
-
def test_clifford_gate_act_on_fail():
|
|
886
|
+
def test_clifford_gate_act_on_fail() -> None:
|
|
883
887
|
with pytest.raises(TypeError, match="Failed to act"):
|
|
884
888
|
cirq.act_on(cirq.CliffordGate.X, ExampleSimulationState(), qubits=())
|
|
885
889
|
|
|
886
890
|
|
|
887
|
-
def test_all_single_qubit_clifford_unitaries():
|
|
891
|
+
def test_all_single_qubit_clifford_unitaries() -> None:
|
|
888
892
|
i = np.eye(2)
|
|
889
893
|
x = np.array([[0, 1], [1, 0]])
|
|
890
894
|
y = np.array([[0, -1j], [1j, 0]])
|
|
@@ -924,7 +928,7 @@ def test_all_single_qubit_clifford_unitaries():
|
|
|
924
928
|
assert cirq.equal_up_to_global_phase(cs[23], (i - 1j * (-x - y - z)) / 2)
|
|
925
929
|
|
|
926
930
|
|
|
927
|
-
def test_clifford_gate_repr():
|
|
931
|
+
def test_clifford_gate_repr() -> None:
|
|
928
932
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
929
933
|
assert (
|
|
930
934
|
repr(cirq.ops.CliffordGate.from_op_list([cirq.ops.X(q0), cirq.CZ(q1, q2)], [q0, q1, q2]))
|
|
@@ -947,7 +951,7 @@ stable | destable
|
|
|
947
951
|
)
|
|
948
952
|
|
|
949
953
|
|
|
950
|
-
def test_single_qubit_clifford_gate_repr():
|
|
954
|
+
def test_single_qubit_clifford_gate_repr() -> None:
|
|
951
955
|
# Common gates
|
|
952
956
|
assert repr(cirq.ops.SingleQubitCliffordGate.X) == (
|
|
953
957
|
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
|
|
@@ -996,7 +1000,7 @@ def test_single_qubit_clifford_gate_repr():
|
|
|
996
1000
|
)
|
|
997
1001
|
|
|
998
1002
|
|
|
999
|
-
def test_cxswap_czswap():
|
|
1003
|
+
def test_cxswap_czswap() -> None:
|
|
1000
1004
|
|
|
1001
1005
|
# cirq unitary for CNOT then SWAP (big endian)
|
|
1002
1006
|
cxswap_expected = np.asarray([[1, 0, 0, 0], [0, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 0]])
|
|
@@ -32,7 +32,7 @@ class UnitaryGate(cirq.Gate):
|
|
|
32
32
|
return self._num_qubits
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def test_any_unitary_gate_family():
|
|
35
|
+
def test_any_unitary_gate_family() -> None:
|
|
36
36
|
with pytest.raises(ValueError, match='must be a positive integer'):
|
|
37
37
|
_ = cirq.AnyUnitaryGateFamily(0)
|
|
38
38
|
eq = cirq.testing.EqualsTester()
|
|
@@ -57,15 +57,17 @@ def test_any_unitary_gate_family():
|
|
|
57
57
|
assert cirq.testing.SingleQubitGate() not in cirq.AnyUnitaryGateFamily()
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def test_any_integer_power_gate_family():
|
|
60
|
+
def test_any_integer_power_gate_family() -> None:
|
|
61
61
|
with pytest.raises(ValueError, match='subclass of `cirq.EigenGate`'):
|
|
62
|
-
cirq.AnyIntegerPowerGateFamily(gate=cirq.testing.SingleQubitGate)
|
|
62
|
+
cirq.AnyIntegerPowerGateFamily(gate=cirq.testing.SingleQubitGate) # type: ignore[arg-type]
|
|
63
63
|
with pytest.raises(ValueError, match='subclass of `cirq.EigenGate`'):
|
|
64
|
-
cirq.AnyIntegerPowerGateFamily(gate=CustomXPowGate())
|
|
64
|
+
cirq.AnyIntegerPowerGateFamily(gate=CustomXPowGate()) # type: ignore[arg-type]
|
|
65
65
|
eq = cirq.testing.EqualsTester()
|
|
66
66
|
gate_family = cirq.AnyIntegerPowerGateFamily(CustomXPowGate)
|
|
67
67
|
eq.add_equality_group(gate_family)
|
|
68
|
-
eq.add_equality_group(
|
|
68
|
+
eq.add_equality_group(
|
|
69
|
+
cirq.AnyIntegerPowerGateFamily(cirq.EigenGate) # type: ignore[type-abstract]
|
|
70
|
+
)
|
|
69
71
|
cirq.testing.assert_equivalent_repr(gate_family)
|
|
70
72
|
assert CustomX in gate_family
|
|
71
73
|
assert CustomX**2 in gate_family
|
|
@@ -78,7 +80,7 @@ def test_any_integer_power_gate_family():
|
|
|
78
80
|
@pytest.mark.parametrize('gate', [CustomX, cirq.ParallelGate(CustomX, 2), CustomXPowGate])
|
|
79
81
|
@pytest.mark.parametrize('name,description', [(None, None), ("Custom Name", "Custom Description")])
|
|
80
82
|
@pytest.mark.parametrize('max_parallel_allowed', [None, 3])
|
|
81
|
-
def test_parallel_gate_family(gate, name, description, max_parallel_allowed):
|
|
83
|
+
def test_parallel_gate_family(gate, name, description, max_parallel_allowed) -> None:
|
|
82
84
|
gate_family = cirq.ParallelGateFamily(
|
|
83
85
|
gate, name=name, description=description, max_parallel_allowed=max_parallel_allowed
|
|
84
86
|
)
|
|
@@ -99,7 +101,7 @@ def test_parallel_gate_family(gate, name, description, max_parallel_allowed):
|
|
|
99
101
|
assert str_to_search in gate_family.description
|
|
100
102
|
|
|
101
103
|
|
|
102
|
-
def test_parallel_gate_family_eq():
|
|
104
|
+
def test_parallel_gate_family_eq() -> None:
|
|
103
105
|
eq = cirq.testing.EqualsTester()
|
|
104
106
|
for name, description in [(None, None), ("Custom Name", "Custom Description")]:
|
|
105
107
|
eq.add_equality_group(
|