cirq-core 1.5.0.dev20250127034426__py3-none-any.whl → 1.5.0.dev20250128173701__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.dev20250127034426"
31
+ __version__ = "1.5.0.dev20250128173701"
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.dev20250127034426"
6
+ assert cirq.__version__ == "1.5.0.dev20250128173701"
@@ -34,11 +34,9 @@ class _BaseGridQid(ops.Qid):
34
34
  _col: int
35
35
  _dimension: int
36
36
  _comp_key: Optional[Tuple[int, int]] = None
37
- _hash: Optional[int] = None
37
+ _hash: int
38
38
 
39
39
  def __hash__(self) -> int:
40
- if self._hash is None:
41
- self._hash = ((self._dimension - 2) * 1_000_003 + self._col) * 1_000_003 + self._row
42
40
  return self._hash
43
41
 
44
42
  def __eq__(self, other) -> bool:
@@ -215,6 +213,9 @@ class GridQid(_BaseGridQid):
215
213
  dimension: The dimension of the qid's Hilbert space, i.e.
216
214
  the number of quantum levels.
217
215
  """
216
+ row = int(row)
217
+ col = int(col)
218
+ dimension = int(dimension)
218
219
  key = (row, col, dimension)
219
220
  inst = cls._cache.get(key)
220
221
  if inst is None:
@@ -223,6 +224,7 @@ class GridQid(_BaseGridQid):
223
224
  inst._row = row
224
225
  inst._col = col
225
226
  inst._dimension = dimension
227
+ inst._hash = ((dimension - 2) * 1_000_003 + col) * 1_000_003 + row
226
228
  cls._cache[key] = inst
227
229
  return inst
228
230
 
@@ -378,12 +380,15 @@ class GridQubit(_BaseGridQid):
378
380
  row: the row coordinate
379
381
  col: the column coordinate
380
382
  """
383
+ row = int(row)
384
+ col = int(col)
381
385
  key = (row, col)
382
386
  inst = cls._cache.get(key)
383
387
  if inst is None:
384
388
  inst = super().__new__(cls)
385
389
  inst._row = row
386
390
  inst._col = col
391
+ inst._hash = col * 1_000_003 + row
387
392
  cls._cache[key] = inst
388
393
  return inst
389
394
 
@@ -391,3 +391,24 @@ def test_immutable():
391
391
  def test_complex():
392
392
  assert complex(cirq.GridQubit(row=1, col=2)) == 2 + 1j
393
393
  assert isinstance(complex(cirq.GridQubit(row=1, col=2)), complex)
394
+
395
+
396
+ def test_numpy_index():
397
+ np5, np6, np3 = [np.int64(i) for i in [5, 6, 3]]
398
+ q = cirq.GridQubit(np5, np6)
399
+ hash(q) # doesn't throw
400
+ assert q.row == 5
401
+ assert q.col == 6
402
+ assert q.dimension == 2
403
+ assert isinstance(q.row, int)
404
+ assert isinstance(q.col, int)
405
+ assert isinstance(q.dimension, int)
406
+
407
+ q = cirq.GridQid(np5, np6, dimension=np3)
408
+ hash(q) # doesn't throw
409
+ assert q.row == 5
410
+ assert q.col == 6
411
+ assert q.dimension == 3
412
+ assert isinstance(q.row, int)
413
+ assert isinstance(q.col, int)
414
+ assert isinstance(q.dimension, int)
@@ -30,11 +30,9 @@ class _BaseLineQid(ops.Qid):
30
30
 
31
31
  _x: int
32
32
  _dimension: int
33
- _hash: Optional[int] = None
33
+ _hash: int
34
34
 
35
35
  def __hash__(self) -> int:
36
- if self._hash is None:
37
- self._hash = (self._dimension - 2) * 1_000_003 + self._x
38
36
  return self._hash
39
37
 
40
38
  def __eq__(self, other) -> bool:
@@ -193,6 +191,8 @@ class LineQid(_BaseLineQid):
193
191
  dimension: The dimension of the qid's Hilbert space, i.e.
