cirq-core 1.6.0.dev20250524010305__py3-none-any.whl → 1.6.0.dev20250527171805__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cirq-core might be problematic. Click here for more details.
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/ops/controlled_gate.py +21 -28
- cirq/ops/controlled_gate_test.py +29 -0
- {cirq_core-1.6.0.dev20250524010305.dist-info → cirq_core-1.6.0.dev20250527171805.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250524010305.dist-info → cirq_core-1.6.0.dev20250527171805.dist-info}/RECORD +9 -9
- {cirq_core-1.6.0.dev20250524010305.dist-info → cirq_core-1.6.0.dev20250527171805.dist-info}/WHEEL +1 -1
- {cirq_core-1.6.0.dev20250524010305.dist-info → cirq_core-1.6.0.dev20250527171805.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250524010305.dist-info → cirq_core-1.6.0.dev20250527171805.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
cirq/ops/controlled_gate.py
CHANGED
|
@@ -152,34 +152,27 @@ class ControlledGate(raw_types.Gate):
|
|
|
152
152
|
# Prefer the subgate controlled version if available
|
|
153
153
|
if self != controlled_sub_gate:
|
|
154
154
|
return controlled_sub_gate.on(*qubits)
|
|
155
|
-
if (
|
|
156
|
-
protocols.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
# Could work in theory, but DiagonalGate decompose does not support them.
|
|
177
|
-
return NotImplemented
|
|
178
|
-
angle = np.angle(complex(self.sub_gate.coefficient))
|
|
179
|
-
rads = np.zeros(shape=shape)
|
|
180
|
-
for hot in self.control_values.expand():
|
|
181
|
-
rads[hot] = angle
|
|
182
|
-
return dg.DiagonalGate(diag_angles_radians=[*rads.flatten()]).on(*qubits)
|
|
155
|
+
if protocols.has_unitary(self.sub_gate) and all(q.dimension == 2 for q in qubits):
|
|
156
|
+
n_qubits = protocols.num_qubits(self.sub_gate)
|
|
157
|
+
# Case 1: Global Phase (1x1 Matrix)
|
|
158
|
+
if n_qubits == 0:
|
|
159
|
+
angle = np.angle(protocols.unitary(self.sub_gate)[0, 0])
|
|
160
|
+
rads = np.zeros(shape=self.control_qid_shape)
|
|
161
|
+
for hot in self.control_values.expand():
|
|
162
|
+
rads[hot] = angle
|
|
163
|
+
return dg.DiagonalGate(diag_angles_radians=[*rads.flatten()]).on(*qubits)
|
|
164
|
+
# Case 2: Multi-controlled single-qubit gate decomposition
|
|
165
|
+
if n_qubits == 1 and isinstance(self.control_values, cv.ProductOfSums):
|
|
166
|
+
invert_ops: list[cirq.Operation] = []
|
|
167
|
+
for cvals, cqbit in zip(self.control_values, qubits[: self.num_controls()]):
|
|
168
|
+
if set(cvals) == {0}:
|
|
169
|
+
invert_ops.append(common_gates.X(cqbit))
|
|
170
|
+
elif set(cvals) == {0, 1}:
|
|
171
|
+
control_qubits.remove(cqbit)
|
|
172
|
+
decomposed_ops = controlled_gate_decomposition.decompose_multi_controlled_rotation(
|
|
173
|
+
protocols.unitary(self.sub_gate), control_qubits, qubits[-1]
|
|
174
|
+
)
|
|
175
|
+
return invert_ops + decomposed_ops + invert_ops
|
|
183
176
|
if isinstance(self.sub_gate, common_gates.CZPowGate):
|
|
184
177
|
z_sub_gate = common_gates.ZPowGate(exponent=self.sub_gate.exponent)
|
|
185
178
|
num_controls = self.num_controls() + 1
|
cirq/ops/controlled_gate_test.py
CHANGED
|
@@ -773,3 +773,32 @@ def test_controlled_mixture():
|
|
|
773
773
|
c_yes = cirq.ControlledGate(sub_gate=cirq.phase_flip(0.25), num_controls=1)
|
|
774
774
|
assert cirq.has_mixture(c_yes)
|
|
775
775
|
assert cirq.approx_eq(cirq.mixture(c_yes), [(0.75, np.eye(4)), (0.25, cirq.unitary(cirq.CZ))])
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
@pytest.mark.parametrize(
|
|
779
|
+
'num_controls, angle, control_values',
|
|
780
|
+
[
|
|
781
|
+
(1, np.pi / 4, ((1,),)),
|
|
782
|
+
(3, -np.pi / 2, ((1,), (1,), (1,))),
|
|
783
|
+
(2, 0.0, ((1,), (1,))),
|
|
784
|
+
(2, np.pi / 5, ((0,), (0,))),
|
|
785
|
+
(3, np.pi, ((1,), (0,), (1,))),
|
|
786
|
+
(4, -np.pi / 3, ((0,), (1,), (1,), (0,))),
|
|
787
|
+
],
|
|
788
|
+
)
|
|
789
|
+
def test_controlled_global_phase_matrix_gate_decomposes(num_controls, angle, control_values):
|
|
790
|
+
all_qubits = cirq.LineQubit.range(num_controls)
|
|
791
|
+
control_values = cirq.ops.control_values.ProductOfSums(control_values)
|
|
792
|
+
control_qid_shape = (2,) * num_controls
|
|
793
|
+
phase_value = np.exp(1j * angle)
|
|
794
|
+
|
|
795
|
+
cg_matrix = cirq.ControlledGate(
|
|
796
|
+
sub_gate=cirq.MatrixGate(np.array([[phase_value]])),
|
|
797
|
+
num_controls=num_controls,
|
|
798
|
+
control_values=control_values,
|
|
799
|
+
control_qid_shape=control_qid_shape,
|
|
800
|
+
)
|
|
801
|
+
|
|
802
|
+
decomposed = cirq.decompose(cg_matrix(*all_qubits))
|
|
803
|
+
assert not any(isinstance(op.gate, cirq.MatrixGate) for op in decomposed)
|
|
804
|
+
np.testing.assert_allclose(cirq.unitary(cirq.Circuit(decomposed)), cirq.unitary(cg_matrix))
|
{cirq_core-1.6.0.dev20250524010305.dist-info → cirq_core-1.6.0.dev20250527171805.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.6.0.
|
|
3
|
+
Version: 1.6.0.dev20250527171805
|
|
4
4
|
Summary: A framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
|
|
5
5
|
Home-page: http://github.com/quantumlib/cirq
|
|
6
6
|
Author: The Cirq Developers
|
{cirq_core-1.6.0.dev20250524010305.dist-info → cirq_core-1.6.0.dev20250527171805.dist-info}/RECORD
RENAMED
|
@@ -4,8 +4,8 @@ cirq/_compat_test.py,sha256=ZSmenkbqEfRJpGsvutmV8vgIlfZCWj8GAVgi3t5YRso,34635
|
|
|
4
4
|
cirq/_doc.py,sha256=BrnoABo1hk5RgB3Cgww4zLHUfiyFny0F1V-tOMCbdaU,2909
|
|
5
5
|
cirq/_import.py,sha256=ixBu4EyGl46Ram2cP3p5eZVEFDW5L2DS-VyTjz4N9iw,8429
|
|
6
6
|
cirq/_import_test.py,sha256=oF4izzOVZLc7NZ0aZHFcGv-r01eiFFt_JORx_x7_D4s,1089
|
|
7
|
-
cirq/_version.py,sha256=
|
|
8
|
-
cirq/_version_test.py,sha256=
|
|
7
|
+
cirq/_version.py,sha256=dxVGqTeVKFZRX0pW8_XsVMMZFPIGBgp1RPpnUieGnWg,1206
|
|
8
|
+
cirq/_version_test.py,sha256=Vrro3klHl9asaoG93RXDIXBBDTA1aE8NpnazReNk2fU,155
|
|
9
9
|
cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
|
|
10
10
|
cirq/json_resolver_cache.py,sha256=S-zUVI4D_XnAxyR6z7WHDImCVmB_awJp6EStD1-CNPU,13621
|
|
11
11
|
cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
|
|
@@ -287,8 +287,8 @@ cirq/ops/common_gates.py,sha256=uNDMUj3mru-WsfLPJrxtiXfKfsZ5y8y3Ngha0AsZaXs,5620
|
|
|
287
287
|
cirq/ops/common_gates_test.py,sha256=Yan_k_H8xBmBWAWpKdB-gZIbhlA6vo0EpTjCKMJgt1Q,47367
|
|
288
288
|
cirq/ops/control_values.py,sha256=GrNi8YJZSZDCl8Su6Ocimvd1R1SejFJjVu2thcJ8VLI,13346
|
|
289
289
|
cirq/ops/control_values_test.py,sha256=JYaFLJSIqZSaQ94y0kyWRRVzcQ9mgc6-s1ws2q4EiAg,12943
|
|
290
|
-
cirq/ops/controlled_gate.py,sha256=
|
|
291
|
-
cirq/ops/controlled_gate_test.py,sha256=
|
|
290
|
+
cirq/ops/controlled_gate.py,sha256=WaimPh4J5tNGf65t6LLylx8l_RBCnqgQhz8DmUPCN5I,15077
|
|
291
|
+
cirq/ops/controlled_gate_test.py,sha256=8clPcyiE0hCSIqWYpqm6Kw4R_oORf-G0hVetrJqavOc,27847
|
|
292
292
|
cirq/ops/controlled_operation.py,sha256=l0pjUfru39HBuAbBkRCqJmrJDxah0JOFxXXILcUt0v8,13978
|
|
293
293
|
cirq/ops/controlled_operation_test.py,sha256=qXpnUoeWmOQaTMZPAuuICtX9Idf-JWtdARTsTENv54g,16546
|
|
294
294
|
cirq/ops/dense_pauli_string.py,sha256=1TijNu1D2HIbbnwLbT_f546R2L4OCQtm1bKjqhno1Kg,24234
|
|
@@ -1220,8 +1220,8 @@ cirq/work/sampler.py,sha256=rxbMWvrhu3gfNSBjZKozw28lLKVvBAS_1EGyPdYe8Xg,19041
|
|
|
1220
1220
|
cirq/work/sampler_test.py,sha256=SsMrRvLDYELyOAWLKISjkdEfrBwLYWRsT6D8WrsLM3Q,13533
|
|
1221
1221
|
cirq/work/zeros_sampler.py,sha256=Fs2JWwq0n9zv7_G5Rm-9vPeHUag7uctcMOHg0JTkZpc,2371
|
|
1222
1222
|
cirq/work/zeros_sampler_test.py,sha256=lQLgQDGBLtfImryys2HzQ2jOSGxHgc7-koVBUhv8qYk,3345
|
|
1223
|
-
cirq_core-1.6.0.
|
|
1224
|
-
cirq_core-1.6.0.
|
|
1225
|
-
cirq_core-1.6.0.
|
|
1226
|
-
cirq_core-1.6.0.
|
|
1227
|
-
cirq_core-1.6.0.
|
|
1223
|
+
cirq_core-1.6.0.dev20250527171805.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1224
|
+
cirq_core-1.6.0.dev20250527171805.dist-info/METADATA,sha256=H8dpr9NXF4NkVD4GafpzEa46-PBe2rwM35rtUKJUzMY,4857
|
|
1225
|
+
cirq_core-1.6.0.dev20250527171805.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
1226
|
+
cirq_core-1.6.0.dev20250527171805.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1227
|
+
cirq_core-1.6.0.dev20250527171805.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|