Skip to content

Commit 698b9f0

Browse files
authored
[Docs] Fix TOCs and update QNN derived primitives (#862)
* Fix docs and update QNN derived primitives * Fix LearningRate in TOCs * Fix string formatting * Fix spelling * Fix spelling * Fix spelling * Fix copyright
1 parent 3b912a8 commit 698b9f0

File tree

18 files changed

+148
-113
lines changed

18 files changed

+148
-113
lines changed

.pylintdict

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ dp
123123
dt
124124
125125
eda
126+
edaspy
126127
egger
127128
eigen
128129
eigenphase
@@ -576,6 +577,7 @@ vatan
576577
vec
577578
vectorized
578579
veeravalli
580+
vicente
579581
vicentini
580582
vigo
581583
ville
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _qiskit-machine-learning-gradients:
2+
3+
.. automodule:: qiskit_machine_learning.gradients
4+
:no-members:
5+
:no-inherited-members:
6+
:no-special-members:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _qiskit-machine-learning-optimizers:
2+
3+
.. automodule:: qiskit_machine_learning.optimizers
4+
:no-members:
5+
:no-inherited-members:
6+
:no-special-members:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _qiskit-machine-learning-state_fidelities:
2+
3+
.. automodule:: qiskit_machine_learning.state_fidelities
4+
:no-members:
5+
:no-inherited-members:
6+
:no-special-members:

qiskit_machine_learning/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737
circuit.library
3838
connectors
3939
datasets
40+
gradients
4041
kernels
4142
neural_networks
43+
optimizers
44+
state_fidelities
4245
utils
4346
4447
"""

qiskit_machine_learning/algorithms/__init__.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,8 @@
5353
5454
PegasosQSVC
5555
QSVC
56-
NeuralNetworkClassifier
5756
VQC
58-
59-
Inference
60-
+++++++++++
61-
Algorithms for inference.
62-
63-
.. autosummary::
64-
:toctree: ../stubs/
65-
:nosignatures:
66-
67-
QBayesian
57+
NeuralNetworkClassifier
6858
6959
Regressors
7060
++++++++++
@@ -75,9 +65,18 @@
7565
:nosignatures:
7666
7767
QSVR
78-
NeuralNetworkRegressor
7968
VQR
69+
NeuralNetworkRegressor
70+
71+
Inference
72+
+++++++++++
73+
Algorithms for inference.
8074
75+
.. autosummary::
76+
:toctree: ../stubs/
77+
:nosignatures:
78+
79+
QBayesian
8180
"""
8281
from .trainable_model import TrainableModel
8382
from .serializable_model import SerializableModelMixin

qiskit_machine_learning/algorithms/trainable_model.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
class TrainableModel(SerializableModelMixin):
35-
"""Base class for ML model that defines a scikit-learn like interface for Estimators."""
35+
"""Base class for ML model that defines a scikit-learn-like interface for `Estimator` instances."""
3636

3737
# pylint: disable=too-many-positional-arguments
3838
def __init__(
@@ -46,10 +46,10 @@ def __init__(
4646
):
4747
"""
4848
Args:
49-
neural_network: An instance of an quantum neural network. If the neural network has a
49+
neural_network: An instance of a quantum neural network. If the neural network has a
5050
one-dimensional output, i.e., `neural_network.output_shape=(1,)`, then it is
5151
expected to return values in [-1, +1] and it can only be used for binary
52-
classification. If the output is multi-dimensional, it is assumed that the result
52+
classification. If the output is multidimensional, it is assumed that the result
5353
is a probability distribution, i.e., that the entries are non-negative and sum up
5454
to one. Then there are two options, either one-hot encoding or not. In case of
5555
one-hot encoding, each probability vector resulting a neural network is considered

qiskit_machine_learning/circuit/library/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2020, 2023.
3+
# (C) Copyright IBM 2020, 2024.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -19,7 +19,7 @@
1919
2020
.. currentmodule:: qiskit_machine_learning.circuit.library
2121
22-
Feature Maps
22+
Feature maps
2323
------------
2424
2525
.. autosummary::
@@ -29,7 +29,7 @@
2929
3030
RawFeatureVector
3131
32-
Helper Circuits
32+
Helper circuits
3333
---------------
3434
3535
.. autosummary::

qiskit_machine_learning/connectors/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2021, 2023.
3+
# (C) Copyright IBM 2021, 2024.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -14,7 +14,7 @@
1414
Connectors (:mod:`qiskit_machine_learning.connectors`)
1515
======================================================
1616
17-
Connectors from Qiskit Machine Learning to other frameworks.
17+
"Connector" tools to couple Qiskit Machine Learning to other frameworks.
1818
1919
.. currentmodule:: qiskit_machine_learning.connectors
2020

qiskit_machine_learning/datasets/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2019, 2023.
3+
# (C) Copyright IBM 2019, 2024.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -14,7 +14,7 @@
1414
Datasets (:mod:`qiskit_machine_learning.datasets`)
1515
==================================================
1616
17-
A set of sample datasets suitable for machine learning problems
17+
A set of sample datasets to test machine learning algorithms.
1818
1919
.. currentmodule:: qiskit_machine_learning.datasets
2020

qiskit_machine_learning/gradients/__init__.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
"""
13+
r"""
1414
Gradients (:mod:`qiskit_machine_learning.gradients`)
15-
==============================================
16-
Algorithms to calculate the gradient of a quantum circuit.
15+
====================================================
16+
17+
Algorithms to calculate the gradient of a cost landscape to optimize a given objective function.
1718
1819
.. currentmodule:: qiskit_machine_learning.gradients
1920
@@ -29,7 +30,7 @@
2930
EstimatorGradientResult
3031
SamplerGradientResult
3132
32-
Linear Combination of Unitaries
33+
Linear combination of unitaries
3334
-------------------------------
3435
3536
.. autosummary::
@@ -39,7 +40,7 @@
3940
LinCombEstimatorGradient
4041
LinCombSamplerGradient
4142
42-
Parameter Shift Rules
43+
Parameter-shift rules
4344
---------------------
4445
4546
.. autosummary::
@@ -49,7 +50,7 @@
4950
ParamShiftEstimatorGradient
5051
ParamShiftSamplerGradient
5152
52-
Simultaneous Perturbation Stochastic Approximation
53+
Simultaneous perturbation stochastic approximation
5354
--------------------------------------------------
5455
5556
.. autosummary::

qiskit_machine_learning/neural_networks/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2019, 2023.
3+
# (C) Copyright IBM 2019, 2024.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -36,7 +36,7 @@
3636
3737
NeuralNetwork
3838
39-
Neural Networks
39+
Neural networks
4040
---------------
4141
4242
.. autosummary::
@@ -46,8 +46,8 @@
4646
EstimatorQNN
4747
SamplerQNN
4848
49-
Neural Network Metrics
50-
----------------------
49+
Metrics for neural networks
50+
---------------------------
5151
5252
.. autosummary::
5353
:toctree: ../stubs/

qiskit_machine_learning/neural_networks/estimator_qnn.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,25 @@ def __init__(
120120
):
121121
r"""
122122
Args:
123-
estimator: The estimator used to compute neural network's results.
124-
If ``None``, a default instance of the reference estimator,
125-
:class:`~qiskit.primitives.Estimator`, will be used.
126123
circuit: The quantum circuit to represent the neural network. If a
127124
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is passed, the
128-
`input_params` and `weight_params` do not have to be provided, because these two
125+
``input_params`` and ``weight_params`` do not have to be provided, because these two
129126
properties are taken from the
130127
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit`.
128+
estimator: The estimator used to compute neural network's results.
129+
If ``None``, a default instance of the reference estimator,
130+
:class:`~qiskit.primitives.Estimator`, will be used.
131+
132+
.. warning::
133+
134+
The assignment ``estimator=None`` defaults to using
135+
:class:`~qiskit.primitives.Estimator`, which points to a deprecated estimator V1
136+
(as of Qiskit 1.2). ``EstimatorQNN`` will adopt Estimator V2 as default no later than
137+
Qiskit Machine Learning 0.9.
138+
131139
observables: The observables for outputs of the neural network. If ``None``,
132-
use the default :math:`Z^{\otimes num\_qubits}` observable.
140+
use the default :math:`Z^{\otimes n}` observable, where :math:`n`
141+
is the number of qubits.
133142
input_params: The parameters that correspond to the input data of the network.
134143
If ``None``, the input data is not bound to any parameters.
135144
If a :class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is provided the
@@ -139,9 +148,10 @@ def __init__(
139148
If ``None``, the weights are not bound to any parameters.
140149
If a :class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is provided the
141150
`weight_params` value here is ignored. Instead, the value is taken from the
142-
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` weight_parameters.
151+
`weight_parameters` associated with
152+
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit`.
143153
gradient: The estimator gradient to be used for the backward pass.
144-
If None, a default instance of the estimator gradient,
154+
If ``None``, a default instance of the estimator gradient,
145155
:class:`~qiskit_machine_learning.gradients.ParamShiftEstimatorGradient`, will be used.
146156
input_gradients: Determines whether to compute gradients with respect to input data.
147157
Note that this parameter is ``False`` by default, and must be explicitly set to
@@ -152,7 +162,6 @@ def __init__(
152162
Defaults to ``None``, as some primitives do not need transpiled circuits.
153163
Raises:
154164
QiskitMachineLearningError: Invalid parameter values.
155-
QiskitMachineLearningError: Gradient is required if
156165
"""
157166
if estimator is None:
158167
estimator = Estimator()

qiskit_machine_learning/neural_networks/sampler_qnn.py

+45-32
Original file line numberDiff line numberDiff line change
@@ -143,39 +143,52 @@ def __init__(
143143
input_gradients: bool = False,
144144
pass_manager: BasePassManager | None = None,
145145
):
146-
"""
147-
Args: sampler: The sampler primitive used to compute the neural network's results. If
148-
``None`` is given, a default instance of the reference sampler defined by
149-
:class:`~qiskit.primitives.Sampler` will be used. circuit: The parametrized quantum
150-
circuit that generates the samples of this network. If a
151-
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is passed,
152-
the `input_params` and `weight_params` do not have to be provided, because these two
153-
properties are taken from the :class:`~qiskit_machine_learning.circuit.library.QNNCircuit
154-
`. input_params: The parameters of the circuit corresponding to the input. If a
155-
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is provided the
156-
`input_params` value here is ignored. Instead, the value is taken from the
157-
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` input_parameters.
158-
weight_params: The parameters of the circuit corresponding to the trainable weights. If a
159-
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is provided the
160-
`weight_params` value here is ignored. Instead, the value is taken from the
161-
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` weight_parameters. sparse:
162-
Returns whether the output is sparse or not. interpret: A callable that maps the measured
163-
integer to another unsigned integer or tuple of unsigned integers. These are used as new
164-
indices for the (potentially sparse) output array. If no interpret function is passed,
165-
then an identity function will be used by this neural network. output_shape: The output
166-
shape of the custom interpretation. For SamplerV1, it is ignored if no custom interpret
167-
method is provided where the shape is taken to be ``2^circuit.num_qubits``. gradient: An
168-
optional sampler gradient to be used for the backward pass. If ``None`` is given,
169-
a default instance of
170-
:class:`~qiskit_machine_learning.gradients.ParamShiftSamplerGradient` will be used.
171-
input_gradients: Determines whether to compute gradients with respect to input data. Note
172-
that this parameter is ``False`` by default, and must be explicitly set to ``True`` for a
173-
proper gradient computation when using
174-
:class:`~qiskit_machine_learning.connectors.TorchConnector`.
175-
pass_manager: The pass manager to transpile the circuits, if necessary.
176-
Defaults to ``None``, as some primitives do not need transpiled circuits.
146+
r"""
147+
Args:
148+
circuit: The parametrized quantum
149+
circuit that generates the samples of this network. If a
150+
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is passed,
151+
the `input_params` and `weight_params` do not have to be provided, because these two
152+
properties are taken from the
153+
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit`.
154+
sampler: The sampler primitive used to compute the neural network's results. If
155+
``None`` is given, a default instance of the reference sampler defined by
156+
:class:`~qiskit.primitives.Sampler` will be used.
157+
158+
.. warning::
159+
160+
The assignment ``sampler=None`` defaults to using
161+
:class:`~qiskit.primitives.Sampler`, which points to a deprecated Sampler V1
162+
(as of Qiskit 1.2). ``SamplerQNN`` will adopt Sampler V2 as default no later than
163+
Qiskit Machine Learning 0.9.
164+
165+
input_params: The parameters of the circuit corresponding to the input. If a
166+
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is provided the
167+
`input_params` value here is ignored. Instead, the value is taken from the
168+
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` input_parameters.
169+
weight_params: The parameters of the circuit corresponding to the trainable weights. If a
170+
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is provided the
171+
`weight_params` value here is ignored. Instead, the value is taken from the
172+
:class:`~qiskit_machine_learning.circuit.library.QNNCircuit` ``weight_parameters``.
173+
sparse: Returns whether the output is sparse or not.
174+
interpret: A callable that maps the measured integer to another unsigned integer or tuple
175+
of unsigned integers. These are used as new indices for the (potentially sparse)
176+
output array. If no interpret function is passed, then an identity function will be
177+
used by this neural network.
178+
output_shape: The output shape of the custom interpretation. For SamplerV1, it is ignored
179+
if no custom interpret method is provided where the shape is taken to be
180+
``2^circuit.num_qubits``.
181+
gradient: An optional sampler gradient to be used for the backward pass. If ``None`` is
182+
given, a default instance of
183+
:class:`~qiskit_machine_learning.gradients.ParamShiftSamplerGradient` will be used.
184+
input_gradients: Determines whether to compute gradients with respect to input data. Note
185+
that this parameter is ``False`` by default, and must be explicitly set to ``True``
186+
for a proper gradient computation when using
187+
:class:`~qiskit_machine_learning.connectors.TorchConnector`.
188+
pass_manager: The pass manager to transpile the circuits, if necessary.
189+
Defaults to ``None``, as some primitives do not need transpiled circuits.
177190
Raises:
178-
QiskitMachineLearningError: Invalid parameter values.
191+
QiskitMachineLearningError: Invalid parameter values.
179192
"""
180193
# set primitive, provide default
181194
if sampler is None:

0 commit comments

Comments
 (0)