cirq-core 1.5.0.dev20241108000946__py3-none-any.whl → 1.5.0.dev20241108192215__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.dev20241108000946"
31
+ __version__ = "1.5.0.dev20241108192215"
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.dev20241108000946"
6
+ assert cirq.__version__ == "1.5.0.dev20241108192215"
@@ -53,6 +53,46 @@ def _manhattan_distance(qubit1: 'cirq.GridQubit', qubit2: 'cirq.GridQubit') -> i
53
53
  return abs(qubit1.row - qubit2.row) + abs(qubit1.col - qubit2.col)
54
54
 
55
55
 
56
+ def qubits_and_pairs(
57
+ sampler: 'cirq.Sampler',
58
+ qubits: Optional[Sequence['cirq.GridQubit']] = None,
59
+ pairs: Optional[Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]] = None,
60
+ ) -> Tuple[Sequence['cirq.GridQubit'], Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]]:
61
+ """Extract qubits and pairs from sampler.
62
+
63
+
64
+ If qubits are not provided, then they are extracted from the pairs (if given) or the sampler.
65
+ If pairs are not provided then all pairs of adjacent qubits are used.
66
+
67
+ Args:
68
+ sampler: The quantum engine or simulator to run the circuits.
69
+ qubits: Optional list of qubits.
70
+ pairs: Optional list of pair to use.
71
+
72
+ Returns:
73
+ - Qubits to use.
74
+ - Pairs of qubits to use.
75
+
76
+ Raises:
77
+ ValueError: If qubits are not specified and can't be deduced from other arguments.
78
+ """
79
+ if qubits is None:
80
+ if pairs is None:
81
+ qubits = _grid_qubits_for_sampler(sampler)
82
+ if qubits is None:
83
+ raise ValueError("Couldn't determine qubits from sampler. Please specify them.")
84
+ else:
85
+ qubits_set = set(itertools.chain(*pairs))
86
+ qubits = list(qubits_set)
87
+
88
+ if pairs is None:
89
+ pairs = [
90
+ pair for pair in itertools.combinations(qubits, 2) if _manhattan_distance(*pair) == 1
91
+ ]
92
+
93
+ return qubits, pairs
94
+
95
+
56
96
  @dataclass(frozen=True)
57
97
  class TwoQubitXEBResult:
58
98
  """Results from an XEB experiment."""
@@ -359,6 +399,7 @@ def parallel_xeb_workflow(
359
399
  cycle_depths: Sequence[int] = (5, 25, 50, 100, 200, 300),
360
400
  random_state: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None,
361
401
  ax: Optional[plt.Axes] = None,
402
+ pairs: Optional[Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]] = None,
362
403
  pool: Optional['multiprocessing.pool.Pool'] = None,
363
404
  **plot_kwargs,
364
405
  ) -> Tuple[pd.DataFrame, Sequence['cirq.Circuit'], pd.DataFrame]:
