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
cirq/ops/fsim_gate_test.py
CHANGED
|
@@ -19,7 +19,7 @@ import sympy
|
|
|
19
19
|
import cirq
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def test_fsim_init():
|
|
22
|
+
def test_fsim_init() -> None:
|
|
23
23
|
f = cirq.FSimGate(1, 2)
|
|
24
24
|
assert f.theta == 1
|
|
25
25
|
assert f.phi == 2
|
|
@@ -33,7 +33,7 @@ def test_fsim_init():
|
|
|
33
33
|
assert f3.phi == -5 + 2 * np.pi
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def test_fsim_eq():
|
|
36
|
+
def test_fsim_eq() -> None:
|
|
37
37
|
eq = cirq.testing.EqualsTester()
|
|
38
38
|
a, b = cirq.LineQubit.range(2)
|
|
39
39
|
|
|
@@ -45,7 +45,7 @@ def test_fsim_eq():
|
|
|
45
45
|
eq.add_equality_group(cirq.FSimGate(np.pi, np.pi), cirq.FSimGate(-np.pi, -np.pi))
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
def test_fsim_approx_eq():
|
|
48
|
+
def test_fsim_approx_eq() -> None:
|
|
49
49
|
assert cirq.approx_eq(cirq.FSimGate(1, 2), cirq.FSimGate(1.00001, 2.00001), atol=0.01)
|
|
50
50
|
|
|
51
51
|
|
|
@@ -60,12 +60,12 @@ def test_fsim_approx_eq():
|
|
|
60
60
|
(np.pi / 2, 0.5),
|
|
61
61
|
],
|
|
62
62
|
)
|
|
63
|
-
def test_fsim_consistent(theta, phi):
|
|
63
|
+
def test_fsim_consistent(theta, phi) -> None:
|
|
64
64
|
gate = cirq.FSimGate(theta=theta, phi=phi)
|
|
65
65
|
cirq.testing.assert_implements_consistent_protocols(gate)
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
def test_fsim_circuit():
|
|
68
|
+
def test_fsim_circuit() -> None:
|
|
69
69
|
a, b = cirq.LineQubit.range(2)
|
|
70
70
|
c = cirq.Circuit(
|
|
71
71
|
cirq.FSimGate(np.pi / 2, np.pi).on(a, b), cirq.FSimGate(-np.pi, np.pi / 2).on(a, b)
|
|
@@ -109,7 +109,7 @@ def test_fsim_circuit():
|
|
|
109
109
|
|
|
110
110
|
|
|
111
111
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
112
|
-
def test_fsim_resolve(resolve_fn):
|
|
112
|
+
def test_fsim_resolve(resolve_fn) -> None:
|
|
113
113
|
f = cirq.FSimGate(sympy.Symbol('a'), sympy.Symbol('b'))
|
|
114
114
|
assert cirq.is_parameterized(f)
|
|
115
115
|
|
|
@@ -122,7 +122,7 @@ def test_fsim_resolve(resolve_fn):
|
|
|
122
122
|
assert not cirq.is_parameterized(f)
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
def test_fsim_unitary():
|
|
125
|
+
def test_fsim_unitary() -> None:
|
|
126
126
|
# fmt: off
|
|
127
127
|
np.testing.assert_allclose(
|
|
128
128
|
cirq.unitary(cirq.FSimGate(theta=0, phi=0)),
|
|
@@ -265,7 +265,7 @@ def test_fsim_unitary():
|
|
|
265
265
|
(3.5 * np.pi, 4 * np.pi),
|
|
266
266
|
),
|
|
267
267
|
)
|
|
268
|
-
def test_fsim_iswap_cphase(theta, phi):
|
|
268
|
+
def test_fsim_iswap_cphase(theta, phi) -> None:
|
|
269
269
|
q0, q1 = cirq.NamedQubit('q0'), cirq.NamedQubit('q1')
|
|
270
270
|
iswap = cirq.ISWAP ** (-theta * 2 / np.pi)
|
|
271
271
|
cphase = cirq.CZPowGate(exponent=-phi / np.pi)
|
|
@@ -274,16 +274,16 @@ def test_fsim_iswap_cphase(theta, phi):
|
|
|
274
274
|
assert np.allclose(cirq.unitary(iswap_cphase), cirq.unitary(fsim))
|
|
275
275
|
|
|
276
276
|
|
|
277
|
-
def test_fsim_repr():
|
|
277
|
+
def test_fsim_repr() -> None:
|
|
278
278
|
f = cirq.FSimGate(sympy.Symbol('a'), sympy.Symbol('b'))
|
|
279
279
|
cirq.testing.assert_equivalent_repr(f)
|
|
280
280
|
|
|
281
281
|
|
|
282
|
-
def test_fsim_json_dict():
|
|
282
|
+
def test_fsim_json_dict() -> None:
|
|
283
283
|
assert cirq.FSimGate(theta=0.123, phi=0.456)._json_dict_() == {'theta': 0.123, 'phi': 0.456}
|
|
284
284
|
|
|
285
285
|
|
|
286
|
-
def test_phased_fsim_init():
|
|
286
|
+
def test_phased_fsim_init() -> None:
|
|
287
287
|
f = cirq.PhasedFSimGate(1, 2, 3, 4, 5)
|
|
288
288
|
assert f.theta == 1
|
|
289
289
|
assert f.zeta == 2
|
|
@@ -307,7 +307,7 @@ def test_phased_fsim_init():
|
|
|
307
307
|
(np.pi / 5, np.pi / 6, (0.1, 0.2), (0.3, 0.5)),
|
|
308
308
|
),
|
|
309
309
|
)
|
|
310
|
-
def test_phased_fsim_from_fsim_rz(theta, phi, rz_angles_before, rz_angles_after):
|
|
310
|
+
def test_phased_fsim_from_fsim_rz(theta, phi, rz_angles_before, rz_angles_after) -> None:
|
|
311
311
|
f = cirq.PhasedFSimGate.from_fsim_rz(theta, phi, rz_angles_before, rz_angles_after)
|
|
312
312
|
q0, q1 = cirq.LineQubit.range(2)
|
|
313
313
|
c = cirq.Circuit(
|
|
@@ -330,7 +330,7 @@ def test_phased_fsim_from_fsim_rz(theta, phi, rz_angles_before, rz_angles_after)
|
|
|
330
330
|
((np.pi / 5, -np.pi / 3), (0, np.pi / 2)),
|
|
331
331
|
),
|
|
332
332
|
)
|
|
333
|
-
def test_phased_fsim_recreate_from_phase_angles(rz_angles_before, rz_angles_after):
|
|
333
|
+
def test_phased_fsim_recreate_from_phase_angles(rz_angles_before, rz_angles_after) -> None:
|
|
334
334
|
f = cirq.PhasedFSimGate.from_fsim_rz(np.pi / 3, np.pi / 5, rz_angles_before, rz_angles_after)
|
|
335
335
|
f2 = cirq.PhasedFSimGate.from_fsim_rz(f.theta, f.phi, f.rz_angles_before, f.rz_angles_after)
|
|
336
336
|
assert cirq.approx_eq(f, f2)
|
|
@@ -346,7 +346,7 @@ def test_phased_fsim_recreate_from_phase_angles(rz_angles_before, rz_angles_afte
|
|
|
346
346
|
((np.pi, np.pi / 6), (-np.pi / 2, 0)),
|
|
347
347
|
),
|
|
348
348
|
)
|
|
349
|
-
def test_phased_fsim_phase_angle_symmetry(rz_angles_before, rz_angles_after):
|
|
349
|
+
def test_phased_fsim_phase_angle_symmetry(rz_angles_before, rz_angles_after) -> None:
|
|
350
350
|
f = cirq.PhasedFSimGate.from_fsim_rz(np.pi / 3, np.pi / 5, rz_angles_before, rz_angles_after)
|
|
351
351
|
for d in (-10, -7, -2 * np.pi, -0.2, 0, 0.1, 0.2, np.pi, 8, 20):
|
|
352
352
|
rz_angles_before2 = (rz_angles_before[0] + d, rz_angles_before[1] + d)
|
|
@@ -357,7 +357,7 @@ def test_phased_fsim_phase_angle_symmetry(rz_angles_before, rz_angles_after):
|
|
|
357
357
|
assert cirq.approx_eq(f, f2)
|
|
358
358
|
|
|
359
359
|
|
|
360
|
-
def test_phased_fsim_eq():
|
|
360
|
+
def test_phased_fsim_eq() -> None:
|
|
361
361
|
eq = cirq.testing.EqualsTester()
|
|
362
362
|
a, b = cirq.LineQubit.range(2)
|
|
363
363
|
r, s = sympy.Symbol('r'), sympy.Symbol('s')
|
|
@@ -435,7 +435,7 @@ def test_phased_fsim_eq():
|
|
|
435
435
|
(cirq.PhasedFSimGate(1, np.pi / 2, 0, 4, 5), False),
|
|
436
436
|
),
|
|
437
437
|
)
|
|
438
|
-
def test_qubit_interchangeability(gate, interchangeable):
|
|
438
|
+
def test_qubit_interchangeability(gate, interchangeable) -> None:
|
|
439
439
|
a, b = cirq.LineQubit.range(2)
|
|
440
440
|
c1 = cirq.Circuit(gate.on(a, b))
|
|
441
441
|
c2 = cirq.Circuit(cirq.SWAP(a, b), gate.on(a, b), cirq.SWAP(a, b))
|
|
@@ -444,7 +444,7 @@ def test_qubit_interchangeability(gate, interchangeable):
|
|
|
444
444
|
assert np.all(u1 == u2) == interchangeable
|
|
445
445
|
|
|
446
446
|
|
|
447
|
-
def test_phased_fsim_approx_eq():
|
|
447
|
+
def test_phased_fsim_approx_eq() -> None:
|
|
448
448
|
assert cirq.approx_eq(
|
|
449
449
|
cirq.PhasedFSimGate(1, 2, 3, 4, 5),
|
|
450
450
|
cirq.PhasedFSimGate(1.00001, 2.00001, 3.00001, 4.00004, 5.00005),
|
|
@@ -469,12 +469,12 @@ def test_phased_fsim_approx_eq():
|
|
|
469
469
|
(np.pi, 0, 0, sympy.Symbol('a'), 0),
|
|
470
470
|
],
|
|
471
471
|
)
|
|
472
|
-
def test_phased_fsim_consistent(theta, zeta, chi, gamma, phi):
|
|
472
|
+
def test_phased_fsim_consistent(theta, zeta, chi, gamma, phi) -> None:
|
|
473
473
|
gate = cirq.PhasedFSimGate(theta=theta, zeta=zeta, chi=chi, gamma=gamma, phi=phi)
|
|
474
474
|
cirq.testing.assert_implements_consistent_protocols(gate)
|
|
475
475
|
|
|
476
476
|
|
|
477
|
-
def test_phased_fsim_circuit():
|
|
477
|
+
def test_phased_fsim_circuit() -> None:
|
|
478
478
|
a, b = cirq.LineQubit.range(2)
|
|
479
479
|
c = cirq.Circuit(
|
|
480
480
|
cirq.PhasedFSimGate(np.pi / 2, np.pi, np.pi / 2, 0, -np.pi / 4).on(a, b),
|
|
@@ -529,7 +529,7 @@ def test_phased_fsim_circuit():
|
|
|
529
529
|
|
|
530
530
|
|
|
531
531
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
532
|
-
def test_phased_fsim_resolve(resolve_fn):
|
|
532
|
+
def test_phased_fsim_resolve(resolve_fn) -> None:
|
|
533
533
|
f = cirq.PhasedFSimGate(
|
|
534
534
|
sympy.Symbol('a'),
|
|
535
535
|
sympy.Symbol('b'),
|
|
@@ -562,7 +562,7 @@ def test_phased_fsim_resolve(resolve_fn):
|
|
|
562
562
|
assert not cirq.is_parameterized(f)
|
|
563
563
|
|
|
564
564
|
|
|
565
|
-
def test_phased_fsim_unitary():
|
|
565
|
+
def test_phased_fsim_unitary() -> None:
|
|
566
566
|
# fmt: off
|
|
567
567
|
np.testing.assert_allclose(
|
|
568
568
|
cirq.unitary(cirq.PhasedFSimGate(theta=0, phi=0)),
|
|
@@ -776,13 +776,13 @@ def test_phased_fsim_unitary():
|
|
|
776
776
|
(3.5 * np.pi, 4 * np.pi),
|
|
777
777
|
),
|
|
778
778
|
)
|
|
779
|
-
def test_phased_fsim_vs_fsim(theta, phi):
|
|
779
|
+
def test_phased_fsim_vs_fsim(theta, phi) -> None:
|
|
780
780
|
g1 = cirq.FSimGate(theta, phi)
|
|
781
781
|
g2 = cirq.PhasedFSimGate(theta, 0, 0, 0, phi)
|
|
782
782
|
assert np.allclose(cirq.unitary(g1), cirq.unitary(g2))
|
|
783
783
|
|
|
784
784
|
|
|
785
|
-
def test_phased_fsim_repr():
|
|
785
|
+
def test_phased_fsim_repr() -> None:
|
|
786
786
|
f = cirq.PhasedFSimGate(
|
|
787
787
|
sympy.Symbol('a'),
|
|
788
788
|
sympy.Symbol('b'),
|
|
@@ -793,7 +793,7 @@ def test_phased_fsim_repr():
|
|
|
793
793
|
cirq.testing.assert_equivalent_repr(f)
|
|
794
794
|
|
|
795
795
|
|
|
796
|
-
def test_phased_fsim_json_dict():
|
|
796
|
+
def test_phased_fsim_json_dict() -> None:
|
|
797
797
|
assert cirq.PhasedFSimGate(
|
|
798
798
|
theta=0.12, zeta=0.34, chi=0.56, gamma=0.78, phi=0.9
|
|
799
799
|
)._json_dict_() == {'theta': 0.12, 'zeta': 0.34, 'chi': 0.56, 'gamma': 0.78, 'phi': 0.9}
|
|
@@ -811,10 +811,10 @@ def test_phased_fsim_json_dict():
|
|
|
811
811
|
cirq.CZ**0.2,
|
|
812
812
|
],
|
|
813
813
|
)
|
|
814
|
-
def test_phase_fsim_from_matrix(gate):
|
|
814
|
+
def test_phase_fsim_from_matrix(gate) -> None:
|
|
815
815
|
u = cirq.unitary(gate)
|
|
816
816
|
np.testing.assert_allclose(cirq.unitary(cirq.PhasedFSimGate.from_matrix(u)), u, atol=1e-8)
|
|
817
817
|
|
|
818
818
|
|
|
819
|
-
def test_phase_fsim_from_matrix_not_fsim_returns_none():
|
|
819
|
+
def test_phase_fsim_from_matrix_not_fsim_returns_none() -> None:
|
|
820
820
|
assert cirq.PhasedFSimGate.from_matrix(np.ones((4, 4))) is None
|
cirq/ops/gate_features_test.py
CHANGED
|
@@ -17,7 +17,7 @@ import pytest
|
|
|
17
17
|
import cirq
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def test_qasm_output_args_validate():
|
|
20
|
+
def test_qasm_output_args_validate() -> None:
|
|
21
21
|
args = cirq.QasmArgs(version='2.0')
|
|
22
22
|
args.validate_version('2.0')
|
|
23
23
|
|
|
@@ -25,7 +25,7 @@ def test_qasm_output_args_validate():
|
|
|
25
25
|
args.validate_version('2.1')
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def test_qasm_output_args_format():
|
|
28
|
+
def test_qasm_output_args_format() -> None:
|
|
29
29
|
a = cirq.NamedQubit('a')
|
|
30
30
|
b = cirq.NamedQubit('b')
|
|
31
31
|
m_a = cirq.measure(a, key='meas_a')
|
|
@@ -52,7 +52,7 @@ def test_qasm_output_args_format():
|
|
|
52
52
|
assert args.format('_{0}_', 'other') == '_other_'
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
def test_multi_qubit_gate_validate():
|
|
55
|
+
def test_multi_qubit_gate_validate() -> None:
|
|
56
56
|
class Example(cirq.Gate):
|
|
57
57
|
def _num_qubits_(self) -> int:
|
|
58
58
|
return self._num_qubits
|
|
@@ -30,7 +30,7 @@ class GateAllocInDecompose(cirq.Gate):
|
|
|
30
30
|
qm.qfree([q])
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
def test_greedy_qubit_manager():
|
|
33
|
+
def test_greedy_qubit_manager() -> None:
|
|
34
34
|
def make_circuit(qm: cirq.QubitManager):
|
|
35
35
|
q = cirq.LineQubit.range(2)
|
|
36
36
|
g = GateAllocInDecompose(1)
|
|
@@ -90,12 +90,12 @@ ancilla_1: ───X───X───
|
|
|
90
90
|
)
|
|
91
91
|
|
|
92
92
|
|
|
93
|
-
def test_empty_qubits():
|
|
93
|
+
def test_empty_qubits() -> None:
|
|
94
94
|
qm = cirq.GreedyQubitManager(prefix="anc")
|
|
95
95
|
assert qm.qalloc(0) == []
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def test_greedy_qubit_manager_preserves_order():
|
|
98
|
+
def test_greedy_qubit_manager_preserves_order() -> None:
|
|
99
99
|
qm = cirq.GreedyQubitManager(prefix="anc")
|
|
100
100
|
ancillae = [cirq.q(f"anc_{i}") for i in range(100)]
|
|
101
101
|
assert qm.qalloc(100) == ancillae
|
|
@@ -5,7 +5,7 @@ import pytest
|
|
|
5
5
|
import cirq
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def test_matrix_mixture_from_mixture():
|
|
8
|
+
def test_matrix_mixture_from_mixture() -> None:
|
|
9
9
|
q0 = cirq.LineQubit(0)
|
|
10
10
|
dp = cirq.depolarize(0.1)
|
|
11
11
|
mm = cirq.MixedUnitaryChannel.from_mixture(dp, key='dp')
|
|
@@ -22,7 +22,7 @@ def test_matrix_mixture_from_mixture():
|
|
|
22
22
|
assert results.measurements['dp'] in range(4)
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
def test_matrix_mixture_equality():
|
|
25
|
+
def test_matrix_mixture_equality() -> None:
|
|
26
26
|
dp_pt1 = cirq.depolarize(0.1)
|
|
27
27
|
dp_pt2 = cirq.depolarize(0.2)
|
|
28
28
|
mm_a1 = cirq.MixedUnitaryChannel.from_mixture(dp_pt1, key='a')
|
|
@@ -45,7 +45,7 @@ def test_matrix_mixture_equality():
|
|
|
45
45
|
assert half_flip != half_flip_inv
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
def test_matrix_mixture_remap_keys():
|
|
48
|
+
def test_matrix_mixture_remap_keys() -> None:
|
|
49
49
|
dp = cirq.depolarize(0.1)
|
|
50
50
|
mm = cirq.MixedUnitaryChannel.from_mixture(dp)
|
|
51
51
|
with pytest.raises(TypeError):
|
|
@@ -63,7 +63,7 @@ def test_matrix_mixture_remap_keys():
|
|
|
63
63
|
assert cirq.with_measurement_key_mapping(mm_a, {'a': 'b'}) == mm_b
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
def test_matrix_mixture_from_unitaries():
|
|
66
|
+
def test_matrix_mixture_from_unitaries() -> None:
|
|
67
67
|
q0 = cirq.LineQubit(0)
|
|
68
68
|
mix = [(0.5, np.array([[1, 0], [0, 1]])), (0.5, np.array([[0, 1], [1, 0]]))]
|
|
69
69
|
half_flip = cirq.MixedUnitaryChannel(mix, key='flip')
|
|
@@ -77,7 +77,7 @@ def test_matrix_mixture_from_unitaries():
|
|
|
77
77
|
assert results.measurements['flip'] == results.measurements['m']
|
|
78
78
|
|
|
79
79
|
|
|
80
|
-
def test_matrix_mixture_str():
|
|
80
|
+
def test_matrix_mixture_str() -> None:
|
|
81
81
|
mix = [(0.5, np.array([[1, 0], [0, 1]])), (0.5, np.array([[0, 1], [1, 0]]))]
|
|
82
82
|
half_flip = cirq.MixedUnitaryChannel(mix)
|
|
83
83
|
assert (
|
|
@@ -95,7 +95,7 @@ def test_matrix_mixture_str():
|
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def test_matrix_mixture_repr():
|
|
98
|
+
def test_matrix_mixture_repr() -> None:
|
|
99
99
|
mix = [
|
|
100
100
|
(0.5, np.array([[1, 0], [0, 1]], dtype=np.dtype('complex64'))),
|
|
101
101
|
(0.5, np.array([[0, 1], [1, 0]], dtype=np.dtype('complex64'))),
|
|
@@ -111,19 +111,19 @@ key='flip')"""
|
|
|
111
111
|
)
|
|
112
112
|
|
|
113
113
|
|
|
114
|
-
def test_mix_no_unitaries_fails():
|
|
114
|
+
def test_mix_no_unitaries_fails() -> None:
|
|
115
115
|
with pytest.raises(ValueError, match='must have at least one unitary'):
|
|
116
116
|
_ = cirq.MixedUnitaryChannel(mixture=[], key='m')
|
|
117
117
|
|
|
118
118
|
|
|
119
|
-
def test_mix_bad_prob_fails():
|
|
119
|
+
def test_mix_bad_prob_fails() -> None:
|
|
120
120
|
mix = [(0.5, np.array([[1, 0], [0, 0]]))]
|
|
121
121
|
|
|
122
122
|
with pytest.raises(ValueError, match='Unitary probabilities must sum to 1'):
|
|
123
123
|
_ = cirq.MixedUnitaryChannel(mixture=mix, key='m')
|
|
124
124
|
|
|
125
125
|
|
|
126
|
-
def test_mix_mismatch_fails():
|
|
126
|
+
def test_mix_mismatch_fails() -> None:
|
|
127
127
|
op2 = np.zeros((4, 4))
|
|
128
128
|
op2[1][1] = 1
|
|
129
129
|
mix = [(0.5, np.array([[1, 0], [0, 0]])), (0.5, op2)]
|
|
@@ -132,14 +132,14 @@ def test_mix_mismatch_fails():
|
|
|
132
132
|
_ = cirq.MixedUnitaryChannel(mixture=mix, key='m')
|
|
133
133
|
|
|
134
134
|
|
|
135
|
-
def test_nonqubit_mixture_fails():
|
|
135
|
+
def test_nonqubit_mixture_fails() -> None:
|
|
136
136
|
mix = [(0.5, np.array([[1, 0, 0], [0, 1, 0]])), (0.5, np.array([[0, 1, 0], [1, 0, 0]]))]
|
|
137
137
|
|
|
138
138
|
with pytest.raises(ValueError, match='Input mixture'):
|
|
139
139
|
_ = cirq.MixedUnitaryChannel(mixture=mix, key='m')
|
|
140
140
|
|
|
141
141
|
|
|
142
|
-
def test_validate():
|
|
142
|
+
def test_validate() -> None:
|
|
143
143
|
mix = [(0.5, np.array([[1, 0], [0, 0]])), (0.5, np.array([[0, 0], [0, 1]]))]
|
|
144
144
|
with pytest.raises(ValueError, match='non-unitary'):
|
|
145
145
|
_ = cirq.MixedUnitaryChannel(mixture=mix, key='m', validate=True)
|
cirq/ops/parallel_gate_test.py
CHANGED
|
@@ -26,7 +26,7 @@ import cirq
|
|
|
26
26
|
(cirq.X**0.5, 4, cirq.LineQubit.range(4)),
|
|
27
27
|
],
|
|
28
28
|
)
|
|
29
|
-
def test_parallel_gate_operation_init(gate, num_copies, qubits):
|
|
29
|
+
def test_parallel_gate_operation_init(gate, num_copies, qubits) -> None:
|
|
30
30
|
v = cirq.ParallelGate(gate, num_copies)
|
|
31
31
|
assert v.sub_gate == gate
|
|
32
32
|
assert v.num_copies == num_copies
|
|
@@ -52,7 +52,7 @@ def test_parallel_gate_operation_init(gate, num_copies, qubits):
|
|
|
52
52
|
(cirq.testing.TwoQubitGate(), 2, cirq.LineQubit.range(4), "must be a single qubit gate"),
|
|
53
53
|
],
|
|
54
54
|
)
|
|
55
|
-
def test_invalid_parallel_gate_operation(gate, num_copies, qubits, error_msg):
|
|
55
|
+
def test_invalid_parallel_gate_operation(gate, num_copies, qubits, error_msg) -> None:
|
|
56
56
|
with pytest.raises(ValueError, match=error_msg):
|
|
57
57
|
cirq.ParallelGate(gate, num_copies)(*qubits)
|
|
58
58
|
|
|
@@ -61,27 +61,27 @@ def test_invalid_parallel_gate_operation(gate, num_copies, qubits, error_msg):
|
|
|
61
61
|
'gate, num_copies, qubits',
|
|
62
62
|
[(cirq.X, 2, cirq.LineQubit.range(2)), (cirq.H**0.5, 4, cirq.LineQubit.range(4))],
|
|
63
63
|
)
|
|
64
|
-
def test_decompose(gate, num_copies, qubits):
|
|
64
|
+
def test_decompose(gate, num_copies, qubits) -> None:
|
|
65
65
|
g = cirq.ParallelGate(gate, num_copies)
|
|
66
66
|
step = gate.num_qubits()
|
|
67
67
|
qubit_lists = [qubits[i * step : (i + 1) * step] for i in range(num_copies)]
|
|
68
68
|
assert set(cirq.decompose_once(g(*qubits))) == set(gate.on_each(qubit_lists))
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
def test_decompose_raises():
|
|
71
|
+
def test_decompose_raises() -> None:
|
|
72
72
|
g = cirq.ParallelGate(cirq.X, 2)
|
|
73
73
|
qubits = cirq.LineQubit.range(4)
|
|
74
74
|
with pytest.raises(ValueError, match=r'len\(qubits\)=4 should be 2'):
|
|
75
75
|
cirq.decompose_once_with_qubits(g, qubits)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
def test_with_num_copies():
|
|
78
|
+
def test_with_num_copies() -> None:
|
|
79
79
|
g = cirq.testing.SingleQubitGate()
|
|
80
80
|
pg = cirq.ParallelGate(g, 3)
|
|
81
81
|
assert pg.with_num_copies(5) == cirq.ParallelGate(g, 5)
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
def test_extrapolate():
|
|
84
|
+
def test_extrapolate() -> None:
|
|
85
85
|
# If the gate isn't extrapolatable, you get a type error.
|
|
86
86
|
g = cirq.ParallelGate(cirq.testing.SingleQubitGate(), 2)
|
|
87
87
|
with pytest.raises(TypeError):
|
|
@@ -93,7 +93,7 @@ def test_extrapolate():
|
|
|
93
93
|
|
|
94
94
|
|
|
95
95
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
96
|
-
def test_parameterizable_gates(resolve_fn):
|
|
96
|
+
def test_parameterizable_gates(resolve_fn) -> None:
|
|
97
97
|
r = cirq.ParamResolver({'a': 0.5})
|
|
98
98
|
g1 = cirq.ParallelGate(cirq.Z ** sympy.Symbol('a'), 2)
|
|
99
99
|
assert cirq.is_parameterized(g1)
|
|
@@ -102,7 +102,7 @@ def test_parameterizable_gates(resolve_fn):
|
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
@pytest.mark.parametrize('gate', [cirq.X ** sympy.Symbol("a"), cirq.testing.SingleQubitGate()])
|
|
105
|
-
def test_no_unitary(gate):
|
|
105
|
+
def test_no_unitary(gate) -> None:
|
|
106
106
|
g = cirq.ParallelGate(gate, 2)
|
|
107
107
|
assert not cirq.has_unitary(g)
|
|
108
108
|
assert cirq.unitary(g, None) is None
|
|
@@ -115,7 +115,7 @@ def test_no_unitary(gate):
|
|
|
115
115
|
(cirq.MatrixGate(cirq.unitary(cirq.H**0.25)), 6, cirq.LineQubit.range(6)),
|
|
116
116
|
],
|
|
117
117
|
)
|
|
118
|
-
def test_unitary(gate, num_copies, qubits):
|
|
118
|
+
def test_unitary(gate, num_copies, qubits) -> None:
|
|
119
119
|
g = cirq.ParallelGate(gate, num_copies)
|
|
120
120
|
step = gate.num_qubits()
|
|
121
121
|
qubit_lists = [qubits[i * step : (i + 1) * step] for i in range(num_copies)]
|
|
@@ -124,7 +124,7 @@ def test_unitary(gate, num_copies, qubits):
|
|
|
124
124
|
)
|
|
125
125
|
|
|
126
126
|
|
|
127
|
-
def test_not_implemented_diagram():
|
|
127
|
+
def test_not_implemented_diagram() -> None:
|
|
128
128
|
q = cirq.LineQubit.range(2)
|
|
129
129
|
g = cirq.testing.SingleQubitGate()
|
|
130
130
|
c = cirq.Circuit()
|
|
@@ -132,15 +132,15 @@ def test_not_implemented_diagram():
|
|
|
132
132
|
assert 'cirq.testing.gate_features.SingleQubitGate ' in str(c)
|
|
133
133
|
|
|
134
134
|
|
|
135
|
-
def test_repr():
|
|
135
|
+
def test_repr() -> None:
|
|
136
136
|
assert repr(cirq.ParallelGate(cirq.X, 2)) == 'cirq.ParallelGate(sub_gate=cirq.X, num_copies=2)'
|
|
137
137
|
|
|
138
138
|
|
|
139
|
-
def test_str():
|
|
139
|
+
def test_str() -> None:
|
|
140
140
|
assert str(cirq.ParallelGate(cirq.X**0.5, 10)) == 'X**0.5 x 10'
|
|
141
141
|
|
|
142
142
|
|
|
143
|
-
def test_equivalent_circuit():
|
|
143
|
+
def test_equivalent_circuit() -> None:
|
|
144
144
|
qreg = cirq.LineQubit.range(4)
|
|
145
145
|
oldc = cirq.Circuit()
|
|
146
146
|
newc = cirq.Circuit()
|
|
@@ -154,11 +154,11 @@ def test_equivalent_circuit():
|
|
|
154
154
|
|
|
155
155
|
|
|
156
156
|
@pytest.mark.parametrize('gate, num_copies', [(cirq.X, 1), (cirq.Y, 2), (cirq.Z, 3), (cirq.H, 4)])
|
|
157
|
-
def test_parallel_gate_operation_is_consistent(gate, num_copies):
|
|
157
|
+
def test_parallel_gate_operation_is_consistent(gate, num_copies) -> None:
|
|
158
158
|
cirq.testing.assert_implements_consistent_protocols(cirq.ParallelGate(gate, num_copies))
|
|
159
159
|
|
|
160
160
|
|
|
161
|
-
def test_trace_distance():
|
|
161
|
+
def test_trace_distance() -> None:
|
|
162
162
|
s = cirq.X**0.25
|
|
163
163
|
two_g = cirq.ParallelGate(s, 2)
|
|
164
164
|
three_g = cirq.ParallelGate(s, 3)
|
|
@@ -171,6 +171,6 @@ def test_trace_distance():
|
|
|
171
171
|
|
|
172
172
|
|
|
173
173
|
@pytest.mark.parametrize('gate, num_copies', [(cirq.X, 1), (cirq.Y, 2), (cirq.Z, 3), (cirq.H, 4)])
|
|
174
|
-
def test_parallel_gate_op(gate, num_copies):
|
|
174
|
+
def test_parallel_gate_op(gate, num_copies) -> None:
|
|
175
175
|
qubits = cirq.LineQubit.range(num_copies * gate.num_qubits())
|
|
176
176
|
assert cirq.parallel_gate_op(gate, *qubits) == cirq.ParallelGate(gate, num_copies).on(*qubits)
|