From 7912e35b1a19f95b2607a5853dfd390ff4617649 Mon Sep 17 00:00:00 2001 From: MichaelBroughton Date: Tue, 12 Jul 2022 16:28:06 -0700 Subject: [PATCH] Remove gatesets deprecations. (#5679) --- .../cirq_google/engine/abstract_processor.py | 7 +++--- cirq-google/cirq_google/engine/engine.py | 11 +++------ .../cirq_google/engine/engine_processor.py | 6 ++--- .../engine/simulated_local_processor.py | 7 +++--- cirq-google/cirq_google/engine/util.py | 23 ------------------- .../engine/virtual_engine_factory.py | 20 ++++------------ 6 files changed, 15 insertions(+), 59 deletions(-) diff --git a/cirq-google/cirq_google/engine/abstract_processor.py b/cirq-google/cirq_google/engine/abstract_processor.py index baa8f66a576..07f58c7b651 100644 --- a/cirq-google/cirq_google/engine/abstract_processor.py +++ b/cirq-google/cirq_google/engine/abstract_processor.py @@ -20,14 +20,14 @@ 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 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 @@ -282,8 +282,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 fd2097c2025..bd884797b4d 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: @@ -835,12 +835,7 @@ 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: +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/engine_processor.py b/cirq-google/cirq_google/engine/engine_processor.py index 3cb9a3bb966..eeecc91f73f 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 @@ -314,8 +313,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 84f2b77002e..27198f0616f 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 @@ -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/util.py b/cirq-google/cirq_google/engine/util.py index efccb441607..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 @@ -44,25 +43,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 dddffd427d2..7c7cc299eaa 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 @@ -205,11 +204,8 @@ 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, + processor_id: str, device_specification: v2.device_pb2.DeviceSpecification ) -> SimulatedLocalProcessor: """Creates a simulated local processor from a device specification proto. @@ -230,13 +226,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 +292,8 @@ 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, + processor_id: str, template_name: str ) -> SimulatedLocalProcessor: """Creates a simulated local processor from a device specification template. @@ -319,11 +310,8 @@ 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, + processor_ids: Union[str, List[str]], template_names: Union[str, List[str]] ) -> SimulatedLocalEngine: """Creates a noiseless virtual engine object from a device specification template.