Skip to content

Commit 011f3fb

Browse files
committed
Merge branch 'main' into 2023-11-blacklist-these-terms
2 parents 3161d30 + 2f3c1e2 commit 011f3fb

File tree

105 files changed

+498
-349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+498
-349
lines changed

Diff for: .github/workflows/ci-daily.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ jobs:
8686
pip install \
8787
-r dev_tools/requirements/deps/format.txt \
8888
-r dev_tools/requirements/deps/pylint.txt \
89-
-r dev_tools/requirements/deps/pytest.txt
89+
-r dev_tools/requirements/deps/pytest.txt \
90+
-r dev_tools/requirements/deps/notebook.txt
9091
- name: Pytest check
9192
run: check/pytest -n auto --ignore=cirq-core/cirq/contrib --enable-slow-tests

Diff for: CONTRIBUTING.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,27 @@ Forking creates a new github repo at the location
3838
your github id. Use the directions on the
3939
[development page](docs/dev/development.md) to download a copy to
4040
your local machine. You need only do this once.
41-
1. Checkout master and create a new branch from this master
41+
1. Checkout main and create a new branch from this main
4242
```shell
43-
git checkout master -b new_branch_name
43+
git checkout main -b new_branch_name
4444
```
4545
where ```new_branch_name``` is the name of your new branch.
4646
1. Do your work and commit your changes to this branch.
47-
1. If you have drifted out of sync with the master from the
47+
1. If you have drifted out of sync with the main from the
4848
main cirq repo you may need to merge in changes. To do this,
49-
first update your local master and then merge the local master
49+
first update your local main and then merge the local main
5050
into your branch:
5151
```shell
5252
# Track the upstream repo (if your local repo hasn't):
5353
git remote add upstream https://github.com/quantumlib/Cirq.git
5454
55-
# Update your local master.
55+
# Update your local main.
5656
git fetch upstream
57-
git checkout master
58-
git merge upstream/master
59-
# Merge local master into your branch.
57+
git checkout main
58+
git merge upstream/main
59+
# Merge local main into your branch.
6060
git checkout new_branch_name
61-
git merge master
61+
git merge main
6262
```
6363
You may need to fix merge conflicts for both of these merge
6464
commands.

Diff for: README.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. image:: https://raw.githubusercontent.com/quantumlib/Cirq/master/docs/images/Cirq_logo_color.png
1+
.. image:: https://raw.githubusercontent.com/quantumlib/Cirq/main/docs/images/Cirq_logo_color.png
22
:target: https://github.com/quantumlib/cirq
33
:alt: Cirq
44
:width: 500px
@@ -10,7 +10,7 @@ circuits and running them against quantum computers and simulators.
1010
:target: https://github.com/quantumlib/Cirq
1111
:alt: Build Status
1212

13-
.. image:: https://codecov.io/gh/quantumlib/Cirq/branch/master/graph/badge.svg
13+
.. image:: https://codecov.io/gh/quantumlib/Cirq/branch/main/graph/badge.svg
1414
:target: https://codecov.io/gh/quantumlib/Cirq
1515

1616
.. image:: https://badge.fury.io/py/cirq.svg
@@ -26,7 +26,7 @@ Installation and Documentation
2626

2727
Cirq documentation is available at `quantumai.google/cirq <https://quantumai.google/cirq>`_.
2828

