From b7a52cf79d6dad006de5168a78d08bc97409dbe8 Mon Sep 17 00:00:00 2001 From: Michael Broughton Date: Thu, 7 Jul 2022 13:30:40 -0700 Subject: [PATCH 1/4] Remove gatesets deprecations. --- cirq-google/cirq_google/engine/abstract_processor.py | 3 +-- cirq-google/cirq_google/engine/engine.py | 2 -- cirq-google/cirq_google/engine/engine_processor.py | 3 +-- .../cirq_google/engine/simulated_local_processor.py | 3 +-- cirq-google/cirq_google/engine/virtual_engine_factory.py | 8 -------- 5 files changed, 3 insertions(+), 16 deletions(-) diff --git a/cirq-google/cirq_google/engine/abstract_processor.py b/cirq-google/cirq_google/engine/abstract_processor.py index fc0aff01e1e..58658f2ed93 100644 --- a/cirq-google/cirq_google/engine/abstract_processor.py +++ b/cirq-google/cirq_google/engine/abstract_processor.py @@ -262,8 +262,7 @@ def get_device_specification(self) -> Optional[v2.device_pb2.DeviceSpecification """ @abc.abstractmethod - @util.deprecated_get_device_gate_sets_parameter() - def get_device(self, gate_sets: Iterable['serializer.Serializer'] = ()) -> cirq.Device: + def get_device(self) -> cirq.Device: """Returns a `Device` created from the processor's device specification. This method queries the processor to retrieve the device specification, diff --git a/cirq-google/cirq_google/engine/engine.py b/cirq-google/cirq_google/engine/engine.py index 29e816a8c7e..ac780b8c60f 100644 --- a/cirq-google/cirq_google/engine/engine.py +++ b/cirq-google/cirq_google/engine/engine.py @@ -826,11 +826,9 @@ def get_engine(project_id: Optional[str] = None) -> Engine: return Engine(project_id=project_id, service_args=service_args) -@util.deprecated_get_device_gate_sets_parameter(param_name='gatesets') def get_engine_device( processor_id: str, project_id: Optional[str] = None, - gatesets: Iterable[SerializableGateSet] = (), ) -> cirq.Device: """Returns a `Device` object for a given processor. diff --git a/cirq-google/cirq_google/engine/engine_processor.py b/cirq-google/cirq_google/engine/engine_processor.py index fcb43a4757b..8b4c7cbbdd5 100644 --- a/cirq-google/cirq_google/engine/engine_processor.py +++ b/cirq-google/cirq_google/engine/engine_processor.py @@ -314,8 +314,7 @@ def get_device_specification(self) -> Optional[v2.device_pb2.DeviceSpecification else: return None - @util.deprecated_get_device_gate_sets_parameter() - def get_device(self, gate_sets: Iterable[serializer.Serializer] = ()) -> cirq.Device: + def get_device(self) -> cirq.Device: """Returns a `Device` created from the processor's device specification. This method queries the processor to retrieve the device specification, diff --git a/cirq-google/cirq_google/engine/simulated_local_processor.py b/cirq-google/cirq_google/engine/simulated_local_processor.py index 5e7bfe4a4b5..750c324339a 100644 --- a/cirq-google/cirq_google/engine/simulated_local_processor.py +++ b/cirq-google/cirq_google/engine/simulated_local_processor.py @@ -126,8 +126,7 @@ def get_latest_calibration(self, timestamp: int) -> Optional[calibration.Calibra def get_current_calibration(self) -> Optional[calibration.Calibration]: return self.get_latest_calibration(int(datetime.datetime.now().timestamp())) - @util.deprecated_get_device_gate_sets_parameter() - def get_device(self, gate_sets: Iterable['Serializer'] = ()) -> cirq.Device: + def get_device(self) -> cirq.Device: """Returns a `Device` created from the processor's device specification. This method queries the processor to retrieve the device specification, diff --git a/cirq-google/cirq_google/engine/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index 7ecca420d05..a1ffb160309 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -205,11 +205,9 @@ def create_noiseless_virtual_engine_from_device( return SimulatedLocalEngine([_create_virtual_processor_from_device(processor_id, device)]) -@util.deprecated_get_device_gate_sets_parameter() def create_noiseless_virtual_processor_from_proto( processor_id: str, device_specification: v2.device_pb2.DeviceSpecification, - gate_sets: Optional[Iterable[serializable_gate_set.SerializableGateSet]] = None, ) -> SimulatedLocalProcessor: """Creates a simulated local processor from a device specification proto. @@ -230,13 +228,11 @@ def create_noiseless_virtual_processor_from_proto( return processor -@util.deprecated_get_device_gate_sets_parameter() def create_noiseless_virtual_engine_from_proto( processor_ids: Union[str, List[str]], device_specifications: Union[ v2.device_pb2.DeviceSpecification, List[v2.device_pb2.DeviceSpecification] ], - gate_sets: Optional[Iterable[serializable_gate_set.SerializableGateSet]] = None, ) -> SimulatedLocalEngine: """Creates a noiseless virtual engine object from a device specification proto. @@ -298,11 +294,9 @@ def create_device_from_processor_id(processor_id: str) -> cirq.Device: return grid_device.GridDevice.from_proto(device_specification) -@util.deprecated_get_device_gate_sets_parameter() def create_noiseless_virtual_processor_from_template( processor_id: str, template_name: str, - gate_sets: Optional[Iterable[serializable_gate_set.SerializableGateSet]] = None, ) -> SimulatedLocalProcessor: """Creates a simulated local processor from a device specification template. @@ -319,11 +313,9 @@ def create_noiseless_virtual_processor_from_template( ) -@util.deprecated_get_device_gate_sets_parameter() def create_noiseless_virtual_engine_from_templates( processor_ids: Union[str, List[str]], template_names: Union[str, List[str]], - gate_sets: Optional[Iterable[serializable_gate_set.SerializableGateSet]] = None, ) -> SimulatedLocalEngine: """Creates a noiseless virtual engine object from a device specification template. From c4314213caacd277087a3d86d2a222c4faf5a3c4 Mon Sep 17 00:00:00 2001 From: Michael Broughton Date: Thu, 7 Jul 2022 13:37:13 -0700 Subject: [PATCH 2/4] format. --- cirq-google/cirq_google/engine/engine.py | 5 +---- cirq-google/cirq_google/engine/util.py | 22 ------------------- .../engine/virtual_engine_factory.py | 9 +++----- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/cirq-google/cirq_google/engine/engine.py b/cirq-google/cirq_google/engine/engine.py index ac780b8c60f..c3ddde7a741 100644 --- a/cirq-google/cirq_google/engine/engine.py +++ b/cirq-google/cirq_google/engine/engine.py @@ -826,10 +826,7 @@ def get_engine(project_id: Optional[str] = None) -> Engine: return Engine(project_id=project_id, service_args=service_args) -def get_engine_device( - processor_id: str, - project_id: Optional[str] = None, -) -> cirq.Device: +def get_engine_device(processor_id: str, project_id: Optional[str] = None) -> cirq.Device: """Returns a `Device` object for a given processor. This is a short-cut for creating an engine object, getting the diff --git a/cirq-google/cirq_google/engine/util.py b/cirq-google/cirq_google/engine/util.py index efccb441607..9ba9f8c32ec 100644 --- a/cirq-google/cirq_google/engine/util.py +++ b/cirq-google/cirq_google/engine/util.py @@ -44,25 +44,3 @@ def pack_any(message: Message) -> any_pb2.Any: def unpack_any(message: any_pb2.Any, out: M) -> M: message.Unpack(out) return out - - -def deprecated_get_device_gate_sets_parameter(param_name='gate_sets'): - """Decorates get device functions, which take a deprecated 'gate_sets' parameter.""" - - def decorator(func): - signature = inspect.signature(func) - gate_sets_param = signature.parameters[param_name] - assert gate_sets_param.default == () or gate_sets_param.default is None - idx = list(signature.parameters).index(param_name) - - deprecation_decorator = cirq._compat.deprecated_parameter( - deadline='v0.16', - fix='Specifying gate_sets is no longer necessary to get a device.' - ' Remove the gate_sets parameter.', - parameter_desc=param_name, - match=lambda args, kwargs: param_name in kwargs - or (gate_sets_param.kind != inspect.Parameter.KEYWORD_ONLY and len(args) > idx), - ) - return deprecation_decorator(func) - - return decorator diff --git a/cirq-google/cirq_google/engine/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index a1ffb160309..e93ab42f7cb 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -206,8 +206,7 @@ def create_noiseless_virtual_engine_from_device( def create_noiseless_virtual_processor_from_proto( - processor_id: str, - device_specification: v2.device_pb2.DeviceSpecification, + processor_id: str, device_specification: v2.device_pb2.DeviceSpecification ) -> SimulatedLocalProcessor: """Creates a simulated local processor from a device specification proto. @@ -295,8 +294,7 @@ def create_device_from_processor_id(processor_id: str) -> cirq.Device: def create_noiseless_virtual_processor_from_template( - processor_id: str, - template_name: str, + processor_id: str, template_name: str ) -> SimulatedLocalProcessor: """Creates a simulated local processor from a device specification template. @@ -314,8 +312,7 @@ def create_noiseless_virtual_processor_from_template( def create_noiseless_virtual_engine_from_templates( - processor_ids: Union[str, List[str]], - template_names: Union[str, List[str]], + processor_ids: Union[str, List[str]], template_names: Union[str, List[str]] ) -> SimulatedLocalEngine: """Creates a noiseless virtual engine object from a device specification template. From 671cf76de8ac1fa9ac5a2b6c80391a2cb447b522 Mon Sep 17 00:00:00 2001 From: Michael Broughton Date: Thu, 7 Jul 2022 14:43:42 -0700 Subject: [PATCH 3/4] lint. --- cirq-google/cirq_google/engine/abstract_processor.py | 4 ++-- cirq-google/cirq_google/engine/engine.py | 4 ++-- cirq-google/cirq_google/engine/engine_processor.py | 3 +-- cirq-google/cirq_google/engine/simulated_local_processor.py | 4 ++-- cirq-google/cirq_google/engine/util.py | 1 - cirq-google/cirq_google/engine/virtual_engine_factory.py | 3 +-- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/cirq-google/cirq_google/engine/abstract_processor.py b/cirq-google/cirq_google/engine/abstract_processor.py index 58658f2ed93..40326f5ac76 100644 --- a/cirq-google/cirq_google/engine/abstract_processor.py +++ b/cirq-google/cirq_google/engine/abstract_processor.py @@ -21,13 +21,13 @@ import abc import datetime -from typing import Dict, Iterable, List, Optional, Sequence, TYPE_CHECKING, Union +from typing import Dict, List, Optional, Sequence, TYPE_CHECKING, Union import cirq from cirq_google.api import v2 from cirq_google.cloud import quantum -from cirq_google.engine import calibration, util +from cirq_google.engine import calibration if TYPE_CHECKING: import cirq_google as cg diff --git a/cirq-google/cirq_google/engine/engine.py b/cirq-google/cirq_google/engine/engine.py index c3ddde7a741..fa6ef501285 100644 --- a/cirq-google/cirq_google/engine/engine.py +++ b/cirq-google/cirq_google/engine/engine.py @@ -27,7 +27,7 @@ import enum import random import string -from typing import Dict, Iterable, List, Optional, Sequence, Set, TypeVar, Union, TYPE_CHECKING +from typing import Dict, List, Optional, Sequence, Set, TypeVar, Union, TYPE_CHECKING import duet import google.auth @@ -47,7 +47,7 @@ ) from cirq_google.cloud import quantum from cirq_google.engine.result_type import ResultType -from cirq_google.serialization import CIRCUIT_SERIALIZER, SerializableGateSet, Serializer +from cirq_google.serialization import CIRCUIT_SERIALIZER, Serializer from cirq_google.serialization.arg_func_langs import arg_to_proto if TYPE_CHECKING: diff --git a/cirq-google/cirq_google/engine/engine_processor.py b/cirq-google/cirq_google/engine/engine_processor.py index 8b4c7cbbdd5..650d01a16d8 100644 --- a/cirq-google/cirq_google/engine/engine_processor.py +++ b/cirq-google/cirq_google/engine/engine_processor.py @@ -13,7 +13,7 @@ # limitations under the License. import datetime -from typing import Dict, Iterable, List, Optional, Sequence, TYPE_CHECKING, Union +from typing import Dict, List, Optional, Sequence, TYPE_CHECKING, Union from google.protobuf import any_pb2 @@ -28,7 +28,6 @@ processor_sampler, util, ) -from cirq_google.serialization import serializer if TYPE_CHECKING: import cirq_google as cg diff --git a/cirq-google/cirq_google/engine/simulated_local_processor.py b/cirq-google/cirq_google/engine/simulated_local_processor.py index 750c324339a..8b8ba64edd5 100644 --- a/cirq-google/cirq_google/engine/simulated_local_processor.py +++ b/cirq-google/cirq_google/engine/simulated_local_processor.py @@ -13,12 +13,12 @@ # limitations under the License. import datetime -from typing import Dict, Iterable, List, Optional, Sequence, TYPE_CHECKING, Union +from typing import Dict, List, Optional, Sequence, TYPE_CHECKING, Union import cirq from cirq_google.api import v2 -from cirq_google.engine import calibration, util, validating_sampler +from cirq_google.engine import calibration, validating_sampler from cirq_google.engine.abstract_local_processor import AbstractLocalProcessor from cirq_google.engine.abstract_local_program import AbstractLocalProgram from cirq_google.engine.abstract_program import AbstractProgram diff --git a/cirq-google/cirq_google/engine/util.py b/cirq-google/cirq_google/engine/util.py index 9ba9f8c32ec..a9b03595bc9 100644 --- a/cirq-google/cirq_google/engine/util.py +++ b/cirq-google/cirq_google/engine/util.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import inspect from typing import Dict, Tuple, TypeVar from google.protobuf import any_pb2 diff --git a/cirq-google/cirq_google/engine/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index e93ab42f7cb..2c88862d72d 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -14,7 +14,7 @@ """Functions to instantiate SimulatedLocalEngines to simulate various Google Devices.""" import json -from typing import cast, Iterable, List, Optional, Union, Type +from typing import cast, List, Union, Type import pathlib import time @@ -25,7 +25,6 @@ from cirq_google.engine import calibration, engine_validator, simulated_local_processor, util from cirq_google.devices import grid_device from cirq_google.devices.google_noise_properties import NoiseModelFromGoogleNoiseProperties -from cirq_google.serialization import serializable_gate_set from cirq_google.engine.calibration_to_noise_properties import noise_properties_from_calibration from cirq_google.engine.simulated_local_engine import SimulatedLocalEngine from cirq_google.engine.simulated_local_processor import SimulatedLocalProcessor From 98c6f3a3a972ab327cad7a8a793c591a7f0029d0 Mon Sep 17 00:00:00 2001 From: Michael Broughton Date: Tue, 12 Jul 2022 15:36:15 -0700 Subject: [PATCH 4/4] Remove unused iterable. --- cirq-google/cirq_google/engine/abstract_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirq-google/cirq_google/engine/abstract_processor.py b/cirq-google/cirq_google/engine/abstract_processor.py index 2733433a620..07f58c7b651 100644 --- a/cirq-google/cirq_google/engine/abstract_processor.py +++ b/cirq-google/cirq_google/engine/abstract_processor.py @@ -20,7 +20,7 @@ import abc import datetime -from typing import Dict, Iterable, List, Optional, Sequence, TYPE_CHECKING, Union +from typing import Dict, List, Optional, Sequence, TYPE_CHECKING, Union import duet