Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove gatesets deprecations. #5679

Merged
merged 7 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cirq-google/cirq_google/engine/abstract_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions cirq-google/cirq_google/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions cirq-google/cirq_google/engine/engine_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,7 +28,6 @@
processor_sampler,
util,
)
from cirq_google.serialization import serializer

if TYPE_CHECKING:
import cirq_google as cg
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions cirq-google/cirq_google/engine/simulated_local_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 0 additions & 23 deletions cirq-google/cirq_google/engine/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
20 changes: 4 additions & 16 deletions cirq-google/cirq_google/engine/virtual_engine_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand Down