cirq-core 1.4.0.dev20231202032139__py3-none-any.whl → 1.4.0.dev20231205195308__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/_compat_test.py CHANGED
@@ -346,7 +346,7 @@ def test_wrap_module():
346
346
 
347
347
 
348
348
  def test_deprecate_attributes_assert_attributes_in_sys_modules():
349
- subprocess_context(_test_deprecate_attributes_assert_attributes_in_sys_modules)()
349
+ run_in_subprocess(_test_deprecate_attributes_assert_attributes_in_sys_modules)
350
350
 
351
351
 
352
352
  def _test_deprecate_attributes_assert_attributes_in_sys_modules():
@@ -635,42 +635,49 @@ _repeated_child_deprecation_msg = [
635
635
  ] + _deprecation_origin
636
636
 
637
637
 
638
- def _trace_unhandled_exceptions(*args, queue: 'multiprocessing.Queue', func: Callable, **kwargs):
638
+ def _trace_unhandled_exceptions(*args, queue: 'multiprocessing.Queue', func: Callable):
639
639
  try:
640
- func(*args, **kwargs)
640
+ func(*args)
641
641
  queue.put(None)
642
642
  except BaseException as ex:
643
643
  msg = str(ex)
644
644
  queue.put((type(ex).__name__, msg, traceback.format_exc()))
645
645
 
646
646
 
647
- def subprocess_context(test_func):
648
- """Ensures that sys.modules changes in subprocesses won't impact the parent process."""
647
+ def run_in_subprocess(test_func, *args):
648
+ """Run a function in a subprocess.
649
+
650
+ This ensures that sys.modules changes in subprocesses won't impact the parent process.
651
+
652
+ Args:
653
+ test_func: The function to be run in a subprocess.
654
+ *args: Positional args to pass to the function.
655
+ """
656
+
649
657
  assert callable(test_func), (
650
- "subprocess_context expects a function. Did you call the function instead of passing "
658
+ "run_in_subprocess expects a function. Did you call the function instead of passing "
651
659
  "it to this method?"
652
660
  )
653
661
 
654
- ctx = multiprocessing.get_context('spawn' if os.name == 'nt' else 'fork')
655
-
656
- exception = ctx.Queue()
662
+ # Use spawn to ensure subprocesses are isolated.
663
+ # See https://github.com/quantumlib/Cirq/issues/6373
664
+ ctx = multiprocessing.get_context('spawn')
657
665
 
658
- def isolated_func(*args, **kwargs):
659
- kwargs['queue'] = exception
660
- kwargs['func'] = test_func
661
- p = ctx.Process(target=_trace_unhandled_exceptions, args=args, kwargs=kwargs)
662
- p.start()
663
- p.join()
664
- result = exception.get()
665
- if result: # pragma: no cover
666
- ex_type, msg, ex_trace = result
667
- if ex_type == "Skipped":
668
- warnings.warn(f"Skipping: {ex_type}: {msg}\n{ex_trace}")
669
- pytest.skip(f'{ex_type}: {msg}\n{ex_trace}')
670
- else:
671
- pytest.fail(f'{ex_type}: {msg}\n{ex_trace}')
666
+ queue = ctx.Queue()
672
667
 
673
- return isolated_func
668
+ p = ctx.Process(
669
+ target=_trace_unhandled_exceptions, args=args, kwargs={'queue': queue, 'func': test_func}
670
+ )
671
+ p.start()
672
+ p.join()
673
+ result = queue.get()
674
+ if result: # pragma: no cover
675
+ ex_type, msg, ex_trace = result
676
+ if ex_type == "Skipped":
677
+ warnings.warn(f"Skipping: {ex_type}: {msg}\n{ex_trace}")
678
+ pytest.skip(f'{ex_type}: {msg}\n{ex_trace}')
679
+ else:
680
+ pytest.fail(f'{ex_type}: {msg}\n{ex_trace}')
674
681
 
675
682
 
676
683
  @mock.patch.dict(os.environ, {"CIRQ_FORCE_DEDUPE_MODULE_DEPRECATION": "1"})
@@ -698,7 +705,7 @@ def subprocess_context(test_func):
698
705
  ],
699
706
  )
700
707
  def test_deprecated_module(outdated_method, deprecation_messages):
701
- subprocess_context(_test_deprecated_module_inner)(outdated_method, deprecation_messages)
708
+ run_in_subprocess(_test_deprecated_module_inner, outdated_method, deprecation_messages)
702
709
 
703
710
 
704
711
  def _test_deprecated_module_inner(outdated_method, deprecation_messages):
