From 09c4ec38fc7bae2b9f94ca8f01540cbb58827866 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 9 Jul 2024 15:39:15 -0700 Subject: [PATCH 1/6] fix mypy --- cirq-core/cirq/circuits/circuit_operation_test.py | 6 +++--- .../cirq/experiments/qubit_characterizations.py | 7 ++++--- .../experiments/single_qubit_readout_calibration.py | 7 ++++--- cirq-core/cirq/interop/quirk/cells/parse.py | 2 +- cirq-core/cirq/ops/global_phase_op.py | 2 +- cirq-core/cirq/sim/density_matrix_simulator_test.py | 4 ++-- cirq-core/cirq/sim/sparse_simulator_test.py | 4 ++-- cirq-core/cirq/study/flatten_expressions.py | 3 +-- cirq-core/cirq/study/resolver.py | 12 +++++------- cirq-core/cirq/study/sweepable.py | 2 +- cirq-core/cirq/study/sweeps.py | 5 +---- cirq-core/cirq/vis/heatmap.py | 2 -- cirq-core/cirq/vis/state_histogram.py | 3 +-- cirq-google/cirq_google/engine/calibration.py | 1 - .../serialization/circuit_serializer_test.py | 4 ++-- .../cirq_google/serialization/op_deserializer.py | 2 +- cirq-rigetti/cirq_rigetti/conftest.py | 2 +- dev_tools/docs/build_api_docs.py | 4 +++- dev_tools/modules.py | 2 ++ 19 files changed, 35 insertions(+), 39 deletions(-) diff --git a/cirq-core/cirq/circuits/circuit_operation_test.py b/cirq-core/cirq/circuits/circuit_operation_test.py index f3ba30dd62a..f2840e1e102 100644 --- a/cirq-core/cirq/circuits/circuit_operation_test.py +++ b/cirq-core/cirq/circuits/circuit_operation_test.py @@ -327,9 +327,9 @@ def test_repeat(add_measurements: bool, use_default_ids_for_initial_rep: bool) - _ = op_base.repeat() with pytest.raises(TypeError, match='Only integer or sympy repetitions are allowed'): - _ = op_base.repeat(1.3) # type: ignore[arg-type] - assert op_base.repeat(3.00000000001).repetitions == 3 # type: ignore[arg-type] - assert op_base.repeat(2.99999999999).repetitions == 3 # type: ignore[arg-type] + _ = op_base.repeat(1.3) + assert op_base.repeat(3.00000000001).repetitions == 3 + assert op_base.repeat(2.99999999999).repetitions == 3 @pytest.mark.parametrize('add_measurements', [True, False]) diff --git a/cirq-core/cirq/experiments/qubit_characterizations.py b/cirq-core/cirq/experiments/qubit_characterizations.py index 9ba7928b81c..916c662e468 100644 --- a/cirq-core/cirq/experiments/qubit_characterizations.py +++ b/cirq-core/cirq/experiments/qubit_characterizations.py @@ -17,8 +17,8 @@ import functools from typing import ( - Any, cast, + Any, Iterator, List, Optional, @@ -107,7 +107,6 @@ def plot(self, ax: Optional[plt.Axes] = None, **plot_kwargs: Any) -> plt.Axes: show_plot = not ax if not ax: fig, ax = plt.subplots(1, 1, figsize=(8, 8)) # pragma: no cover - ax = cast(plt.Axes, ax) # pragma: no cover ax.set_ylim((0.0, 1.0)) # pragma: no cover ax.plot(self._num_cfds_seq, self._gnd_state_probs, 'ro', label='data', **plot_kwargs) x = np.linspace(self._num_cfds_seq[0], self._num_cfds_seq[-1], 100) @@ -304,7 +303,9 @@ def plot(self, axes: Optional[List[plt.Axes]] = None, **plot_kwargs: Any) -> Lis """ show_plot = axes is None if axes is None: - fig, axes = plt.subplots(1, 2, figsize=(12.0, 5.0), subplot_kw={'projection': '3d'}) + fig, axes_v = plt.subplots(1, 2, figsize=(12.0, 5.0), subplot_kw={'projection': '3d'}) + axes_v = cast(np.ndarray, axes_v) + axes = list(axes_v) elif len(axes) != 2: raise ValueError('A TomographyResult needs 2 axes to plot.') mat = self._density_matrix diff --git a/cirq-core/cirq/experiments/single_qubit_readout_calibration.py b/cirq-core/cirq/experiments/single_qubit_readout_calibration.py index cad1c27a36c..76891d57065 100644 --- a/cirq-core/cirq/experiments/single_qubit_readout_calibration.py +++ b/cirq-core/cirq/experiments/single_qubit_readout_calibration.py @@ -14,7 +14,7 @@ """Single qubit readout experiments using parallel or isolated statistics.""" import dataclasses import time -from typing import Any, Dict, Iterable, List, Optional, TYPE_CHECKING +from typing import cast, Any, Dict, Iterable, List, Optional, TYPE_CHECKING import sympy import numpy as np @@ -77,8 +77,9 @@ def plot_heatmap( """ if axs is None: - _, axs = plt.subplots(1, 2, dpi=200, facecolor='white', figsize=(12, 4)) - + _, axs_v = plt.subplots(1, 2, dpi=200, facecolor='white', figsize=(12, 4)) + axs_v = cast(np.ndarray, axs_v) + axs = cast(tuple[plt.Axes, plt.Axes], (axs_v[0], axs_v[1])) else: if ( not isinstance(axs, (tuple, list, np.ndarray)) diff --git a/cirq-core/cirq/interop/quirk/cells/parse.py b/cirq-core/cirq/interop/quirk/cells/parse.py index e09722b3e87..8d680ef15fb 100644 --- a/cirq-core/cirq/interop/quirk/cells/parse.py +++ b/cirq-core/cirq/interop/quirk/cells/parse.py @@ -154,7 +154,7 @@ def apply(op: Union[str, _HangingNode]) -> None: a = vals.pop() # Note: vals seems to be _HangingToken # func operates on _ResolvedTokens. Ignoring type issues for now. - vals.append(op.func(a, b)) # type: ignore[arg-type] + vals.append(op.func(a, b)) def close_paren() -> None: while True: diff --git a/cirq-core/cirq/ops/global_phase_op.py b/cirq-core/cirq/ops/global_phase_op.py index e1a66272244..6a64a634aa6 100644 --- a/cirq-core/cirq/ops/global_phase_op.py +++ b/cirq-core/cirq/ops/global_phase_op.py @@ -28,7 +28,7 @@ class GlobalPhaseGate(raw_types.Gate): def __init__(self, coefficient: 'cirq.TParamValComplex', atol: float = 1e-8) -> None: if not isinstance(coefficient, sympy.Basic): - if abs(1 - abs(coefficient)) > atol: # type: ignore[operator] + if abs(1 - abs(coefficient)) > atol: raise ValueError(f'Coefficient is not unitary: {coefficient!r}') self._coefficient = coefficient diff --git a/cirq-core/cirq/sim/density_matrix_simulator_test.py b/cirq-core/cirq/sim/density_matrix_simulator_test.py index 119bc3f1830..d0272f33c38 100644 --- a/cirq-core/cirq/sim/density_matrix_simulator_test.py +++ b/cirq-core/cirq/sim/density_matrix_simulator_test.py @@ -402,10 +402,10 @@ def test_run_param_resolver(dtype: Type[np.complexfloating], split: bool): cirq.measure(q1), ) param_resolver = {'b0': b0, 'b1': b1} - result = simulator.run(circuit, param_resolver=param_resolver) # type: ignore + result = simulator.run(circuit, param_resolver=param_resolver) np.testing.assert_equal(result.measurements, {'q(0)': [[b0]], 'q(1)': [[b1]]}) # pylint: disable=line-too-long - np.testing.assert_equal(result.params, cirq.ParamResolver(param_resolver)) # type: ignore + np.testing.assert_equal(result.params, cirq.ParamResolver(param_resolver)) @pytest.mark.parametrize('dtype', [np.complex64, np.complex128]) diff --git a/cirq-core/cirq/sim/sparse_simulator_test.py b/cirq-core/cirq/sim/sparse_simulator_test.py index a769be3028d..d07e95ecd86 100644 --- a/cirq-core/cirq/sim/sparse_simulator_test.py +++ b/cirq-core/cirq/sim/sparse_simulator_test.py @@ -498,11 +498,11 @@ def test_simulate_param_resolver(dtype: Type[np.complexfloating], split: bool): (cirq.X ** sympy.Symbol('b0'))(q0), (cirq.X ** sympy.Symbol('b1'))(q1) ) resolver = {'b0': b0, 'b1': b1} - result = simulator.simulate(circuit, param_resolver=resolver) # type: ignore + result = simulator.simulate(circuit, param_resolver=resolver) expected_state = np.zeros(shape=(2, 2)) expected_state[b0][b1] = 1.0 np.testing.assert_equal(result.final_state_vector, np.reshape(expected_state, 4)) - assert result.params == cirq.ParamResolver(resolver) # type: ignore + assert result.params == cirq.ParamResolver(resolver) assert len(result.measurements) == 0 diff --git a/cirq-core/cirq/study/flatten_expressions.py b/cirq-core/cirq/study/flatten_expressions.py index d532b4bcf09..5000880e72a 100644 --- a/cirq-core/cirq/study/flatten_expressions.py +++ b/cirq-core/cirq/study/flatten_expressions.py @@ -225,8 +225,7 @@ def __init__( params = param_dict if param_dict else {} # TODO: Support complex values for typing below. symbol_params: resolver.ParamDictType = { - _ensure_not_str(param): _ensure_not_str(val) # type: ignore[misc] - for param, val in params.items() + _ensure_not_str(param): _ensure_not_str(val) for param, val in params.items() } super().__init__(symbol_params) if get_param_name is None: diff --git a/cirq-core/cirq/study/resolver.py b/cirq-core/cirq/study/resolver.py index b66c31ac884..f9bd4e52b41 100644 --- a/cirq-core/cirq/study/resolver.py +++ b/cirq-core/cirq/study/resolver.py @@ -139,10 +139,10 @@ def value_of( if isinstance(param_value, str): param_value = sympy.Symbol(param_value) elif not isinstance(param_value, sympy.Basic): - return value # type: ignore[return-value] + return value if recursive: param_value = self._value_of_recursive(value) - return param_value # type: ignore[return-value] + return param_value if not isinstance(value, sympy.Basic): # No known way to resolve this variable, return unchanged. @@ -207,7 +207,7 @@ def _value_of_recursive(self, value: 'cirq.TParamKey') -> 'cirq.TParamValComplex # There isn't a full evaluation for 'value' yet. Until it's ready, # map value to None to identify loops in component evaluation. - self._deep_eval_map[value] = _RECURSION_FLAG # type: ignore + self._deep_eval_map[value] = _RECURSION_FLAG v = self.value_of(value, recursive=False) if v == value: @@ -220,10 +220,8 @@ def _resolve_parameters_(self, resolver: 'ParamResolver', recursive: bool) -> 'P new_dict: Dict['cirq.TParamKey', Union[float, str, sympy.Symbol, sympy.Expr]] = { k: k for k in resolver } - new_dict.update({k: self.value_of(k, recursive) for k in self}) # type: ignore[misc] - new_dict.update( - {k: resolver.value_of(v, recursive) for k, v in new_dict.items()} # type: ignore[misc] - ) + new_dict.update({k: self.value_of(k, recursive) for k in self}) + new_dict.update({k: resolver.value_of(v, recursive) for k, v in new_dict.items()}) if recursive and self._param_dict: new_resolver = ParamResolver(cast(ParamDictType, new_dict)) # Resolve down to single-step mappings. diff --git a/cirq-core/cirq/study/sweepable.py b/cirq-core/cirq/study/sweepable.py index dd3356b212d..bfb5553b7f8 100644 --- a/cirq-core/cirq/study/sweepable.py +++ b/cirq-core/cirq/study/sweepable.py @@ -65,7 +65,7 @@ def to_sweeps(sweepable: Sweepable) -> List[Sweep]: product_sweep = dict_to_product_sweep(sweepable) return [_resolver_to_sweep(resolver) for resolver in product_sweep] if isinstance(sweepable, Iterable) and not isinstance(sweepable, str): - return [sweep for item in sweepable for sweep in to_sweeps(item)] # type: ignore[arg-type] + return [sweep for item in sweepable for sweep in to_sweeps(item)] raise TypeError(f'Unrecognized sweepable type: {type(sweepable)}.\nsweepable: {sweepable}') diff --git a/cirq-core/cirq/study/sweeps.py b/cirq-core/cirq/study/sweeps.py index f075de48058..b87a4f02deb 100644 --- a/cirq-core/cirq/study/sweeps.py +++ b/cirq-core/cirq/study/sweeps.py @@ -591,10 +591,7 @@ def dict_to_product_sweep(factor_dict: ProductOrZipSweepLike) -> Product: Cartesian product of the sweeps. """ return Product( - *( - Points(k, v if isinstance(v, Sequence) else [v]) # type: ignore - for k, v in factor_dict.items() - ) + *(Points(k, v if isinstance(v, Sequence) else [v]) for k, v in factor_dict.items()) ) diff --git a/cirq-core/cirq/vis/heatmap.py b/cirq-core/cirq/vis/heatmap.py index e672a2b8c27..07e5b93c483 100644 --- a/cirq-core/cirq/vis/heatmap.py +++ b/cirq-core/cirq/vis/heatmap.py @@ -296,7 +296,6 @@ def plot( show_plot = not ax if not ax: fig, ax = plt.subplots(figsize=(8, 8)) - ax = cast(plt.Axes, ax) original_config = copy.deepcopy(self._config) self.update_config(**kwargs) collection = self._plot_on_axis(ax) @@ -383,7 +382,6 @@ def plot( show_plot = not ax if not ax: fig, ax = plt.subplots(figsize=(8, 8)) - ax = cast(plt.Axes, ax) original_config = copy.deepcopy(self._config) self.update_config(**kwargs) qubits = set([q for qubits in self._value_map.keys() for q in qubits]) diff --git a/cirq-core/cirq/vis/state_histogram.py b/cirq-core/cirq/vis/state_histogram.py index 3a3706cf04f..d2525c06687 100644 --- a/cirq-core/cirq/vis/state_histogram.py +++ b/cirq-core/cirq/vis/state_histogram.py @@ -14,7 +14,7 @@ """Tool to visualize the results of a study.""" -from typing import cast, Optional, Sequence, SupportsFloat, Union +from typing import Optional, Sequence, SupportsFloat, Union import collections import numpy as np import matplotlib.pyplot as plt @@ -87,7 +87,6 @@ def plot_state_histogram( show_fig = not ax if not ax: fig, ax = plt.subplots(1, 1) - ax = cast(plt.Axes, ax) if isinstance(data, result.Result): values = get_state_histogram(data) elif isinstance(data, collections.Counter): diff --git a/cirq-google/cirq_google/engine/calibration.py b/cirq-google/cirq_google/engine/calibration.py index 8e0ac4c1560..dfbe73e467d 100644 --- a/cirq-google/cirq_google/engine/calibration.py +++ b/cirq-google/cirq_google/engine/calibration.py @@ -277,7 +277,6 @@ def plot_histograms( show_plot = not ax if not ax: fig, ax = plt.subplots(1, 1) - ax = cast(plt.Axes, ax) if isinstance(keys, str): keys = [keys] diff --git a/cirq-google/cirq_google/serialization/circuit_serializer_test.py b/cirq-google/cirq_google/serialization/circuit_serializer_test.py index 573b8f018c3..2403e7865ba 100644 --- a/cirq-google/cirq_google/serialization/circuit_serializer_test.py +++ b/cirq-google/cirq_google/serialization/circuit_serializer_test.py @@ -79,11 +79,11 @@ def circuit_proto(json: Dict, qubits: List[str]): op_proto({'xpowgate': {'exponent': {'float_value': 0.125}}, 'qubit_constant_index': [0]}), ), ( - cirq.XPowGate(exponent=np.double(0.125))(Q1), # type: ignore + cirq.XPowGate(exponent=np.double(0.125))(Q1), op_proto({'xpowgate': {'exponent': {'float_value': 0.125}}, 'qubit_constant_index': [0]}), ), ( - cirq.XPowGate(exponent=np.short(1))(Q1), # type: ignore + cirq.XPowGate(exponent=np.short(1))(Q1), op_proto({'xpowgate': {'exponent': {'float_value': 1.0}}, 'qubit_constant_index': [0]}), ), ( diff --git a/cirq-google/cirq_google/serialization/op_deserializer.py b/cirq-google/cirq_google/serialization/op_deserializer.py index e682712a189..44dec4f09d7 100644 --- a/cirq-google/cirq_google/serialization/op_deserializer.py +++ b/cirq-google/cirq_google/serialization/op_deserializer.py @@ -153,5 +153,5 @@ def from_proto( ) return cirq.CircuitOperation( - circuit, repetitions, qubit_map, measurement_key_map, arg_map, rep_ids # type: ignore + circuit, repetitions, qubit_map, measurement_key_map, arg_map, rep_ids ) diff --git a/cirq-rigetti/cirq_rigetti/conftest.py b/cirq-rigetti/cirq_rigetti/conftest.py index da647f43ac8..5a95581de05 100644 --- a/cirq-rigetti/cirq_rigetti/conftest.py +++ b/cirq-rigetti/cirq_rigetti/conftest.py @@ -41,7 +41,7 @@ def __init__(self, *args, **kwargs) -> None: self._run_count = 0 self._mock_results: Dict[str, np.ndarray] = {} - def execute(self, executable: QuantumExecutable) -> T: # type: ignore[empty-body] + def execute(self, executable: QuantumExecutable) -> T: pass def run(self, program: QuantumExecutable) -> QAMExecutionResult: diff --git a/dev_tools/docs/build_api_docs.py b/dev_tools/docs/build_api_docs.py index e0c55100abe..e71d4b7279c 100644 --- a/dev_tools/docs/build_api_docs.py +++ b/dev_tools/docs/build_api_docs.py @@ -38,9 +38,11 @@ import cirq_google import cirq_ionq import cirq_pasqal -import cirq_rigetti import cirq_web +# temporary fix for #6661 +import cirq_rigetti # type: ignore + from cirq import _doc flags.DEFINE_string("output_dir", "docs/api_docs", "Where to output the docs") diff --git a/dev_tools/modules.py b/dev_tools/modules.py index b684300955f..19953b8049e 100644 --- a/dev_tools/modules.py +++ b/dev_tools/modules.py @@ -103,6 +103,8 @@ def list_modules( for f in search_dir.glob("*") if f.is_dir() and (f / "setup.py").is_file() ) + # Temporarily ignore cirq-rigetti (see #6661). + relative_folders = [rf for rf in relative_folders if 'cirq-rigetti' not in str(rf)] if include_parent: parent_setup_py = search_dir / "setup.py" if not parent_setup_py.exists(): From 3f2421df0504df5439d95fbfccf2ffb4c966d62b Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 9 Jul 2024 15:43:40 -0700 Subject: [PATCH 2/6] lint --- cirq-core/cirq/study/sweepable.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cirq-core/cirq/study/sweepable.py b/cirq-core/cirq/study/sweepable.py index 9d12d0220ba..6ae9dcb681f 100644 --- a/cirq-core/cirq/study/sweepable.py +++ b/cirq-core/cirq/study/sweepable.py @@ -65,11 +65,7 @@ def to_sweeps(sweepable: Sweepable, metadata: Optional[dict] = None) -> List[Swe product_sweep = dict_to_product_sweep(sweepable) return [_resolver_to_sweep(resolver, metadata) for resolver in product_sweep] if isinstance(sweepable, Iterable) and not isinstance(sweepable, str): - return [ - sweep - for item in sweepable - for sweep in to_sweeps(item, metadata) - ] + return [sweep for item in sweepable for sweep in to_sweeps(item, metadata)] raise TypeError(f'Unrecognized sweepable type: {type(sweepable)}.\nsweepable: {sweepable}') From b4febd1cb76a25bfa46533ce67f647c2228de7cf Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 9 Jul 2024 16:06:32 -0700 Subject: [PATCH 3/6] change method --- dev_tools/conf/mypy.ini | 4 ++-- dev_tools/docs/build_api_docs.py | 4 +--- dev_tools/modules.py | 16 +++------------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/dev_tools/conf/mypy.ini b/dev_tools/conf/mypy.ini index e9fa42a9d15..1206a0d8a20 100644 --- a/dev_tools/conf/mypy.ini +++ b/dev_tools/conf/mypy.ini @@ -1,5 +1,5 @@ [mypy] -exclude = dev_tools/modules_test_data/.*/setup\.py +exclude = dev_tools/modules_test_data/.*/setup\.py|cirq-rigetti/(?!__init__.)*\.py # Temperarly exclude cirq-rigetti (see #6661) show_error_codes = true plugins = duet.typing warn_unused_ignores = true @@ -12,7 +12,7 @@ ignore_missing_imports = true # 3rd-party libs for which we don't have stubs # Google -[mypy-google.api_core.*,google.auth.*,google.colab.*,google.cloud.*] +[mypy-google.api_core.*,google.auth.*,google.colab.*,google.cloud.*,google.oauth2.*] follow_imports = silent ignore_missing_imports = true diff --git a/dev_tools/docs/build_api_docs.py b/dev_tools/docs/build_api_docs.py index e71d4b7279c..e0c55100abe 100644 --- a/dev_tools/docs/build_api_docs.py +++ b/dev_tools/docs/build_api_docs.py @@ -38,11 +38,9 @@ import cirq_google import cirq_ionq import cirq_pasqal +import cirq_rigetti import cirq_web -# temporary fix for #6661 -import cirq_rigetti # type: ignore - from cirq import _doc flags.DEFINE_string("output_dir", "docs/api_docs", "Where to output the docs") diff --git a/dev_tools/modules.py b/dev_tools/modules.py index 08027c87164..b684300955f 100644 --- a/dev_tools/modules.py +++ b/dev_tools/modules.py @@ -103,8 +103,6 @@ def list_modules( for f in search_dir.glob("*") if f.is_dir() and (f / "setup.py").is_file() ) - # Temporarily ignore cirq-rigetti (see #6661). - relative_folders = [rf for rf in relative_folders if 'cirq-rigetti' not in str(rf)] if include_parent: parent_setup_py = search_dir / "setup.py" if not parent_setup_py.exists(): @@ -162,9 +160,9 @@ def replace_version(search_dir: Path = _DEFAULT_SEARCH_DIR, *, old: str, new: st for m in list_modules(search_dir=search_dir, include_parent=True): version_file = _find_version_file(search_dir / m.root) - _rewrite_version(version_file, old, new) - version_test = version_file.parent / "_version_test.py" - _rewrite_version(version_test, old, new) + content = version_file.read_text("UTF-8") + new_content = content.replace(old, new) + version_file.write_text(new_content) def _validate_version(new_version: str): @@ -172,14 +170,6 @@ def _validate_version(new_version: str): raise ValueError(f"{new_version} is not a valid version number.") -def _rewrite_version(version_file: Path, old: str, new: str) -> None: - pattern = f"(^[^#]*__version__ ==? )(['\"])({re.escape(old)})(\\2)" - repl = f"\\1\\g<2>{new}\\4" - content = version_file.read_text("UTF-8") - new_content = re.sub(pattern, repl, content, flags=re.MULTILINE) - version_file.write_text(new_content) - - def _find_version_file(top: Path) -> Path: for root, _, files in os.walk(str(top)): if "_version.py" in files: From c50774c8d4c2721935ddda8f4b1e25fe17102c67 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 9 Jul 2024 16:08:05 -0700 Subject: [PATCH 4/6] nit --- dev_tools/modules.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dev_tools/modules.py b/dev_tools/modules.py index b684300955f..07299940f4c 100644 --- a/dev_tools/modules.py +++ b/dev_tools/modules.py @@ -160,9 +160,9 @@ def replace_version(search_dir: Path = _DEFAULT_SEARCH_DIR, *, old: str, new: st for m in list_modules(search_dir=search_dir, include_parent=True): version_file = _find_version_file(search_dir / m.root) - content = version_file.read_text("UTF-8") - new_content = content.replace(old, new) - version_file.write_text(new_content) + _rewrite_version(version_file, old, new) + version_test = version_file.parent / "_version_test.py" + _rewrite_version(version_test, old, new) def _validate_version(new_version: str): @@ -170,6 +170,14 @@ def _validate_version(new_version: str): raise ValueError(f"{new_version} is not a valid version number.") +def _rewrite_version(version_file: Path, old: str, new: str) -> None: + pattern = f"(^[^#]*__version__ ==? )(['\"])({re.escape(old)})(\\2)" + repl = f"\\1\\g<2>{new}\\4" + content = version_file.read_text("UTF-8") + new_content = re.sub(pattern, repl, content, flags=re.MULTILINE) + version_file.write_text(new_content) + + def _find_version_file(top: Path) -> Path: for root, _, files in os.walk(str(top)): if "_version.py" in files: From bcf256a823d508c2d4ab71332fff15b03a0c96c1 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 9 Jul 2024 17:08:04 -0700 Subject: [PATCH 5/6] xfail --- cirq-core/cirq/ops/common_gates_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cirq-core/cirq/ops/common_gates_test.py b/cirq-core/cirq/ops/common_gates_test.py index fb878d5e508..c676ca4f68f 100644 --- a/cirq-core/cirq/ops/common_gates_test.py +++ b/cirq-core/cirq/ops/common_gates_test.py @@ -899,6 +899,8 @@ def test_cphase_unitary(angle_rads, expected_unitary): np.testing.assert_allclose(cirq.unitary(cirq.cphase(angle_rads)), expected_unitary) +# TODO(#6663): fix this use case. +@pytest.mark.xfail def test_parameterized_cphase(): assert cirq.cphase(sympy.pi) == cirq.CZ assert cirq.cphase(sympy.pi / 2) == cirq.CZ**0.5 From d6a26e3e5426c09608b1f5042fd7ddeac3675639 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Wed, 10 Jul 2024 11:15:18 -0700 Subject: [PATCH 6/6] typo --- dev_tools/conf/mypy.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev_tools/conf/mypy.ini b/dev_tools/conf/mypy.ini index 1206a0d8a20..bf12f103e86 100644 --- a/dev_tools/conf/mypy.ini +++ b/dev_tools/conf/mypy.ini @@ -1,5 +1,5 @@ [mypy] -exclude = dev_tools/modules_test_data/.*/setup\.py|cirq-rigetti/(?!__init__.)*\.py # Temperarly exclude cirq-rigetti (see #6661) +exclude = dev_tools/modules_test_data/.*/setup\.py|cirq-rigetti/(?!__init__.)*\.py # Temporarily exclude cirq-rigetti (see #6661) show_error_codes = true plugins = duet.typing warn_unused_ignores = true