qiboml.differentiation#
- class qiboml.operations.differentiation.Differentiation(circuit: Circuit, decoding: QuantumDecoding)[source]#
Bases:
ABCAbstract differentiator object.
- circuit: Circuit#
- decoding: QuantumDecoding#
- abstract evaluate(parameters: ndarray[tuple[int, ...], dtype[_ScalarType_co]], wrt_inputs: bool = False)[source]#
Evaluate the gradient of the quantum circuit w.r.t its parameters, i.e. its rotation angles.
- property backend#
- property non_trainable_gates#
- _abc_impl = <_abc._abc_data object>#
- class qiboml.operations.differentiation.PSR(circuit: Circuit, decoding: QuantumDecoding)[source]#
Bases:
DifferentiationThe Parameter Shift Rule differentiator. Especially useful for non analytical derivative calculation which, thus, makes it hardware compatible.
- evaluate(parameters: ndarray[tuple[int, ...], dtype[_ScalarType_co]], wrt_inputs: bool = False)[source]#
Evaluate the gradient of the quantum circuit w.r.t its parameters, i.e. its rotation angles. :param parameters: the parameters at which to evaluate the model, and thus the derivative. :type parameters: List[ndarray] :param wrt_inputs: whether to calculate the derivative with respect to, also, inputs (i.e. encoding angles) :type wrt_inputs: bool
or not, by default
False. :returns: the calculated jacobian. :rtype: (ndarray)
- one_parameter_shift(parameters: ndarray[tuple[int, ...], dtype[_ScalarType_co]], parameter_index: int, wrt_inputs: bool = False) Tuple[Circuit, Circuit, float][source]#
Compute one derivative of the decoding strategy w.r.t. a target parameter.
- _abc_impl = <_abc._abc_data object>#
- property backend#
- property non_trainable_gates#
- nparams(wrt_inputs)#
- circuit: Circuit#
- decoding: QuantumDecoding#
- class qiboml.operations.differentiation.Adjoint(circuit: Circuit, decoding: QuantumDecoding)[source]#
Bases:
DifferentiationAdjoint differentiation following Algorithm 1 from https://arxiv.org/abs/2009.02823. Only
qiboml.models.decoding.Expectation. as decoding is supported and all parametrized_gates must have a gradient method returning the gradient of the single gate.- evaluate(parameters: ndarray[tuple[int, ...], dtype[_ScalarType_co]], wrt_inputs: bool = False)[source]#
Evaluate the gradient of the quantum circuit w.r.t its parameters, i.e. its rotation angles. :param parameters: the parameters at which to evaluate the model, and thus the derivative. :type parameters: List[ndarray] :param wrt_inputs: whether to calculate the derivate with respect to inputs or not, by default
False. :type wrt_inputs: bool- Returns:
the calculated gradients.
- Return type:
(ndarray)
- _abc_impl = <_abc._abc_data object>#
- property backend#
- property non_trainable_gates#
- nparams(wrt_inputs)#
- circuit: Circuit#
- decoding: QuantumDecoding#
- class qiboml.operations.differentiation.Jax(circuit: Circuit, decoding: QuantumDecoding)[source]#
Bases:
Differentiation- property circuit#
- property decoding#
- _abc_impl = <_abc._abc_data object>#
- property backend#
- property non_trainable_gates#
- nparams(wrt_inputs)#
- evaluate(parameters, wrt_inputs: bool = False)[source]#
Evaluate the jacobian of the internal quantum model (circuit + decoding) w.r.t to its
parameters, i.e. the parameterized gates in the circuit. :param parameters: the parameters at which to evaluate the circuit, and thus the derivatives. :type parameters: list[ndarray] :param wrt_inputs: whether to calculate the derivative with respect to, also, inputs (i.e. encoding angles) :type wrt_inputs: boolor not, by default
False. :returns: the calculated jacobian. :rtype: (ndarray)