cirq-core 1.6.0.dev20250508231110__py3-none-any.whl → 1.6.0.dev20250512192405__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 +2 -2
- cirq/circuits/_block_diagram_drawer_test.py +6 -6
- cirq/circuits/_box_drawing_character_data_test.py +1 -1
- cirq/circuits/insert_strategy_test.py +2 -2
- cirq/circuits/optimization_pass_test.py +5 -5
- cirq/contrib/acquaintance/inspection_utils_test.py +2 -2
- cirq/contrib/acquaintance/mutation_utils_test.py +2 -2
- cirq/contrib/acquaintance/optimizers_test.py +1 -1
- cirq/contrib/acquaintance/shift_test.py +6 -6
- cirq/contrib/acquaintance/strategies/cubic_test.py +2 -2
- cirq/contrib/acquaintance/topological_sort_test.py +1 -1
- cirq/contrib/hacks/disable_validation_test.py +1 -1
- cirq/contrib/json_test.py +3 -3
- cirq/contrib/noise_models/noise_models_test.py +8 -8
- cirq/contrib/paulistring/clifford_optimize_test.py +5 -5
- cirq/contrib/paulistring/clifford_target_gateset_test.py +11 -11
- cirq/contrib/paulistring/optimize_test.py +3 -3
- cirq/contrib/paulistring/pauli_string_dag_test.py +1 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +3 -3
- cirq/contrib/paulistring/recombine_test.py +1 -1
- cirq/contrib/paulistring/separate_test.py +1 -1
- cirq/contrib/qasm_import/_parser_test.py +67 -67
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +1 -1
- cirq/contrib/qcircuit/qcircuit_test.py +6 -6
- cirq/contrib/routing/greedy_test.py +2 -2
- cirq/contrib/routing/initialization_test.py +3 -3
- cirq/contrib/svg/svg_test.py +5 -5
- cirq/devices/device_test.py +4 -4
- cirq/devices/insertion_noise_model_test.py +5 -5
- cirq/devices/named_topologies_test.py +10 -10
- cirq/devices/noise_properties_test.py +1 -1
- cirq/experiments/n_qubit_tomography_test.py +5 -5
- cirq/experiments/t1_decay_experiment_test.py +11 -11
- cirq/interop/quirk/cells/arithmetic_cells_test.py +14 -14
- cirq/interop/quirk/cells/control_cells_test.py +5 -5
- cirq/interop/quirk/cells/frequency_space_cells_test.py +1 -1
- cirq/interop/quirk/cells/ignored_cells_test.py +1 -1
- cirq/interop/quirk/cells/input_cells_test.py +5 -5
- cirq/interop/quirk/cells/input_rotation_cells_test.py +7 -7
- cirq/interop/quirk/cells/measurement_cells_test.py +1 -1
- cirq/interop/quirk/cells/qubit_permutation_cells_test.py +7 -7
- cirq/interop/quirk/cells/scalar_cells_test.py +1 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells_test.py +3 -3
- cirq/interop/quirk/cells/swap_cell_test.py +4 -4
- cirq/interop/quirk/cells/testing_test.py +6 -6
- cirq/interop/quirk/cells/unsupported_cells_test.py +2 -2
- cirq/linalg/combinators_test.py +7 -7
- cirq/linalg/diagonalize_test.py +10 -10
- cirq/linalg/operator_spaces_test.py +11 -11
- cirq/linalg/tolerance_test.py +4 -4
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +1 -1
- cirq/ops/arithmetic_operation_test.py +2 -2
- cirq/ops/common_channels_test.py +80 -80
- cirq/ops/fsim_gate_test.py +26 -26
- cirq/ops/gate_features_test.py +3 -3
- cirq/ops/greedy_qubit_manager_test.py +3 -3
- cirq/ops/mixed_unitary_channel_test.py +11 -11
- cirq/ops/parallel_gate_test.py +16 -16
- cirq/ops/parity_gates_test.py +34 -32
- cirq/ops/pauli_gates_test.py +20 -20
- cirq/ops/pauli_interaction_gate_test.py +8 -8
- cirq/ops/pauli_sum_exponential_test.py +10 -10
- cirq/ops/permutation_gate_test.py +8 -8
- cirq/ops/phased_iswap_gate_test.py +15 -15
- cirq/ops/qubit_manager_test.py +4 -4
- cirq/ops/random_gate_channel_test.py +11 -11
- cirq/ops/state_preparation_channel_test.py +8 -8
- cirq/ops/swap_gates_test.py +17 -17
- cirq/ops/tags_test.py +2 -2
- cirq/ops/three_qubit_gates_test.py +17 -17
- cirq/ops/two_qubit_diagonal_gate_test.py +8 -8
- cirq/ops/uniform_superposition_gate_test.py +3 -3
- cirq/protocols/act_on_protocol_test.py +6 -6
- cirq/protocols/circuit_diagram_info_protocol_test.py +13 -13
- cirq/protocols/control_key_protocol_test.py +1 -1
- cirq/protocols/decompose_protocol_test.py +12 -12
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +6 -6
- cirq/protocols/has_stabilizer_effect_protocol_test.py +5 -5
- cirq/protocols/has_unitary_protocol_test.py +8 -8
- cirq/protocols/hash_from_pickle_test.py +1 -1
- cirq/protocols/inverse_protocol_test.py +2 -2
- cirq/protocols/kraus_protocol_test.py +9 -9
- cirq/protocols/measurement_key_protocol_test.py +10 -10
- cirq/protocols/pauli_expansion_protocol_test.py +2 -2
- cirq/protocols/phase_protocol_test.py +1 -1
- cirq/protocols/qasm_test.py +3 -3
- cirq/protocols/qid_shape_protocol_test.py +1 -1
- cirq/protocols/resolve_parameters_test.py +5 -5
- cirq/protocols/trace_distance_bound_test.py +1 -1
- cirq/qis/channels_test.py +16 -16
- cirq/qis/measures_test.py +16 -14
- cirq/qis/noise_utils_test.py +7 -7
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +3 -3
- cirq/sim/clifford/stabilizer_ch_form_simulation_state_test.py +6 -6
- cirq/sim/clifford/stabilizer_sampler_test.py +2 -2
- cirq/sim/clifford/stabilizer_simulation_state_test.py +4 -4
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +2 -2
- cirq/sim/density_matrix_simulation_state_test.py +8 -8
- cirq/sim/density_matrix_utils_test.py +36 -36
- cirq/sim/simulation_product_state_test.py +22 -22
- cirq/sim/simulation_state_test.py +12 -12
- cirq/sim/simulation_utils_test.py +1 -1
- cirq/sim/state_vector_simulation_state_test.py +12 -12
- cirq/study/flatten_expressions_test.py +11 -11
- cirq/study/resolver_test.py +20 -20
- cirq/testing/consistent_act_on_test.py +1 -1
- cirq/testing/consistent_channels_test.py +8 -8
- cirq/testing/consistent_controlled_gate_op_test.py +2 -2
- cirq/testing/consistent_decomposition_test.py +2 -2
- cirq/testing/consistent_pauli_expansion_test.py +1 -1
- cirq/testing/consistent_phase_by_test.py +1 -1
- cirq/testing/consistent_qasm_test.py +1 -1
- cirq/testing/consistent_specified_has_unitary_test.py +4 -4
- cirq/testing/consistent_unitary_test.py +2 -2
- cirq/testing/deprecation_test.py +2 -2
- cirq/testing/devices_test.py +4 -4
- cirq/testing/equivalent_basis_map_test.py +2 -2
- cirq/testing/equivalent_repr_eval_test.py +3 -3
- cirq/testing/gate_features_test.py +5 -5
- cirq/testing/json_test.py +3 -3
- cirq/testing/lin_alg_utils_test.py +12 -12
- cirq/testing/logs_test.py +7 -7
- cirq/testing/no_identifier_qubit_test.py +3 -3
- cirq/testing/op_tree_test.py +1 -1
- cirq/testing/order_tester_test.py +6 -6
- cirq/testing/pytest_utils_test.py +2 -2
- cirq/testing/random_circuit_test.py +5 -5
- cirq/testing/repr_pretty_tester_test.py +3 -3
- cirq/testing/routing_devices_test.py +6 -6
- cirq/testing/sample_circuits_test.py +1 -1
- cirq/testing/sample_gates_test.py +2 -2
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +3 -3
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +7 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +6 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +5 -5
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +1 -1
- cirq/transformers/drop_empty_moments_test.py +2 -2
- cirq/transformers/eject_phased_paulis_test.py +9 -9
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +7 -7
- cirq/transformers/insertion_sort_test.py +1 -1
- cirq/transformers/merge_k_qubit_gates_test.py +9 -9
- cirq/transformers/qubit_management_transformers_test.py +3 -3
- cirq/transformers/randomized_measurements_test.py +8 -4
- cirq/transformers/routing/line_initial_mapper_test.py +5 -5
- cirq/transformers/routing/route_circuit_cqc_test.py +13 -13
- cirq/transformers/routing/visualize_routed_circuit_test.py +2 -2
- cirq/transformers/synchronize_terminal_measurements_test.py +10 -10
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +8 -8
- cirq/transformers/target_gatesets/cz_gateset_test.py +17 -17
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +23 -23
- cirq/value/angle_test.py +3 -3
- cirq/value/classical_data_test.py +8 -8
- cirq/value/periodic_value_test.py +9 -7
- cirq/value/probability_test.py +2 -2
- cirq/value/value_equality_attr_test.py +11 -11
- cirq/vis/histogram_test.py +2 -2
- cirq/vis/state_histogram_test.py +5 -5
- cirq/vis/vis_utils_test.py +1 -1
- cirq/work/observable_grouping_test.py +8 -8
- cirq/work/observable_readout_calibration_test.py +1 -1
- cirq/work/zeros_sampler_test.py +4 -4
- {cirq_core-1.6.0.dev20250508231110.dist-info → cirq_core-1.6.0.dev20250512192405.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250508231110.dist-info → cirq_core-1.6.0.dev20250512192405.dist-info}/RECORD +167 -167
- {cirq_core-1.6.0.dev20250508231110.dist-info → cirq_core-1.6.0.dev20250512192405.dist-info}/WHEEL +1 -1
- {cirq_core-1.6.0.dev20250508231110.dist-info → cirq_core-1.6.0.dev20250512192405.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250508231110.dist-info → cirq_core-1.6.0.dev20250512192405.dist-info}/top_level.txt +0 -0
|
@@ -22,7 +22,7 @@ import cirq
|
|
|
22
22
|
np.set_printoptions(linewidth=300)
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
def test_phased_iswap_init():
|
|
25
|
+
def test_phased_iswap_init() -> None:
|
|
26
26
|
p = -0.25
|
|
27
27
|
t = 0.75
|
|
28
28
|
s = 0.5
|
|
@@ -32,7 +32,7 @@ def test_phased_iswap_init():
|
|
|
32
32
|
assert gate.global_shift == s
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def test_phased_iswap_equality():
|
|
35
|
+
def test_phased_iswap_equality() -> None:
|
|
36
36
|
eq = cirq.testing.EqualsTester()
|
|
37
37
|
eq.add_equality_group(cirq.PhasedISwapPowGate(phase_exponent=0, exponent=0.4))
|
|
38
38
|
eq.add_equality_group(cirq.ISWAP**0.4)
|
|
@@ -40,7 +40,7 @@ def test_phased_iswap_equality():
|
|
|
40
40
|
eq.add_equality_group(cirq.ISwapPowGate(global_shift=0.3) ** 0.4)
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
def test_repr():
|
|
43
|
+
def test_repr() -> None:
|
|
44
44
|
p = -0.25
|
|
45
45
|
t = 0.75
|
|
46
46
|
s = 0.3
|
|
@@ -48,7 +48,7 @@ def test_repr():
|
|
|
48
48
|
cirq.testing.assert_equivalent_repr(gate)
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
def test_phased_iswap_unitary():
|
|
51
|
+
def test_phased_iswap_unitary() -> None:
|
|
52
52
|
p = 0.3
|
|
53
53
|
t = 0.4
|
|
54
54
|
actual = cirq.unitary(cirq.PhasedISwapPowGate(phase_exponent=p, exponent=t))
|
|
@@ -64,7 +64,7 @@ def test_phased_iswap_unitary():
|
|
|
64
64
|
assert np.allclose(actual, expected)
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
def test_phased_iswap_equivalent_circuit():
|
|
67
|
+
def test_phased_iswap_equivalent_circuit() -> None:
|
|
68
68
|
p = 0.7
|
|
69
69
|
t = -0.4
|
|
70
70
|
gate = cirq.PhasedISwapPowGate(phase_exponent=p, exponent=t)
|
|
@@ -81,7 +81,7 @@ def test_phased_iswap_equivalent_circuit():
|
|
|
81
81
|
assert np.allclose(cirq.unitary(gate), cirq.unitary(equivalent_circuit))
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
def test_phased_iswap_str():
|
|
84
|
+
def test_phased_iswap_str() -> None:
|
|
85
85
|
assert str(cirq.PhasedISwapPowGate(exponent=1)) == 'PhasedISWAP'
|
|
86
86
|
assert str(cirq.PhasedISwapPowGate(exponent=0.5)) == 'PhasedISWAP**0.5'
|
|
87
87
|
assert (
|
|
@@ -90,7 +90,7 @@ def test_phased_iswap_str():
|
|
|
90
90
|
)
|
|
91
91
|
|
|
92
92
|
|
|
93
|
-
def test_phased_iswap_pow():
|
|
93
|
+
def test_phased_iswap_pow() -> None:
|
|
94
94
|
gate1 = cirq.PhasedISwapPowGate(phase_exponent=0.1, exponent=0.25)
|
|
95
95
|
gate2 = cirq.PhasedISwapPowGate(phase_exponent=0.1, exponent=0.5)
|
|
96
96
|
assert gate1**2 == gate2
|
|
@@ -108,7 +108,7 @@ def test_phased_iswap_pow():
|
|
|
108
108
|
assert np.allclose(u1 @ u1, u2)
|
|
109
109
|
|
|
110
110
|
|
|
111
|
-
def test_decompose_invalid_qubits():
|
|
111
|
+
def test_decompose_invalid_qubits() -> None:
|
|
112
112
|
qs = cirq.LineQubit.range(3)
|
|
113
113
|
with pytest.raises(ValueError):
|
|
114
114
|
cirq.protocols.decompose_once_with_qubits(cirq.PhasedISwapPowGate(), qs)
|
|
@@ -134,7 +134,7 @@ def test_decompose_invalid_qubits():
|
|
|
134
134
|
(sympy.Symbol('t'), sympy.Symbol('p'), 1),
|
|
135
135
|
],
|
|
136
136
|
)
|
|
137
|
-
def test_phased_iswap_has_consistent_protocols(phase_exponent, exponent, global_shift):
|
|
137
|
+
def test_phased_iswap_has_consistent_protocols(phase_exponent, exponent, global_shift) -> None:
|
|
138
138
|
cirq.testing.assert_implements_consistent_protocols(
|
|
139
139
|
cirq.PhasedISwapPowGate(
|
|
140
140
|
phase_exponent=phase_exponent, exponent=exponent, global_shift=global_shift
|
|
@@ -142,7 +142,7 @@ def test_phased_iswap_has_consistent_protocols(phase_exponent, exponent, global_
|
|
|
142
142
|
)
|
|
143
143
|
|
|
144
144
|
|
|
145
|
-
def test_diagram():
|
|
145
|
+
def test_diagram() -> None:
|
|
146
146
|
q0, q1 = cirq.LineQubit.range(2)
|
|
147
147
|
c = cirq.Circuit(
|
|
148
148
|
cirq.PhasedISwapPowGate(phase_exponent=sympy.Symbol('p'), exponent=sympy.Symbol('t')).on(
|
|
@@ -165,7 +165,7 @@ def test_diagram():
|
|
|
165
165
|
|
|
166
166
|
|
|
167
167
|
@pytest.mark.parametrize('angle_rads', (-np.pi, -np.pi / 3, -0.1, np.pi / 5))
|
|
168
|
-
def test_givens_rotation_unitary(angle_rads):
|
|
168
|
+
def test_givens_rotation_unitary(angle_rads) -> None:
|
|
169
169
|
actual = cirq.unitary(cirq.givens(angle_rads))
|
|
170
170
|
c = np.cos(angle_rads)
|
|
171
171
|
s = np.sin(angle_rads)
|
|
@@ -179,7 +179,7 @@ def test_givens_rotation_unitary(angle_rads):
|
|
|
179
179
|
|
|
180
180
|
|
|
181
181
|
@pytest.mark.parametrize('angle_rads', (-2 * np.pi / 3, -0.2, 0.4, np.pi / 4))
|
|
182
|
-
def test_givens_rotation_hamiltonian(angle_rads):
|
|
182
|
+
def test_givens_rotation_hamiltonian(angle_rads) -> None:
|
|
183
183
|
actual = cirq.unitary(cirq.givens(angle_rads))
|
|
184
184
|
x = np.array([[0, 1], [1, 0]])
|
|
185
185
|
y = np.array([[0, -1j], [1j, 0]])
|
|
@@ -189,7 +189,7 @@ def test_givens_rotation_hamiltonian(angle_rads):
|
|
|
189
189
|
assert np.allclose(actual, expected)
|
|
190
190
|
|
|
191
191
|
|
|
192
|
-
def test_givens_rotation_equivalent_circuit():
|
|
192
|
+
def test_givens_rotation_equivalent_circuit() -> None:
|
|
193
193
|
angle_rads = 3 * np.pi / 7
|
|
194
194
|
t = 2 * angle_rads / np.pi
|
|
195
195
|
gate = cirq.givens(angle_rads)
|
|
@@ -201,11 +201,11 @@ def test_givens_rotation_equivalent_circuit():
|
|
|
201
201
|
|
|
202
202
|
|
|
203
203
|
@pytest.mark.parametrize('angle_rads', (-np.pi / 5, 0.4, 2, np.pi))
|
|
204
|
-
def test_givens_rotation_has_consistent_protocols(angle_rads):
|
|
204
|
+
def test_givens_rotation_has_consistent_protocols(angle_rads) -> None:
|
|
205
205
|
cirq.testing.assert_implements_consistent_protocols(cirq.givens(angle_rads))
|
|
206
206
|
|
|
207
207
|
|
|
208
|
-
def test_approx_eq():
|
|
208
|
+
def test_approx_eq() -> None:
|
|
209
209
|
gate0 = cirq.PhasedISwapPowGate(phase_exponent=0)
|
|
210
210
|
gate1 = cirq.PhasedISwapPowGate(phase_exponent=1e-12)
|
|
211
211
|
gate2 = cirq.PhasedISwapPowGate(phase_exponent=2e-12)
|
cirq/ops/qubit_manager_test.py
CHANGED
|
@@ -18,7 +18,7 @@ import cirq
|
|
|
18
18
|
from cirq.ops import qubit_manager as cqi
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def test_clean_qubits():
|
|
21
|
+
def test_clean_qubits() -> None:
|
|
22
22
|
q = cqi.CleanQubit(1)
|
|
23
23
|
assert q.id == 1
|
|
24
24
|
assert q.dimension == 2
|
|
@@ -39,7 +39,7 @@ def test_clean_qubits():
|
|
|
39
39
|
assert cqi.CleanQubit(1) < cqi.CleanQubit(2)
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
def test_ancilla_qubits_prefix():
|
|
42
|
+
def test_ancilla_qubits_prefix() -> None:
|
|
43
43
|
assert cqi.CleanQubit(1, prefix="1") != cqi.CleanQubit(1, prefix="2")
|
|
44
44
|
assert cqi.CleanQubit(1, prefix="1") < cqi.CleanQubit(1, prefix="2")
|
|
45
45
|
assert cqi.CleanQubit(1, prefix="1") < cqi.CleanQubit(2, prefix="1")
|
|
@@ -49,7 +49,7 @@ def test_ancilla_qubits_prefix():
|
|
|
49
49
|
assert cqi.CleanQubit(1, prefix="1") != cqi.BorrowableQubit(1, prefix="1")
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
def test_borrow_qubits():
|
|
52
|
+
def test_borrow_qubits() -> None:
|
|
53
53
|
q = cqi.BorrowableQubit(10)
|
|
54
54
|
assert q.id == 10
|
|
55
55
|
assert q.dimension == 2
|
|
@@ -71,7 +71,7 @@ def test_borrow_qubits():
|
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
@pytest.mark.parametrize('_', range(2))
|
|
74
|
-
def test_simple_qubit_manager(_):
|
|
74
|
+
def test_simple_qubit_manager(_) -> None:
|
|
75
75
|
qm = cirq.ops.SimpleQubitManager()
|
|
76
76
|
assert qm.qalloc(1) == [cqi.CleanQubit(0)]
|
|
77
77
|
assert qm.qalloc(2) == [cqi.CleanQubit(1), cqi.CleanQubit(2)]
|
|
@@ -18,7 +18,7 @@ import sympy
|
|
|
18
18
|
import cirq
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def test_init():
|
|
21
|
+
def test_init() -> None:
|
|
22
22
|
p = cirq.RandomGateChannel(sub_gate=cirq.X, probability=0.5)
|
|
23
23
|
assert p.sub_gate is cirq.X
|
|
24
24
|
assert p.probability == 0.5
|
|
@@ -29,7 +29,7 @@ def test_init():
|
|
|
29
29
|
_ = cirq.RandomGateChannel(sub_gate=cirq.X, probability=-1)
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def test_eq():
|
|
32
|
+
def test_eq() -> None:
|
|
33
33
|
eq = cirq.testing.EqualsTester()
|
|
34
34
|
q = cirq.LineQubit(0)
|
|
35
35
|
|
|
@@ -67,7 +67,7 @@ def test_eq():
|
|
|
67
67
|
)
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def test_consistent_protocols():
|
|
70
|
+
def test_consistent_protocols() -> None:
|
|
71
71
|
cirq.testing.assert_implements_consistent_protocols(
|
|
72
72
|
cirq.RandomGateChannel(sub_gate=cirq.X, probability=1),
|
|
73
73
|
ignore_decompose_to_default_gateset=True,
|
|
@@ -86,7 +86,7 @@ def test_consistent_protocols():
|
|
|
86
86
|
)
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
def test_diagram():
|
|
89
|
+
def test_diagram() -> None:
|
|
90
90
|
class NoDetailsGate(cirq.Gate):
|
|
91
91
|
def num_qubits(self) -> int:
|
|
92
92
|
raise NotImplementedError()
|
|
@@ -115,7 +115,7 @@ def test_diagram():
|
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
118
|
-
def test_parameterized(resolve_fn):
|
|
118
|
+
def test_parameterized(resolve_fn) -> None:
|
|
119
119
|
op = cirq.X.with_probability(sympy.Symbol('x'))
|
|
120
120
|
assert cirq.is_parameterized(op)
|
|
121
121
|
assert not cirq.has_kraus(op)
|
|
@@ -128,7 +128,7 @@ def test_parameterized(resolve_fn):
|
|
|
128
128
|
assert cirq.has_mixture(op2)
|
|
129
129
|
|
|
130
130
|
|
|
131
|
-
def test_mixture():
|
|
131
|
+
def test_mixture() -> None:
|
|
132
132
|
class NoDetailsGate(cirq.Gate):
|
|
133
133
|
def num_qubits(self) -> int:
|
|
134
134
|
return 1
|
|
@@ -150,7 +150,7 @@ def test_mixture():
|
|
|
150
150
|
assert {p for p, _ in m} == {7 / 8, 1 / 32, 3 / 32}
|
|
151
151
|
|
|
152
152
|
|
|
153
|
-
def test_channel():
|
|
153
|
+
def test_channel() -> None:
|
|
154
154
|
class NoDetailsGate(cirq.Gate):
|
|
155
155
|
def num_qubits(self) -> int:
|
|
156
156
|
return 1
|
|
@@ -192,7 +192,7 @@ def test_channel():
|
|
|
192
192
|
np.testing.assert_allclose(m[2], cirq.unitary(cirq.I) * np.sqrt(0.75), atol=1e-8)
|
|
193
193
|
|
|
194
194
|
|
|
195
|
-
def test_trace_distance():
|
|
195
|
+
def test_trace_distance() -> None:
|
|
196
196
|
t = cirq.trace_distance_bound
|
|
197
197
|
assert 0.999 <= t(cirq.X.with_probability(sympy.Symbol('x')))
|
|
198
198
|
assert t(cirq.X.with_probability(0)) == 0
|
|
@@ -201,18 +201,18 @@ def test_trace_distance():
|
|
|
201
201
|
assert 0.35 <= t(cirq.S.with_probability(0.5)) <= 0.36
|
|
202
202
|
|
|
203
203
|
|
|
204
|
-
def test_str():
|
|
204
|
+
def test_str() -> None:
|
|
205
205
|
assert str(cirq.X.with_probability(0.5)) == 'X[prob=0.5]'
|
|
206
206
|
|
|
207
207
|
|
|
208
|
-
def test_stabilizer_supports_probability():
|
|
208
|
+
def test_stabilizer_supports_probability() -> None:
|
|
209
209
|
q = cirq.LineQubit(0)
|
|
210
210
|
c = cirq.Circuit(cirq.X(q).with_probability(0.5), cirq.measure(q, key='m'))
|
|
211
211
|
m = np.sum(cirq.StabilizerSampler().sample(c, repetitions=100)['m'])
|
|
212
212
|
assert 5 < m < 95
|
|
213
213
|
|
|
214
214
|
|
|
215
|
-
def test_unsupported_stabilizer_safety():
|
|
215
|
+
def test_unsupported_stabilizer_safety() -> None:
|
|
216
216
|
from cirq.protocols.act_on_protocol_test import ExampleSimulationState
|
|
217
217
|
|
|
218
218
|
with pytest.raises(TypeError, match="act_on"):
|
|
@@ -36,7 +36,7 @@ import cirq
|
|
|
36
36
|
]
|
|
37
37
|
),
|
|
38
38
|
)
|
|
39
|
-
def test_state_prep_channel_kraus(state):
|
|
39
|
+
def test_state_prep_channel_kraus(state) -> None:
|
|
40
40
|
qubits = cirq.LineQubit.range(2)
|
|
41
41
|
gate = cirq.StatePreparationChannel(state)(qubits[0], qubits[1])
|
|
42
42
|
cirq.testing.assert_consistent_channel(gate)
|
|
@@ -53,7 +53,7 @@ def test_state_prep_channel_kraus(state):
|
|
|
53
53
|
)
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
def test_state_prep_channel_kraus_small():
|
|
56
|
+
def test_state_prep_channel_kraus_small() -> None:
|
|
57
57
|
gate = cirq.StatePreparationChannel(np.array([0.0, 1.0]))(cirq.LineQubit(0))
|
|
58
58
|
np.testing.assert_almost_equal(
|
|
59
59
|
cirq.kraus(gate), (np.array([[0.0, 0.0], [1.0, 0.0]]), np.array([[0.0, 0.0], [0.0, 1.0]]))
|
|
@@ -69,7 +69,7 @@ def test_state_prep_channel_kraus_small():
|
|
|
69
69
|
assert not cirq.has_mixture(gate)
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def test_state_prep_gate_printing():
|
|
72
|
+
def test_state_prep_gate_printing() -> None:
|
|
73
73
|
circuit = cirq.Circuit()
|
|
74
74
|
qubits = cirq.LineQubit.range(2)
|
|
75
75
|
gate = cirq.StatePreparationChannel(np.array([1, 0, 0, 1]) / np.sqrt(2))
|
|
@@ -87,7 +87,7 @@ def test_state_prep_gate_printing():
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
@pytest.mark.parametrize('name', ['Prep', 'S'])
|
|
90
|
-
def test_state_prep_gate_printing_with_name(name):
|
|
90
|
+
def test_state_prep_gate_printing_with_name(name) -> None:
|
|
91
91
|
circuit = cirq.Circuit()
|
|
92
92
|
qubits = cirq.LineQubit.range(2)
|
|
93
93
|
gate = cirq.StatePreparationChannel(np.array([1, 0, 0, 1]) / np.sqrt(2), name=name)
|
|
@@ -104,7 +104,7 @@ def test_state_prep_gate_printing_with_name(name):
|
|
|
104
104
|
)
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
def test_gate_params():
|
|
107
|
+
def test_gate_params() -> None:
|
|
108
108
|
state = np.array([1, 0, 0, 0], dtype=np.complex64)
|
|
109
109
|
gate = cirq.StatePreparationChannel(state)
|
|
110
110
|
assert gate.num_qubits() == 2
|
|
@@ -114,14 +114,14 @@ def test_gate_params():
|
|
|
114
114
|
cirq.testing.assert_equivalent_repr(gate)
|
|
115
115
|
|
|
116
116
|
|
|
117
|
-
def test_gate_error_handling():
|
|
117
|
+
def test_gate_error_handling() -> None:
|
|
118
118
|
with pytest.raises(ValueError, match='`target_state` must be a 1d numpy array.'):
|
|
119
119
|
cirq.StatePreparationChannel(np.eye(2))
|
|
120
120
|
with pytest.raises(ValueError, match='Matrix width \\(5\\) is not a power of 2'):
|
|
121
121
|
cirq.StatePreparationChannel(np.ones(shape=5))
|
|
122
122
|
|
|
123
123
|
|
|
124
|
-
def test_equality_of_gates():
|
|
124
|
+
def test_equality_of_gates() -> None:
|
|
125
125
|
state = np.array([1, 0, 0, 0], dtype=np.complex64)
|
|
126
126
|
gate_1 = cirq.StatePreparationChannel(state)
|
|
127
127
|
gate_2 = cirq.StatePreparationChannel(state)
|
|
@@ -134,7 +134,7 @@ def test_equality_of_gates():
|
|
|
134
134
|
assert gate_1 != gate_3, "Different states shouldn't lead to same gate"
|
|
135
135
|
|
|
136
136
|
|
|
137
|
-
def test_approx_equality_of_gates():
|
|
137
|
+
def test_approx_equality_of_gates() -> None:
|
|
138
138
|
state = np.array([1, 0, 0, 0], dtype=np.complex64)
|
|
139
139
|
gate_1 = cirq.StatePreparationChannel(state)
|
|
140
140
|
gate_2 = cirq.StatePreparationChannel(state)
|
cirq/ops/swap_gates_test.py
CHANGED
|
@@ -21,11 +21,11 @@ import cirq
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
@pytest.mark.parametrize('eigen_gate_type', [cirq.ISwapPowGate, cirq.SwapPowGate])
|
|
24
|
-
def test_phase_sensitive_eigen_gates_consistent_protocols(eigen_gate_type):
|
|
24
|
+
def test_phase_sensitive_eigen_gates_consistent_protocols(eigen_gate_type) -> None:
|
|
25
25
|
cirq.testing.assert_eigengate_implements_consistent_protocols(eigen_gate_type)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def test_interchangeable_qubit_eq():
|
|
28
|
+
def test_interchangeable_qubit_eq() -> None:
|
|
29
29
|
a = cirq.NamedQubit('a')
|
|
30
30
|
b = cirq.NamedQubit('b')
|
|
31
31
|
c = cirq.NamedQubit('c')
|
|
@@ -44,7 +44,7 @@ def test_interchangeable_qubit_eq():
|
|
|
44
44
|
eq.add_equality_group(cirq.ISWAP(a, c) ** 0.3)
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
def test_text_diagrams():
|
|
47
|
+
def test_text_diagrams() -> None:
|
|
48
48
|
a = cirq.NamedQubit('a')
|
|
49
49
|
b = cirq.NamedQubit('b')
|
|
50
50
|
circuit = cirq.Circuit(cirq.SWAP(a, b), cirq.ISWAP(a, b) ** -1)
|
|
@@ -69,14 +69,14 @@ b: ---Swap---iSwap^-1---
|
|
|
69
69
|
)
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def test_swap_has_stabilizer_effect():
|
|
72
|
+
def test_swap_has_stabilizer_effect() -> None:
|
|
73
73
|
assert cirq.has_stabilizer_effect(cirq.SWAP)
|
|
74
74
|
assert cirq.has_stabilizer_effect(cirq.SWAP**2)
|
|
75
75
|
assert not cirq.has_stabilizer_effect(cirq.SWAP**0.5)
|
|
76
76
|
assert not cirq.has_stabilizer_effect(cirq.SWAP ** sympy.Symbol('foo'))
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
def test_swap_unitary():
|
|
79
|
+
def test_swap_unitary() -> None:
|
|
80
80
|
# yapf: disable
|
|
81
81
|
np.testing.assert_almost_equal(
|
|
82
82
|
cirq.unitary(cirq.SWAP**0.5),
|
|
@@ -89,7 +89,7 @@ def test_swap_unitary():
|
|
|
89
89
|
# yapf: enable
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
def test_iswap_unitary():
|
|
92
|
+
def test_iswap_unitary() -> None:
|
|
93
93
|
# yapf: disable
|
|
94
94
|
cirq.testing.assert_allclose_up_to_global_phase(
|
|
95
95
|
cirq.unitary(cirq.ISWAP),
|
|
@@ -103,7 +103,7 @@ def test_iswap_unitary():
|
|
|
103
103
|
# yapf: enable
|
|
104
104
|
|
|
105
105
|
|
|
106
|
-
def test_iswap_inv_unitary():
|
|
106
|
+
def test_iswap_inv_unitary() -> None:
|
|
107
107
|
# yapf: disable
|
|
108
108
|
cirq.testing.assert_allclose_up_to_global_phase(
|
|
109
109
|
cirq.unitary(cirq.ISWAP_INV),
|
|
@@ -117,7 +117,7 @@ def test_iswap_inv_unitary():
|
|
|
117
117
|
# yapf: enable
|
|
118
118
|
|
|
119
119
|
|
|
120
|
-
def test_sqrt_iswap_unitary():
|
|
120
|
+
def test_sqrt_iswap_unitary() -> None:
|
|
121
121
|
# yapf: disable
|
|
122
122
|
cirq.testing.assert_allclose_up_to_global_phase(
|
|
123
123
|
cirq.unitary(cirq.SQRT_ISWAP),
|
|
@@ -131,7 +131,7 @@ def test_sqrt_iswap_unitary():
|
|
|
131
131
|
# yapf: enable
|
|
132
132
|
|
|
133
133
|
|
|
134
|
-
def test_sqrt_iswap_inv_unitary():
|
|
134
|
+
def test_sqrt_iswap_inv_unitary() -> None:
|
|
135
135
|
# yapf: disable
|
|
136
136
|
cirq.testing.assert_allclose_up_to_global_phase(
|
|
137
137
|
cirq.unitary(cirq.SQRT_ISWAP_INV),
|
|
@@ -145,7 +145,7 @@ def test_sqrt_iswap_inv_unitary():
|
|
|
145
145
|
# yapf: enable
|
|
146
146
|
|
|
147
147
|
|
|
148
|
-
def test_repr():
|
|
148
|
+
def test_repr() -> None:
|
|
149
149
|
assert repr(cirq.SWAP) == 'cirq.SWAP'
|
|
150
150
|
assert repr(cirq.SWAP**0.5) == '(cirq.SWAP**0.5)'
|
|
151
151
|
|
|
@@ -156,7 +156,7 @@ def test_repr():
|
|
|
156
156
|
assert repr(cirq.ISWAP_INV**0.5) == '(cirq.ISWAP**-0.5)'
|
|
157
157
|
|
|
158
158
|
|
|
159
|
-
def test_str():
|
|
159
|
+
def test_str() -> None:
|
|
160
160
|
assert str(cirq.SWAP) == 'SWAP'
|
|
161
161
|
assert str(cirq.SWAP**0.5) == 'SWAP**0.5'
|
|
162
162
|
|
|
@@ -167,7 +167,7 @@ def test_str():
|
|
|
167
167
|
assert str(cirq.ISWAP_INV**0.5) == 'ISWAP**-0.5'
|
|
168
168
|
|
|
169
169
|
|
|
170
|
-
def test_iswap_decompose_diagram():
|
|
170
|
+
def test_iswap_decompose_diagram() -> None:
|
|
171
171
|
a = cirq.NamedQubit('a')
|
|
172
172
|
b = cirq.NamedQubit('b')
|
|
173
173
|
|
|
@@ -182,7 +182,7 @@ b: ───X───────@───────@───────
|
|
|
182
182
|
)
|
|
183
183
|
|
|
184
184
|
|
|
185
|
-
def test_trace_distance():
|
|
185
|
+
def test_trace_distance() -> None:
|
|
186
186
|
foo = sympy.Symbol('foo')
|
|
187
187
|
sswap = cirq.SWAP**foo
|
|
188
188
|
siswap = cirq.ISWAP**foo
|
|
@@ -194,14 +194,14 @@ def test_trace_distance():
|
|
|
194
194
|
assert cirq.approx_eq(cirq.trace_distance_bound(cirq.ISWAP**0), 0.0)
|
|
195
195
|
|
|
196
196
|
|
|
197
|
-
def test_trace_distance_over_range_of_exponents():
|
|
197
|
+
def test_trace_distance_over_range_of_exponents() -> None:
|
|
198
198
|
for exp in np.linspace(0, 4, 20):
|
|
199
199
|
cirq.testing.assert_has_consistent_trace_distance_bound(cirq.SWAP**exp)
|
|
200
200
|
cirq.testing.assert_has_consistent_trace_distance_bound(cirq.ISWAP**exp)
|
|
201
201
|
|
|
202
202
|
|
|
203
203
|
@pytest.mark.parametrize('angle_rads', (-np.pi, -np.pi / 3, -0.1, np.pi / 5))
|
|
204
|
-
def test_riswap_unitary(angle_rads):
|
|
204
|
+
def test_riswap_unitary(angle_rads) -> None:
|
|
205
205
|
actual = cirq.unitary(cirq.riswap(angle_rads))
|
|
206
206
|
c = np.cos(angle_rads)
|
|
207
207
|
s = 1j * np.sin(angle_rads)
|
|
@@ -215,7 +215,7 @@ def test_riswap_unitary(angle_rads):
|
|
|
215
215
|
|
|
216
216
|
|
|
217
217
|
@pytest.mark.parametrize('angle_rads', (-2 * np.pi / 3, -0.2, 0.4, np.pi / 4))
|
|
218
|
-
def test_riswap_hamiltonian(angle_rads):
|
|
218
|
+
def test_riswap_hamiltonian(angle_rads) -> None:
|
|
219
219
|
actual = cirq.unitary(cirq.riswap(angle_rads))
|
|
220
220
|
x = np.array([[0, 1], [1, 0]])
|
|
221
221
|
y = np.array([[0, -1j], [1j, 0]])
|
|
@@ -226,5 +226,5 @@ def test_riswap_hamiltonian(angle_rads):
|
|
|
226
226
|
|
|
227
227
|
|
|
228
228
|
@pytest.mark.parametrize('angle_rads', (-np.pi / 5, 0.4, 2, np.pi))
|
|
229
|
-
def test_riswap_has_consistent_protocols(angle_rads):
|
|
229
|
+
def test_riswap_has_consistent_protocols(angle_rads) -> None:
|
|
230
230
|
cirq.testing.assert_implements_consistent_protocols(cirq.riswap(angle_rads))
|
cirq/ops/tags_test.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import cirq
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
def test_virtual_tag():
|
|
18
|
+
def test_virtual_tag() -> None:
|
|
19
19
|
tag1 = cirq.ops.VirtualTag()
|
|
20
20
|
tag2 = cirq.ops.VirtualTag()
|
|
21
21
|
|
|
@@ -26,7 +26,7 @@ def test_virtual_tag():
|
|
|
26
26
|
cirq.testing.assert_equivalent_repr(tag2)
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
def test_routing_swap_tag():
|
|
29
|
+
def test_routing_swap_tag() -> None:
|
|
30
30
|
tag1 = cirq.ops.RoutingSwapTag()
|
|
31
31
|
tag2 = cirq.ops.RoutingSwapTag()
|
|
32
32
|
|
|
@@ -22,7 +22,7 @@ import cirq
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
@pytest.mark.parametrize('eigen_gate_type', [cirq.CCXPowGate, cirq.CCZPowGate])
|
|
25
|
-
def test_eigen_gates_consistent_protocols(eigen_gate_type):
|
|
25
|
+
def test_eigen_gates_consistent_protocols(eigen_gate_type) -> None:
|
|
26
26
|
cirq.testing.assert_eigengate_implements_consistent_protocols(eigen_gate_type)
|
|
27
27
|
|
|
28
28
|
|
|
@@ -36,18 +36,18 @@ def test_eigen_gates_consistent_protocols(eigen_gate_type):
|
|
|
36
36
|
(cirq.CCZ),
|
|
37
37
|
),
|
|
38
38
|
)
|
|
39
|
-
def test_consistent_protocols(gate):
|
|
39
|
+
def test_consistent_protocols(gate) -> None:
|
|
40
40
|
cirq.testing.assert_implements_consistent_protocols(gate)
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
def test_init():
|
|
43
|
+
def test_init() -> None:
|
|
44
44
|
assert (cirq.CCZ**0.5).exponent == 0.5
|
|
45
45
|
assert (cirq.CCZ**0.25).exponent == 0.25
|
|
46
46
|
assert (cirq.CCX**0.5).exponent == 0.5
|
|
47
47
|
assert (cirq.CCX**0.25).exponent == 0.25
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
def test_unitary():
|
|
50
|
+
def test_unitary() -> None:
|
|
51
51
|
assert cirq.has_unitary(cirq.CCX)
|
|
52
52
|
np.testing.assert_allclose(
|
|
53
53
|
cirq.unitary(cirq.CCX),
|
|
@@ -123,7 +123,7 @@ def test_unitary():
|
|
|
123
123
|
)
|
|
124
124
|
|
|
125
125
|
|
|
126
|
-
def test_str():
|
|
126
|
+
def test_str() -> None:
|
|
127
127
|
assert str(cirq.CCX) == 'TOFFOLI'
|
|
128
128
|
assert str(cirq.TOFFOLI) == 'TOFFOLI'
|
|
129
129
|
assert str(cirq.CSWAP) == 'FREDKIN'
|
|
@@ -134,7 +134,7 @@ def test_str():
|
|
|
134
134
|
assert str(cirq.CCZ**0.5) == 'CCZ**0.5'
|
|
135
135
|
|
|
136
136
|
|
|
137
|
-
def test_repr():
|
|
137
|
+
def test_repr() -> None:
|
|
138
138
|
assert repr(cirq.CCX) == 'cirq.TOFFOLI'
|
|
139
139
|
assert repr(cirq.TOFFOLI) == 'cirq.TOFFOLI'
|
|
140
140
|
assert repr(cirq.CSWAP) == 'cirq.FREDKIN'
|
|
@@ -145,7 +145,7 @@ def test_repr():
|
|
|
145
145
|
assert repr(cirq.CCZ**0.5) == '(cirq.CCZ**0.5)'
|
|
146
146
|
|
|
147
147
|
|
|
148
|
-
def test_eq():
|
|
148
|
+
def test_eq() -> None:
|
|
149
149
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
150
150
|
eq = cirq.testing.EqualsTester()
|
|
151
151
|
eq.add_equality_group(cirq.CCZ(a, b, c), cirq.CCZ(a, c, b), cirq.CCZ(b, c, a))
|
|
@@ -163,7 +163,7 @@ def test_eq():
|
|
|
163
163
|
eq.add_equality_group(cirq.CSWAP(b, a, c), cirq.CSWAP(b, c, a))
|
|
164
164
|
|
|
165
165
|
|
|
166
|
-
def test_gate_equality():
|
|
166
|
+
def test_gate_equality() -> None:
|
|
167
167
|
eq = cirq.testing.EqualsTester()
|
|
168
168
|
eq.add_equality_group(cirq.CSwapGate(), cirq.CSwapGate())
|
|
169
169
|
eq.add_equality_group(cirq.CZPowGate(), cirq.CZPowGate())
|
|
@@ -171,7 +171,7 @@ def test_gate_equality():
|
|
|
171
171
|
eq.add_equality_group(cirq.CCZPowGate(), cirq.CCZPowGate())
|
|
172
172
|
|
|
173
173
|
|
|
174
|
-
def test_identity_multiplication():
|
|
174
|
+
def test_identity_multiplication() -> None:
|
|
175
175
|
a, b, c = cirq.LineQubit.range(3)
|
|
176
176
|
assert cirq.CCX(a, b, c) * cirq.I(a) == cirq.CCX(a, b, c)
|
|
177
177
|
assert cirq.CCX(a, b, c) * cirq.I(b) == cirq.CCX(a, b, c)
|
|
@@ -197,7 +197,7 @@ def test_identity_multiplication():
|
|
|
197
197
|
),
|
|
198
198
|
],
|
|
199
199
|
)
|
|
200
|
-
def test_decomposition_cost(op: cirq.Operation, max_two_cost: int):
|
|
200
|
+
def test_decomposition_cost(op: cirq.Operation, max_two_cost: int) -> None:
|
|
201
201
|
ops = tuple(cirq.flatten_op_tree(cirq.decompose(op)))
|
|
202
202
|
two_cost = len([e for e in ops if len(e.qubits) == 2])
|
|
203
203
|
over_cost = len([e for e in ops if len(e.qubits) > 2])
|
|
@@ -205,12 +205,12 @@ def test_decomposition_cost(op: cirq.Operation, max_two_cost: int):
|
|
|
205
205
|
assert two_cost == max_two_cost
|
|
206
206
|
|
|
207
207
|
|
|
208
|
-
def test_parameterized_ccz_decompose_no_global_phase():
|
|
208
|
+
def test_parameterized_ccz_decompose_no_global_phase() -> None:
|
|
209
209
|
decomposed_ops = cirq.decompose(cirq.CCZ(*cirq.LineQubit.range(3)) ** sympy.Symbol("theta"))
|
|
210
210
|
assert not any(isinstance(op.gate, cirq.GlobalPhaseGate) for op in decomposed_ops)
|
|
211
211
|
|
|
212
212
|
|
|
213
|
-
def test_diagonal_gate_property():
|
|
213
|
+
def test_diagonal_gate_property() -> None:
|
|
214
214
|
assert cirq.ThreeQubitDiagonalGate([2, 3, 5, 7, 0, 0, 0, 1]).diag_angles_radians == (
|
|
215
215
|
(2, 3, 5, 7, 0, 0, 0, 1)
|
|
216
216
|
)
|
|
@@ -220,7 +220,7 @@ def test_diagonal_gate_property():
|
|
|
220
220
|
'gate',
|
|
221
221
|
[cirq.CCX, cirq.CSWAP, cirq.CCZ, cirq.ThreeQubitDiagonalGate([2, 3, 5, 7, 11, 13, 17, 19])],
|
|
222
222
|
)
|
|
223
|
-
def test_decomposition_respects_locality(gate):
|
|
223
|
+
def test_decomposition_respects_locality(gate) -> None:
|
|
224
224
|
a = cirq.GridQubit(0, 0)
|
|
225
225
|
b = cirq.GridQubit(1, 0)
|
|
226
226
|
c = cirq.GridQubit(0, 1)
|
|
@@ -231,7 +231,7 @@ def test_decomposition_respects_locality(gate):
|
|
|
231
231
|
dev.validate_circuit(circuit)
|
|
232
232
|
|
|
233
233
|
|
|
234
|
-
def test_diagram():
|
|
234
|
+
def test_diagram() -> None:
|
|
235
235
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
236
236
|
circuit = cirq.Circuit(
|
|
237
237
|
cirq.TOFFOLI(a, b, c),
|
|
@@ -295,7 +295,7 @@ def test_diagram():
|
|
|
295
295
|
)
|
|
296
296
|
|
|
297
297
|
|
|
298
|
-
def test_diagonal_exponent():
|
|
298
|
+
def test_diagonal_exponent() -> None:
|
|
299
299
|
diagonal_angles = [2, 3, 5, 7, 11, 13, 17, 19]
|
|
300
300
|
diagonal_gate = cirq.ThreeQubitDiagonalGate(diagonal_angles)
|
|
301
301
|
|
|
@@ -308,7 +308,7 @@ def test_diagonal_exponent():
|
|
|
308
308
|
|
|
309
309
|
|
|
310
310
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
311
|
-
def test_resolve(resolve_fn):
|
|
311
|
+
def test_resolve(resolve_fn) -> None:
|
|
312
312
|
diagonal_angles = [2, 3, 5, 7, 11, 13, 17, 19]
|
|
313
313
|
diagonal_gate = cirq.ThreeQubitDiagonalGate(
|
|
314
314
|
diagonal_angles[:6] + [sympy.Symbol('a'), sympy.Symbol('b')]
|
|
@@ -325,7 +325,7 @@ def test_resolve(resolve_fn):
|
|
|
325
325
|
|
|
326
326
|
|
|
327
327
|
@pytest.mark.parametrize('gate', [cirq.CCX, cirq.CCZ, cirq.CSWAP])
|
|
328
|
-
def test_controlled_ops_consistency(gate):
|
|
328
|
+
def test_controlled_ops_consistency(gate) -> None:
|
|
329
329
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
330
330
|
assert gate.controlled(0) is gate
|
|
331
331
|
assert gate(a, b, c).controlled_by(d) == gate(d, b, c).controlled_by(a)
|
|
@@ -30,15 +30,15 @@ import cirq
|
|
|
30
30
|
)
|
|
31
31
|
),
|
|
32
32
|
)
|
|
33
|
-
def test_consistent_protocols(gate):
|
|
33
|
+
def test_consistent_protocols(gate) -> None:
|
|
34
34
|
cirq.testing.assert_implements_consistent_protocols(gate)
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
def test_property():
|
|
37
|
+
def test_property() -> None:
|
|
38
38
|
assert cirq.TwoQubitDiagonalGate([2, 3, 5, 7]).diag_angles_radians == (2, 3, 5, 7)
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
def test_parameterized_decompose():
|
|
41
|
+
def test_parameterized_decompose() -> None:
|
|
42
42
|
angles = sympy.symbols('x0, x1, x2, x3')
|
|
43
43
|
parameterized_op = cirq.TwoQubitDiagonalGate(angles).on(*cirq.LineQubit.range(2))
|
|
44
44
|
decomposed_circuit = cirq.Circuit(cirq.decompose(parameterized_op))
|
|
@@ -54,7 +54,7 @@ def test_parameterized_decompose():
|
|
|
54
54
|
)
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
def test_unitary():
|
|
57
|
+
def test_unitary() -> None:
|
|
58
58
|
diagonal_angles = [2, 3, 5, 7]
|
|
59
59
|
assert cirq.has_unitary(cirq.TwoQubitDiagonalGate(diagonal_angles))
|
|
60
60
|
np.testing.assert_allclose(
|
|
@@ -64,7 +64,7 @@ def test_unitary():
|
|
|
64
64
|
)
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
def test_diagram():
|
|
67
|
+
def test_diagram() -> None:
|
|
68
68
|
a, b = cirq.LineQubit.range(2)
|
|
69
69
|
|
|
70
70
|
diagonal_circuit = cirq.Circuit(cirq.TwoQubitDiagonalGate([2, 3, 5, 7])(a, b))
|
|
@@ -87,7 +87,7 @@ def test_diagram():
|
|
|
87
87
|
)
|
|
88
88
|
|
|
89
89
|
|
|
90
|
-
def test_diagonal_exponent():
|
|
90
|
+
def test_diagonal_exponent() -> None:
|
|
91
91
|
diagonal_angles = [2, 3, 5, 7]
|
|
92
92
|
diagonal_gate = cirq.TwoQubitDiagonalGate(diagonal_angles)
|
|
93
93
|
|
|
@@ -99,7 +99,7 @@ def test_diagonal_exponent():
|
|
|
99
99
|
assert cirq.pow(cirq.TwoQubitDiagonalGate(diagonal_angles), "test", None) is None
|
|
100
100
|
|
|
101
101
|
|
|
102
|
-
def test_protocols_mul_not_implemented():
|
|
102
|
+
def test_protocols_mul_not_implemented() -> None:
|
|
103
103
|
diagonal_angles = [2, 3, None, 7]
|
|
104
104
|
diagonal_gate = cirq.TwoQubitDiagonalGate(diagonal_angles)
|
|
105
105
|
with pytest.raises(TypeError):
|
|
@@ -107,7 +107,7 @@ def test_protocols_mul_not_implemented():
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
110
|
-
def test_resolve(resolve_fn):
|
|
110
|
+
def test_resolve(resolve_fn) -> None:
|
|
111
111
|
diagonal_angles = [2, 3, 5, 7]
|
|
112
112
|
diagonal_gate = cirq.TwoQubitDiagonalGate(
|
|
113
113
|
diagonal_angles[:2] + [sympy.Symbol('a'), sympy.Symbol('b')]
|