@@ -736,7 +743,7 @@ def test_same_name_submodule_earlier_in_subtree():
736
743
  cirq.ops.engine.calibration packages. The wrong resolution resulted in false circular
737
744
  imports!
738
745
  """
739
- subprocess_context(_test_same_name_submodule_earlier_in_subtree_inner)()
746
+ run_in_subprocess(_test_same_name_submodule_earlier_in_subtree_inner)
740
747
 
741
748
 
742
749
  def _test_same_name_submodule_earlier_in_subtree_inner():
@@ -748,7 +755,7 @@ def _test_same_name_submodule_earlier_in_subtree_inner():
748
755
  def test_metadata_search_path():
749
756
  # to cater for metadata path finders
750
757
  # https://docs.python.org/3/library/importlib.metadata.html#extending-the-search-algorithm
751
- subprocess_context(_test_metadata_search_path_inner)()
758
+ run_in_subprocess(_test_metadata_search_path_inner)
752
759
 
753
760
 
754
761
  def _test_metadata_search_path_inner(): # pragma: no cover
@@ -760,7 +767,7 @@ def _test_metadata_search_path_inner(): # pragma: no cover
760
767
 
761
768
 
762
769
  def test_metadata_distributions_after_deprecated_submodule():
763
- subprocess_context(_test_metadata_distributions_after_deprecated_submodule)()
770
+ run_in_subprocess(_test_metadata_distributions_after_deprecated_submodule)
764
771
 
765
772
 
766
773
  def _test_metadata_distributions_after_deprecated_submodule():
@@ -779,7 +786,7 @@ def _test_metadata_distributions_after_deprecated_submodule():
779
786
 
780
787
 
781
788
  def test_parent_spec_after_deprecated_submodule():
782
- subprocess_context(_test_parent_spec_after_deprecated_submodule)()
789
+ run_in_subprocess(_test_parent_spec_after_deprecated_submodule)
783
790
 
784
791
 
785
792
  def _test_parent_spec_after_deprecated_submodule():
@@ -791,7 +798,7 @@ def _test_parent_spec_after_deprecated_submodule():
791
798
  def test_type_repr_in_new_module():
792
799
  # to cater for metadata path finders
793
800
  # https://docs.python.org/3/library/importlib.metadata.html#extending-the-search-algorithm
794
- subprocess_context(_test_type_repr_in_new_module_inner)()
801
+ run_in_subprocess(_test_type_repr_in_new_module_inner)
795
802
 
796
803
 
797
804
  def _test_type_repr_in_new_module_inner():
@@ -849,19 +856,19 @@ def _test_broken_module_3_inner():
849
856
 
850
857
 
851
858
  def test_deprecated_module_error_handling_1():
852
- subprocess_context(_test_broken_module_1_inner)()
859
+ run_in_subprocess(_test_broken_module_1_inner)
853
860
 
854
861
 
855
862
  def test_deprecated_module_error_handling_2():
856
- subprocess_context(_test_broken_module_2_inner)()
863
+ run_in_subprocess(_test_broken_module_2_inner)
857
864
 
858
865
 
859
866
  def test_deprecated_module_error_handling_3():
860
- subprocess_context(_test_broken_module_3_inner)()
867
+ run_in_subprocess(_test_broken_module_3_inner)
861
868
 
862
869
 
863
870
  def test_new_module_is_top_level():
864
- subprocess_context(_test_new_module_is_top_level_inner)()
871
+ run_in_subprocess(_test_new_module_is_top_level_inner)
865
872
 
866
873
 
867
874
  def _test_new_module_is_top_level_inner():
@@ -877,7 +884,7 @@ def _test_new_module_is_top_level_inner():
877
884
 
878
885
 
879
886
  def test_import_deprecated_with_no_attribute():
880
- subprocess_context(_test_import_deprecated_with_no_attribute_inner)()
887
+ run_in_subprocess(_test_import_deprecated_with_no_attribute_inner)
881
888
 
882
889
 
883
890
  def _test_import_deprecated_with_no_attribute_inner():
@@ -970,7 +977,7 @@ def test_deprecated_module_loader_repr():
970
977
 
971
978
  def test_subprocess_test_failure():
972
979
  with pytest.raises(Failed, match='ValueError.*this fails'):
973
- subprocess_context(_test_subprocess_test_failure_inner)()
980
+ run_in_subprocess(_test_subprocess_test_failure_inner)
974
981
 
975
982
 
976
983
  def _test_subprocess_test_failure_inner():
@@ -978,7 +985,7 @@ def _test_subprocess_test_failure_inner():
978
985
 
979
986
 
980
987
  def test_dir_is_still_valid():
981
- subprocess_context(_dir_is_still_valid_inner)()
988
+ run_in_subprocess(_dir_is_still_valid_inner)
982
989
 
983
990
 
984
991
  def _dir_is_still_valid_inner():
@@ -986,7 +993,7 @@ def _dir_is_still_valid_inner():
986
993
 
987
994
  import cirq.testing._compat_test_data as mod
988
995
 
989
- for m in ['fake_a', 'info', 'module_a', 'sys']:
996
+ for m in ['fake_a', 'logging', 'module_a']:
990
997
  assert m in dir(mod)
991
998
 
992
999
 
cirq/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.4.0.dev20231202032139"
1
+ __version__ = "1.4.0.dev20231205195308"
@@ -3,11 +3,11 @@
3
3
  See cirq/_compat_test.py for the tests.
4
4
  This module contains example deprecations for modules.
5
5
  """
