From c063c91df0daa04ca44cb2ae415d3bb001722be9 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Thu, 24 Nov 2022 18:20:06 +0000 Subject: [PATCH] Remove deprecated functions from `ParameterView` (#9184) * Remove deprecated functions from `ParameterView` These were deprecated since Terra 0.17, when the type of the return changed. * Restore non-deprecated function Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- qiskit/circuit/parametertable.py | 109 ------------------ ...ecated-parameterview-cc08100049605b73.yaml | 6 + 2 files changed, 6 insertions(+), 109 deletions(-) create mode 100644 releasenotes/notes/remove-deprecated-parameterview-cc08100049605b73.yaml diff --git a/qiskit/circuit/parametertable.py b/qiskit/circuit/parametertable.py index 0fd00951eb49..d3318b0b6c3c 100644 --- a/qiskit/circuit/parametertable.py +++ b/qiskit/circuit/parametertable.py @@ -12,8 +12,6 @@ """ Look-up table for variable parameters in QuantumCircuit. """ -import functools -import warnings from collections.abc import MappingView, MutableMapping, MutableSet @@ -162,30 +160,6 @@ def __repr__(self): return f"ParameterTable({repr(self._table)})" -def _deprecated_set_method(): - def deprecate(func): - @functools.wraps(func) - def wrapper(*args, **kwargs): - # warn only once - if not wrapper._warned: - warnings.warn( - f"The ParameterView.{func.__name__} method is deprecated as of " - "Qiskit Terra 0.17.0 and will be removed no sooner than 3 months " - "after the release date. Circuit parameters are returned as View " - "object, not set. To use set methods you can explicitly cast to a " - "set.", - DeprecationWarning, - stacklevel=2, - ) - wrapper._warned = True - return func(*args, **kwargs) - - wrapper._warned = False - return wrapper - - return deprecate - - class ParameterView(MappingView): """Temporary class to transition from a set return-type to list. @@ -201,81 +175,14 @@ def __init__(self, iterable=None): super().__init__(self.data) - @_deprecated_set_method() - def add(self, x): - """Add a new element.""" - if x not in self.data: - self.data.append(x) - def copy(self): """Copy the ParameterView.""" return self.__class__(self.data.copy()) - @_deprecated_set_method() - def difference(self, *s): - """Get the difference between self and the input.""" - return self.__sub__(s) - - @_deprecated_set_method() - def difference_update(self, *s): - """Get the difference between self and the input in-place.""" - for element in self: - if element in s: - self.remove(element) - - @_deprecated_set_method() - def discard(self, x): - """Remove an element from self.""" - if x in self: - self.remove(x) - - @_deprecated_set_method() - def intersection(self, *x): - """Get the intersection between self and the input.""" - return self.__and__(x) - - @_deprecated_set_method() - def intersection_update(self, *x): - """Get the intersection between self and the input in-place.""" - return self.__iand__(x) - def isdisjoint(self, x): """Check whether self and the input are disjoint.""" return not any(element in self for element in x) - @_deprecated_set_method() - def issubset(self, x): - """Check whether self is a subset of the input.""" - return self.__le__(x) - - @_deprecated_set_method() - def issuperset(self, x): - """Check whether self is a superset of the input.""" - return self.__ge__(x) - - @_deprecated_set_method() - def symmetric_difference(self, x): - """Get the symmetric difference of self and the input.""" - return self.__xor__(x) - - @_deprecated_set_method() - def symmetric_difference_update(self, x): - """Get the symmetric difference of self and the input in-place.""" - backward = x.difference(self) - self.difference_update(x) - self.update(backward) - - @_deprecated_set_method() - def union(self, *x): - """Get the union of self and the input.""" - return self.__or__(x) - - @_deprecated_set_method() - def update(self, *x): - """Update self with the input.""" - for element in x: - self.add(element) - def remove(self, x): """Remove an existing element from the view.""" self.data.remove(x) @@ -316,30 +223,14 @@ def __or__(self, x): """Get the union of self and the input.""" return set(self) | set(x) - def __ior__(self, x): - """Update self with the input.""" - self.update(*x) - return self - def __sub__(self, x): """Get the difference between self and the input.""" return set(self) - set(x) - @_deprecated_set_method() - def __isub__(self, x): - """Get the difference between self and the input in-place.""" - return self.difference_update(*x) - def __xor__(self, x): """Get the symmetric difference between self and the input.""" return set(self) ^ set(x) - @_deprecated_set_method() - def __ixor__(self, x): - """Get the symmetric difference between self and the input in-place.""" - self.symmetric_difference_update(x) - return self - def __ne__(self, other): return set(other) != set(self) diff --git a/releasenotes/notes/remove-deprecated-parameterview-cc08100049605b73.yaml b/releasenotes/notes/remove-deprecated-parameterview-cc08100049605b73.yaml new file mode 100644 index 000000000000..e98fb817bcd5 --- /dev/null +++ b/releasenotes/notes/remove-deprecated-parameterview-cc08100049605b73.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + Methods inherited from ``set`` have been removed from :class:`.ParameterView`, the type returned + by :attr:`.QuantumCircuit.parameters`. These were deprecated since Terra 0.17; this type has been + a general view type since then.