cirq-core 1.5.0.dev20250312025605__py3-none-any.whl → 1.5.0.dev20250312165047__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, 10, 0): # pragma: no cover
28
28
  'of cirq (e.g. "python -m pip install cirq==1.1.*")'
29
29
  )
30
30
 
31
- __version__ = "1.5.0.dev20250312025605"
31
+ __version__ = "1.5.0.dev20250312165047"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version():
6
- assert cirq.__version__ == "1.5.0.dev20250312025605"
6
+ assert cirq.__version__ == "1.5.0.dev20250312165047"
@@ -24,7 +24,6 @@ from typing import (
24
24
  Iterable,
25
25
  List,
26
26
  Optional,
27
- Set,
28
27
  Tuple,
29
28
  TYPE_CHECKING,
30
29
  TypeVar,
@@ -106,29 +105,6 @@ def deconstruct_single_qubit_matrix_into_angles(mat: np.ndarray) -> Tuple[float,
106
105
  return right_phase + diagonal_phase, rotation * 2, bottom_phase
107
106
 
108
107
 
109
- def _group_similar(items: List[T], comparer: Callable[[T, T], bool]) -> List[List[T]]:
110
- """Combines similar items into groups.
111
-
112
- Args:
113
- items: The list of items to group.
114
- comparer: Determines if two items are similar.
115
-
116
- Returns:
117
- A list of groups of items.
118
- """
119
- groups: List[List[T]] = []
120
- used: Set[int] = set()
121
- for i in range(len(items)):
122
- if i not in used:
123
- group = [items[i]]
124
- for j in range(i + 1, len(items)):
125
- if j not in used and comparer(items[i], items[j]):
126
- used.add(j)
127
- group.append(items[j])
128
- groups.append(group)
129
- return groups
130
-
131
-
132
108
  def unitary_eig(
133
109
  matrix: np.ndarray, check_preconditions: bool = True, atol: float = 1e-8
134
110
  ) -> Tuple[np.ndarray, np.ndarray]:
@@ -175,7 +151,6 @@ def map_eigenvalues(
175
151
  Args:
176
152
  matrix: The matrix to modify with the function.
177
153
  func: The function to apply to the eigenvalues of the matrix.
178
- rtol: Relative threshold used when separating eigenspaces.
179
154
  atol: Absolute threshold used when separating eigenspaces.
180
155
 
181
156
  Returns:
@@ -191,15 +166,18 @@ def map_eigenvalues(
191
166
  return total
192
167
 
193
168
 
194
- def kron_factor_4x4_to_2x2s(matrix: np.ndarray) -> Tuple[complex, np.ndarray, np.ndarray]:
169
+ def kron_factor_4x4_to_2x2s(
170
+ matrix: np.ndarray, rtol=1e-5, atol=1e-8
171
+ ) -> Tuple[complex, np.ndarray, np.ndarray]:
195
172
  """Splits a 4x4 matrix U = kron(A, B) into A, B, and a global factor.
196
173
 
197
174
  Requires the matrix to be the kronecker product of two 2x2 unitaries.
198
175
  Requires the matrix to have a non-zero determinant.
199
- Giving an incorrect matrix will cause garbage output.
200
176
 
201
177
  Args:
202
178
  matrix: The 4x4 unitary matrix to factor.
179
+ rtol: Per-matrix-entry relative tolerance on equality.
180
+ atol: Per-matrix-entry absolute tolerance on equality.
203
181
 
204
182
  Returns:
205
183
  A scalar factor and a pair of 2x2 unit-determinant matrices. The
@@ -232,6 +210,9 @@ def kron_factor_4x4_to_2x2s(matrix: np.ndarray) -> Tuple[complex, np.ndarray, np
232
210
  f1 *= -1
233
211
  g = -g
234
212
 
213
+ if not np.allclose(matrix, g * np.kron(f1, f2), rtol=rtol, atol=atol):
214
+ raise ValueError("Invalid 4x4 kronecker product.")
215
+
235
216
  return g, f1, f2
236
217
 
237
218
 
@@ -266,7 +247,7 @@ def so4_to_magic_su2s(
266
247
  raise ValueError('mat must be 4x4 special orthogonal.')
267
248
 
268
249
  ab = combinators.dot(MAGIC, mat, MAGIC_CONJ_T)
269
- _, a, b = kron_factor_4x4_to_2x2s(ab)
250
+ _, a, b = kron_factor_4x4_to_2x2s(ab, rtol, atol)
270
251
 
271
252
  return a, b
272
253
 
@@ -987,7 +968,7 @@ def _canonicalize_kak_vector(k_vec: np.ndarray, atol: float) -> np.ndarray:
987
968
  unitaries required to bring the KAK vector into canonical form.
988
969
 
989
970
  Args:
990
- k_vec: THe KAK vector to be canonicalized. This input may be vectorized,
971
+ k_vec: The KAK vector to be canonicalized. This input may be vectorized,
991
972
  with shape (...,3), where the final axis denotes the k_vector and
992
973
  all other axes are broadcast.
993
974
  atol: How close x2 must be to π/4 to guarantee z2 >= 0.
@@ -20,6 +20,7 @@ import pytest
20
20
  import cirq
21
21
  from cirq import value
22
22
  from cirq import unitary_eig
23
+ from cirq.linalg.decompositions import MAGIC, MAGIC_CONJ_T
23
24
 
24
25
  X = np.array([[0, 1], [1, 0]])
25
26
  Y = np.array([[0, -1j], [1j, 0]])
@@ -45,9 +46,7 @@ def assert_kronecker_factorization_not_within_tolerance(matrix, g, f1, f2):
45
46
 
46
47
 
47
48
  def assert_magic_su2_within_tolerance(mat, a, b):
48
- M = cirq.linalg.decompositions.MAGIC
49
- MT = cirq.linalg.decompositions.MAGIC_CONJ_T
50
- recon = cirq.linalg.combinators.dot(MT, cirq.linalg.combinators.kron(a, b), M)
49
+ recon = cirq.linalg.combinators.dot(MAGIC_CONJ_T, cirq.linalg.combinators.kron(a, b), MAGIC)
51
50
  assert np.allclose(recon, mat), "Failed to decompose within tolerance."
52
51
 
53
52
 
@@ -149,14 +148,15 @@ def test_kron_factor_special_unitaries(f1, f2):
149
148
  assert_kronecker_factorization_within_tolerance(p, g, g1, g2)
150
149
 
151
150
 
152
- def test_kron_factor_fail():
153
- mat = cirq.kron_with_controls(cirq.CONTROL_TAG, X)
154
- g, f1, f2 = cirq.kron_factor_4x4_to_2x2s(mat)
155
- with pytest.raises(ValueError):
156
- assert_kronecker_factorization_not_within_tolerance(mat, g, f1, f2)
157
- mat = cirq.kron_factor_4x4_to_2x2s(np.diag([1, 1, 1, 1j]))
158
- with pytest.raises(ValueError):
159
- assert_kronecker_factorization_not_within_tolerance(mat, g, f1, f2)
151
+ def test_kron_factor_invalid_input():
152
+ mats = [
153
+ cirq.kron_with_controls(cirq.CONTROL_TAG, X),
154
+ np.array([[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 2, 3, 4]]),
155
+ np.diag([1, 1, 1, 1j]),
156
+ ]
157
+ for mat in mats:
158
+ with pytest.raises(ValueError, match="Invalid 4x4 kronecker product"):
159
+ cirq.kron_factor_4x4_to_2x2s(mat)
160
160
 
161
161
 
162
162
  def recompose_so4(a: np.ndarray, b: np.ndarray) -> np.ndarray:
@@ -165,8 +165,7 @@ def recompose_so4(a: np.ndarray, b: np.ndarray) -> np.ndarray:
165
165
  assert cirq.is_special_unitary(a)
166
166
  assert cirq.is_special_unitary(b)
167
167
 
168
- magic = np.array([[1, 0, 0, 1j], [0, 1j, 1, 0], [0, 1j, -1, 0], [1, 0, 0, -1j]]) * np.sqrt(0.5)
169
- result = np.real(cirq.dot(np.conj(magic.T), cirq.kron(a, b), magic))
168
+ result = np.real(cirq.dot(MAGIC_CONJ_T, cirq.kron(a, b), MAGIC))
170
169
  assert cirq.is_orthogonal(result)
171
170
  return result
172
171
 
@@ -656,7 +655,7 @@ def test_kak_vector_matches_vectorized():
656
655
  np.testing.assert_almost_equal(actual, expected)
657
656
 
658
657
 
659
- def test_KAK_vector_local_invariants_random_input():
658
+ def test_kak_vector_local_invariants_random_input():
660
659
  actual = _local_invariants_from_kak(cirq.kak_vector(_random_unitaries))
661
660
  expected = _local_invariants_from_kak(_kak_vecs)
662
661
 
@@ -697,7 +696,7 @@ def test_kak_vector_on_weyl_chamber_face():
697
696
  (np.kron(X, X), (0, 0, 0)),
698
697
  ),
699
698
  )
700
- def test_KAK_vector_weyl_chamber_vertices(unitary, expected):
699
+ def test_kak_vector_weyl_chamber_vertices(unitary, expected):
701
700
  actual = cirq.kak_vector(unitary)
702
701
  np.testing.assert_almost_equal(actual, expected)
703
702
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.5.0.dev20250312025605
3
+ Version: 1.5.0.dev20250312165047
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=Qq3ZcfgD-Nb81cEppQdJqhAyrVqXKtfXZYGXT0p-Wh0,34718
4
4
  cirq/_doc.py,sha256=yDyWUD_2JDS0gShfGRb-rdqRt9-WeL7DhkqX7np0Nko,2879
5
5
  cirq/_import.py,sha256=p9gMHJscbtDDkfHOaulvd3Aer0pwUF5AXpL89XR8dNw,8402
6
6
  cirq/_import_test.py,sha256=6K_v0riZJXOXUphHNkGA8MY-JcmGlezFaGmvrNhm3OQ,1015
7
- cirq/_version.py,sha256=1c8Umgcd9CvWRzr_UJzu2D1Nt-30wH84XH0hvcLWyNI,1206
8
- cirq/_version_test.py,sha256=PYPQQBi6NAIMQQS2Cia6SOcwGBuohg1qHJVsKudZ214,147
7
+ cirq/_version.py,sha256=VQxk2g1sWEn_8YXUP8gbpf7HeQHJhWO6-aFrAf1Sy4M,1206
8
+ cirq/_version_test.py,sha256=vIpq3Juh3HROax8NXtDNZ9YSSXCWmcqmoYArhPoIYIc,147
9
9
  cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
10
10
  cirq/json_resolver_cache.py,sha256=p-vEOa-8GQ2cFIAdze-kd6C1un1uRvtujVPljVKaHBg,13557
11
11
  cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
@@ -248,8 +248,8 @@ cirq/ion/__init__.py,sha256=F6tf4JZOGpDdxX0FxT42qgq8rF96ZTFHMJ0OV09Yj1c,787
248
248
  cirq/linalg/__init__.py,sha256=9WLnBqLQ02FzCIUcchHBMYpOGVcENAjzv7GyDNgh89I,4013
249
249
  cirq/linalg/combinators.py,sha256=bq--LTsTI2WFRnok3weeIX7_QYKTW2OEFC2xktPMwA0,5336
250
250
  cirq/linalg/combinators_test.py,sha256=nZ3snkVA2nAOZ6WJK1hNd1f_i2a5xNdnostfMD1upbc,4699
251
- cirq/linalg/decompositions.py,sha256=8FlQKq5gwORCbDU807gCu6zsuC9o0VEVOUbNGaJPZbM,39164
252
- cirq/linalg/decompositions_test.py,sha256=S6p9AJO_9wwQdmNHYTAgBK4TL6_lz1U93sLNNuUJmBw,25840
251
+ cirq/linalg/decompositions.py,sha256=FZRJb6bnZghT7y2C-pg5utsWHeopzorjFF86Z9DZ1ew,38652
252
+ cirq/linalg/decompositions_test.py,sha256=7ydYawGYe4R0zu0zD4mh_ua26x9Z5W5bKFAuidq9dTw,25663
253
253
  cirq/linalg/diagonalize.py,sha256=Ym7C0JTAC9xfRQDYI72U6NxMYg0DfchjfXcbdg_92QE,10051
254
254
  cirq/linalg/diagonalize_test.py,sha256=H-JcLvcCBdN-DrKo2o1Gs7B8Q9SU70oAZmdT4yTLAi4,9089
255
255
  cirq/linalg/operator_spaces.py,sha256=-i5DEAW-b_sgmfZKXFf37XzX5h7cZ7R6EeW7RcFNeE0,4128
@@ -1204,8 +1204,8 @@ cirq/work/sampler.py,sha256=bE5tmVkcR6cZZMLETxDfHehdsYUMbx2RvBeIBetehI4,19187
1204
1204
  cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
1205
1205
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1206
1206
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1207
- cirq_core-1.5.0.dev20250312025605.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1208
- cirq_core-1.5.0.dev20250312025605.dist-info/METADATA,sha256=AXKUCsh6lkWsm1plwtJX29Ew9-4rkfXuIqPjRWr0LwM,4817
1209
- cirq_core-1.5.0.dev20250312025605.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
1210
- cirq_core-1.5.0.dev20250312025605.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1211
- cirq_core-1.5.0.dev20250312025605.dist-info/RECORD,,
1207
+ cirq_core-1.5.0.dev20250312165047.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1208
+ cirq_core-1.5.0.dev20250312165047.dist-info/METADATA,sha256=_LRbqdYXqIYKyRB_MVfTZb42-79oHf3ir-6JfSSmte8,4817
1209
+ cirq_core-1.5.0.dev20250312165047.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
1210
+ cirq_core-1.5.0.dev20250312165047.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1211
+ cirq_core-1.5.0.dev20250312165047.dist-info/RECORD,,