194
192
  the number of quantum levels.
195
193
  """
194
+ x = int(x)
195
+ dimension = int(dimension)
196
196
  key = (x, dimension)
197
197
  inst = cls._cache.get(key)
198
198
  if inst is None:
@@ -200,6 +200,7 @@ class LineQid(_BaseLineQid):
200
200
  inst = super().__new__(cls)
201
201
  inst._x = x
202
202
  inst._dimension = dimension
203
+ inst._hash = (dimension - 2) * 1_000_003 + x
203
204
  cls._cache[key] = inst
204
205
  return inst
205
206
 
@@ -301,10 +302,12 @@ class LineQubit(_BaseLineQid):
301
302
  Args:
302
303
  x: The x coordinate.
303
304
  """
305
+ x = int(x)
304
306
  inst = cls._cache.get(x)
305
307
  if inst is None:
306
308
  inst = super().__new__(cls)
307
309
  inst._x = x
310
+ inst._hash = x
308
311
  cls._cache[x] = inst
309
312
  return inst
310
313
 
@@ -12,6 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ import numpy as np
15
16
  import pytest
16
17
 
17
18
  import cirq
@@ -284,3 +285,20 @@ def test_numeric():
284
285
  assert isinstance(int(cirq.LineQubit(x=5)), int)
285
286
  assert isinstance(float(cirq.LineQubit(x=5)), float)
286
287
  assert isinstance(complex(cirq.LineQubit(x=5)), complex)
