qiboml.differentiation#
- class qiboml.operations.differentiation.Differentiation[source]#
Bases:
ABC
Abstract differentiator object.
- abstract evaluate(x: ndarray[Any, dtype[_ScalarType_co]], encoding: QuantumEncoding, training: Circuit, decoding: QuantumDecoding, backend: Backend, *parameters: list[numpy.ndarray[typing.Any, numpy.dtype[+_ScalarType_co]]], wrt_inputs: bool = False)[source]#
Evaluate the gradient of a quantum model w.r.t inputs and parameters, respectively represented by x and parameters.
- Parameters:
x (ndarray) – the input data.
encoding (QunatumEncoding) – the encoding layer.
training (Circuit) – the trainable quantum circuit.
decoding (QunatumDecoding) – the decoding layer.
backend (Backend) – the backend to execute the circuit with.
parameters (list[ndarray]) – the parameters at which to evaluate the model, and thus the derivative.
wrt_inputs (bool) – whether to calculate the derivate with respect to inputs or not, by default
False
.
- Returns:
the calculated gradients.
- Return type:
(list[ndarray])
- _abc_impl = <_abc._abc_data object>#
- class qiboml.operations.differentiation.PSR[source]#
Bases:
Differentiation
The Parameter Shift Rule differentiatior. Especially useful for non analytical derivative calculation which, thus, makes it hardware compatible.
- evaluate(x: ndarray[Any, dtype[_ScalarType_co]], encoding: QuantumEncoding, training: Circuit, decoding: QuantumDecoding, backend: Backend, *parameters: list[numpy.ndarray[typing.Any, numpy.dtype[+_ScalarType_co]]], wrt_inputs: bool = False)[source]#
Evaluate the gradient of a quantum model w.r.t inputs and parameters, respectively represented by x and parameters.
- Parameters:
x (ndarray) – the input data.
encoding (QunatumEncoding) – the encoding layer.
training (Circuit) – the trainable quantum circuit.
decoding (QunatumDecoding) – the decoding layer.
backend (Backend) – the backend to execute the circuit with.
parameters (list[ndarray]) – the parameters at which to evaluate the model, and thus the derivative.
wrt_inputs (bool) – whether to calculate the derivate with respect to inputs or not, by default
False
.
- Returns:
the calculated gradients.
- Return type:
(list[ndarray])
- one_parameter_shift(circuit, decoding, parameters, parameter_index, backend)[source]#
Compute one derivative of the decoding strategy w.r.t. a target parameter.
- _abc_impl = <_abc._abc_data object>#
- class qiboml.operations.differentiation.Jax[source]#
Bases:
Differentiation
The Jax differentiator object. Particularly useful for enabling gradient calculation in those backends that do not provide it. Note however, that for this reason the circuit is executed with the JaxBackend whenever a derivative is needed
- evaluate(x: ndarray[Any, dtype[_ScalarType_co]], encoding: QuantumEncoding, circuit: Circuit, decoding: QuantumDecoding, backend: Backend, *parameters: list[numpy.ndarray[typing.Any, numpy.dtype[+_ScalarType_co]]], wrt_inputs: bool = False)[source]#
Evaluate the gradient of a quantum model w.r.t inputs and parameters, respectively represented by x and parameters.
- Parameters:
x (ndarray) – the input data.
encoding (QunatumEncoding) – the encoding layer.
training (Circuit) – the trainable quantum circuit.
decoding (QunatumDecoding) – the decoding layer.
backend (Backend) – the backend to execute the circuit with.
parameters (list[ndarray]) – the parameters at which to evaluate the model, and thus the derivative.
wrt_inputs (bool) – whether to calculate the derivate with respect to inputs or not, by default
False
.
- Returns:
the calculated gradients.
- Return type:
(list[ndarray])
- _abc_impl = <_abc._abc_data object>#