cirq-core 1.5.0.dev20250114132800__py3-none-any.whl → 1.5.0.dev20250114140248__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.dev20250114132800"
31
+ __version__ = "1.5.0.dev20250114140248"
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.dev20250114132800"
6
+ assert cirq.__version__ == "1.5.0.dev20250114140248"
cirq/circuits/moment.py CHANGED
@@ -15,6 +15,7 @@
15
15
  """A simplified time-slice of operations within a sequenced circuit."""
16
16
 
17
17
  import itertools
18
+ from functools import cached_property
18
19
  from types import NotImplementedType
19
20
  from typing import (
20
21
  AbstractSet,
@@ -113,7 +114,6 @@ class Moment:
113
114
  raise ValueError(f'Overlapping operations: {self.operations}')
114
115
  self._qubit_to_op[q] = op
115
116
 
116
- self._qubits = frozenset(self._qubit_to_op.keys())
117
117
  self._measurement_key_objs: Optional[FrozenSet['cirq.MeasurementKey']] = None
118
118
  self._control_keys: Optional[FrozenSet['cirq.MeasurementKey']] = None
119
119
 
@@ -135,9 +135,9 @@ class Moment:
135
135
  def operations(self) -> Tuple['cirq.Operation', ...]:
136
136
  return self._operations
137
137
 
138
- @property
138
+ @cached_property
139
139
  def qubits(self) -> FrozenSet['cirq.Qid']:
140
- return self._qubits
140
+ return frozenset(self._qubit_to_op)
141
141
 
142
142
  def operates_on_single_qubit(self, qubit: 'cirq.Qid') -> bool:
143
143
  """Determines if the moment has operations touching the given qubit.
@@ -157,7 +157,7 @@ class Moment:
157
157
  Returns:
158
158
  Whether this moment has operations involving the qubits.
159
159
  """
160
- return not self._qubits.isdisjoint(qubits)
160
+ return not self._qubit_to_op.keys().isdisjoint(qubits)
161
161
 
162
162
  def operation_at(self, qubit: raw_types.Qid) -> Optional['cirq.Operation']:
163
163
  """Returns the operation on a certain qubit for the moment.
@@ -185,14 +185,13 @@ class Moment:
185
185
  Raises:
186
186
  ValueError: If the operation given overlaps a current operation in the moment.
187
187
  """
188
- if any(q in self._qubits for q in operation.qubits):
188
+ if any(q in self._qubit_to_op for q in operation.qubits):
189
189
  raise ValueError(f'Overlapping operations: {operation}')
190
190
 
191
191
  # Use private variables to facilitate a quick copy.
192
192
  m = Moment(_flatten_contents=False)
193
193
  m._operations = self._operations + (operation,)
194
194
  m._sorted_operations = None
195
- m._qubits = self._qubits.union(operation.qubits)
196
195
  m._qubit_to_op = {**self._qubit_to_op, **{q: operation for q in operation.qubits}}
197
196
 
198
197
  m._measurement_key_objs = self._measurement_key_objs_().union(
@@ -222,14 +221,11 @@ class Moment:
222
221
  m = Moment(_flatten_contents=False)
223
222
  # Use private variables to facilitate a quick copy.
224
223
  m._qubit_to_op = self._qubit_to_op.copy()
225
- qubits = set(self._qubits)
226
224
  for op in flattened_contents:
227
- if any(q in qubits for q in op.qubits):
225
+ if any(q in m._qubit_to_op for q in op.qubits):
228
226
  raise ValueError(f'Overlapping operations: {op}')
229
- qubits.update(op.qubits)
230
227
  for q in op.qubits:
231
228
  m._qubit_to_op[q] = op
232
- m._qubits = frozenset(qubits)
233
229
 
234
230
  m._operations = self._operations + flattened_contents
235
231
  m._sorted_operations = None
@@ -450,7 +446,9 @@ class Moment:
450
446
  @_compat.cached_method()
451
447
  def _has_kraus_(self) -> bool:
452
448
  """Returns True if self has a Kraus representation and self uses <= 10 qubits."""
453
- return all(protocols.has_kraus(op) for op in self.operations) and len(self.qubits) <= 10
449
+ return (
450
+ all(protocols.has_kraus(op) for op in self.operations) and len(self._qubit_to_op) <= 10
451
+ )
454
452
 
455
453
  def _kraus_(self) -> Sequence[np.ndarray]:
456
454
  r"""Returns Kraus representation of self.
@@ -475,7 +473,7 @@ class Moment:
475
473
  if not self._has_kraus_():
476
474
  return NotImplemented
477
475
 
478
- qubits = sorted(self.qubits)
476
+ qubits = sorted(self._qubit_to_op)
479
477
  n = len(qubits)
480
478
  if n < 1:
481
479
  return (np.array([[1 + 0j]]),)
@@ -602,7 +600,7 @@ class Moment:
602
600
  """
603
601
 
604
602
  # Figure out where to place everything.
605
- qs = set(self.qubits) | set(extra_qubits)
603
+ qs = self._qubit_to_op.keys() | set(extra_qubits)
606
604
  points = {xy_breakdown_func(q) for q in qs}
607
605
  x_keys = sorted({pt[0] for pt in points}, key=_SortByValFallbackToType)
608
606
  y_keys = sorted({pt[1] for pt in points}, key=_SortByValFallbackToType)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.5.0.dev20250114132800
3
+ Version: 1.5.0.dev20250114140248
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=jK3gvqXyZDutAVaBdBK-H5Nuwi8HFrtpFwjD6JHHh3E,1206
8
- cirq/_version_test.py,sha256=_ar4m8n4XqpWUD8U0dZQEqa9QSgjeSSt927Co-SpuYY,147
7
+ cirq/_version.py,sha256=4Nu2-SQ9Au-CrPhkpefx0QhDIq8_Vx203K9sJNGHCBE,1206
8
+ cirq/_version_test.py,sha256=RYYrAblIrko91JohfWmYwJOjQnuYRUQM0IwGc6b0uII,147
9
9
  cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
10
10
  cirq/json_resolver_cache.py,sha256=cpbvJMNIh0U-l1mEVb-TqhJUEXfm2vpuR3v432ORSmg,13702
11
11
  cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
@@ -24,7 +24,7 @@ cirq/circuits/frozen_circuit.py,sha256=qSbLHqIszCbVipNZQy4N829v_mWf8N2926cYRzpxG
24
24
  cirq/circuits/frozen_circuit_test.py,sha256=rHyii8hLhOQ6jdA8dC1OcYPGnyeBC4uY5Q53XspkkCk,4133
25
25
  cirq/circuits/insert_strategy.py,sha256=L0OLXuo24TtBfdJGOAG2PsVDMrbvQl4iN5lUk6IPuyo,2851
26
26
  cirq/circuits/insert_strategy_test.py,sha256=dgz13_ssa_GWqzzx5W4G4sJJw4SUHC3-g3K0_Z4TRiA,686
27
- cirq/circuits/moment.py,sha256=MskIVl5jbGnZdKKLNWbrQhWI5FHwjsuPOEm0hze8GDE,26299
27
+ cirq/circuits/moment.py,sha256=y9hyP-QObxgL64a1veeTwDsqdGHbDkbE_o1VmgsfY6Y,26203
28
28
  cirq/circuits/moment_test.py,sha256=oNHNXhiPEoCKbzeh16tRwiW1qZWlg4X2O_uiVDP1D58,27375
29
29
  cirq/circuits/optimization_pass.py,sha256=uw3ne0-ebZo6GNjwfQMuQ3b5u9RCgyaXRfhpbljlxao,6468
30
30
  cirq/circuits/optimization_pass_test.py,sha256=eQB0NBJ9EvqjgSFGQMgaHIh5niQhksdnvqSXhsj3nOg,5947
@@ -1203,8 +1203,8 @@ cirq/work/sampler.py,sha256=bE5tmVkcR6cZZMLETxDfHehdsYUMbx2RvBeIBetehI4,19187
1203
1203
  cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
1204
1204
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1205
1205
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1206
- cirq_core-1.5.0.dev20250114132800.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1207
- cirq_core-1.5.0.dev20250114132800.dist-info/METADATA,sha256=Tq7ezBR_LYWBUdhnZiJSDLPb3CdrK-LB63BzINPfO8Q,2105
1208
- cirq_core-1.5.0.dev20250114132800.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
1209
- cirq_core-1.5.0.dev20250114132800.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1210
- cirq_core-1.5.0.dev20250114132800.dist-info/RECORD,,
1206
+ cirq_core-1.5.0.dev20250114140248.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1207
+ cirq_core-1.5.0.dev20250114140248.dist-info/METADATA,sha256=zMgfgKqmOsvGDQQ-Nmv4NMHv6ptckiKRI9oUtdjratI,2105
1208
+ cirq_core-1.5.0.dev20250114140248.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
1209
+ cirq_core-1.5.0.dev20250114140248.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1210
+ cirq_core-1.5.0.dev20250114140248.dist-info/RECORD,,