Skip to content

Commit

Permalink
Remove deprecated functions from ParameterView (#9184)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
jakelishman and mergify[bot] committed Nov 24, 2022
1 parent 479bde3 commit c063c91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 109 deletions.
109 changes: 0 additions & 109 deletions qiskit/circuit/parametertable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"""
Look-up table for variable parameters in QuantumCircuit.
"""
import functools
import warnings
from collections.abc import MappingView, MutableMapping, MutableSet


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

Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit c063c91

Please sign in to comment.