29-
Documentation for the latest **pre-release** version of cirq (tracks the repository's master branch; what you get if you ``pip install --pre cirq``), is available `here <https://quantumai.google/reference/python/cirq/all_symbols?version=nightly>`__.
29+
Documentation for the latest **pre-release** version of cirq (tracks the repository's main branch; what you get if you ``pip install --pre cirq``), is available `here <https://quantumai.google/reference/python/cirq/all_symbols?version=nightly>`__.
3030

3131
Documentation for the latest **stable** version of cirq (what you get if you ``pip install cirq``) is available `here <https://quantumai.google/reference/python/cirq/all_symbols>`__.
3232

@@ -98,10 +98,10 @@ Cirq Contributors Community
9898
---------------------------
9999

100100
We welcome contributions! Before opening your first PR, a good place to start is to read our
101-
`guidelines <https://github.com/quantumlib/cirq/blob/master/CONTRIBUTING.md>`__.
101+
`guidelines <https://github.com/quantumlib/cirq/blob/main/CONTRIBUTING.md>`__.
102102

103103
We are dedicated to cultivating an open and inclusive community to build software for near term quantum computers.
104-
Please read our `code of conduct <https://github.com/quantumlib/cirq/blob/master/CODE_OF_CONDUCT.md>`__ for the rules of engagement within our community.
104+
Please read our `code of conduct <https://github.com/quantumlib/cirq/blob/main/CODE_OF_CONDUCT.md>`__ for the rules of engagement within our community.
105105

106106
For real time informal discussions about Cirq, join our `cirqdev <https://gitter.im/cirqdev/community>`__ Gitter channel, come hangout with us!
107107

Diff for: cirq-aqt/cirq_aqt/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
"""Define version number here, read it from setup.py automatically"""
1616

17-
__version__ = "1.3.0.dev"
17+
__version__ = "1.4.0.dev"

Diff for: cirq-aqt/cirq_aqt/_version_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44

55
def test_version():
6-
assert cirq_aqt.__version__ == "1.3.0.dev"
6+
assert cirq_aqt.__version__ == "1.4.0.dev"

Diff for: cirq-core/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. image:: https://raw.githubusercontent.com/quantumlib/Cirq/master/docs/images/Cirq_logo_color.png
1+
.. image:: https://raw.githubusercontent.com/quantumlib/Cirq/main/docs/images/Cirq_logo_color.png
22
:target: https://github.com/quantumlib/cirq
33
:alt: Cirq
44
:width: 500px

Diff for: cirq-core/cirq/_compat.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def with_debug(value: bool) -> Iterator[None]:
6767
from backports.cached_property import cached_property # type: ignore[no-redef]
6868

6969

70+
# Sentinel used by wrapped_no_args below when method has not yet been cached.
71+
_NOT_FOUND = object()
72+
73+
7074
TFunc = TypeVar('TFunc', bound=Callable)
7175

7276

@@ -103,9 +107,11 @@ def decorator(func):
103107

104108
@functools.wraps(func)
105109
def wrapped_no_args(self):
106-
if not hasattr(self, cache_name):
107-
object.__setattr__(self, cache_name, func(self))
108-
return getattr(self, cache_name)
110+
result = getattr(self, cache_name, _NOT_FOUND)
111+
if result is _NOT_FOUND:
112+
result = func(self)
113+
object.__setattr__(self, cache_name, result)
114+
return result
109115

110116
return wrapped_no_args
111117

Diff for: cirq-core/cirq/_compat_test.py

+45-38
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def test_wrap_module():
346346

347347

348348
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)
350350

351351

352352
def _test_deprecate_attributes_assert_attributes_in_sys_modules():
@@ -635,42 +635,49 @@ def _type_repr_in_deprecated_module():
635635
] + _deprecation_origin
636636

637637

638-
def _trace_unhandled_exceptions(*args, queue: 'multiprocessing.Queue', func: Callable, **kwargs):
638+
def _trace_unhandled_exceptions(*args, queue: 'multiprocessing.Queue', func: Callable):
639639
try:
640-
func(*args, **kwargs)
640+
func(*args)
641641
queue.put(None)
642642
except BaseException as ex:
643643
msg = str(ex)
644644
queue.put((type(ex).__name__, msg, traceback.format_exc()))
645645

646646

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+
649657
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 "
651659
"it to this method?"
652660
)
653661

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')
657665

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()
672667

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}')
674681

675682

676683
@mock.patch.dict(os.environ, {"CIRQ_FORCE_DEDUPE_MODULE_DEPRECATION": "1"})
@@ -698,7 +705,7 @@ def isolated_func(*args, **kwargs):
698705
],
699706
)
700707
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)
702709

