cirq-core 1.5.0.dev20240612172743__py3-none-any.whl → 1.5.0.dev20240614203213__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.dev20240612172743"
31
+ __version__ = "1.5.0.dev20240614203213"
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.dev20240612172743"
6
+ assert cirq.__version__ == "1.5.0.dev20240614203213"
cirq/vis/heatmap.py CHANGED
@@ -111,6 +111,7 @@ class Heatmap:
111
111
  applying format(value, annotation_format) for each key in value_map.
112
112
  This is ignored if annotation_map is explicitly specified.
113
113
  annotation_text_kwargs: Matplotlib Text **kwargs,
114
+ highlighted_qubits: An iterable of qubits to highlight.
114
115
 
115
116
  colorbar_position: {'right', 'left', 'top', 'bottom'}, default = 'right'
116
117
  colorbar_size: str, default = '5%'
@@ -157,6 +158,7 @@ class Heatmap:
157
158
  "annotation_map",
158
159
  "annotation_text_kwargs",
159
160
  "annotation_format",
161
+ "highlighted_qubits",
160
162
  ]
161
163
  valid_kwargs = (
162
164
  valid_colorbar_kwargs
@@ -299,6 +301,37 @@ class Heatmap:
299
301
  ax = cast(plt.Axes, ax)
300
302
  original_config = copy.deepcopy(self._config)
301
303
  self.update_config(**kwargs)
304
+
305
+ highlighted_qubits = frozenset(kwargs.get("highlighted_qubits", ()))
306
+ if highlighted_qubits:
307
+ edgecolors = tuple(
308
+ (
309
+ "red"
310
+ if not highlighted_qubits.isdisjoint(qubits)
311
+ else self._config["collection_options"].get("edgecolors", "grey")
312
+ )
313
+ for qubits in sorted(self._value_map.keys())
314
+ )
315
+ linestyles = tuple(
316
+ (
317
+ "solid"
318
+ if not highlighted_qubits.isdisjoint(qubits)
319
+ else self._config["collection_options"].get("linestyles", "dashed")
320
+ )
321
+ for qubits in sorted(self._value_map.keys())
322
+ )
323
+ linewidths = tuple(
324
+ (
325
+ 4
326
+ if not highlighted_qubits.isdisjoint(qubits)
327
+ else self._config["collection_options"].get("linewidths", 2)
328
+ )
329
+ for qubits in sorted(self._value_map.keys())
330
+ )
331
+ self._config["collection_options"].update(
332
+ {"edgecolors": edgecolors, "linestyles": linestyles, "linewidths": linewidths}
333
+ )
334
+
302
335
  collection = self._plot_on_axis(ax)
303
336
  if show_plot:
304
337
  fig.show()
@@ -387,16 +420,18 @@ class TwoQubitInteractionHeatmap(Heatmap):
387
420
  original_config = copy.deepcopy(self._config)
388
421
  self.update_config(**kwargs)
389
422
  qubits = set([q for qubits in self._value_map.keys() for q in qubits])
423
+ collection_options: Dict[str, Any] = {"cmap": "binary"}
424
+ highlighted_qubits = frozenset(kwargs.get("highlighted_qubits", ()))
425
+ if not highlighted_qubits:
426
+ collection_options.update(
427
+ {"linewidths": 2, "edgecolors": "lightgrey", "linestyles": "dashed"}
428
+ )
390
429
  Heatmap({q: 0.0 for q in qubits}).plot(
391
430
  ax=ax,
392
- collection_options={
393
- 'cmap': 'binary',
394
- 'linewidths': 2,
395
- 'edgecolor': 'lightgrey',
396
- 'linestyle': 'dashed',
397
- },
431
+ collection_options=collection_options,
398
432
  plot_colorbar=False,
399
433
  annotation_format=None,
434
+ highlighted_qubits=highlighted_qubits,
400
435
  )
401
436
  collection = self._plot_on_axis(ax)
402
437
  if show_plot:
cirq/vis/heatmap_test.py CHANGED
@@ -23,6 +23,7 @@ import pytest
23
23
 
24
24
  import matplotlib as mpl
25
25
  import matplotlib.pyplot as plt
26
+ from matplotlib.colors import to_rgba_array
26
27
 
27
28
  from cirq.devices import grid_qubit
28
29
  from cirq.vis import heatmap
@@ -34,6 +35,11 @@ def ax():
34
35
  return figure.add_subplot(111)
35
36
 
36
37
 
38
+ def _to_linestyle_tuple(linestyles, linewidths=None):
39
+ collection = mpl.collections.Collection(linestyles=linestyles, linewidths=linewidths)
40
+ return collection.get_linestyles()[0]
41
+
42
+
37
43
  def test_default_ax():
38
44
  row_col_list = ((0, 5), (8, 1), (7, 0), (13, 5), (1, 6), (3, 2), (2, 8))
39
45
  test_value_map = {
@@ -343,3 +349,162 @@ def test_plot_updates_local_config():
343
349
  _, ax = plt.subplots()
344
350
  random_heatmap.plot(ax)
345
351
  assert ax.get_title() == original_title
352
+
353
+
354
+ @pytest.mark.usefixtures('closefigures')
355
+ def test_heatmap_plot_highlighted_qubits():
356
+ value_map = {
357
+ (grid_qubit.GridQubit(0, 0),): 0.1,
358
+ (grid_qubit.GridQubit(0, 1),): 0.2,
359
+ (grid_qubit.GridQubit(0, 2),): 0.3,
360
+ (grid_qubit.GridQubit(1, 0),): 0.4,
361
+ }
362
+ single_qubit_heatmap = heatmap.Heatmap(value_map)
363
+
364
+ highlighted_qubits = [grid_qubit.GridQubit(0, 1), grid_qubit.GridQubit(1, 0)]
365
+
366
+ expected_linewidths = [2, 4, 2, 4]
367
+ expected_edgecolors = np.vstack(
368
+ (to_rgba_array("grey"), to_rgba_array("red"), to_rgba_array("grey"), to_rgba_array("red"))
369
+ )
370
+ # list of tuples: (offset, onoffseq), onoffseq = None for solid line.
371
+ expected_linestyles = [
372
+ _to_linestyle_tuple("dashed", linewidths=2),
373
+ _to_linestyle_tuple("solid"),
374
+ _to_linestyle_tuple("dashed", linewidths=2),
375
+ _to_linestyle_tuple("solid"),
376
+ ]
377
+
378
+ _, ax = plt.subplots()
379
+ _ = single_qubit_heatmap.plot(ax, highlighted_qubits=highlighted_qubits)
380
+
381
+ for artist in ax.get_children():
382
+ if isinstance(artist, mpl.collections.PolyCollection):
383
+ assert np.all(artist.get_linewidths() == expected_linewidths)
384
+ assert np.array_equal(artist.get_edgecolors(), expected_edgecolors)
385
+ assert artist.get_linestyles() == expected_linestyles
386
+
387
+
388
+ @pytest.mark.usefixtures('closefigures')
389
+ def test_heatmap_plot_highlighted_qubits_two_qubit():
390
+ value_map = {
391
+ (grid_qubit.GridQubit(0, 0), grid_qubit.GridQubit(0, 1)): 0.1,
392
+ (grid_qubit.GridQubit(0, 1), grid_qubit.GridQubit(0, 2)): 0.2,
393
+ (grid_qubit.GridQubit(1, 0), grid_qubit.GridQubit(0, 0)): 0.3,
394
+ (grid_qubit.GridQubit(3, 3), grid_qubit.GridQubit(3, 2)): 0.9,
395
+ }
396
+ two_qubit_interaction_heatmap = heatmap.TwoQubitInteractionHeatmap(value_map)
397
+
398
+ highlighted_qubits = [
399
+ grid_qubit.GridQubit(0, 1),
400
+ grid_qubit.GridQubit(0, 0),
401
+ grid_qubit.GridQubit(3, 3),
402
+ ]
403
+
404
+ expected_linewidths = [4, 4, 2, 2, 2, 4]
405
+ expected_edgecolors = np.vstack(
406
+ (
407
+ to_rgba_array("red"),
408
+ to_rgba_array("red"),
409
+ to_rgba_array("grey"),
410
+ to_rgba_array("grey"),
411
+ to_rgba_array("grey"),
412
+ to_rgba_array("red"),
413
+ )
414
+ )
415
+ # list of tuples: (offset, onoffseq), onoffseq = None for solid line.
416
+ expected_linestyles = [
417
+ _to_linestyle_tuple("solid"),
418
+ _to_linestyle_tuple("solid"),
419
+ _to_linestyle_tuple("dashed", linewidths=2),
420
+ _to_linestyle_tuple("dashed", linewidths=2),
421
+ _to_linestyle_tuple("dashed", linewidths=2),
422
+ _to_linestyle_tuple("solid"),
423
+ ]
424
+
425
+ _, ax = plt.subplots()
426
+ _ = two_qubit_interaction_heatmap.plot(ax, highlighted_qubits=highlighted_qubits)
427
+
428
+ for artist in ax.get_children():
429
+ if isinstance(artist, mpl.collections.PolyCollection):
430
+ # Since for two qubit interactions, there are two collections:
431
+ # one to highlight individual qubits and one showing their interaction.
432
+ # Here, the former is required, so the latter is excluded.
433
+ if artist.get_cmap().name != 'viridis': # assuming 'viridis' is the default cmap used.
434
+ assert np.all(artist.get_linewidths() == expected_linewidths)
435
+ assert np.array_equal(artist.get_edgecolors(), expected_edgecolors)
436
+ assert artist.get_linestyles() == expected_linestyles
437
+
438
+
439
+ @pytest.mark.usefixtures('closefigures')
440
+ def test_heatmap_highlighted_repeat_qubits():
441
+ value_map = {
442
+ (grid_qubit.GridQubit(0, 0), grid_qubit.GridQubit(0, 1)): 0.1,
443
+ (grid_qubit.GridQubit(0, 1), grid_qubit.GridQubit(0, 2)): 0.2,
444
+ (grid_qubit.GridQubit(1, 0), grid_qubit.GridQubit(0, 0)): 0.3,
445
+ (grid_qubit.GridQubit(3, 3), grid_qubit.GridQubit(3, 2)): 0.9,
446
+ }
447
+ two_qubit_interaction_heatmap = heatmap.TwoQubitInteractionHeatmap(value_map)
448
+
449
+ highlighted_qubits_1 = [
450
+ grid_qubit.GridQubit(0, 1),
451
+ grid_qubit.GridQubit(0, 0),
452
+ grid_qubit.GridQubit(3, 3),
453
+ ]
454
+ highlighted_qubits_2 = highlighted_qubits_1 + [grid_qubit.GridQubit(0, 0)] * 5
455
+
456
+ _, ax1 = plt.subplots()
457
+ _ = two_qubit_interaction_heatmap.plot(ax1, highlighted_qubits=highlighted_qubits_1)
458
+ _, ax2 = plt.subplots()
459
+ _ = two_qubit_interaction_heatmap.plot(ax2, highlighted_qubits=highlighted_qubits_2)
460
+
461
+ for artist_1, artist_2 in zip(ax1.get_children(), ax2.get_children()):
462
+ if isinstance(artist_1, mpl.collections.PolyCollection) and isinstance(
463
+ artist_2, mpl.collections.PolyCollection
464
+ ):
465
+ # Since for two qubit interactions, there are two collections:
466
+ # one to highlight individual qubits and one showing their interaction.
467
+ # Here, the former is required, so the latter is excluded.
468
+ if (
469
+ artist_1.get_cmap().name != 'viridis' and artist_2.get_cmap().name != 'viridis'
470
+ ): # assuming 'viridis' is the default cmap used.
471
+ assert np.all(artist_1.get_linewidths() == artist_1.get_linewidths())
472
+ assert np.array_equal(artist_1.get_edgecolors(), artist_2.get_edgecolors())
473
+ assert artist_1.get_linestyles() == artist_2.get_linestyles()
474
+
475
+
476
+ @pytest.mark.usefixtures('closefigures')
477
+ def test_heatmap_highlighted_init_collection_options_used():
478
+ value_map = {
479
+ (grid_qubit.GridQubit(0, 0),): 0.1,
480
+ (grid_qubit.GridQubit(0, 1),): 0.2,
481
+ (grid_qubit.GridQubit(0, 2),): 0.3,
482
+ (grid_qubit.GridQubit(1, 0),): 0.4,
483
+ }
484
+ single_qubit_heatmap = heatmap.Heatmap(
485
+ value_map,
486
+ collection_options={"edgecolors": "blue", "linewidths": 6, "linestyles": "dashed"},
487
+ )
488
+
489
+ highlighted_qubits = [grid_qubit.GridQubit(0, 1), grid_qubit.GridQubit(1, 0)]
490
+
491
+ expected_linewidths = [6, 4, 6, 4]
492
+ expected_edgecolors = np.vstack(
493
+ (to_rgba_array("blue"), to_rgba_array("red"), to_rgba_array("blue"), to_rgba_array("red"))
494
+ )
495
+ # list of tuples: (offset, onoffseq), onoffseq = None for solid line.
496
+ expected_linestyles = [
497
+ _to_linestyle_tuple("dashed", linewidths=6),
498
+ _to_linestyle_tuple("solid"),
499
+ _to_linestyle_tuple("dashed", linewidths=6),
500
+ _to_linestyle_tuple("solid"),
501
+ ]
502
+
503
+ _, ax = plt.subplots()
504
+ _ = single_qubit_heatmap.plot(ax, highlighted_qubits=highlighted_qubits)
505
+
506
+ for artist in ax.get_children():
507
+ if isinstance(artist, mpl.collections.PolyCollection):
508
+ assert np.all(artist.get_linewidths() == expected_linewidths)
509
+ assert np.array_equal(artist.get_edgecolors(), expected_edgecolors)
510
+ assert artist.get_linestyles() == expected_linestyles
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.5.0.dev20240612172743
3
+ Version: 1.5.0.dev20240614203213
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=xmYoyHWit1r14JEequoLl7rv01RixPWRo_yYhsOM7II,1206
8
- cirq/_version_test.py,sha256=AABs-160Fj5gKNW-bDHvvS92P-TytvZ8CoJZsMCg4cc,147
7
+ cirq/_version.py,sha256=bdQEjWc5JORCzOHoHUEclMSXikO7EhNcVGSQRwYWzwA,1206
8
+ cirq/_version_test.py,sha256=_ly9PE3B8n_2oh-GmVUf6ByOEo6Ik_9akuV_vMZgIfE,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
@@ -1148,8 +1148,8 @@ cirq/value/value_equality_attr_test.py,sha256=k_nl5hWxo4yMO6WNu0wU68wyeb-RN9Ua_I
1148
1148
  cirq/vis/__init__.py,sha256=e3Z1PI-Ay0hDHhIgFZEDwQIuO8C_aayNdL-EByF0J4o,1001
1149
1149
  cirq/vis/density_matrix.py,sha256=kMAPcRh6f0ghZKSe86nB_2iFngrDsw0pNael1EZ5BEw,4819
1150
1150
  cirq/vis/density_matrix_test.py,sha256=Xg41NQZBfoyrkaX3n9pW4q1LIxWpOW3Cr_I_Wx51GlQ,6965
1151
- cirq/vis/heatmap.py,sha256=O7BM3POKmbAuSHjiWPEUc7-KO5d3ckCQ0ovz5BCx4dI,16203
1152
- cirq/vis/heatmap_test.py,sha256=Hg4DwRKoTe7it2RQhsvX8aNZzs5MULtwaYteJvD6-_g,13605
1151
+ cirq/vis/heatmap.py,sha256=9FHviJR0-OY9ksdoh0OrjdDvkb5ISd5OxcYd9WRlqYo,17758
1152
+ cirq/vis/heatmap_test.py,sha256=5kWIxJZZbZcc93XZrZ18lF2gRUleR1iqYbWfHs4cvu4,20531
1153
1153
  cirq/vis/histogram.py,sha256=gQUrcebsk5wgPT38pWFW55jG9zaKhxp8zLRGmmVDk8s,5107
1154
1154
  cirq/vis/histogram_test.py,sha256=Qlw0e3amw_MFga-hNweiLzRCH174W9bB2qkmX_RiS-U,1904
1155
1155
  cirq/vis/state_histogram.py,sha256=i8PvGLMHu74mJVD18EuS7YFGw9aM3pTa-ocnZHOW2kc,4298
@@ -1175,8 +1175,8 @@ cirq/work/sampler.py,sha256=JEAeQQRF3bqlO9AkOf4XbrTATDI5f5JgyM_FAUCNxao,19751
1175
1175
  cirq/work/sampler_test.py,sha256=B2ZsuqGT854gQtBIAh8k0LiG9Vj5wSzcGvkxOUoTcW4,13217
1176
1176
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1177
1177
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1178
- cirq_core-1.5.0.dev20240612172743.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1179
- cirq_core-1.5.0.dev20240612172743.dist-info/METADATA,sha256=1dI7mDTgwgeT57GV7DNRn7XYOqMbvXPKDNcZ2LzdG3E,2007
1180
- cirq_core-1.5.0.dev20240612172743.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
1181
- cirq_core-1.5.0.dev20240612172743.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1182
- cirq_core-1.5.0.dev20240612172743.dist-info/RECORD,,
1178
+ cirq_core-1.5.0.dev20240614203213.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1179
+ cirq_core-1.5.0.dev20240614203213.dist-info/METADATA,sha256=sU217097DRkhKE0jjzuJiMagVaXl5Lsaqs9-38z8pL4,2007
1180
+ cirq_core-1.5.0.dev20240614203213.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
1181
+ cirq_core-1.5.0.dev20240614203213.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1182
+ cirq_core-1.5.0.dev20240614203213.dist-info/RECORD,,