Skip to content

Commit

Permalink
Remove positional arguments in QSVC/QSVR (#535)
Browse files Browse the repository at this point in the history
* remove positional arguments

* add reno
  • Loading branch information
adekusar-drl authored Dec 1, 2022
1 parent aae9172 commit 089ec0e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
12 changes: 2 additions & 10 deletions qiskit_machine_learning/algorithms/classifiers/qsvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,13 @@ class QSVC(SVC, SerializableModelMixin):
qsvc.predict(sample_test)
"""

def __init__(self, *args, quantum_kernel: Optional[BaseKernel] = None, **kwargs):
def __init__(self, *, quantum_kernel: Optional[BaseKernel] = None, **kwargs):
"""
Args:
quantum_kernel: Quantum kernel to be used for classification.
*args: Variable length argument list to pass to SVC constructor.
**kwargs: Arbitrary keyword arguments to pass to SVC constructor.
"""
if (len(args)) != 0:
msg = (
f"Positional arguments ({args}) are deprecated as of version 0.3.0 and "
f"will be removed no sooner than 3 months after the release. Instead use "
f"keyword arguments."
)
warnings.warn(msg, DeprecationWarning, stacklevel=2)

if "kernel" in kwargs:
msg = (
"'kernel' argument is not supported and will be discarded, "
Expand All @@ -71,7 +63,7 @@ def __init__(self, *args, quantum_kernel: Optional[BaseKernel] = None, **kwargs)
if "random_state" not in kwargs:
kwargs["random_state"] = algorithm_globals.random_seed

super().__init__(kernel=self._quantum_kernel.evaluate, *args, **kwargs)
super().__init__(kernel=self._quantum_kernel.evaluate, **kwargs)

@property
def quantum_kernel(self) -> BaseKernel:
Expand Down
12 changes: 2 additions & 10 deletions qiskit_machine_learning/algorithms/regressors/qsvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,13 @@ class QSVR(SVR, SerializableModelMixin):
qsvr.predict(sample_test)
"""

def __init__(self, *args, quantum_kernel: Optional[BaseKernel] = None, **kwargs):
def __init__(self, *, quantum_kernel: Optional[BaseKernel] = None, **kwargs):
"""
Args:
quantum_kernel: Quantum kernel to be used for regression.
*args: Variable length argument list to pass to SVR constructor.
**kwargs: Arbitrary keyword arguments to pass to SVR constructor.
"""
if (len(args)) != 0:
msg = (
f"Positional arguments ({args}) are deprecated as of version 0.3.0 and "
f"will be removed no sooner than 3 months after the release. Instead use "
f"keyword arguments."
)
warnings.warn(msg, DeprecationWarning, stacklevel=2)

if "kernel" in kwargs:
msg = (
"'kernel' argument is not supported and will be discarded, "
Expand All @@ -67,7 +59,7 @@ def __init__(self, *args, quantum_kernel: Optional[BaseKernel] = None, **kwargs)

self._quantum_kernel = quantum_kernel if quantum_kernel else FidelityQuantumKernel()

super().__init__(kernel=self._quantum_kernel.evaluate, *args, **kwargs)
super().__init__(kernel=self._quantum_kernel.evaluate, **kwargs)

@property
def quantum_kernel(self) -> BaseKernel:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
deprecations:
- |
Positional arguments in :class:`~qiskit_machine_learning.algorithms.QSVC` and
:class:`~qiskit_machine_learning.algorithms.QSVR` were deprecated as of version 0.3. Support of
the positional arguments was completely removed in this version, please replace them with
corresponding keyword arguments.

0 comments on commit 089ec0e

Please sign in to comment.