@@ -375,6 +416,7 @@ def parallel_xeb_workflow(
375
416
  random_state: The random state to use.
376
417
  ax: the plt.Axes to plot the device layout on. If not given,
377
418
  no plot is created.
419
+ pairs: Pairs to use. If not specified, use all pairs between adjacent qubits.
378
420
  pool: An optional multiprocessing pool.
379
421
  **plot_kwargs: Arguments to be passed to 'plt.Axes.plot'.
380
422
 
@@ -391,14 +433,8 @@ def parallel_xeb_workflow(
391
433
  """
392
434
  rs = value.parse_random_state(random_state)
393
435
 
394
- if qubits is None:
395
- qubits = _grid_qubits_for_sampler(sampler)
396
- if qubits is None:
397
- raise ValueError("Couldn't determine qubits from sampler. Please specify them.")
398
-
399
- graph = nx.Graph(
400
- pair for pair in itertools.combinations(qubits, 2) if _manhattan_distance(*pair) == 1
401
- )
436
+ qubits, pairs = qubits_and_pairs(sampler, qubits, pairs)
437
+ graph = nx.Graph(pairs)
402
438
 
403
439
  if ax is not None:
404
440
  nx.draw_networkx(graph, pos={q: (q.row, q.col) for q in qubits}, ax=ax)
@@ -445,6 +481,7 @@ def parallel_two_qubit_xeb(
445
481
  cycle_depths: Sequence[int] = (5, 25, 50, 100, 200, 300),
446
482
  random_state: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None,
447
483
  ax: Optional[plt.Axes] = None,
484
+ pairs: Optional[Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]] = None,
448
485
  **plot_kwargs,
449
486
  ) -> TwoQubitXEBResult:
450
487
  """A convenience method that runs the full XEB workflow.
@@ -460,6 +497,7 @@ def parallel_two_qubit_xeb(
460
497
  random_state: The random state to use.
461
498
  ax: the plt.Axes to plot the device layout on. If not given,
462
499
  no plot is created.
500
+ pairs: Pairs to use. If not specified, use all pairs between adjacent qubits.
463
501
  **plot_kwargs: Arguments to be passed to 'plt.Axes.plot'.
464
502
  Returns:
465
503
  A TwoQubitXEBResult object representing the results of the experiment.
@@ -469,6 +507,7 @@ def parallel_two_qubit_xeb(
469
507
  fids, *_ = parallel_xeb_workflow(
470
508
  sampler=sampler,
471
509
  qubits=qubits,
510
+ pairs=pairs,
472
511
  entangling_gate=entangling_gate,
473
512
  n_repetitions=n_repetitions,
474
513
  n_combinations=n_combinations,
@@ -493,6 +532,7 @@ def run_rb_and_xeb(
493
532
  depths_xeb: Sequence[int] = (5, 25, 50, 100, 200, 300),
494
533
  xeb_combinations: int = 10,
495
534
  random_state: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None,
535
+ pairs: Optional[Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]] = None,
496
536
  ) -> InferredXEBResult:
497
537
  """A convenience method that runs both RB and XEB workflows.
498
538
 
@@ -506,6 +546,7 @@ def run_rb_and_xeb(
506
546
  depths_xeb: The cycle depths to use for XEB.
507
547
  xeb_combinations: The number of combinations to generate for XEB.
508
548
  random_state: The random state to use.
549
+ pairs: Pairs to use. If not specified, use all pairs between adjacent qubits.
509
550
 
510
551
  Returns:
511
552
  An InferredXEBResult object representing the results of the experiment.
@@ -514,10 +555,7 @@ def run_rb_and_xeb(
514
555
  ValueError: If qubits are not specified and the sampler has no device.
515
556
  """
516
557
 
517
- if qubits is None:
518
- qubits = _grid_qubits_for_sampler(sampler)
519
- if qubits is None:
520
- raise ValueError("Couldn't determine qubits from sampler. Please specify them.")
558
+ qubits, pairs = qubits_and_pairs(sampler, qubits, pairs)
521
559
 
522
560
  rb = parallel_single_qubit_randomized_benchmarking(
523
561
  sampler=sampler,
@@ -530,6 +568,7 @@ def run_rb_and_xeb(
530
568
  xeb = parallel_two_qubit_xeb(
531
569
  sampler=sampler,
532
570
  qubits=qubits,
571
+ pairs=pairs,
533
572
  entangling_gate=entangling_gate,
534
573
  n_repetitions=repetitions,
535
574
  n_circuits=num_circuits,
@@ -261,26 +261,43 @@ def test_inferred_plots(ax, target_error, kind):
261
261
 
262
262
 
263
263
  @pytest.mark.parametrize(
264
- 'sampler,qubits',
264
+ 'sampler,qubits,pairs',
265
265
  [
266
266
  (
267
267
  cirq.DensityMatrixSimulator(
268
268
  seed=0, noise=cirq.ConstantQubitNoiseModel(cirq.amplitude_damp(0.1))
269
269
  ),
270
270
  cirq.GridQubit.rect(3, 2, 4, 3),
271
+ None,
272
+ ),
273
+ (
274
+ cirq.DensityMatrixSimulator(
275
+ seed=0, noise=cirq.ConstantQubitNoiseModel(cirq.amplitude_damp(0.1))
276
+ ),
277
+ None,
278
+ [
279
+ (cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)),
280
+ (cirq.GridQubit(0, 0), cirq.GridQubit(1, 0)),
281
+ ],
271
282
  ),
272
283
  (
273
284
  DensityMatrixSimulatorWithProcessor(
274
285
  seed=0, noise=cirq.ConstantQubitNoiseModel(cirq.amplitude_damp(0.1))
275
286
  ),
276
287
  None,
288
+ None,
277
289
  ),
278
290
  ],
279
291
  )
280
- def test_run_rb_and_xeb(sampler: cirq.Sampler, qubits: Optional[Sequence[cirq.GridQubit]]):
292
+ def test_run_rb_and_xeb(
293
+ sampler: cirq.Sampler,
294
+ qubits: Optional[Sequence[cirq.GridQubit]],
295
+ pairs: Optional[Sequence[tuple[cirq.GridQubit, cirq.GridQubit]]],
296
+ ):
281
297
  res = cirq.experiments.run_rb_and_xeb(
282
298
  sampler=sampler,
283
299
  qubits=qubits,
300
+ pairs=pairs,
284
301
  repetitions=100,
285
302
  num_clifford_range=tuple(np.arange(3, 10, 1)),
286
303
  xeb_combinations=1,
cirq/work/sampler.py CHANGED
@@ -291,7 +291,6 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
291
291
  programs: Sequence['cirq.AbstractCircuit'],
292
292
  params_list: Optional[Sequence['cirq.Sweepable']] = None,
293
293
  repetitions: Union[int, Sequence[int]] = 1,
294
- limiter: duet.Limiter = duet.Limiter(10),
295
294
  ) -> Sequence[Sequence['cirq.Result']]:
296
295
  """Runs the supplied circuits asynchronously.
297
296
 
@@ -299,7 +298,7 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
299
298
  """
300
299
  params_list, repetitions = self._normalize_batch_args(programs, params_list, repetitions)
301
300
  return await duet.pstarmap_async(
302
- self.run_sweep_async, zip(programs, params_list, repetitions, [limiter] * len(programs))
301
+ self.run_sweep_async, zip(programs, params_list, repetitions)
303
302
  )
304
303
 
305
304
  def _normalize_batch_args(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.5.0.dev20241108000946
3
+ Version: 1.5.0.dev20241108192215
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=nLBLggkBN0DieQBaZbvaR3lLwkBovuzp-fGSnDMTHWg,1206
8
- cirq/_version_test.py,sha256=pb1073s50b2-w67rs2zQmSYC-Gu6JxTNT-JALyhxxLM,147
7
+ cirq/_version.py,sha256=Y1RnnKT4Y70O23a5y2F8kiykVQB4vSJmB7-CgFgRQuU,1206
8
+ cirq/_version_test.py,sha256=8Ah4kIz0Wd8U_3srmAgTFXTf_92dXApXtl8_9nuKujE,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
@@ -196,8 +196,8 @@ cirq/experiments/t1_decay_experiment.py,sha256=ealdmc_RTE__z1YUcaDEncDzQOaiT0K6I
196
196
  cirq/experiments/t1_decay_experiment_test.py,sha256=Pgbm-37JiCdw9iQg2OaXVvs72xGWV2629CgsTQlLQnw,9139
197
197
  cirq/experiments/t2_decay_experiment.py,sha256=lTgZ9yJ7Fk9_ozUCHysQn1qKrMQwTpsgEv-QnvsEif0,19158
198
198
  cirq/experiments/t2_decay_experiment_test.py,sha256=DFR0BGn0Id4qNPfqIExj70TEAqf7Vrc8eK91Wj0YKTc,15031
199
- cirq/experiments/two_qubit_xeb.py,sha256=GFTB6yBvvda5hQvbjhjduXeNSQNJwbcOMPeDb0n_Wa0,20085
200
- cirq/experiments/two_qubit_xeb_test.py,sha256=ZeZvClUAB8ir42Bd3PWr-s0_-QKWbFdYqfvvOMawsm0,10204
199
+ cirq/experiments/two_qubit_xeb.py,sha256=QsGQ-wR8T-m4YhOOJ1COXKi6roJuZmFuv1u8YWXkHBI,21636
200
+ cirq/experiments/two_qubit_xeb_test.py,sha256=wJi-ulxtSJyE5pzJPoUgoV8X2NLZG_H0jlW1JKHSo_I,10681
201
201
  cirq/experiments/xeb_fitting.py,sha256=Tzo2kg62udpRp654XArSDVcyVNhlhkNmpx9UVyxZiiw,30337
202
202
  cirq/experiments/xeb_fitting_test.py,sha256=0GQ6ifSWdvEJ6-ICIcSR-R9lFLRwBykgf6toLElmg0o,15483
203
203
  cirq/experiments/xeb_sampling.py,sha256=6ZOidGi7Kt6p4cMQCjK7qQuIUXVHCYl47B2GnL8M-Bw,14987
@@ -1184,12 +1184,12 @@ cirq/work/observable_settings.py,sha256=OsZS8XvHT2LCFGkzu-wh1WShOx93I1nZ2K7uce-i
1184
1184
  cirq/work/observable_settings_test.py,sha256=hV3g5ld5OZchTjVMVL_8cLXsbSBMz5DAsE4Vui2xTuk,4233
1185
1185
  cirq/work/pauli_sum_collector.py,sha256=N1IsIwudBi84XWP1x7LNE2uQ6DGR2LFIWPhGbdHxaA4,4230
1186
1186
  cirq/work/pauli_sum_collector_test.py,sha256=aeo06iLIYZjWjN3C4loVHRYWpV35lSSlcX2cOVdt2Ss,2437
1187
- cirq/work/sampler.py,sha256=BDd1HrUOOcHBOvXNJqVX0vRcvmm8btZmZa5yYC5y8n0,19856
1187
+ cirq/work/sampler.py,sha256=y6qtCpAwO8SqZ_JKU8PwlbMLHpJskNPqGWD_pNbyZew,19779
1188
1188
  cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
1189
1189
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1190
1190
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1191
- cirq_core-1.5.0.dev20241108000946.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1192
- cirq_core-1.5.0.dev20241108000946.dist-info/METADATA,sha256=6X_nrqT_Q3cxXDC8_UOdP1Eas1a4Hn5zTvaFG7pGB9g,1992
1193
- cirq_core-1.5.0.dev20241108000946.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
1194
- cirq_core-1.5.0.dev20241108000946.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1195
- cirq_core-1.5.0.dev20241108000946.dist-info/RECORD,,
1191
+ cirq_core-1.5.0.dev20241108192215.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1192
+ cirq_core-1.5.0.dev20241108192215.dist-info/METADATA,sha256=aUiSN81s4I2d40hGOeR7TU1ti5SKuErVgqvbtx-WOjo,1992
1193
+ cirq_core-1.5.0.dev20241108192215.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
1194
+ cirq_core-1.5.0.dev20241108192215.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1195
+ cirq_core-1.5.0.dev20241108192215.dist-info/RECORD,,