cirq-core 1.7.0.dev20251002223432__py3-none-any.whl → 1.7.0.dev20251007180852__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/_doc.py +4 -3
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/linalg/decompositions.py +3 -0
- cirq/linalg/decompositions_test.py +1 -0
- cirq/ops/fourier_transform_test.py +2 -4
- cirq/ops/raw_types.py +3 -0
- cirq/protocols/apply_unitary_protocol_test.py +2 -0
- cirq/protocols/kraus_protocol.py +3 -3
- cirq/protocols/kraus_protocol_test.py +2 -2
- cirq/protocols/unitary_protocol.py +1 -1
- cirq/testing/consistent_resolve_parameters.py +1 -1
- cirq/testing/consistent_unitary.py +1 -1
- cirq/testing/consistent_unitary_test.py +1 -1
- cirq/testing/equals_tester.py +2 -2
- cirq/testing/equivalent_basis_map.py +3 -1
- cirq/testing/json.py +1 -1
- cirq/testing/op_tree.py +1 -1
- cirq/testing/order_tester.py +2 -2
- cirq/testing/repr_pretty_tester.py +3 -3
- cirq/transformers/align_test.py +13 -13
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +8 -8
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +5 -5
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +11 -11
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +6 -6
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +1 -1
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +10 -9
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +5 -5
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +17 -18
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +32 -26
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +1 -1
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +12 -11
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +3 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +3 -3
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +32 -30
- cirq/transformers/drop_negligible_operations_test.py +7 -7
- cirq/transformers/dynamical_decoupling_test.py +22 -22
- cirq/transformers/eject_phased_paulis_test.py +1 -1
- cirq/transformers/eject_z.py +2 -2
- cirq/transformers/eject_z_test.py +23 -25
- cirq/transformers/expand_composite.py +1 -1
- cirq/transformers/expand_composite_test.py +14 -14
- cirq/transformers/gauge_compiling/gauge_compiling.py +1 -1
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +14 -12
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +3 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +6 -6
- cirq/transformers/measurement_transformers_test.py +45 -39
- cirq/transformers/merge_k_qubit_gates_test.py +1 -1
- cirq/transformers/merge_single_qubit_gates_test.py +22 -22
- cirq/transformers/noise_adding_test.py +2 -2
- cirq/transformers/optimize_for_target_gateset_test.py +11 -9
- cirq/transformers/qubit_management_transformers_test.py +6 -2
- {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251007180852.dist-info}/METADATA +1 -1
- {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251007180852.dist-info}/RECORD +58 -58
- {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251007180852.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251007180852.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251007180852.dist-info}/top_level.txt +0 -0
|
@@ -24,7 +24,7 @@ import sympy
|
|
|
24
24
|
import cirq
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
def test_symbols():
|
|
27
|
+
def test_symbols() -> None:
|
|
28
28
|
with pytest.raises(ValueError, match='Symbolic arguments'):
|
|
29
29
|
cirq.compute_cphase_exponents_for_fsim_decomposition(
|
|
30
30
|
cirq.FSimGate(theta=sympy.Symbol('t'), phi=sympy.Symbol('phi'))
|
|
@@ -36,8 +36,9 @@ class FakeSycamoreGate(cirq.FSimGate):
|
|
|
36
36
|
super().__init__(theta=np.pi / 2, phi=np.pi / 6)
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
def test_parameterized_gates():
|
|
39
|
+
def test_parameterized_gates() -> None:
|
|
40
40
|
t = sympy.Symbol('t')
|
|
41
|
+
fsim_gate: cirq.FSimGate
|
|
41
42
|
with pytest.raises(ValueError):
|
|
42
43
|
cphase_gate = cirq.CZPowGate(exponent=t)
|
|
43
44
|
fsim_gate = FakeSycamoreGate()
|
|
@@ -54,14 +55,14 @@ def test_parameterized_gates():
|
|
|
54
55
|
cirq.decompose_cphase_into_two_fsim(cphase_gate, fsim_gate=fsim_gate)
|
|
55
56
|
|
|
56
57
|
|
|
57
|
-
def test_invalid_qubits():
|
|
58
|
+
def test_invalid_qubits() -> None:
|
|
58
59
|
with pytest.raises(ValueError):
|
|
59
60
|
cirq.decompose_cphase_into_two_fsim(
|
|
60
61
|
cphase_gate=cirq.CZ, fsim_gate=FakeSycamoreGate(), qubits=cirq.LineQubit.range(3)
|
|
61
62
|
)
|
|
62
63
|
|
|
63
64
|
|
|
64
|
-
def test_circuit_structure():
|
|
65
|
+
def test_circuit_structure() -> None:
|
|
65
66
|
syc = FakeSycamoreGate()
|
|
66
67
|
ops = cirq.decompose_cphase_into_two_fsim(cirq.CZ, fsim_gate=syc)
|
|
67
68
|
num_interaction_moments = 0
|
|
@@ -73,7 +74,7 @@ def test_circuit_structure():
|
|
|
73
74
|
assert num_interaction_moments == 2
|
|
74
75
|
|
|
75
76
|
|
|
76
|
-
def assert_decomposition_valid(cphase_gate, fsim_gate):
|
|
77
|
+
def assert_decomposition_valid(cphase_gate, fsim_gate) -> None:
|
|
77
78
|
u_expected = cirq.unitary(cphase_gate)
|
|
78
79
|
ops = cirq.decompose_cphase_into_two_fsim(cphase_gate, fsim_gate=fsim_gate)
|
|
79
80
|
u_actual = cirq.unitary(cirq.Circuit(ops))
|
|
@@ -83,7 +84,7 @@ def assert_decomposition_valid(cphase_gate, fsim_gate):
|
|
|
83
84
|
@pytest.mark.parametrize(
|
|
84
85
|
'exponent', (-5.5, -3, -1.5, -1, -0.65, -0.2, 0, 0.1, 0.75, 1, 1.5, 2, 5.5)
|
|
85
86
|
)
|
|
86
|
-
def test_decomposition_to_sycamore_gate(exponent):
|
|
87
|
+
def test_decomposition_to_sycamore_gate(exponent) -> None:
|
|
87
88
|
cphase_gate = cirq.CZPowGate(exponent=exponent)
|
|
88
89
|
assert_decomposition_valid(cphase_gate, FakeSycamoreGate())
|
|
89
90
|
|
|
@@ -95,7 +96,7 @@ def test_decomposition_to_sycamore_gate(exponent):
|
|
|
95
96
|
(-1.4 * np.pi, -np.pi / 9, np.pi / 11, np.pi / 2, 2.4 * np.pi),
|
|
96
97
|
),
|
|
97
98
|
)
|
|
98
|
-
def test_valid_cphase_exponents(theta, phi):
|
|
99
|
+
def test_valid_cphase_exponents(theta, phi) -> None:
|
|
99
100
|
fsim_gate = cirq.FSimGate(theta=theta, phi=phi)
|
|
100
101
|
valid_exponent_intervals = cirq.compute_cphase_exponents_for_fsim_decomposition(fsim_gate)
|
|
101
102
|
assert valid_exponent_intervals
|
|
@@ -131,7 +132,7 @@ def complement_intervals(intervals: Sequence[tuple[float, float]]) -> Sequence[t
|
|
|
131
132
|
(-1.7 * np.pi, -np.pi / 5, np.pi / 7, 2.5 * np.pi),
|
|
132
133
|
),
|
|
133
134
|
)
|
|
134
|
-
def test_invalid_cphase_exponents(theta, phi):
|
|
135
|
+
def test_invalid_cphase_exponents(theta, phi) -> None:
|
|
135
136
|
fsim_gate = cirq.FSimGate(theta=theta, phi=phi)
|
|
136
137
|
valid_exponent_intervals = cirq.compute_cphase_exponents_for_fsim_decomposition(fsim_gate)
|
|
137
138
|
invalid_exponent_intervals = complement_intervals(valid_exponent_intervals)
|
|
@@ -151,6 +152,6 @@ def test_invalid_cphase_exponents(theta, phi):
|
|
|
151
152
|
@pytest.mark.parametrize(
|
|
152
153
|
'bad_fsim_gate', (cirq.FSimGate(theta=0, phi=0), cirq.FSimGate(theta=np.pi / 4, phi=np.pi / 2))
|
|
153
154
|
)
|
|
154
|
-
def test_invalid_fsim_gate(bad_fsim_gate):
|
|
155
|
+
def test_invalid_fsim_gate(bad_fsim_gate) -> None:
|
|
155
156
|
with pytest.raises(ValueError):
|
|
156
157
|
cirq.decompose_cphase_into_two_fsim(cirq.CZ, fsim_gate=bad_fsim_gate)
|
|
@@ -21,7 +21,7 @@ https://arxiv.org/abs/quant-ph/0406176
|
|
|
21
21
|
|
|
22
22
|
from __future__ import annotations
|
|
23
23
|
|
|
24
|
-
from typing import Callable, cast, Iterable, TYPE_CHECKING
|
|
24
|
+
from typing import Callable, cast, Iterable, Sequence, TYPE_CHECKING
|
|
25
25
|
|
|
26
26
|
import numpy as np
|
|
27
27
|
from attr import define
|
|
@@ -47,7 +47,7 @@ class _TwoQubitGate:
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
def quantum_shannon_decomposition(
|
|
50
|
-
qubits:
|
|
50
|
+
qubits: Sequence[cirq.Qid], u: np.ndarray, atol: float = 1e-8
|
|
51
51
|
) -> Iterable[cirq.Operation]:
|
|
52
52
|
"""Decomposes n-qubit unitary 1-q, 2-q and GlobalPhase gates, preserving global phase.
|
|
53
53
|
|
|
@@ -149,7 +149,7 @@ def quantum_shannon_decomposition(
|
|
|
149
149
|
yield from cast(Iterable[ops.Operation], ops.flatten_op_tree(shannon_decomp))
|
|
150
150
|
|
|
151
151
|
|
|
152
|
-
def _recursive_decomposition(qubits:
|
|
152
|
+
def _recursive_decomposition(qubits: Sequence[cirq.Qid], u: np.ndarray) -> Iterable[cirq.Operation]:
|
|
153
153
|
"""Recursive step in the quantum shannon decomposition.
|
|
154
154
|
|
|
155
155
|
Decomposes n-qubit unitary into generic 2-qubit gates, CNOT, CZ and 1-qubit gates.
|
|
@@ -270,7 +270,7 @@ def _single_qubit_decomposition(qubit: cirq.Qid, u: np.ndarray) -> Iterable[cirq
|
|
|
270
270
|
|
|
271
271
|
|
|
272
272
|
def _msb_demuxer(
|
|
273
|
-
demux_qubits:
|
|
273
|
+
demux_qubits: Sequence[cirq.Qid], u1: np.ndarray, u2: np.ndarray
|
|
274
274
|
) -> Iterable[cirq.Operation]:
|
|
275
275
|
"""Demultiplexes a unitary matrix that is multiplexed in its most-significant-qubit.
|
|
276
276
|
|
|
@@ -336,7 +336,7 @@ def _nth_gray(n: int) -> int:
|
|
|
336
336
|
|
|
337
337
|
|
|
338
338
|
def _multiplexed_cossin(
|
|
339
|
-
cossin_qubits:
|
|
339
|
+
cossin_qubits: Sequence[cirq.Qid], angles: list[float], rot_func: Callable = ops.ry
|
|
340
340
|
) -> Iterable[cirq.Operation]:
|
|
341
341
|
"""Performs a multiplexed rotation over all qubits in this unitary matrix,
|
|
342
342
|
|
|
@@ -33,7 +33,7 @@ from cirq.transformers.analytical_decompositions.quantum_shannon_decomposition i
|
|
|
33
33
|
|
|
34
34
|
@pytest.mark.xfail(reason='#6765')
|
|
35
35
|
@pytest.mark.parametrize('n_qubits', list(range(1, 8)))
|
|
36
|
-
def test_random_qsd_n_qubit(n_qubits):
|
|
36
|
+
def test_random_qsd_n_qubit(n_qubits) -> None:
|
|
37
37
|
U = unitary_group.rvs(2**n_qubits)
|
|
38
38
|
qubits = [cirq.NamedQubit(f'q{i}') for i in range(n_qubits)]
|
|
39
39
|
circuit = cirq.Circuit(quantum_shannon_decomposition(qubits, U))
|
|
@@ -43,7 +43,7 @@ def test_random_qsd_n_qubit(n_qubits):
|
|
|
43
43
|
assert all(cirq.num_qubits(op) <= 2 for op in circuit.all_operations())
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
def test_qsd_n_qubit_errors():
|
|
46
|
+
def test_qsd_n_qubit_errors() -> None:
|
|
47
47
|
qubits = [cirq.NamedQubit(f'q{i}') for i in range(3)]
|
|
48
48
|
with pytest.raises(ValueError, match="shaped numpy array"):
|
|
49
49
|
cirq.Circuit(quantum_shannon_decomposition(qubits, np.eye(9)))
|
|
@@ -51,7 +51,7 @@ def test_qsd_n_qubit_errors():
|
|
|
51
51
|
cirq.Circuit(quantum_shannon_decomposition(qubits, np.ones((8, 8))))
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
def test_recursive_decomposition_n_qubit_errors():
|
|
54
|
+
def test_recursive_decomposition_n_qubit_errors() -> None:
|
|
55
55
|
qubits = [cirq.NamedQubit(f'q{i}') for i in range(3)]
|
|
56
56
|
with pytest.raises(ValueError, match="shaped numpy array"):
|
|
57
57
|
cirq.Circuit(_recursive_decomposition(qubits, np.eye(9)))
|
|
@@ -59,7 +59,7 @@ def test_recursive_decomposition_n_qubit_errors():
|
|
|
59
59
|
cirq.Circuit(_recursive_decomposition(qubits, np.eye(2)))
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
def test_random_single_qubit_decomposition():
|
|
62
|
+
def test_random_single_qubit_decomposition() -> None:
|
|
63
63
|
U = unitary_group.rvs(2)
|
|
64
64
|
qubit = cirq.NamedQubit('q0')
|
|
65
65
|
circuit = cirq.Circuit(_single_qubit_decomposition(qubit, U))
|
|
@@ -69,7 +69,7 @@ def test_random_single_qubit_decomposition():
|
|
|
69
69
|
assert all(cirq.num_qubits(op) <= 2 for op in circuit.all_operations())
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def test_msb_demuxer():
|
|
72
|
+
def test_msb_demuxer() -> None:
|
|
73
73
|
U1 = unitary_group.rvs(4)
|
|
74
74
|
U2 = unitary_group.rvs(4)
|
|
75
75
|
U_full = np.kron([[1, 0], [0, 0]], U1) + np.kron([[0, 0], [0, 1]], U2)
|
|
@@ -81,13 +81,12 @@ def test_msb_demuxer():
|
|
|
81
81
|
assert all(cirq.num_qubits(op) <= 2 for op in circuit.all_operations())
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
def test_multiplexed_cossin():
|
|
84
|
+
def test_multiplexed_cossin() -> None:
|
|
85
85
|
angle_1 = np.random.random_sample() * 2 * np.pi
|
|
86
86
|
angle_2 = np.random.random_sample() * 2 * np.pi
|
|
87
87
|
c1, s1 = np.cos(angle_1), np.sin(angle_1)
|
|
88
88
|
c2, s2 = np.cos(angle_2), np.sin(angle_2)
|
|
89
|
-
multiplexed_ry = [[c1, 0, -s1, 0], [0, c2, 0, -s2], [s1, 0, c1, 0], [0, s2, 0, c2]]
|
|
90
|
-
multiplexed_ry = np.array(multiplexed_ry)
|
|
89
|
+
multiplexed_ry = np.asarray([[c1, 0, -s1, 0], [0, c2, 0, -s2], [s1, 0, c1, 0], [0, s2, 0, c2]])
|
|
91
90
|
qubits = [cirq.NamedQubit(f'q{i}') for i in range(2)]
|
|
92
91
|
circuit = cirq.Circuit(_multiplexed_cossin(qubits, [angle_1, angle_2]))
|
|
93
92
|
# Add back the CZ gate removed by the A.1 optimization
|
|
@@ -126,11 +125,11 @@ def test_multiplexed_cossin():
|
|
|
126
125
|
(15, 8),
|
|
127
126
|
],
|
|
128
127
|
)
|
|
129
|
-
def test_nth_gray(n, gray):
|
|
128
|
+
def test_nth_gray(n, gray) -> None:
|
|
130
129
|
assert _nth_gray(n) == gray
|
|
131
130
|
|
|
132
131
|
|
|
133
|
-
def test_ghz_circuit_decomposes():
|
|
132
|
+
def test_ghz_circuit_decomposes() -> None:
|
|
134
133
|
# Test case from #6725
|
|
135
134
|
ghz_circuit = cirq.Circuit(cirq.H(cirq.q(0)), cirq.CNOT(cirq.q(0), cirq.q(1)))
|
|
136
135
|
ghz_unitary = cirq.unitary(ghz_circuit)
|
|
@@ -141,7 +140,7 @@ def test_ghz_circuit_decomposes():
|
|
|
141
140
|
np.testing.assert_allclose(new_unitary, ghz_unitary, atol=1e-6)
|
|
142
141
|
|
|
143
142
|
|
|
144
|
-
def test_qft_decomposes():
|
|
143
|
+
def test_qft_decomposes() -> None:
|
|
145
144
|
# Test case from #6666
|
|
146
145
|
qs = cirq.LineQubit.range(4)
|
|
147
146
|
qft_circuit = cirq.Circuit(cirq.qft(*qs))
|
|
@@ -163,7 +162,7 @@ def test_qft_decomposes():
|
|
|
163
162
|
(cirq.S, 1), # rz & ry
|
|
164
163
|
],
|
|
165
164
|
)
|
|
166
|
-
def test_cliffords(gate, num_ops):
|
|
165
|
+
def test_cliffords(gate, num_ops) -> None:
|
|
167
166
|
desired_unitary = cirq.unitary(gate)
|
|
168
167
|
shannon_circuit = cirq.Circuit(quantum_shannon_decomposition((cirq.q(0),), desired_unitary))
|
|
169
168
|
new_unitary = cirq.unitary(shannon_circuit)
|
|
@@ -173,7 +172,7 @@ def test_cliffords(gate, num_ops):
|
|
|
173
172
|
|
|
174
173
|
|
|
175
174
|
@pytest.mark.parametrize('gate', [cirq.X, cirq.Y, cirq.Z, cirq.H, cirq.S])
|
|
176
|
-
def test_cliffords_with_global_phase(gate):
|
|
175
|
+
def test_cliffords_with_global_phase(gate) -> None:
|
|
177
176
|
global_phase = np.exp(1j * np.random.choice(np.linspace(0.1, 2 * np.pi, 10)))
|
|
178
177
|
desired_unitary = cirq.unitary(gate) * global_phase
|
|
179
178
|
shannon_circuit = cirq.Circuit(quantum_shannon_decomposition((cirq.q(0),), desired_unitary))
|
|
@@ -181,7 +180,7 @@ def test_cliffords_with_global_phase(gate):
|
|
|
181
180
|
np.testing.assert_allclose(new_unitary, desired_unitary)
|
|
182
181
|
|
|
183
182
|
|
|
184
|
-
def test_global_phase():
|
|
183
|
+
def test_global_phase() -> None:
|
|
185
184
|
global_phase = np.exp(1j * np.random.choice(np.linspace(0, 2 * np.pi, 10)))
|
|
186
185
|
shannon_circuit = cirq.Circuit(
|
|
187
186
|
quantum_shannon_decomposition((cirq.q(0),), np.eye(2) * global_phase)
|
|
@@ -191,7 +190,7 @@ def test_global_phase():
|
|
|
191
190
|
|
|
192
191
|
|
|
193
192
|
@pytest.mark.parametrize('gate', [cirq.CZ, cirq.CNOT, cirq.XX, cirq.YY, cirq.ZZ])
|
|
194
|
-
def test_two_qubit_gate(gate):
|
|
193
|
+
def test_two_qubit_gate(gate) -> None:
|
|
195
194
|
global_phase = np.exp(1j * np.random.choice(np.linspace(0, 2 * np.pi, 10)))
|
|
196
195
|
desired_unitary = cirq.unitary(gate) * global_phase
|
|
197
196
|
shannon_circuit = cirq.Circuit(
|
|
@@ -202,7 +201,7 @@ def test_two_qubit_gate(gate):
|
|
|
202
201
|
|
|
203
202
|
|
|
204
203
|
@pytest.mark.parametrize('gate', [cirq.CCNOT, cirq.qft(*cirq.LineQubit.range(3))])
|
|
205
|
-
def test_three_qubit_gate(gate):
|
|
204
|
+
def test_three_qubit_gate(gate) -> None:
|
|
206
205
|
global_phase = np.exp(1j * np.random.choice(np.linspace(0, 2 * np.pi, 10)))
|
|
207
206
|
desired_unitary = cirq.unitary(gate) * global_phase
|
|
208
207
|
shannon_circuit = cirq.Circuit(
|
|
@@ -213,7 +212,7 @@ def test_three_qubit_gate(gate):
|
|
|
213
212
|
|
|
214
213
|
|
|
215
214
|
@pytest.mark.xfail(reason='#6765')
|
|
216
|
-
def test_qft5():
|
|
215
|
+
def test_qft5() -> None:
|
|
217
216
|
global_phase = np.exp(1j * np.random.choice(np.linspace(0, 2 * np.pi, 10)))
|
|
218
217
|
desired_unitary = cirq.unitary(cirq.qft(*cirq.LineQubit.range(5))) * global_phase
|
|
219
218
|
shannon_circuit = cirq.Circuit(
|
|
@@ -223,7 +222,7 @@ def test_qft5():
|
|
|
223
222
|
np.testing.assert_allclose(new_unitary, desired_unitary, atol=1e-6)
|
|
224
223
|
|
|
225
224
|
|
|
226
|
-
def test_random_circuit_decomposition():
|
|
225
|
+
def test_random_circuit_decomposition() -> None:
|
|
227
226
|
qubits = cirq.LineQubit.range(3)
|
|
228
227
|
test_circuit = (
|
|
229
228
|
random_two_qubit_circuit_with_czs(3, qubits[0], qubits[1])
|
|
@@ -25,13 +25,13 @@ import cirq
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def assert_gates_implement_unitary(
|
|
28
|
-
gates: Sequence[cirq.
|
|
29
|
-
):
|
|
28
|
+
gates: Sequence[cirq.Gate], intended_effect: np.ndarray, atol: float
|
|
29
|
+
) -> None:
|
|
30
30
|
actual_effect = cirq.dot(*[cirq.unitary(g) for g in reversed(gates)])
|
|
31
31
|
cirq.testing.assert_allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
def test_is_negligible_turn():
|
|
34
|
+
def test_is_negligible_turn() -> None:
|
|
35
35
|
assert cirq.is_negligible_turn(0, 1e-5)
|
|
36
36
|
assert cirq.is_negligible_turn(1e-6, 1e-5)
|
|
37
37
|
assert cirq.is_negligible_turn(1, 1e-5)
|
|
@@ -57,37 +57,37 @@ def test_is_negligible_turn():
|
|
|
57
57
|
assert not cirq.is_negligible_turn(sympy.Symbol('a') * 0 + 1.5 - 1e-6, 1e-5)
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def test_single_qubit_matrix_to_gates_known_x():
|
|
60
|
+
def test_single_qubit_matrix_to_gates_known_x() -> None:
|
|
61
61
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[0, 1], [1, 0]]), tolerance=0.01)
|
|
62
62
|
|
|
63
63
|
assert cirq.approx_eq(actual, [cirq.X], atol=1e-9)
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
def test_single_qubit_matrix_to_gates_known_y():
|
|
66
|
+
def test_single_qubit_matrix_to_gates_known_y() -> None:
|
|
67
67
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[0, -1j], [1j, 0]]), tolerance=0.01)
|
|
68
68
|
|
|
69
69
|
assert cirq.approx_eq(actual, [cirq.Y], atol=1e-9)
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def test_single_qubit_matrix_to_gates_known_z():
|
|
72
|
+
def test_single_qubit_matrix_to_gates_known_z() -> None:
|
|
73
73
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[1, 0], [0, -1]]), tolerance=0.01)
|
|
74
74
|
|
|
75
75
|
assert cirq.approx_eq(actual, [cirq.Z], atol=1e-9)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
def test_single_qubit_matrix_to_gates_known_s():
|
|
78
|
+
def test_single_qubit_matrix_to_gates_known_s() -> None:
|
|
79
79
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[1, 0], [0, 1j]]), tolerance=0.01)
|
|
80
80
|
|
|
81
81
|
assert cirq.approx_eq(actual, [cirq.Z**0.5], atol=1e-9)
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
def test_known_s_dag():
|
|
84
|
+
def test_known_s_dag() -> None:
|
|
85
85
|
actual = cirq.single_qubit_matrix_to_gates(np.array([[1, 0], [0, -1j]]), tolerance=0.01)
|
|
86
86
|
|
|
87
87
|
assert cirq.approx_eq(actual, [cirq.Z**-0.5], atol=1e-9)
|
|
88
88
|
|
|
89
89
|
|
|
90
|
-
def test_known_h():
|
|
90
|
+
def test_known_h() -> None:
|
|
91
91
|
actual = cirq.single_qubit_matrix_to_gates(
|
|
92
92
|
np.array([[1, 1], [1, -1]]) * np.sqrt(0.5), tolerance=0.001
|
|
93
93
|
)
|
|
@@ -109,7 +109,7 @@ def test_known_h():
|
|
|
109
109
|
]
|
|
110
110
|
+ [cirq.testing.random_unitary(2) for _ in range(10)],
|
|
111
111
|
)
|
|
112
|
-
def test_single_qubit_matrix_to_gates_cases(intended_effect):
|
|
112
|
+
def test_single_qubit_matrix_to_gates_cases(intended_effect) -> None:
|
|
113
113
|
for atol in [1e-1, 1e-8]:
|
|
114
114
|
gates = cirq.single_qubit_matrix_to_gates(intended_effect, tolerance=atol / 10)
|
|
115
115
|
assert len(gates) <= 3
|
|
@@ -120,7 +120,7 @@ def test_single_qubit_matrix_to_gates_cases(intended_effect):
|
|
|
120
120
|
@pytest.mark.parametrize(
|
|
121
121
|
'pre_turns,post_turns', [(random.random(), random.random()) for _ in range(10)]
|
|
122
122
|
)
|
|
123
|
-
def test_single_qubit_matrix_to_gates_fuzz_half_turns_merge_z_gates(pre_turns, post_turns):
|
|
123
|
+
def test_single_qubit_matrix_to_gates_fuzz_half_turns_merge_z_gates(pre_turns, post_turns) -> None:
|
|
124
124
|
intended_effect = cirq.dot(
|
|
125
125
|
cirq.unitary(cirq.Z ** (2 * pre_turns)),
|
|
126
126
|
cirq.unitary(cirq.X),
|
|
@@ -133,7 +133,7 @@ def test_single_qubit_matrix_to_gates_fuzz_half_turns_merge_z_gates(pre_turns, p
|
|
|
133
133
|
assert_gates_implement_unitary(gates, intended_effect, atol=1e-6)
|
|
134
134
|
|
|
135
135
|
|
|
136
|
-
def test_single_qubit_matrix_to_gates_tolerance_z():
|
|
136
|
+
def test_single_qubit_matrix_to_gates_tolerance_z() -> None:
|
|
137
137
|
z = np.diag([1, np.exp(1j * 0.01)])
|
|
138
138
|
|
|
139
139
|
optimized_away = cirq.single_qubit_matrix_to_gates(z, tolerance=0.1)
|
|
@@ -143,7 +143,7 @@ def test_single_qubit_matrix_to_gates_tolerance_z():
|
|
|
143
143
|
assert len(kept) == 1
|
|
144
144
|
|
|
145
145
|
|
|
146
|
-
def test_single_qubit_matrix_to_gates_tolerance_xy():
|
|
146
|
+
def test_single_qubit_matrix_to_gates_tolerance_xy() -> None:
|
|
147
147
|
c, s = np.cos(0.01), np.sin(0.01)
|
|
148
148
|
xy = np.array([[c, -s], [s, c]])
|
|
149
149
|
|
|
@@ -154,7 +154,7 @@ def test_single_qubit_matrix_to_gates_tolerance_xy():
|
|
|
154
154
|
assert len(kept) == 1
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def test_single_qubit_matrix_to_gates_tolerance_half_turn_phasing():
|
|
157
|
+
def test_single_qubit_matrix_to_gates_tolerance_half_turn_phasing() -> None:
|
|
158
158
|
a = np.pi / 2 + 0.01
|
|
159
159
|
c, s = np.cos(a), np.sin(a)
|
|
160
160
|
nearly_x = np.array([[c, -s], [s, c]])
|
|
@@ -189,13 +189,13 @@ def _random_unitary_with_close_eigenvalues():
|
|
|
189
189
|
]
|
|
190
190
|
+ [cirq.testing.random_unitary(2) for _ in range(10)],
|
|
191
191
|
)
|
|
192
|
-
def test_single_qubit_op_to_framed_phase_form_equivalent_on_known_and_random(mat):
|
|
192
|
+
def test_single_qubit_op_to_framed_phase_form_equivalent_on_known_and_random(mat) -> None:
|
|
193
193
|
u, t, g = cirq.single_qubit_op_to_framed_phase_form(mat)
|
|
194
194
|
z = np.diag([g, g * t])
|
|
195
195
|
assert np.allclose(mat, np.conj(u.T).dot(z).dot(u))
|
|
196
196
|
|
|
197
197
|
|
|
198
|
-
def test_single_qubit_matrix_to_phased_x_z_known():
|
|
198
|
+
def test_single_qubit_matrix_to_phased_x_z_known() -> None:
|
|
199
199
|
actual = cirq.single_qubit_matrix_to_phased_x_z(np.array([[0, 1], [1, 0]]), atol=0.01)
|
|
200
200
|
assert cirq.approx_eq(actual, [cirq.PhasedXPowGate(phase_exponent=1.0)], atol=1e-9)
|
|
201
201
|
|
|
@@ -223,7 +223,7 @@ def test_single_qubit_matrix_to_phased_x_z_known():
|
|
|
223
223
|
'intended_effect',
|
|
224
224
|
[np.array([[0, 1j], [1, 0]])] + [cirq.testing.random_unitary(2) for _ in range(10)],
|
|
225
225
|
)
|
|
226
|
-
def test_single_qubit_matrix_to_phased_x_z_cases(intended_effect):
|
|
226
|
+
def test_single_qubit_matrix_to_phased_x_z_cases(intended_effect) -> None:
|
|
227
227
|
gates = cirq.single_qubit_matrix_to_phased_x_z(intended_effect, atol=1e-6)
|
|
228
228
|
assert len(gates) <= 2
|
|
229
229
|
assert_gates_implement_unitary(gates, intended_effect, atol=1e-5)
|
|
@@ -232,7 +232,9 @@ def test_single_qubit_matrix_to_phased_x_z_cases(intended_effect):
|
|
|
232
232
|
@pytest.mark.parametrize(
|
|
233
233
|
'pre_turns,post_turns', [(random.random(), random.random()) for _ in range(10)]
|
|
234
234
|
)
|
|
235
|
-
def test_single_qubit_matrix_to_phased_x_z_fuzz_half_turns_always_one_gate(
|
|
235
|
+
def test_single_qubit_matrix_to_phased_x_z_fuzz_half_turns_always_one_gate(
|
|
236
|
+
pre_turns, post_turns
|
|
237
|
+
) -> None:
|
|
236
238
|
atol = 1e-6
|
|
237
239
|
aggr_atol = atol * 10.0
|
|
238
240
|
|
|
@@ -248,7 +250,7 @@ def test_single_qubit_matrix_to_phased_x_z_fuzz_half_turns_always_one_gate(pre_t
|
|
|
248
250
|
assert_gates_implement_unitary(gates, intended_effect, atol=aggr_atol)
|
|
249
251
|
|
|
250
252
|
|
|
251
|
-
def test_single_qubit_matrix_to_phased_x_z_tolerance_z():
|
|
253
|
+
def test_single_qubit_matrix_to_phased_x_z_tolerance_z() -> None:
|
|
252
254
|
z = np.diag([1, np.exp(1j * 0.01)])
|
|
253
255
|
|
|
254
256
|
optimized_away = cirq.single_qubit_matrix_to_phased_x_z(z, atol=0.1)
|
|
@@ -258,7 +260,7 @@ def test_single_qubit_matrix_to_phased_x_z_tolerance_z():
|
|
|
258
260
|
assert len(kept) == 1
|
|
259
261
|
|
|
260
262
|
|
|
261
|
-
def test_single_qubit_matrix_to_phased_x_z_tolerance_xy():
|
|
263
|
+
def test_single_qubit_matrix_to_phased_x_z_tolerance_xy() -> None:
|
|
262
264
|
c, s = np.cos(0.01), np.sin(0.01)
|
|
263
265
|
xy = np.array([[c, -s], [s, c]])
|
|
264
266
|
|
|
@@ -269,7 +271,7 @@ def test_single_qubit_matrix_to_phased_x_z_tolerance_xy():
|
|
|
269
271
|
assert len(kept) == 1
|
|
270
272
|
|
|
271
273
|
|
|
272
|
-
def test_single_qubit_matrix_to_phased_x_z_tolerance_half_turn_phasing():
|
|
274
|
+
def test_single_qubit_matrix_to_phased_x_z_tolerance_half_turn_phasing() -> None:
|
|
273
275
|
a = np.pi / 2 + 0.01
|
|
274
276
|
c, s = np.cos(a), np.sin(a)
|
|
275
277
|
nearly_x = np.array([[c, -s], [s, c]])
|
|
@@ -297,15 +299,16 @@ def test_single_qubit_matrix_to_phased_x_z_tolerance_half_turn_phasing():
|
|
|
297
299
|
*[cirq.testing.random_unitary(2) for _ in range(10)],
|
|
298
300
|
],
|
|
299
301
|
)
|
|
300
|
-
def test_single_qubit_matrix_to_phxz_cases(intended_effect):
|
|
302
|
+
def test_single_qubit_matrix_to_phxz_cases(intended_effect) -> None:
|
|
301
303
|
gate = cirq.single_qubit_matrix_to_phxz(intended_effect, atol=1e-6)
|
|
304
|
+
assert gate is not None
|
|
302
305
|
assert_gates_implement_unitary([gate], intended_effect, atol=1e-5)
|
|
303
306
|
|
|
304
307
|
|
|
305
308
|
@pytest.mark.parametrize(
|
|
306
309
|
'pre_turns,post_turns', [(random.random(), random.random()) for _ in range(10)]
|
|
307
310
|
)
|
|
308
|
-
def test_single_qubit_matrix_to_phxz_fuzz_half_turns_always_one_gate(pre_turns, post_turns):
|
|
311
|
+
def test_single_qubit_matrix_to_phxz_fuzz_half_turns_always_one_gate(pre_turns, post_turns) -> None:
|
|
309
312
|
atol = 1e-6
|
|
310
313
|
aggr_atol = atol * 10.0
|
|
311
314
|
|
|
@@ -317,11 +320,12 @@ def test_single_qubit_matrix_to_phxz_fuzz_half_turns_always_one_gate(pre_turns,
|
|
|
317
320
|
|
|
318
321
|
gate = cirq.single_qubit_matrix_to_phxz(intended_effect, atol=atol)
|
|
319
322
|
|
|
323
|
+
assert gate is not None
|
|
320
324
|
assert gate.z_exponent == 0
|
|
321
325
|
assert_gates_implement_unitary([gate], intended_effect, atol=aggr_atol)
|
|
322
326
|
|
|
323
327
|
|
|
324
|
-
def test_single_qubit_matrix_to_phxz_tolerance_z():
|
|
328
|
+
def test_single_qubit_matrix_to_phxz_tolerance_z() -> None:
|
|
325
329
|
z = np.diag([1, np.exp(1j * 0.01)])
|
|
326
330
|
|
|
327
331
|
optimized_away = cirq.single_qubit_matrix_to_phxz(z, atol=0.1)
|
|
@@ -331,7 +335,7 @@ def test_single_qubit_matrix_to_phxz_tolerance_z():
|
|
|
331
335
|
assert kept is not None
|
|
332
336
|
|
|
333
337
|
|
|
334
|
-
def test_single_qubit_matrix_to_phxz_tolerance_xy():
|
|
338
|
+
def test_single_qubit_matrix_to_phxz_tolerance_xy() -> None:
|
|
335
339
|
c, s = np.cos(0.01), np.sin(0.01)
|
|
336
340
|
xy = np.array([[c, -s], [s, c]])
|
|
337
341
|
|
|
@@ -342,7 +346,7 @@ def test_single_qubit_matrix_to_phxz_tolerance_xy():
|
|
|
342
346
|
assert kept is not None
|
|
343
347
|
|
|
344
348
|
|
|
345
|
-
def test_single_qubit_matrix_to_phxz_tolerance_half_turn_phasing():
|
|
349
|
+
def test_single_qubit_matrix_to_phxz_tolerance_half_turn_phasing() -> None:
|
|
346
350
|
a = np.pi / 2 + 0.01
|
|
347
351
|
c, s = np.cos(a), np.sin(a)
|
|
348
352
|
nearly_x = np.array([[c, -s], [s, c]])
|
|
@@ -351,7 +355,9 @@ def test_single_qubit_matrix_to_phxz_tolerance_half_turn_phasing():
|
|
|
351
355
|
phased_nearly_x = z1.dot(nearly_x).dot(z2)
|
|
352
356
|
|
|
353
357
|
optimized_away = cirq.single_qubit_matrix_to_phxz(phased_nearly_x, atol=0.1)
|
|
358
|
+
assert optimized_away is not None
|
|
354
359
|
assert optimized_away.z_exponent == 0
|
|
355
360
|
|
|
356
361
|
kept = cirq.single_qubit_matrix_to_phxz(phased_nearly_x, atol=0.0001)
|
|
362
|
+
assert kept is not None
|
|
357
363
|
assert kept.z_exponent != 0
|
|
@@ -43,7 +43,7 @@ INVALID_INITIAL_STATES = [
|
|
|
43
43
|
@pytest.mark.parametrize('allow_partial_czs', [True, False])
|
|
44
44
|
def test_two_qubit_matrix_to_cz_isometry(
|
|
45
45
|
initial_state, is_valid, unitary_matrix, allow_partial_czs
|
|
46
|
-
):
|
|
46
|
+
) -> None:
|
|
47
47
|
a, b, c = cirq.LineQubit.range(3)
|
|
48
48
|
decomposed_ops = cirq.two_qubit_matrix_to_cz_isometry(
|
|
49
49
|
a, b, unitary_matrix, allow_partial_czs=allow_partial_czs
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import copy
|
|
20
|
+
from typing import Iterator
|
|
20
21
|
|
|
21
22
|
import numpy as np
|
|
22
23
|
import pytest
|
|
@@ -24,11 +25,11 @@ import pytest
|
|
|
24
25
|
import cirq
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
def random_state(seed: float):
|
|
28
|
+
def random_state(seed: float) -> np.ndarray:
|
|
28
29
|
return cirq.testing.random_superposition(4, random_state=seed)
|
|
29
30
|
|
|
30
31
|
|
|
31
|
-
def states_with_phases(st: np.ndarray):
|
|
32
|
+
def states_with_phases(st: np.ndarray) -> Iterator[np.ndarray]:
|
|
32
33
|
"""Returns several states similar to st with modified global phases."""
|
|
33
34
|
st = np.array(st, dtype="complex64")
|
|
34
35
|
yield st
|
|
@@ -61,10 +62,10 @@ STATES_TO_PREPARE = [
|
|
|
61
62
|
|
|
62
63
|
|
|
63
64
|
@pytest.mark.parametrize("state", STATES_TO_PREPARE)
|
|
64
|
-
def test_prepare_two_qubit_state_using_cz(state):
|
|
65
|
+
def test_prepare_two_qubit_state_using_cz(state) -> None:
|
|
65
66
|
state = cirq.to_valid_state_vector(state, num_qubits=2)
|
|
66
|
-
|
|
67
|
-
circuit = cirq.Circuit(cirq.prepare_two_qubit_state_using_cz(
|
|
67
|
+
q0, q1 = cirq.LineQubit.range(2)
|
|
68
|
+
circuit = cirq.Circuit(cirq.prepare_two_qubit_state_using_cz(q0, q1, state))
|
|
68
69
|
ops_cz = [*circuit.findall_operations(lambda op: op.gate == cirq.CZ)]
|
|
69
70
|
ops_2q = [*circuit.findall_operations(lambda op: cirq.num_qubits(op) > 1)]
|
|
70
71
|
assert ops_cz == ops_2q
|
|
@@ -76,11 +77,11 @@ def test_prepare_two_qubit_state_using_cz(state):
|
|
|
76
77
|
|
|
77
78
|
@pytest.mark.parametrize("state", STATES_TO_PREPARE)
|
|
78
79
|
@pytest.mark.parametrize("use_iswap_inv", [True, False])
|
|
79
|
-
def test_prepare_two_qubit_state_using_iswap(state, use_iswap_inv):
|
|
80
|
+
def test_prepare_two_qubit_state_using_iswap(state, use_iswap_inv) -> None:
|
|
80
81
|
state = cirq.to_valid_state_vector(state, num_qubits=2)
|
|
81
|
-
|
|
82
|
+
q0, q1 = cirq.LineQubit.range(2)
|
|
82
83
|
circuit = cirq.Circuit(
|
|
83
|
-
cirq.prepare_two_qubit_state_using_iswap(
|
|
84
|
+
cirq.prepare_two_qubit_state_using_iswap(q0, q1, state, use_iswap_inv=use_iswap_inv)
|
|
84
85
|
)
|
|
85
86
|
iswap_gate = cirq.ISWAP_INV if use_iswap_inv else cirq.ISWAP
|
|
86
87
|
ops_iswap = [*circuit.findall_operations(lambda op: op.gate == iswap_gate)]
|
|
@@ -94,12 +95,12 @@ def test_prepare_two_qubit_state_using_iswap(state, use_iswap_inv):
|
|
|
94
95
|
|
|
95
96
|
@pytest.mark.parametrize("state", STATES_TO_PREPARE)
|
|
96
97
|
@pytest.mark.parametrize("use_sqrt_iswap_inv", [True, False])
|
|
97
|
-
def test_prepare_two_qubit_state_using_sqrt_iswap(state, use_sqrt_iswap_inv):
|
|
98
|
+
def test_prepare_two_qubit_state_using_sqrt_iswap(state, use_sqrt_iswap_inv) -> None:
|
|
98
99
|
state = cirq.to_valid_state_vector(state, num_qubits=2)
|
|
99
|
-
|
|
100
|
+
q0, q1 = cirq.LineQubit.range(2)
|
|
100
101
|
circuit = cirq.Circuit(
|
|
101
102
|
cirq.prepare_two_qubit_state_using_sqrt_iswap(
|
|
102
|
-
|
|
103
|
+
q0, q1, state, use_sqrt_iswap_inv=use_sqrt_iswap_inv
|
|
103
104
|
)
|
|
104
105
|
)
|
|
105
106
|
sqrt_iswap_gate = cirq.SQRT_ISWAP_INV if use_sqrt_iswap_inv else cirq.SQRT_ISWAP
|
|
@@ -181,7 +181,9 @@ def _xx_yy_zz_interaction_via_full_czs(q0: cirq.Qid, q1: cirq.Qid, x: float, y:
|
|
|
181
181
|
yield ops.H(q1)
|
|
182
182
|
|
|
183
183
|
|
|
184
|
-
def cleanup_operations(
|
|
184
|
+
def cleanup_operations(
|
|
185
|
+
operations: Sequence[ops.Operation], atol: float = 1e-8
|
|
186
|
+
) -> list[ops.Operation]:
|
|
185
187
|
operations = _merge_single_qubit_gates(operations, atol=atol)
|
|
186
188
|
circuit = circuits.Circuit(operations)
|
|
187
189
|
circuit = eject_phased_paulis(circuit)
|
|
@@ -95,7 +95,7 @@ def _random_double_full_cz_effect():
|
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def assert_cz_depth_below(operations, threshold, must_be_full):
|
|
98
|
+
def assert_cz_depth_below(operations, threshold, must_be_full) -> None:
|
|
99
99
|
total_cz = 0
|
|
100
100
|
|
|
101
101
|
for op in operations:
|
|
@@ -110,7 +110,7 @@ def assert_cz_depth_below(operations, threshold, must_be_full):
|
|
|
110
110
|
assert total_cz <= threshold
|
|
111
111
|
|
|
112
112
|
|
|
113
|
-
def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01):
|
|
113
|
+
def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01) -> None:
|
|
114
114
|
actual_effect = _operations_to_matrix(operations, (q0, q1))
|
|
115
115
|
assert cirq.allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
|
|
116
116
|
|
|
@@ -273,7 +273,7 @@ def test_decompose_to_diagonal_and_circuit(v) -> None:
|
|
|
273
273
|
)
|
|
274
274
|
def test_decompose_to_diagonal_and_circuit_returns_circuit_with_expected_number_of_czs(
|
|
275
275
|
mat, num_czs
|
|
276
|
-
):
|
|
276
|
+
) -> None:
|
|
277
277
|
b, c = cirq.LineQubit.range(2)
|
|
278
278
|
_, ops = two_qubit_matrix_to_diagonal_and_cz_operations(b, c, mat, atol=1e-8)
|
|
279
279
|
circuit = cirq.Circuit(ops)
|
|
@@ -60,12 +60,12 @@ def _random_double_MS_effect():
|
|
|
60
60
|
)
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01):
|
|
63
|
+
def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01) -> None:
|
|
64
64
|
actual_effect = _operations_to_matrix(operations, (q0, q1))
|
|
65
65
|
assert cirq.allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
def assert_ms_depth_below(operations, threshold):
|
|
68
|
+
def assert_ms_depth_below(operations, threshold) -> None:
|
|
69
69
|
total_ms = 0
|
|
70
70
|
|
|
71
71
|
for op in operations:
|