cirq-core 1.6.0.dev20250524014359__py3-none-any.whl → 1.6.0.dev20250527184016__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 CHANGED
@@ -28,4 +28,4 @@ if sys.version_info < (3, 11, 0): # pragma: no cover
28
28
  'of cirq (e.g. "python -m pip install cirq==1.5.0")'
29
29
  )
30
30
 
31
- __version__ = "1.6.0.dev20250524014359"
31
+ __version__ = "1.6.0.dev20250527184016"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version() -> None:
6
- assert cirq.__version__ == "1.6.0.dev20250524014359"
6
+ assert cirq.__version__ == "1.6.0.dev20250527184016"
@@ -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.has_unitary(self.sub_gate)
157
- and protocols.num_qubits(self.sub_gate) == 1
158
- and self._qid_shape_() == (2,) * len(self._qid_shape_())
159
- and isinstance(self.control_values, cv.ProductOfSums)
160
- ):
161
- invert_ops: list[cirq.Operation] = []
162
- for cvals, cqbit in zip(self.control_values, qubits[: self.num_controls()]):
163
- if set(cvals) == {0}:
164
- invert_ops.append(common_gates.X(cqbit))
165
- elif set(cvals) == {0, 1}:
166
- control_qubits.remove(cqbit)
167
- decomposed_ops = controlled_gate_decomposition.decompose_multi_controlled_rotation(
168
- protocols.unitary(self.sub_gate), control_qubits, qubits[-1]
169
- )
170
- return invert_ops + decomposed_ops + invert_ops
171
- if isinstance(self.sub_gate, gp.GlobalPhaseGate):
172
- # A controlled global phase is a diagonal gate, where each active control value index
173
- # is set equal to the phase angle.
174
- shape = self.control_qid_shape
175
- if protocols.is_parameterized(self.sub_gate) or set(shape) != {2}:
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
@@ -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))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cirq-core
3
- Version: 1.6.0.dev20250524014359
3
+ Version: 1.6.0.dev20250527184016
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
@@ -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=De6DXpG-pgzaTQA5TcLGGIF_KzzKiwg33EO6g0azxXI,1206
8
- cirq/_version_test.py,sha256=1PflqusisHdKlgCE0uUiSoeNRGgsKvYQQ91eDewZfi8,155
7
+ cirq/_version.py,sha256=jgGDaQGRvrx7X54lT7Kb5NXHRQvjjSAOzFqqnCVlbk8,1206
8
+ cirq/_version_test.py,sha256=U3k01-fnES1NgkGuD-ITKW6qswJurxZ6wPBKrXayNpA,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=8VRUW95foVgPTFwDvuBnT84M8LiGH4pzpRZVaDOAtHk,15331
291
- cirq/ops/controlled_gate_test.py,sha256=VcBb572S17Boe70TJddU-sqhaJqZSUKiqGstJzSspsE,26765
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.dev20250524014359.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1224
- cirq_core-1.6.0.dev20250524014359.dist-info/METADATA,sha256=WB1T6ZPqhiZcDTSpYjKJs-APPbhNZw4yh1Ut_iV4ZPM,4857
1225
- cirq_core-1.6.0.dev20250524014359.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
1226
- cirq_core-1.6.0.dev20250524014359.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1227
- cirq_core-1.6.0.dev20250524014359.dist-info/RECORD,,
1223
+ cirq_core-1.6.0.dev20250527184016.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1224
+ cirq_core-1.6.0.dev20250527184016.dist-info/METADATA,sha256=9QCvYnVxoxz7SzpHcsZypTYNlDX6sdZP4g0-1HaQ2Y8,4857
1225
+ cirq_core-1.6.0.dev20250527184016.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
1226
+ cirq_core-1.6.0.dev20250527184016.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1227
+ cirq_core-1.6.0.dev20250527184016.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5