6
- import sys
7
- from logging import info
6
+ import logging
7
+
8
8
  from cirq import _compat
9
9
 
10
- info("init:compat_test_data")
10
+ logging.info("init:compat_test_data")
11
11
 
12
12
  # simulates a rename of a child module
13
13
  # fake_a -> module_a
@@ -1,7 +1,7 @@
1
1
  # pylint: disable=wrong-or-nonexistent-copyright-notice
2
2
  """module_a for module deprecation tests"""
3
3
 
4
- from logging import info
4
+ import logging
5
5
 
6
6
  from cirq.testing._compat_test_data.module_a import module_b
7
7
 
@@ -11,4 +11,4 @@ from cirq.testing._compat_test_data.module_a.types import SampleType
11
11
 
12
12
  MODULE_A_ATTRIBUTE = "module_a"
13
13
 
14
- info("init:module_a")
14
+ logging.info("init:module_a")
@@ -70,6 +70,8 @@ class _SupportsValueEquality(Protocol):
70
70
 
71
71
 
72
72
  def _value_equality_eq(self: _SupportsValueEquality, other: _SupportsValueEquality) -> bool:
73
+ if other is self:
74
+ return True
73
75
  cls_self = self._value_equality_values_cls_()
74
76
  get_cls_other = getattr(other, '_value_equality_values_cls_', None)
75
77
  if get_cls_other is None:
@@ -91,6 +93,8 @@ def _value_equality_hash(self: _SupportsValueEquality) -> int:
91
93
  def _value_equality_approx_eq(
92
94
  self: _SupportsValueEquality, other: _SupportsValueEquality, atol: float
93
95
  ) -> bool:
96
+ if other is self:
97
+ return True
94
98
  cls_self = self._value_equality_values_cls_()
95
99
  get_cls_other = getattr(other, '_value_equality_values_cls_', None)
96
100
  if get_cls_other is None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.4.0.dev20231202032139
3
+ Version: 1.4.0.dev20231205195308
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
@@ -1,10 +1,10 @@
1
1
  cirq/__init__.py,sha256=GlOnPWDvat-Y203LsbXhkC0UnGm9HHiNx2ywz7Bkc3o,15708
2
2
  cirq/_compat.py,sha256=YPvewnC0gajEIRjauyz_EuDzs38g-bIBkY_0h91U4Pc,29363
3
- cirq/_compat_test.py,sha256=84X6ELsb5fv3Hc0_ly8-IQfMnCNQN6tHs6GZFrnuNyI,35005
3
+ cirq/_compat_test.py,sha256=iQJYqIP1uyRe8mNUwi2VKccyUaJDFYH7b3Fg6cqQLQw,35053
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=dUru8gdunAZIGbW_9lcfO6WcWcVev2Rb5Eo2JIbTJoc,40
7
+ cirq/_version.py,sha256=fdhwsCElG96AMMPO-tMnw0_9FPoBpdsgGeIvQA8NFQE,40
8
8
  cirq/_version_test.py,sha256=yYS6xm5-nuBRQJa9R3n41WdvFtVyY7Lb5Q8bea3VgBI,133
9
9
  cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
10
10
  cirq/json_resolver_cache.py,sha256=S0HaPOCUIck-vNSQlS6KxnQtle6w-2dGuSxkUbJQY9Y,13168
@@ -988,8 +988,8 @@ cirq/testing/sample_circuits.py,sha256=8HTrY_RWoPHV18q7aLz6e5Fjd2Twkt9Wkc_IDBzTE
988
988
  cirq/testing/sample_circuits_test.py,sha256=IMz72CMXJeRt7Eg1rRB68hFV1v3k7OQpYUyhqmfjNpo,876
989
989
  cirq/testing/sample_gates.py,sha256=qSCZhb-A-Mwm_J81Su2sUFyEUdvqfq7Je66dsk8cFy0,3277
