cirq-core 1.5.0.dev20241105230840__py3-none-any.whl → 1.5.0.dev20241105235147__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/_version_test.py +1 -1
- cirq/work/sampler.py +5 -46
- cirq/work/sampler_test.py +3 -51
- {cirq_core-1.5.0.dev20241105230840.dist-info → cirq_core-1.5.0.dev20241105235147.dist-info}/METADATA +1 -1
- {cirq_core-1.5.0.dev20241105230840.dist-info → cirq_core-1.5.0.dev20241105235147.dist-info}/RECORD +9 -9
- {cirq_core-1.5.0.dev20241105230840.dist-info → cirq_core-1.5.0.dev20241105235147.dist-info}/LICENSE +0 -0
- {cirq_core-1.5.0.dev20241105230840.dist-info → cirq_core-1.5.0.dev20241105235147.dist-info}/WHEEL +0 -0
- {cirq_core-1.5.0.dev20241105230840.dist-info → cirq_core-1.5.0.dev20241105235147.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
cirq/work/sampler.py
CHANGED
|
@@ -14,19 +14,7 @@
|
|
|
14
14
|
"""Abstract base class for things sampling quantum circuits."""
|
|
15
15
|
|
|
16
16
|
import collections
|
|
17
|
-
from
|
|
18
|
-
from typing import (
|
|
19
|
-
Dict,
|
|
20
|
-
FrozenSet,
|
|
21
|
-
Iterator,
|
|
22
|
-
List,
|
|
23
|
-
Optional,
|
|
24
|
-
Sequence,
|
|
25
|
-
Tuple,
|
|
26
|
-
TypeVar,
|
|
27
|
-
TYPE_CHECKING,
|
|
28
|
-
Union,
|
|
29
|
-
)
|
|
17
|
+
from typing import Dict, FrozenSet, List, Optional, Sequence, Tuple, TypeVar, TYPE_CHECKING, Union
|
|
30
18
|
|
|
31
19
|
import duet
|
|
32
20
|
import pandas as pd
|
|
@@ -49,14 +37,6 @@ T = TypeVar('T')
|
|
|
49
37
|
class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
50
38
|
"""Something capable of sampling quantum circuits. Simulator or hardware."""
|
|
51
39
|
|
|
52
|
-
# Users have a rate limit of 1000 QPM for read/write requests to
|
|
53
|
-
# the Quantum Engine. The sampler will poll from the DB every 1s
|
|
54
|
-
# for inflight requests for results. Empirically, for circuits
|
|
55
|
-
# sent in run_batch, sending circuits in CHUNK_SIZE=5 for large
|
|
56
|
-
# number of circuits (> 200) with large depths (100 layers)
|
|
57
|
-
# does not encounter quota exceeded issues for non-streaming cases.
|
|
58
|
-
CHUNK_SIZE: int = 5
|
|
59
|
-
|
|
60
40
|
def run(
|
|
61
41
|
self,
|
|
62
42
|
program: 'cirq.AbstractCircuit',
|
|
@@ -311,32 +291,16 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
311
291
|
programs: Sequence['cirq.AbstractCircuit'],
|
|
312
292
|
params_list: Optional[Sequence['cirq.Sweepable']] = None,
|
|
313
293
|
repetitions: Union[int, Sequence[int]] = 1,
|
|
294
|
+
limiter: duet.Limiter = duet.Limiter(10),
|
|
314
295
|
) -> Sequence[Sequence['cirq.Result']]:
|
|
315
296
|
"""Runs the supplied circuits asynchronously.
|
|
316
297
|
|
|
317
298
|
See docs for `cirq.Sampler.run_batch`.
|
|
318
299
|
"""
|
|
319
300
|
params_list, repetitions = self._normalize_batch_args(programs, params_list, repetitions)
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
)
|
|
324
|
-
|
|
325
|
-
results = []
|
|
326
|
-
for program_chunk, params_chunk, reps_chunk in zip(
|
|
327
|
-
_chunked(programs, self.CHUNK_SIZE),
|
|
328
|
-
_chunked(params_list, self.CHUNK_SIZE),
|
|
329
|
-
_chunked(repetitions, self.CHUNK_SIZE),
|
|
330
|
-
):
|
|
331
|
-
# Run_sweep_async for the current chunk
|
|
332
|
-
await duet.sleep(1) # Delay for 1 second between chunk
|
|
333
|
-
results.extend(
|
|
334
|
-
await duet.pstarmap_async(
|
|
335
|
-
self.run_sweep_async, zip(program_chunk, params_chunk, reps_chunk)
|
|
336
|
-
)
|
|
337
|
-
)
|
|
338
|
-
|
|
339
|
-
return results
|
|
301
|
+
return await duet.pstarmap_async(
|
|
302
|
+
self.run_sweep_async, zip(programs, params_list, repetitions, [limiter] * len(programs))
|
|
303
|
+
)
|
|
340
304
|
|
|
341
305
|
def _normalize_batch_args(
|
|
342
306
|
self,
|
|
@@ -489,8 +453,3 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
489
453
|
)
|
|
490
454
|
num_instances[key] += 1
|
|
491
455
|
return {k: (num_instances[k], qid_shape) for k, qid_shape in qid_shapes.items()}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
def _chunked(iterable: Sequence[T], n: int) -> Iterator[tuple[T, ...]]:
|
|
495
|
-
it = iter(iterable)
|
|
496
|
-
return iter(lambda: tuple(islice(it, n)), ())
|
cirq/work/sampler_test.py
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
"""Tests for cirq.Sampler."""
|
|
15
15
|
from typing import Sequence
|
|
16
|
-
from unittest import mock
|
|
17
16
|
|
|
18
17
|
import pytest
|
|
19
18
|
|
|
@@ -224,7 +223,9 @@ async def test_run_batch_async_calls_run_sweep_asynchronously():
|
|
|
224
223
|
params_list = [params1, params2]
|
|
225
224
|
|
|
226
225
|
class AsyncSampler(cirq.Sampler):
|
|
227
|
-
async def run_sweep_async(
|
|
226
|
+
async def run_sweep_async(
|
|
227
|
+
self, program, params, repetitions: int = 1, unused: duet.Limiter = duet.Limiter(None)
|
|
228
|
+
):
|
|
228
229
|
if params == params1:
|
|
229
230
|
await duet.sleep(0.001)
|
|
230
231
|
|
|
@@ -267,55 +268,6 @@ def test_sampler_run_batch_bad_input_lengths():
|
|
|
267
268
|
)
|
|
268
269
|
|
|
269
270
|
|
|
270
|
-
@mock.patch('duet.pstarmap_async')
|
|
271
|
-
@pytest.mark.parametrize('call_count', [1, 2, 3])
|
|
272
|
-
@duet.sync
|
|
273
|
-
async def test_run_batch_async_sends_circuits_in_chunks(spy, call_count):
|
|
274
|
-
class AsyncSampler(cirq.Sampler):
|
|
275
|
-
CHUNK_SIZE = 3
|
|
276
|
-
|
|
277
|
-
async def run_sweep_async(self, _, params, __: int = 1):
|
|
278
|
-
pass # pragma: no cover
|
|
279
|
-
|
|
280
|
-
sampler = AsyncSampler()
|
|
281
|
-
a = cirq.LineQubit(0)
|
|
282
|
-
circuit_list = [cirq.Circuit(cirq.X(a) ** sympy.Symbol('t'), cirq.measure(a, key='m'))] * (
|
|
283
|
-
sampler.CHUNK_SIZE * call_count
|
|
284
|
-
)
|
|
285
|
-
param_list = [cirq.Points('t', [0.3, 0.7])] * (sampler.CHUNK_SIZE * call_count)
|
|
286
|
-
|
|
287
|
-
await sampler.run_batch_async(circuit_list, params_list=param_list)
|
|
288
|
-
|
|
289
|
-
assert spy.call_count == call_count
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
@pytest.mark.parametrize('call_count', [1, 2, 3])
|
|
293
|
-
@duet.sync
|
|
294
|
-
async def test_run_batch_async_runs_runs_sequentially(call_count):
|
|
295
|
-
a = cirq.LineQubit(0)
|
|
296
|
-
finished = []
|
|
297
|
-
circuit1 = cirq.Circuit(cirq.X(a) ** sympy.Symbol('t'), cirq.measure(a, key='m'))
|
|
298
|
-
circuit2 = cirq.Circuit(cirq.Y(a) ** sympy.Symbol('t'), cirq.measure(a, key='m'))
|
|
299
|
-
params1 = cirq.Points('t', [0.3, 0.7])
|
|
300
|
-
params2 = cirq.Points('t', [0.4, 0.6])
|
|
301
|
-
|
|
302
|
-
class AsyncSampler(cirq.Sampler):
|
|
303
|
-
CHUNK_SIZE = 1
|
|
304
|
-
|
|
305
|
-
async def run_sweep_async(self, _, params, __: int = 1):
|
|
306
|
-
if params == params1:
|
|
307
|
-
await duet.sleep(0.001)
|
|
308
|
-
|
|
309
|
-
finished.append(params)
|
|
310
|
-
|
|
311
|
-
sampler = AsyncSampler()
|
|
312
|
-
circuit_list = [circuit1, circuit2] * call_count
|
|
313
|
-
param_list = [params1, params2] * call_count
|
|
314
|
-
await sampler.run_batch_async(circuit_list, params_list=param_list)
|
|
315
|
-
|
|
316
|
-
assert finished == param_list
|
|
317
|
-
|
|
318
|
-
|
|
319
271
|
def test_sampler_simple_sample_expectation_values():
|
|
320
272
|
a = cirq.LineQubit(0)
|
|
321
273
|
sampler = cirq.Simulator()
|
{cirq_core-1.5.0.dev20241105230840.dist-info → cirq_core-1.5.0.dev20241105235147.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.5.0.
|
|
3
|
+
Version: 1.5.0.dev20241105235147
|
|
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.5.0.dev20241105230840.dist-info → cirq_core-1.5.0.dev20241105235147.dist-info}/RECORD
RENAMED
|
@@ -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=
|
|
8
|
-
cirq/_version_test.py,sha256=
|
|
7
|
+
cirq/_version.py,sha256=Ey0ynXkiFaW1nBxhycPXoXoc89NAUMEyK-HXRacOgIk,1206
|
|
8
|
+
cirq/_version_test.py,sha256=4W3uKdYhz6bv2jm6sEvcRfMrIGSsgznYr_IajXVGPUg,147
|
|
9
9
|
cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
|
|
10
10
|
cirq/json_resolver_cache.py,sha256=ytePZtNZgKjOF2NiVpUTuotB-JKZmQNOFIFdvXqsxHw,13271
|
|
11
11
|
cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
|
|
@@ -1182,12 +1182,12 @@ cirq/work/observable_settings.py,sha256=OsZS8XvHT2LCFGkzu-wh1WShOx93I1nZ2K7uce-i
|
|
|
1182
1182
|
cirq/work/observable_settings_test.py,sha256=hV3g5ld5OZchTjVMVL_8cLXsbSBMz5DAsE4Vui2xTuk,4233
|
|
1183
1183
|
cirq/work/pauli_sum_collector.py,sha256=N1IsIwudBi84XWP1x7LNE2uQ6DGR2LFIWPhGbdHxaA4,4230
|
|
1184
1184
|
cirq/work/pauli_sum_collector_test.py,sha256=aeo06iLIYZjWjN3C4loVHRYWpV35lSSlcX2cOVdt2Ss,2437
|
|
1185
|
-
cirq/work/sampler.py,sha256=
|
|
1186
|
-
cirq/work/sampler_test.py,sha256=
|
|
1185
|
+
cirq/work/sampler.py,sha256=BDd1HrUOOcHBOvXNJqVX0vRcvmm8btZmZa5yYC5y8n0,19856
|
|
1186
|
+
cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
|
|
1187
1187
|
cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
|
|
1188
1188
|
cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
|
|
1189
|
-
cirq_core-1.5.0.
|
|
1190
|
-
cirq_core-1.5.0.
|
|
1191
|
-
cirq_core-1.5.0.
|
|
1192
|
-
cirq_core-1.5.0.
|
|
1193
|
-
cirq_core-1.5.0.
|
|
1189
|
+
cirq_core-1.5.0.dev20241105235147.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1190
|
+
cirq_core-1.5.0.dev20241105235147.dist-info/METADATA,sha256=NGfDEt4BBBQBP6UV-QJxn3J-3Rn5d0diLKJ5vDrJyXo,1992
|
|
1191
|
+
cirq_core-1.5.0.dev20241105235147.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
|
1192
|
+
cirq_core-1.5.0.dev20241105235147.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1193
|
+
cirq_core-1.5.0.dev20241105235147.dist-info/RECORD,,
|
{cirq_core-1.5.0.dev20241105230840.dist-info → cirq_core-1.5.0.dev20241105235147.dist-info}/LICENSE
RENAMED
|
File without changes
|
{cirq_core-1.5.0.dev20241105230840.dist-info → cirq_core-1.5.0.dev20241105235147.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|