Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cross-references to Terra and QML objects in docstrings #700

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def __init__(
) -> None:
"""
Args:
quantum_kernel: a quantum kernel to be used for classification. Has to be ``None`` when
a precomputed kernel is used.
quantum_kernel: A subclass of :class:`~qiskit_machine_learning.kernels.BaseKernel`
desmonty marked this conversation as resolved.
Show resolved Hide resolved
to be used for classification.
Has to be ``None`` when a precomputed kernel is used.
C: Positive regularization parameter. The strength of the regularization is inversely
proportional to C. Smaller ``C`` induce smaller weights which generally helps
preventing overfitting. However, due to the nature of this algorithm, some of the
Expand All @@ -87,9 +88,7 @@ def __init__(
ValueError:
- if ``quantum_kernel`` is passed and ``precomputed`` is set to ``True``. To use
a precomputed kernel, ``quantum_kernel`` has to be of the ``None`` type.
TypeError:
- if ``quantum_kernel`` neither instance of
:class:`~qiskit_machine_learning.kernels.BaseKernel` nor ``None``.
- if C is not a positive number.
"""

if precomputed:
Expand Down
4 changes: 3 additions & 1 deletion qiskit_machine_learning/algorithms/classifiers/qsvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class QSVC(SVC, SerializableModelMixin):
def __init__(self, *, quantum_kernel: Optional[BaseKernel] = None, **kwargs):
"""
Args:
quantum_kernel: Quantum kernel to be used for classification.
quantum_kernel: A subclass of :class:`~qiskit_machine_learning.kernels.BaseKernel`
to be used for classification.
If None, default to :class:`~qiskit_machine_learning.kernels.FidelityQuantumKernel`.
desmonty marked this conversation as resolved.
Show resolved Hide resolved
*args: Variable length argument list to pass to SVC constructor.
**kwargs: Arbitrary keyword arguments to pass to SVC constructor.
"""
Expand Down
10 changes: 6 additions & 4 deletions qiskit_machine_learning/algorithms/classifiers/vqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ def __init__(
The number of qubits in the feature map and ansatz are adjusted to this
number if required.
feature_map: The (parametrized) circuit to be used as a feature map for the underlying
QNN. If ``None`` is given, the ``ZZFeatureMap`` is used if the number of qubits
is larger than 1. For a single qubit classification problem the ``ZFeatureMap``
QNN. If ``None`` is given, the :class:`~qiskit.circuit.library.ZZFeatureMap`
is used if the number of qubits is larger than 1. For a single qubit
classification problem the :class:`~qiskit.circuit.library.ZFeatureMap`
is used by default.
ansatz: The (parametrized) circuit to be used as an ansatz for the underlying
QNN. If ``None`` is given then the ``RealAmplitudes`` circuit is used.
ansatz: The (parametrized) circuit to be used as an ansatz for the underlying QNN.
If ``None`` is given then the :class:`~qiskit.circuit.library.RealAmplitudes`
circuit is used.
loss: A target loss function to be used in training. Default value is ``cross_entropy``.
optimizer: An instance of an optimizer or a callable to be used in training.
Refer to :class:`~qiskit_algorithms.optimizers.Minimizer` for more information on
Expand Down
4 changes: 3 additions & 1 deletion qiskit_machine_learning/algorithms/regressors/qsvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class QSVR(SVR, SerializableModelMixin):
def __init__(self, *, quantum_kernel: Optional[BaseKernel] = None, **kwargs):
"""
Args:
quantum_kernel: Quantum kernel to be used for regression.
quantum_kernel: A subclass of :class:`~qiskit_machine_learning.kernels.BaseKernel`
to be used for regression.
If None, default to :class:`~qiskit_machine_learning.kernels.FidelityQuantumKernel`.
*args: Variable length argument list to pass to SVR constructor.
**kwargs: Arbitrary keyword arguments to pass to SVR constructor.
"""
Expand Down
2 changes: 1 addition & 1 deletion qiskit_machine_learning/datasets/ad_hoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def ad_hoc_data(
np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray
]:
r"""Generates a toy dataset that can be fully separated with
``qiskit.circuit.library.ZZ_Feature_Map`` according to the procedure
:class:`~qiskit.circuit.library.ZZFeatureMap` according to the procedure
outlined in [1]. To construct the dataset, we first sample uniformly
distributed vectors :math:`\vec{x} \in (0, 2\pi]^{n}` and apply the
feature map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class FidelityStatevectorKernel(BaseKernel):

K(x,y) = |\langle \phi(x) | \phi(y) \rangle|^2.

In this implementation, :math:`|\phi(y)\rangle` is given by a ``Statevector.data`` array. These
In this implementation, :math:`|\phi(y)\rangle` is given by a
:attr:`qiskit.quantum_info.Statevector.data` array. These
woodsp-ibm marked this conversation as resolved.
Show resolved Hide resolved
arrays are stored in a statevector cache to avoid repeated evaluation of the quantum circuit.
This cache can be cleared using :meth:`clear_cache`. By default the cache is cleared when
:meth:`evaluate` is called, unless ``auto_clear_cache`` is ``False``.
Expand Down
11 changes: 6 additions & 5 deletions qiskit_machine_learning/utils/adjust_num_qubits.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ def derive_num_qubits_feature_map_ansatz(
Derives a correct number of qubits, feature map, and ansatz from the parameters.

If the number of qubits is not ``None``, then the feature map and ansatz are adjusted to this
number of qubits if required. If such an adjustment fails, an error is raised.
Also, if the feature map or ansatz or both are ``None``, then ``ZZFeatureMap`` and
``RealAmplitudes`` are created respectively. If there's just one qubit, ``ZFeatureMap`` is
created instead.
number of qubits if required. If such an adjustment fails, an error is raised. Also, if the
feature map or ansatz or both are ``None``, then :class:`~qiskit.circuit.library.ZZFeatureMap`
and :class:`~qiskit.circuit.library.RealAmplitudes` are created respectively. If there's just
one qubit, :class:`~qiskit.circuit.library.ZFeatureMap` is created instead.

If the number of qubits is ``None``, then the number of qubits is derived from the feature map
or ansatz. Both the feature map and ansatz in this case must have the same number of qubits.
If the number of qubits of the feature map is not the same as the number of qubits of
the ansatz, an error is raised. If only one of the feature map and ansatz are ``None``, then
``ZZFeatureMap`` or ``RealAmplitudes`` are created respectively.
:class:`~qiskit.circuit.library.ZZFeatureMap` or :class:`~qiskit.circuit.library.RealAmplitudes`
are created respectively.

If all the parameters are none an error is raised.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def evaluate(

Args:
parameter_values: an array of values to assign to the user params
quantum_kernel: A ``QuantumKernel`` object to evaluate
quantum_kernel: A :class:`~qiskit_machine_learning.kernels.BaseKernel` object
desmonty marked this conversation as resolved.
Show resolved Hide resolved
to evaluate
data: An ``(N, M)`` matrix containing the data
``N = # samples, M = dimension of data``
labels: A length-N array containing the truth labels
Expand Down