Skip to content

Commit

Permalink
Remove key protocol frozenset conversion (#5660)
Browse files Browse the repository at this point in the history
Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
  • Loading branch information
daxfohl and CirqBot authored Jul 7, 2022
1 parent 446b7ec commit 2657c53
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 64 deletions.
15 changes: 1 addition & 14 deletions cirq-core/cirq/protocols/act_on_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from typing_extensions import Protocol

from cirq import _compat, ops
from cirq import ops
from cirq._doc import doc_private
from cirq.type_workarounds import NotImplementedType

Expand Down Expand Up @@ -86,19 +86,6 @@ def _act_on_(
"""


def _fix_deprecated_args(args, kwargs):
kwargs['sim_state'] = kwargs['args']
del kwargs['args']
return args, kwargs


@_compat.deprecated_parameter(
deadline='v0.16',
fix='Change argument name to `sim_state`',
parameter_desc='args',
match=lambda args, kwargs: 'args' in kwargs,
rewrite=_fix_deprecated_args,
)
def act_on(
action: Any,
sim_state: 'cirq.SimulationStateBase',
Expand Down
6 changes: 0 additions & 6 deletions cirq-core/cirq/protocols/act_on_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,3 @@ def test_qubits_should_be_defined_for_operations():
state = DummySimulationState()
with pytest.raises(ValueError, match='Calls to act_on should'):
cirq.act_on(cirq.KrausChannel([np.array([[1, 0], [0, 0]])]), state, qubits=None)


def test_args_deprecated():
args = DummySimulationState(fallback_result=True)
with cirq.testing.assert_deprecated(deadline='v0.16'):
cirq.act_on(action=op, args=args) # pylint: disable=no-value-for-parameter
7 changes: 0 additions & 7 deletions cirq-core/cirq/protocols/control_key_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from typing_extensions import Protocol

from cirq import _compat
from cirq._doc import doc_private
from cirq.protocols import measurement_key_protocol
from cirq.type_workarounds import NotImplementedType
Expand Down Expand Up @@ -58,12 +57,6 @@ def control_keys(val: Any) -> FrozenSet['cirq.MeasurementKey']:
getter = getattr(val, '_control_keys_', None)
result = NotImplemented if getter is None else getter()
if result is not NotImplemented and result is not None:
if not isinstance(result, FrozenSet):
_compat._warn_or_error(
f'The _control_keys_ implementation of {type(val)} must return a'
f' frozenset instead of {type(result)} by v0.16.'
)
return frozenset(result)
return result

return frozenset()
Expand Down
9 changes: 0 additions & 9 deletions cirq-core/cirq/protocols/control_key_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,3 @@ def _control_keys_(self):
assert cirq.control_keys(Named()) == {cirq.MeasurementKey('key')}
assert not cirq.control_keys(NoImpl())
assert not cirq.control_keys(5)


def test_control_key_enumerable_deprecated():
class Deprecated:
def _control_keys_(self):
return [cirq.MeasurementKey('key')]

with cirq.testing.assert_deprecated('frozenset', deadline='v0.16'):
assert cirq.control_keys(Deprecated()) == {cirq.MeasurementKey('key')}
14 changes: 1 addition & 13 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 import value, _compat
from cirq import value
from cirq._doc import doc_private
from cirq.type_workarounds import NotImplementedType

Expand Down Expand Up @@ -182,12 +182,6 @@ def _measurement_key_objs_from_magic_methods(
getter = getattr(val, '_measurement_key_objs_', None)
result = NotImplemented if getter is None else getter()
if result is not NotImplemented and result is not None:
if not isinstance(result, FrozenSet):
_compat._warn_or_error(
f'The _measurement_key_objs_ implementation of {type(val)} must return a'
f' frozenset instead of {type(result)} by v0.16.'
)
return frozenset(result)
return result

getter = getattr(val, '_measurement_key_obj_', None)
Expand All @@ -205,12 +199,6 @@ def _measurement_key_names_from_magic_methods(
getter = getattr(val, '_measurement_key_names_', None)
result = NotImplemented if getter is None else getter()
if result is not NotImplemented and result is not None:
if not isinstance(result, FrozenSet):
_compat._warn_or_error(
f'The _measurement_key_names_ implementation of {type(val)} must return a'
f' frozenset instead of {type(result)} by v0.16.'
)
return frozenset(result)
return result

getter = getattr(val, '_measurement_key_name_', None)
Expand Down
15 changes: 0 additions & 15 deletions cirq-core/cirq/protocols/measurement_key_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,3 @@ def _with_key_path_(self, path):
assert cirq.measurement_key_names(mkg_cd) == {'c:d:a', 'c:d:b'}

assert cirq.with_key_path(cirq.X, ('c', 'd')) is NotImplemented


def test_measurement_key_enumerable_deprecated():
class Deprecated:
def _measurement_key_objs_(self):
return [cirq.MeasurementKey('key')]

def _measurement_key_names_(self):
return ['key']

with cirq.testing.assert_deprecated('frozenset', deadline='v0.16'):
assert cirq.measurement_key_objs(Deprecated()) == {cirq.MeasurementKey('key')}

with cirq.testing.assert_deprecated('frozenset', deadline='v0.16'):
assert cirq.measurement_key_names(Deprecated()) == {'key'}

0 comments on commit 2657c53

Please sign in to comment.