990
990
  cirq/testing/sample_gates_test.py,sha256=mkfYPNo4WFH6y33Vr_f9zy2Ry1oq5yYLpB__sqSCkjQ,2377
991
- cirq/testing/_compat_test_data/__init__.py,sha256=yIe0dUE7-FT1bxYjc0hcoOZQkecBdYN5onC6KOpsx8U,3040
992
- cirq/testing/_compat_test_data/module_a/__init__.py,sha256=klpfbI8BVz2BA5TwhUDGqMSM0Sjw6ABIA_4hpyADHaE,386
991
+ cirq/testing/_compat_test_data/__init__.py,sha256=T9LHBgX2CLUvAloqrH0F1AAXdtgMuQvG3vZZhNbg61A,3028
992
+ cirq/testing/_compat_test_data/module_a/__init__.py,sha256=MHrL6kJFnYTXaRT-bW-gVPzizJCN4bIU8ZFB-tXUGZg,384
993
993
  cirq/testing/_compat_test_data/module_a/types.py,sha256=XFNOEP88FMOOCgF6jBumwsIBwIr-6KyK7ciaVzMN7T8,83
994
994
  cirq/testing/_compat_test_data/module_a/dupe/__init__.py,sha256=1h4X6AYURm5r2WFH26BltHzn0RzAv94Lf80DlKaG6xc,78
995
995
  cirq/testing/_compat_test_data/module_a/module_b/__init__.py,sha256=QPjVtgaK3kM9SPi3NocWmZ4FGh_V6Ct5qDHZkDIeCCU,159
@@ -1116,7 +1116,7 @@ cirq/value/random_state_test.py,sha256=0VyxtuBYgrbHsNCXFZtcgucd5KwI1obMjILH2ZTZ5
1116
1116
  cirq/value/timestamp.py,sha256=u0v5FmnSF_o3NE7aF-xIfQ5cDAVZzaUb-ZMdrxWYg2Y,3649
1117
1117
  cirq/value/timestamp_test.py,sha256=eZt9LLVK6TQy-2Bo1djitUD4at7i7M4lN60bLCx9UPs,4029
1118
1118
  cirq/value/type_alias.py,sha256=YD5m-77rx-hatIEVi5Q5j5tZ2Ji3Mmg4jUY9GT3LscM,1144
1119
- cirq/value/value_equality_attr.py,sha256=JX5urKm22YUi7xIc55foyhov8wSkHqwEHQh5sfbuAuw,10048
1119
+ cirq/value/value_equality_attr.py,sha256=VrSgnx8NLqIdXBSvZaf7V1NQ-zQO_BlM3CgxENNcEE8,10132
1120
1120
  cirq/value/value_equality_attr_test.py,sha256=k_nl5hWxo4yMO6WNu0wU68wyeb-RN9Ua_Ix7s9UTfOE,6412
1121
1121
  cirq/vis/__init__.py,sha256=e3Z1PI-Ay0hDHhIgFZEDwQIuO8C_aayNdL-EByF0J4o,1001
1122
1122
  cirq/vis/density_matrix.py,sha256=kMAPcRh6f0ghZKSe86nB_2iFngrDsw0pNael1EZ5BEw,4819
@@ -1148,8 +1148,8 @@ cirq/work/sampler.py,sha256=JVv1vvfa6EgFiR3UeDk44U186dCrioH2NZXueCgsb9w,19828
1148
1148
  cirq/work/sampler_test.py,sha256=zo1Hj6sn6fLs_WZMxYRApBqgBsldmptn74NL0jhNukc,12325
1149
1149
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1150
1150
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1151
- cirq_core-1.4.0.dev20231202032139.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1152
- cirq_core-1.4.0.dev20231202032139.dist-info/METADATA,sha256=0_5TDIWbYJCKDZb48y_07zLZZE82xKs4DqlRX8VFJfQ,2075
1153
- cirq_core-1.4.0.dev20231202032139.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
1154
- cirq_core-1.4.0.dev20231202032139.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1155
- cirq_core-1.4.0.dev20231202032139.dist-info/RECORD,,
1151
+ cirq_core-1.4.0.dev20231205195308.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1152
+ cirq_core-1.4.0.dev20231205195308.dist-info/METADATA,sha256=U_YPhFh7CKMoN5GjbZJ_UGCTb1_GjJEiCFz3WEHTIpY,2075
1153
+ cirq_core-1.4.0.dev20231205195308.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
1154
+ cirq_core-1.4.0.dev20231205195308.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1155
+ cirq_core-1.4.0.dev20231205195308.dist-info/RECORD,,