cirq-core 1.3.0.dev20230829170013__py3-none-any.whl → 1.3.0.dev20230830022013__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/value/duration.py +68 -37
- cirq/value/duration_test.py +2 -0
- {cirq_core-1.3.0.dev20230829170013.dist-info → cirq_core-1.3.0.dev20230830022013.dist-info}/METADATA +1 -1
- {cirq_core-1.3.0.dev20230829170013.dist-info → cirq_core-1.3.0.dev20230830022013.dist-info}/RECORD +8 -8
- {cirq_core-1.3.0.dev20230829170013.dist-info → cirq_core-1.3.0.dev20230830022013.dist-info}/LICENSE +0 -0
- {cirq_core-1.3.0.dev20230829170013.dist-info → cirq_core-1.3.0.dev20230830022013.dist-info}/WHEEL +0 -0
- {cirq_core-1.3.0.dev20230829170013.dist-info → cirq_core-1.3.0.dev20230830022013.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.3.0.
|
|
1
|
+
__version__ = "1.3.0.dev20230830022013"
|
cirq/value/duration.py
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
"""A typed time delta that supports picosecond accuracy."""
|
|
15
15
|
|
|
16
|
-
from typing import AbstractSet, Any, Dict, Optional, Tuple, TYPE_CHECKING, Union
|
|
16
|
+
from typing import AbstractSet, Any, Dict, Optional, Tuple, TYPE_CHECKING, Union, List
|
|
17
17
|
import datetime
|
|
18
18
|
|
|
19
19
|
import sympy
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
22
22
|
from cirq import protocols
|
|
23
|
-
from cirq._compat import proper_repr
|
|
23
|
+
from cirq._compat import proper_repr, cached_method
|
|
24
24
|
from cirq._doc import document
|
|
25
25
|
|
|
26
26
|
if TYPE_CHECKING:
|
|
@@ -79,48 +79,53 @@ class Duration:
|
|
|
79
79
|
>>> print(cirq.Duration(micros=1.5 * sympy.Symbol('t')))
|
|
80
80
|
(1500.0*t) ns
|
|
81
81
|
"""
|
|
82
|
+
self._time_vals: List[_NUMERIC_INPUT_TYPE] = [0, 0, 0, 0]
|
|
83
|
+
self._multipliers = [1, 1000, 1000_000, 1000_000_000]
|
|
82
84
|
if value is not None and value != 0:
|
|
83
85
|
if isinstance(value, datetime.timedelta):
|
|
84
86
|
# timedelta has microsecond resolution.
|
|
85
|
-
|
|
87
|
+
self._time_vals[2] = int(value / datetime.timedelta(microseconds=1))
|
|
86
88
|
elif isinstance(value, Duration):
|
|
87
|
-
|
|
89
|
+
self._time_vals = value._time_vals
|
|
88
90
|
else:
|
|
89
91
|
raise TypeError(f'Not a `cirq.DURATION_LIKE`: {repr(value)}.')
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
self._picos: _NUMERIC_OUTPUT_TYPE = float(val) if isinstance(val, np.number) else val
|
|
92
|
+
input_vals = [picos, nanos, micros, millis]
|
|
93
|
+
self._time_vals = _add_time_vals(self._time_vals, input_vals)
|
|
93
94
|
|
|
94
95
|
def _is_parameterized_(self) -> bool:
|
|
95
|
-
return protocols.is_parameterized(self.
|
|
96
|
+
return protocols.is_parameterized(self._time_vals)
|
|
96
97
|
|
|
97
98
|
def _parameter_names_(self) -> AbstractSet[str]:
|
|
98
|
-
return protocols.parameter_names(self.
|
|
99
|
+
return protocols.parameter_names(self._time_vals)
|
|
99
100
|
|
|
100
101
|
def _resolve_parameters_(self, resolver: 'cirq.ParamResolver', recursive: bool) -> 'Duration':
|
|
101
|
-
return
|
|
102
|
+
return _duration_from_time_vals(
|
|
103
|
+
protocols.resolve_parameters(self._time_vals, resolver, recursive)
|
|
104
|
+
)
|
|
102
105
|
|
|
106
|
+
@cached_method
|
|
103
107
|
def total_picos(self) -> _NUMERIC_OUTPUT_TYPE:
|
|
104
108
|
"""Returns the number of picoseconds that the duration spans."""
|
|
105
|
-
|
|
109
|
+
val = sum(a * b for a, b in zip(self._time_vals, self._multipliers))
|
|
110
|
+
return float(val) if isinstance(val, np.number) else val
|
|
106
111
|
|
|
107
112
|
def total_nanos(self) -> _NUMERIC_OUTPUT_TYPE:
|
|
108
113
|
"""Returns the number of nanoseconds that the duration spans."""
|
|
109
|
-
return self.
|
|
114
|
+
return self.total_picos() / 1000
|
|
110
115
|
|
|
111
116
|
def total_micros(self) -> _NUMERIC_OUTPUT_TYPE:
|
|
112
117
|
"""Returns the number of microseconds that the duration spans."""
|
|
113
|
-
return self.
|
|
118
|
+
return self.total_picos() / 1000_000
|
|
114
119
|
|
|
115
120
|
def total_millis(self) -> _NUMERIC_OUTPUT_TYPE:
|
|
116
121
|
"""Returns the number of milliseconds that the duration spans."""
|
|
117
|
-
return self.
|
|
122
|
+
return self.total_picos() / 1000_000_000
|
|
118
123
|
|
|
119
124
|
def __add__(self, other) -> 'Duration':
|
|
120
125
|
other = _attempt_duration_like_to_duration(other)
|
|
121
126
|
if other is None:
|
|
122
127
|
return NotImplemented
|
|
123
|
-
return
|
|
128
|
+
return _duration_from_time_vals(_add_time_vals(self._time_vals, other._time_vals))
|
|
124
129
|
|
|
125
130
|
def __radd__(self, other) -> 'Duration':
|
|
126
131
|
return self.__add__(other)
|
|
@@ -129,29 +134,36 @@ class Duration:
|
|
|
129
134
|
other = _attempt_duration_like_to_duration(other)
|
|
130
135
|
if other is None:
|
|
131
136
|
return NotImplemented
|
|
132
|
-
return
|
|
137
|
+
return _duration_from_time_vals(
|
|
138
|
+
_add_time_vals(self._time_vals, [-x for x in other._time_vals])
|
|
139
|
+
)
|
|
133
140
|
|
|
134
141
|
def __rsub__(self, other) -> 'Duration':
|
|
135
142
|
other = _attempt_duration_like_to_duration(other)
|
|
136
143
|
if other is None:
|
|
137
144
|
return NotImplemented
|
|
138
|
-
return
|
|
145
|
+
return _duration_from_time_vals(
|
|
146
|
+
_add_time_vals(other._time_vals, [-x for x in self._time_vals])
|
|
147
|
+
)
|
|
139
148
|
|
|
140
149
|
def __mul__(self, other) -> 'Duration':
|
|
141
150
|
if not isinstance(other, (int, float, sympy.Expr)):
|
|
142
151
|
return NotImplemented
|
|
143
|
-
|
|
152
|
+
if other == 0:
|
|
153
|
+
return _duration_from_time_vals([0] * 4)
|
|
154
|
+
return _duration_from_time_vals([x * other for x in self._time_vals])
|
|
144
155
|
|
|
145
156
|
def __rmul__(self, other) -> 'Duration':
|
|
146
157
|
return self.__mul__(other)
|
|
147
158
|
|
|
148
159
|
def __truediv__(self, other) -> Union['Duration', float]:
|
|
149
160
|
if isinstance(other, (int, float, sympy.Expr)):
|
|
150
|
-
|
|
161
|
+
new_time_vals = [x / other for x in self._time_vals]
|
|
162
|
+
return _duration_from_time_vals(new_time_vals)
|
|
151
163
|
|
|
152
164
|
other_duration = _attempt_duration_like_to_duration(other)
|
|
153
165
|
if other_duration is not None:
|
|
154
|
-
return self.
|
|
166
|
+
return self.total_picos() / other_duration.total_picos()
|
|
155
167
|
|
|
156
168
|
return NotImplemented
|
|
157
169
|
|
|
@@ -159,56 +171,57 @@ class Duration:
|
|
|
159
171
|
other = _attempt_duration_like_to_duration(other)
|
|
160
172
|
if other is None:
|
|
161
173
|
return NotImplemented
|
|
162
|
-
return self.
|
|
174
|
+
return self.total_picos() == other.total_picos()
|
|
163
175
|
|
|
164
176
|
def __ne__(self, other):
|
|
165
177
|
other = _attempt_duration_like_to_duration(other)
|
|
166
178
|
if other is None:
|
|
167
179
|
return NotImplemented
|
|
168
|
-
return self.
|
|
180
|
+
return self.total_picos() != other.total_picos()
|
|
169
181
|
|
|
170
182
|
def __gt__(self, other):
|
|
171
183
|
other = _attempt_duration_like_to_duration(other)
|
|
172
184
|
if other is None:
|
|
173
185
|
return NotImplemented
|
|
174
|
-
return self.
|
|
186
|
+
return self.total_picos() > other.total_picos()
|
|
175
187
|
|
|
176
188
|
def __lt__(self, other):
|
|
177
189
|
other = _attempt_duration_like_to_duration(other)
|
|
178
190
|
if other is None:
|
|
179
191
|
return NotImplemented
|
|
180
|
-
return self.
|
|
192
|
+
return self.total_picos() < other.total_picos()
|
|
181
193
|
|
|
182
194
|
def __ge__(self, other):
|
|
183
195
|
other = _attempt_duration_like_to_duration(other)
|
|
184
196
|
if other is None:
|
|
185
197
|
return NotImplemented
|
|
186
|
-
return self.
|
|
198
|
+
return self.total_picos() >= other.total_picos()
|
|
187
199
|
|
|
188
200
|
def __le__(self, other):
|
|
189
201
|
other = _attempt_duration_like_to_duration(other)
|
|
190
202
|
if other is None:
|
|
191
203
|
return NotImplemented
|
|
192
|
-
return self.
|
|
204
|
+
return self.total_picos() <= other.total_picos()
|
|
193
205
|
|
|
194
206
|
def __bool__(self):
|
|
195
|
-
return bool(self.
|
|
207
|
+
return bool(self.total_picos())
|
|
196
208
|
|
|
197
209
|
def __hash__(self):
|
|
198
|
-
if isinstance(self.
|
|
199
|
-
return hash(datetime.timedelta(microseconds=self.
|
|
200
|
-
return hash((Duration, self.
|
|
210
|
+
if isinstance(self.total_picos(), (int, float)) and self.total_picos() % 1000000 == 0:
|
|
211
|
+
return hash(datetime.timedelta(microseconds=self.total_picos() / 1000000))
|
|
212
|
+
return hash((Duration, self.total_picos()))
|
|
201
213
|
|
|
202
214
|
def _decompose_into_amount_unit_suffix(self) -> Tuple[int, str, str]:
|
|
215
|
+
picos = self.total_picos()
|
|
203
216
|
if (
|
|
204
|
-
isinstance(
|
|
205
|
-
and len(
|
|
206
|
-
and isinstance(
|
|
217
|
+
isinstance(picos, sympy.Mul)
|
|
218
|
+
and len(picos.args) == 2
|
|
219
|
+
and isinstance(picos.args[0], (sympy.Integer, sympy.Float))
|
|
207
220
|
):
|
|
208
|
-
scale =
|
|
209
|
-
rest =
|
|
221
|
+
scale = picos.args[0]
|
|
222
|
+
rest = picos.args[1]
|
|
210
223
|
else:
|
|
211
|
-
scale =
|
|
224
|
+
scale = picos
|
|
212
225
|
rest = 1
|
|
213
226
|
|
|
214
227
|
if scale % 1000_000_000 == 0:
|
|
@@ -234,7 +247,7 @@ class Duration:
|
|
|
234
247
|
return amount * rest, unit, suffix
|
|
235
248
|
|
|
236
249
|
def __str__(self) -> str:
|
|
237
|
-
if self.
|
|
250
|
+
if self.total_picos() == 0:
|
|
238
251
|
return 'Duration(0)'
|
|
239
252
|
amount, _, suffix = self._decompose_into_amount_unit_suffix()
|
|
240
253
|
if not isinstance(amount, (int, float, sympy.Symbol)):
|
|
@@ -257,3 +270,21 @@ def _attempt_duration_like_to_duration(value: Any) -> Optional[Duration]:
|
|
|
257
270
|
if isinstance(value, (int, float)) and value == 0:
|
|
258
271
|
return Duration()
|
|
259
272
|
return None
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _add_time_vals(
|
|
276
|
+
val1: List[_NUMERIC_INPUT_TYPE], val2: List[_NUMERIC_INPUT_TYPE]
|
|
277
|
+
) -> List[_NUMERIC_INPUT_TYPE]:
|
|
278
|
+
ret: List[_NUMERIC_INPUT_TYPE] = []
|
|
279
|
+
for i in range(4):
|
|
280
|
+
if val1[i] and val2[i]:
|
|
281
|
+
ret.append(val1[i] + val2[i])
|
|
282
|
+
else:
|
|
283
|
+
ret.append(val1[i] or val2[i])
|
|
284
|
+
return ret
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _duration_from_time_vals(time_vals: List[_NUMERIC_INPUT_TYPE]):
|
|
288
|
+
ret = Duration()
|
|
289
|
+
ret._time_vals = time_vals
|
|
290
|
+
return ret
|
cirq/value/duration_test.py
CHANGED
|
@@ -168,9 +168,11 @@ def test_sub():
|
|
|
168
168
|
def test_mul():
|
|
169
169
|
assert Duration(picos=2) * 3 == Duration(picos=6)
|
|
170
170
|
assert 4 * Duration(picos=3) == Duration(picos=12)
|
|
171
|
+
assert 0 * Duration(picos=10) == Duration()
|
|
171
172
|
|
|
172
173
|
t = sympy.Symbol('t')
|
|
173
174
|
assert t * Duration(picos=3) == Duration(picos=3 * t)
|
|
175
|
+
assert 0 * Duration(picos=t) == Duration(picos=0)
|
|
174
176
|
|
|
175
177
|
with pytest.raises(TypeError):
|
|
176
178
|
_ = Duration() * Duration()
|
{cirq_core-1.3.0.dev20230829170013.dist-info → cirq_core-1.3.0.dev20230830022013.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.3.0.
|
|
3
|
+
Version: 1.3.0.dev20230830022013
|
|
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.3.0.dev20230829170013.dist-info → cirq_core-1.3.0.dev20230830022013.dist-info}/RECORD
RENAMED
|
@@ -4,7 +4,7 @@ cirq/_compat_test.py,sha256=84X6ELsb5fv3Hc0_ly8-IQfMnCNQN6tHs6GZFrnuNyI,35005
|
|
|
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=
|
|
7
|
+
cirq/_version.py,sha256=xnpcsGC23F1oooiyAeCIAcy0d4nhPpEYmBLIMULnuBI,40
|
|
8
8
|
cirq/_version_test.py,sha256=Ea3ZNdQKZBsZrSc9xle7TUdT9bUINs-qezPruQ_m38s,133
|
|
9
9
|
cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
|
|
10
10
|
cirq/json_resolver_cache.py,sha256=JJiO1dhHsEqYClUv68eg-hiOzbb_C1QiQ-BCcvoe4Ck,13067
|
|
@@ -1091,8 +1091,8 @@ cirq/value/condition.py,sha256=QrxKBAox4C-z2pL2_xeKMvmfp0OP4tVFXJdPULx1pik,5900
|
|
|
1091
1091
|
cirq/value/condition_test.py,sha256=FGnCFcpeIQFRbnszKsHKA5K7sderTz7kwS7zWbWwx64,4037
|
|
1092
1092
|
cirq/value/digits.py,sha256=pUQi6PIA1FMbXUOWknefb6dBApCyLsTkpLFrhvNgE0Q,6024
|
|
1093
1093
|
cirq/value/digits_test.py,sha256=evx-y619LfjSN_gUO1B6K7O80X5HJmxxBPl61RrOovo,3812
|
|
1094
|
-
cirq/value/duration.py,sha256=
|
|
1095
|
-
cirq/value/duration_test.py,sha256=
|
|
1094
|
+
cirq/value/duration.py,sha256=isNzA1TuKb5rSaAYy4JpgT91Zt9_5XLQBSmMkuWCtD4,10358
|
|
1095
|
+
cirq/value/duration_test.py,sha256=C7nwg7IlHoQOUhWa_aX8vy7_qp654ZIDtmnKF35UiqE,8244
|
|
1096
1096
|
cirq/value/linear_dict.py,sha256=BG3pckQPX4DPqNvp-HxI_dTzQf8sGx6nIRkn0-ye4Qg,10643
|
|
1097
1097
|
cirq/value/linear_dict_test.py,sha256=uEHbvobWV4EypOXQGe6B4xh6atLbQq8YSOomNHgv38o,17107
|
|
1098
1098
|
cirq/value/measurement_key.py,sha256=MThR6rFY_YuSvcvWOacCEfOluJC0u7d8VvnDkHe-HAM,4939
|
|
@@ -1140,8 +1140,8 @@ cirq/work/sampler.py,sha256=JVv1vvfa6EgFiR3UeDk44U186dCrioH2NZXueCgsb9w,19828
|
|
|
1140
1140
|
cirq/work/sampler_test.py,sha256=zo1Hj6sn6fLs_WZMxYRApBqgBsldmptn74NL0jhNukc,12325
|
|
1141
1141
|
cirq/work/zeros_sampler.py,sha256=D3hbNZC-jXKuNAWg2OUiUuT8pmDV_WFnEfMank6In4o,2357
|
|
1142
1142
|
cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
|
|
1143
|
-
cirq_core-1.3.0.
|
|
1144
|
-
cirq_core-1.3.0.
|
|
1145
|
-
cirq_core-1.3.0.
|
|
1146
|
-
cirq_core-1.3.0.
|
|
1147
|
-
cirq_core-1.3.0.
|
|
1143
|
+
cirq_core-1.3.0.dev20230830022013.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1144
|
+
cirq_core-1.3.0.dev20230830022013.dist-info/METADATA,sha256=XARE4q61QY_m8JM-P4JvK_ZGZliH_hqXmkIBp4uAwfA,2077
|
|
1145
|
+
cirq_core-1.3.0.dev20230830022013.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
1146
|
+
cirq_core-1.3.0.dev20230830022013.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1147
|
+
cirq_core-1.3.0.dev20230830022013.dist-info/RECORD,,
|
{cirq_core-1.3.0.dev20230829170013.dist-info → cirq_core-1.3.0.dev20230830022013.dist-info}/LICENSE
RENAMED
|
File without changes
|
{cirq_core-1.3.0.dev20230829170013.dist-info → cirq_core-1.3.0.dev20230830022013.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|