From f28591de4e5c0f771ab4fc073812e7f382577960 Mon Sep 17 00:00:00 2001 From: MatteoRobbiati Date: Thu, 5 Oct 2023 10:25:47 +0200 Subject: [PATCH 1/3] fix parameters docs --- src/qibo/parameter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qibo/parameter.py b/src/qibo/parameter.py index 92f2821dbd..e32ba8b93a 100644 --- a/src/qibo/parameter.py +++ b/src/qibo/parameter.py @@ -5,7 +5,7 @@ def calculate_derivatives(func): - """Calculates derivatives w.r.t to all parameters of a target function `func`.""" + """Calculates derivatives w.r.t. to all parameters of a target function `func`.""" vars = [] for i in range(func.__code__.co_argcount): vars.append(sp.Symbol(f"p{i}")) @@ -47,7 +47,6 @@ class Parameter: described in the code example above. features (list or np.ndarray): array containing possible input features x. trainable (list or np.ndarray): array with initial trainable parameters theta. - nofeatures (bool): flag to explicitly ban the updating of the features. This simplifies the task of updating Parameter objects simultaneously when some have embedded features and some do not. """ def __init__(self, func, trainable=None, features=None): @@ -106,7 +105,7 @@ def nfeat(self): @property def ncomponents(self): - """Returns the number of elements which compose the Parameter""" + """Return the number of elements which compose the Parameter""" return self.nparams + self.nfeat def trainable_parameter_indices(self, start_index): From 91d81d41d91350385fdf46a6902ca6494741ae6e Mon Sep 17 00:00:00 2001 From: MatteoRobbiati Date: Thu, 5 Oct 2023 10:40:25 +0200 Subject: [PATCH 2/3] fix parameters docs and extend documentation --- doc/source/api-reference/qibo.rst | 18 ++++++++++++++++++ src/qibo/parameter.py | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/source/api-reference/qibo.rst b/doc/source/api-reference/qibo.rst index 574c4568c1..919c39baf6 100644 --- a/doc/source/api-reference/qibo.rst +++ b/doc/source/api-reference/qibo.rst @@ -1189,6 +1189,24 @@ variational model. :exclude-members: ParallelBFGS +.. _Parameter: + +Parameter +--------- + +It can be useful to define custom parameters in an optimization context. For +example, the rotational angles which encodes information in a Quantum Neural Network +are usually built as a combination of features and trainable parameters. For +doing this, the :class:`qibo.parameter.Parameter` class can be used. It allows +to define custom parameters which can be inserted into a :class:`qibo.models.circuit.Circuit`. +Moreover, it automatically precompute the analytical derivative of the parameter +function, which can be used to calculate the derivatives of a variational model +with respect to its parameters. + +.. automodule:: qibo.parameter + :members: + :member-order: bysource + .. _Gradients: Gradients diff --git a/src/qibo/parameter.py b/src/qibo/parameter.py index e32ba8b93a..64a99651f3 100644 --- a/src/qibo/parameter.py +++ b/src/qibo/parameter.py @@ -43,8 +43,8 @@ class Parameter: Args: func (function): lambda function which builds the gate parameter. If both features and trainable parameters - compose the function, it must be passed by first providing the features and then the parameters, as - described in the code example above. + compose the function, it must be passed by first providing the features and then the parameters, as + described in the code example above. features (list or np.ndarray): array containing possible input features x. trainable (list or np.ndarray): array with initial trainable parameters theta. """ From 56bcfa928b2caf58b3e72f7cb1dc1163a107b06b Mon Sep 17 00:00:00 2001 From: Matteo Robbiati <62071516+MatteoRobbiati@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:43:28 +0200 Subject: [PATCH 3/3] Update doc/source/api-reference/qibo.rst Co-authored-by: Alessandro Candido --- doc/source/api-reference/qibo.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/api-reference/qibo.rst b/doc/source/api-reference/qibo.rst index 919c39baf6..6a5e4c3c5b 100644 --- a/doc/source/api-reference/qibo.rst +++ b/doc/source/api-reference/qibo.rst @@ -1199,7 +1199,7 @@ example, the rotational angles which encodes information in a Quantum Neural Net are usually built as a combination of features and trainable parameters. For doing this, the :class:`qibo.parameter.Parameter` class can be used. It allows to define custom parameters which can be inserted into a :class:`qibo.models.circuit.Circuit`. -Moreover, it automatically precompute the analytical derivative of the parameter +Moreover, it automatically precomputes the analytical derivative of the parameter function, which can be used to calculate the derivatives of a variational model with respect to its parameters.