288
+
289
+
290
+ def test_numpy_index():
291
+ np5 = np.int64(5)
292
+ q = cirq.LineQubit(np5)
293
+ assert hash(q) == 5
294
+ assert q.x == 5
295
+ assert q.dimension == 2
296
+ assert isinstance(q.x, int)
297
+ assert isinstance(q.dimension, int)
298
+
299
+ q = cirq.LineQid(np5, np.int64(3))
300
+ hash(q) # doesn't throw
301
+ assert q.x == 5
302
+ assert q.dimension == 3
303
+ assert isinstance(q.x, int)
304
+ assert isinstance(q.dimension, int)
cirq/ops/raw_types.py CHANGED
@@ -464,6 +464,18 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
464
464
  """
465
465
  raise NotImplementedError
466
466
 
467
+ def _equal_up_to_global_phase_(
468
+ self, other: Any, atol: Union[int, float] = 1e-8
469
+ ) -> Union[NotImplementedType, bool]:
470
+ """Default fallback for gates that do not implement this protocol."""
471
+ try:
472
+ return protocols.equal_up_to_global_phase(
473
+ protocols.unitary(self), protocols.unitary(other), atol=atol
474
+ )
475
+ except TypeError:
476
+ # Gate has no unitary protocol
477
+ return NotImplemented
478
+
467
479
  def _commutes_on_qids_(
468
480
  self, qids: 'Sequence[cirq.Qid]', other: Any, *, atol: float = 1e-8
469
481
  ) -> Union[bool, NotImplementedType, None]:
@@ -117,3 +117,9 @@ def test_equal_up_to_global_phase_eq_supported():
117
117
  # cast types
118
118
  assert cirq.equal_up_to_global_phase(A(0.1), A(0.1j), atol=1e-2)
119
119
  assert not cirq.equal_up_to_global_phase(1e-8j, B(0.0), atol=1e-10)
120
+
121
+
122
+ def test_equal_up_to_global_phase_non_eigen_gates():
123
+ gate1 = cirq.PhasedXPowGate(phase_exponent=1.5, exponent=1.0)
124
+ gate2 = cirq.PhasedXPowGate(phase_exponent=0.5, exponent=1.0)
125
+ assert cirq.equal_up_to_global_phase(gate1, gate2)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.5.0.dev20250127034426
3
+ Version: 1.5.0.dev20250128173701
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=caRTahIjPw3DWxkspx0AhC96jWwoXPaICJwgdyZ49jE,1206
8
- cirq/_version_test.py,sha256=uP3CcPXXDuMubmtENqlYoE79zXb-HlIxaeo5gY5vz7o,147
7
+ cirq/_version.py,sha256=sudgb7thCjHslTYC-u5xlGPA5amffwV5AeLBeq94L3Y,1206
8
+ cirq/_version_test.py,sha256=8H47RYydWj7MVorJxrsSFudiqs1Y0jGRmsjDNR_PfQI,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
@@ -157,12 +157,12 @@ cirq/devices/device.py,sha256=9rUZwpbbmqk8AUVH4N4KfJ59j5im7hVgDJAHtN9iH_0,5361
157
157
  cirq/devices/device_test.py,sha256=v3gT6jrGLLfYnZbTizIaIMkI3s5_xVM3OV9JQchvAxY,1124
158
158
  cirq/devices/grid_device_metadata.py,sha256=h4Xo_PaiZqQSVUgb1ctVtYYYE2tNik2KQhCgooilZrE,8629
159
159
  cirq/devices/grid_device_metadata_test.py,sha256=IeOqYOZcUGhB4ivuQW2g0Q9dt-zFA0H6Dav6yv6Lul0,8592
160
- cirq/devices/grid_qubit.py,sha256=ynJYYih1QcZPLuNQYbooJWvSruhlep6qKFdiwdfVuSk,18819
161
- cirq/devices/grid_qubit_test.py,sha256=EzI8dWWnCfYbwruwsKlBzb41lQTA6AEOB2X16oQAz-0,14044
160
+ cirq/devices/grid_qubit.py,sha256=7Pvy5FXwOJPxN-EDrEaS3Jip_2PLEeih8uZHYgcgsHM,18927
161
+ cirq/devices/grid_qubit_test.py,sha256=qC7AEp9r8-KWSRiM-GMua8rYAyPWFLSq8dedLjwf6Ks,14621
162
162
  cirq/devices/insertion_noise_model.py,sha256=-X07pSTp-lxQj6AQT_89gTHx_jKtI9GSMrD4dozCwTs,3614
163
163
  cirq/devices/insertion_noise_model_test.py,sha256=i9jB257VXO5wi5QdDO5G4tphx5RKMaouUsdsQT3kiBU,3992
164
- cirq/devices/line_qubit.py,sha256=SFN7VaxVhcEnH9VPtqPeQ3Aygp0xa8kZ0yntkI_DiVc,11836
165
- cirq/devices/line_qubit_test.py,sha256=_X1ofFHtuo0myFfsu1nlTJf9OLuLWRgZHHW2VG23ERY,9547
164
+ cirq/devices/line_qubit.py,sha256=XXZl1WfqOl4PuTgZTbijtwMxzZoB77t3_C-c8XAExBA,11876
165
+ cirq/devices/line_qubit_test.py,sha256=1smZ8Jvf8y0KkLM-zuDWg_TH05nwF07WxZORD1z-6Es,9975
166
166
  cirq/devices/named_topologies.py,sha256=grFXvi0UDHZl1pRyHDWSqjub3xF_Yf7RLXfMAZbyoEA,15790
167
167
  cirq/devices/named_topologies_test.py,sha256=Nj_tlGmqPH7IVUzpUHPnAPlfUWhSGbZsIHdsLLjxIZs,4736
168
168
  cirq/devices/noise_model.py,sha256=c00mxBd7ZYw8k-cCoKgF5ePI8WKcPyJS925NarivIRI,11339
@@ -360,7 +360,7 @@ cirq/ops/qubit_order_or_list.py,sha256=WVnhQcOYCgAhiB4t47Kji-pN1tnvs--X5deCQwwGV
360
360
  cirq/ops/qubit_order_test.py,sha256=B9xMIxlaI7YjRUNA6AkHJuUCFejGYw-lT7ZaSl31yTU,4238
361
361
  cirq/ops/random_gate_channel.py,sha256=gKDqZa6AwdCIuuh2UOvO5oxCdGRDOInA7fI3ZLQ-LTY,5121
362
362
  cirq/ops/random_gate_channel_test.py,sha256=U3EAaAlCZkgFIYxqwcSkPsaVGrKA2PSeG_DK2ou--AE,8606
363
- cirq/ops/raw_types.py,sha256=pPbdomUXHrS8e_eb4sZTVoOrOcbI_yW4ekn97Eowr6U,41700
363
+ cirq/ops/raw_types.py,sha256=n_v0flAXTxHFVNOKrOZRcOIPx1LIZ3F7wYfGJiAF9qk,42176
364
364
  cirq/ops/raw_types_test.py,sha256=AtcaAgu50IK_bsMXo4MkM_fjWQj9EQrkn9ved0_cJoo,33872
365
365
  cirq/ops/state_preparation_channel.py,sha256=PjVtoLbjBAy_XqnFAY40Am-NifeuCFVVLW6RJxph5sQ,4778
366
366
  cirq/ops/state_preparation_channel_test.py,sha256=yKUvLw_ft6cvIgRJcFQ779wZS-V6V-pzQq-rZRWdCmU,5922
@@ -396,7 +396,7 @@ cirq/protocols/control_key_protocol_test.py,sha256=190gp4QBu5QpP2doMmzx9RkAkp6VZ
396
396
  cirq/protocols/decompose_protocol.py,sha256=fFy75GOLiJWwNRVDNtl00-19xCJcI_n9J7GiKuMY2wU,18903
397
397
  cirq/protocols/decompose_protocol_test.py,sha256=5L5lQN_FV9qtE3NHPsnxtdgUtY5uDEIfxZkBHbgDrGs,16025
398
398
  cirq/protocols/equal_up_to_global_phase_protocol.py,sha256=0a93790FDjID46cX94PVAlA9i9Fu7uN8cj6qT94NH9w,4101
399
- cirq/protocols/equal_up_to_global_phase_protocol_test.py,sha256=9H54KKkS3-_BrTSrEynDq1-sAcYfhLVmVqveLHieg24,5722
399
+ cirq/protocols/equal_up_to_global_phase_protocol_test.py,sha256=5uypo6WHTp8AQU1KURl48euQG2J123AXEVFQ6v6cIeE,5964
400
400
  cirq/protocols/has_stabilizer_effect_protocol.py,sha256=XH6Lv9SGuYhuuSB0mi5v8Eg5emR-vbICKUjjqfxDw1U,4295
401
401
  cirq/protocols/has_stabilizer_effect_protocol_test.py,sha256=0ia7ehyGpmscjRP448dBANZKwnlbqSODdPUYRUhDEN0,3879
402
402
  cirq/protocols/has_unitary_protocol.py,sha256=inj17qr8Pz2Zofj0Lsp2o7TWlfmdU1TybtRjs1TWVow,5372
@@ -1202,8 +1202,8 @@ cirq/work/sampler.py,sha256=bE5tmVkcR6cZZMLETxDfHehdsYUMbx2RvBeIBetehI4,19187
1202
1202
  cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
1203
1203
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1204
1204
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1205
- cirq_core-1.5.0.dev20250127034426.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1206
- cirq_core-1.5.0.dev20250127034426.dist-info/METADATA,sha256=kyvG-ReT3GpED8x3UpouFoYZJ4Pbmrup7LgDPncvVDM,2111
1207
- cirq_core-1.5.0.dev20250127034426.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
1208
- cirq_core-1.5.0.dev20250127034426.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1209
- cirq_core-1.5.0.dev20250127034426.dist-info/RECORD,,
1205
+ cirq_core-1.5.0.dev20250128173701.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1206
+ cirq_core-1.5.0.dev20250128173701.dist-info/METADATA,sha256=oJ6WO_LKlb-yFZip8HCt4i-4rq-51P25geaEYbWHbuk,2111
1207
+ cirq_core-1.5.0.dev20250128173701.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
1208
+ cirq_core-1.5.0.dev20250128173701.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1209
+ cirq_core-1.5.0.dev20250128173701.dist-info/RECORD,,