Skip to content

Commit

Permalink
Flush missed v0.13 backlog items. (#4600)
Browse files Browse the repository at this point in the history
Missed these in the original flush here #4567
  • Loading branch information
MichaelBroughton authored Oct 26, 2021
1 parent 954a7b6 commit 009b3da
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 117 deletions.
2 changes: 0 additions & 2 deletions cirq-core/cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,8 @@
json_serializable_dataclass,
dataclass_json_dict,
kraus,
measurement_key,
measurement_key_name,
measurement_key_obj,
measurement_keys,
measurement_key_names,
measurement_key_objs,
mixture,
Expand Down
5 changes: 0 additions & 5 deletions cirq-core/cirq/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import numpy as np

import cirq._version
from cirq._compat import deprecated
from cirq import devices, ops, protocols, value, qis
from cirq.circuits._bucket_priority_queue import BucketPriorityQueue
from cirq.circuits.circuit_operation import CircuitOperation
Expand Down Expand Up @@ -915,10 +914,6 @@ def all_measurement_key_objs(self) -> AbstractSet[value.MeasurementKey]:
def _measurement_key_objs_(self) -> AbstractSet[value.MeasurementKey]:
return self.all_measurement_key_objs()

@deprecated(deadline='v0.13', fix='use all_measurement_key_names instead')
def all_measurement_keys(self) -> AbstractSet[str]:
return self.all_measurement_key_names()

def all_measurement_key_names(self) -> AbstractSet[str]:
return {key for op in self.all_operations() for key in protocols.measurement_key_names(op)}

Expand Down
3 changes: 0 additions & 3 deletions cirq-core/cirq/circuits/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4312,9 +4312,6 @@ def _measurement_key_name_(self):
assert c.all_measurement_key_names() == cirq.measurement_key_names(c)
assert c.all_measurement_key_names() == c.all_measurement_key_objs()

with cirq.testing.assert_deprecated(deadline="v0.13"):
assert c.all_measurement_key_names() == c.all_measurement_keys()

# Empty case.
assert circuit_cls().all_measurement_key_names() == set()

Expand Down
17 changes: 0 additions & 17 deletions cirq-core/cirq/ops/gate_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import numpy as np

from cirq import protocols, value
from cirq._compat import _warn_or_error
from cirq.ops import raw_types, gate_features
from cirq.type_workarounds import NotImplementedType

Expand Down Expand Up @@ -222,28 +221,12 @@ def _measurement_key_name_(self) -> Optional[str]:
getter = getattr(self.gate, '_measurement_key_name_', None)
if getter is not None:
return getter()
getter = getattr(self.gate, '_measurement_key_', None)
if getter is not None:
_warn_or_error(
f'_measurement_key_ was used but is deprecated.\n'
f'It will be removed in cirq v0.13.\n'
f'Use _measurement_key_name_ instead.\n'
)
return getter()
return NotImplemented

def _measurement_key_names_(self) -> Optional[AbstractSet[str]]:
getter = getattr(self.gate, '_measurement_key_names_', None)
if getter is not None:
return getter()
getter = getattr(self.gate, '_measurement_keys_', None)
if getter is not None:
_warn_or_error(
f'_measurement_keys_ was used but is deprecated.\n'
f'It will be removed in cirq v0.13.\n'
f'Use _measurement_key_names_ instead.\n'
)
return getter()
return NotImplemented

def _measurement_key_obj_(self) -> Optional[value.MeasurementKey]:
Expand Down
2 changes: 0 additions & 2 deletions cirq-core/cirq/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@
)
from cirq.protocols.measurement_key_protocol import (
is_measurement,
measurement_key,
measurement_key_name,
measurement_key_obj,
measurement_keys,
measurement_key_names,
measurement_key_objs,
with_key_path,
Expand Down
30 changes: 1 addition & 29 deletions cirq-core/cirq/protocols/measurement_key_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from typing_extensions import Protocol

from cirq._compat import deprecated, deprecated_parameter, _warn_or_error
from cirq._compat import deprecated_parameter
from cirq._doc import doc_private
from cirq import value

Expand Down Expand Up @@ -100,11 +100,6 @@ def _with_measurement_key_mapping_(self, key_map: Dict[str, str]):
"""


@deprecated(deadline='v0.13', fix='use cirq.measurement_key_name instead')
def measurement_key(val: Any, default: Any = RaiseTypeErrorIfNotProvided):
return measurement_key_name(val, default)


def measurement_key_obj(val: Any, default: Any = RaiseTypeErrorIfNotProvided):
"""Get the single measurement key object for the given value.
Expand Down Expand Up @@ -198,38 +193,15 @@ def _measurement_key_names_from_magic_methods(val: Any) -> Optional[AbstractSet[
result = NotImplemented if getter is None else getter()
if result is not NotImplemented and result is not None:
return set(result)
getter = getattr(val, '_measurement_keys_', None)
result = NotImplemented if getter is None else getter()
if result is not NotImplemented and result is not None:
_warn_or_error(
f'_measurement_keys_ was used but is deprecated.\n'
f'It will be removed in cirq v0.13.\n'
f'Use _measurement_key_names_ instead.\n'
)
return set(result)

getter = getattr(val, '_measurement_key_name_', None)
result = NotImplemented if getter is None else getter()
if result is not NotImplemented and result is not None:
return {result}
getter = getattr(val, '_measurement_key_', None)
result = NotImplemented if getter is None else getter()
if result is not NotImplemented and result is not None:
_warn_or_error(
f'_measurement_key_ was used but is deprecated.\n'
f'It will be removed in cirq v0.13.\n'
f'Use _measurement_key_name_ instead.\n'
)
return {result}

return result


@deprecated(deadline='v0.13', fix='use cirq.measurement_key_names instead')
def measurement_keys(val: Any, *, allow_decompose: bool = True):
return measurement_key_names(val, allow_decompose=allow_decompose)


def measurement_key_objs(val: Any) -> AbstractSet[value.MeasurementKey]:
"""Gets the measurement key objects of measurements within the given value.
Expand Down
59 changes: 0 additions & 59 deletions cirq-core/cirq/protocols/measurement_key_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,49 +49,6 @@ def test_measurement_key_obj(gate):
assert cirq.measurement_key_obj(gate, 'a') == 'door locker'


@pytest.mark.parametrize('gate', [ReturnsStr(), ReturnsObj()])
def test_measurement_key_deprecated(gate):
with cirq.testing.assert_deprecated(deadline="v0.13"):
assert isinstance(cirq.measurement_key(gate), str)

with cirq.testing.assert_deprecated(deadline="v0.13"):
assert cirq.measurement_key(gate) == cirq.MeasurementKey(name='door locker')

with cirq.testing.assert_deprecated(deadline="v0.13"):
assert cirq.measurement_key(gate) == 'door locker'

with cirq.testing.assert_deprecated(deadline="v0.13"):
assert cirq.measurement_key(gate, None) == 'door locker'

with cirq.testing.assert_deprecated(deadline="v0.13"):
assert cirq.measurement_key(gate, NotImplemented) == 'door locker'

with cirq.testing.assert_deprecated(deadline="v0.13"):
assert cirq.measurement_key(gate, 'a') == 'door locker'


@pytest.mark.parametrize('key_method', [cirq.measurement_key_name, cirq.measurement_key_obj])
def test_measurement_key_magic_method_deprecated(key_method):
class DeprecatedMagicMethod(cirq.SingleQubitGate):
def _measurement_key_(self):
return 'door locker'

gate = DeprecatedMagicMethod()
with cirq.testing.assert_deprecated(deadline="v0.13"):
assert key_method(gate) == 'door locker'
with cirq.testing.assert_deprecated(deadline="v0.13"):
assert key_method(gate.on(cirq.LineQubit(0))) == 'door locker'

with cirq.testing.assert_deprecated(deadline="v0.13"):
assert key_method(gate, None) == 'door locker'

with cirq.testing.assert_deprecated(deadline="v0.13"):
assert key_method(gate, NotImplemented) == 'door locker'

with cirq.testing.assert_deprecated(deadline="v0.13"):
assert key_method(gate, 'a') == 'door locker'


@pytest.mark.parametrize('key_method', [cirq.measurement_key_name, cirq.measurement_key_obj])
def test_measurement_key_no_method(key_method):
class NoMethod:
Expand Down Expand Up @@ -223,22 +180,6 @@ def num_qubits(self) -> int:
assert key_method(MeasurementKeysGate().on(a)) == keys


@pytest.mark.parametrize('key_method', [cirq.measurement_key_names, cirq.measurement_key_objs])
def test_measurement_keys_magic_method_deprecated(key_method):
class DeprecatedMagicMethod(cirq.Gate):
def _measurement_keys_(self):
return ['a', 'b']

def num_qubits(self) -> int:
return 1

a = cirq.LineQubit(0)
with cirq.testing.assert_deprecated(deadline="v0.13"):
assert key_method(DeprecatedMagicMethod()) == {'a', 'b'}
with cirq.testing.assert_deprecated(deadline="v0.13"):
assert key_method(DeprecatedMagicMethod().on(a)) == {'a', 'b'}


def test_measurement_keys_allow_decompose_deprecated():
a = cirq.LineQubit(0)
with cirq.testing.assert_deprecated(deadline="v0.14"):
Expand Down

0 comments on commit 009b3da

Please sign in to comment.