703710

704711
def _test_deprecated_module_inner(outdated_method, deprecation_messages):
@@ -736,7 +743,7 @@ def test_same_name_submodule_earlier_in_subtree():
736743
cirq.ops.engine.calibration packages. The wrong resolution resulted in false circular
737744
imports!
738745
"""
739-
subprocess_context(_test_same_name_submodule_earlier_in_subtree_inner)()
746+
run_in_subprocess(_test_same_name_submodule_earlier_in_subtree_inner)
740747

741748

742749
def _test_same_name_submodule_earlier_in_subtree_inner():
@@ -748,7 +755,7 @@ def _test_same_name_submodule_earlier_in_subtree_inner():
748755
def test_metadata_search_path():
749756
# to cater for metadata path finders
750757
# 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)
752759

753760

754761
def _test_metadata_search_path_inner(): # pragma: no cover
@@ -760,7 +767,7 @@ def _test_metadata_search_path_inner(): # pragma: no cover
760767

761768

762769
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)
764771

765772

766773
def _test_metadata_distributions_after_deprecated_submodule():
@@ -779,7 +786,7 @@ def _test_metadata_distributions_after_deprecated_submodule():
779786

780787

781788
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)
783790

784791

785792
def _test_parent_spec_after_deprecated_submodule():
@@ -791,7 +798,7 @@ def _test_parent_spec_after_deprecated_submodule():
791798
def test_type_repr_in_new_module():
792799
# to cater for metadata path finders
793800
# 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)
795802

796803

797804
def _test_type_repr_in_new_module_inner():
@@ -849,19 +856,19 @@ def _test_broken_module_3_inner():
849856

850857

851858
def test_deprecated_module_error_handling_1():
852-
subprocess_context(_test_broken_module_1_inner)()
859+
run_in_subprocess(_test_broken_module_1_inner)
853860

854861

855862
def test_deprecated_module_error_handling_2():
856-
subprocess_context(_test_broken_module_2_inner)()
863+
run_in_subprocess(_test_broken_module_2_inner)
857864

858865

859866
def test_deprecated_module_error_handling_3():
860-
subprocess_context(_test_broken_module_3_inner)()
867+
run_in_subprocess(_test_broken_module_3_inner)
861868

862869

863870
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)
865872

866873

867874
def _test_new_module_is_top_level_inner():
@@ -877,7 +884,7 @@ def _test_new_module_is_top_level_inner():
877884

878885

879886
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)
881888

882889

883890
def _test_import_deprecated_with_no_attribute_inner():
@@ -970,23 +977,23 @@ def module_repr(self, module: ModuleType) -> str:
970977

971978
def test_subprocess_test_failure():
972979
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)
974981

975982

976983
def _test_subprocess_test_failure_inner():
977984
raise ValueError('this fails')
978985

979986

980987
def test_dir_is_still_valid():
981-
subprocess_context(_dir_is_still_valid_inner)()
988+
run_in_subprocess(_dir_is_still_valid_inner)
982989

983990

984991
def _dir_is_still_valid_inner():
985992
"""to ensure that create_attribute=True keeps the dir(module) intact"""
986993

987994
import cirq.testing._compat_test_data as mod
988995

989-
for m in ['fake_a', 'info', 'module_a', 'sys']:
996+
for m in ['fake_a', 'logging', 'module_a']:
990997
assert m in dir(mod)
991998

992999

Diff for: cirq-core/cirq/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
'of cirq (e.g. "python -m pip install cirq==1.1.*")'
2929
)
3030

31-
__version__ = "1.3.0.dev"
31+
__version__ = "1.4.0.dev"

Diff for: cirq-core/cirq/_version_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44

55
def test_version():
6-
assert cirq.__version__ == "1.3.0.dev"
6+
assert cirq.__version__ == "1.4.0.dev"

0 commit comments

Comments
 (0)