qiboml.differentiations package#

Submodules#

qiboml.differentiations.abstract module#

class qiboml.differentiations.abstract.Differentiation(circuit: Optional[Circuit] = None, decoding: Optional[QuantumDecoding] = None, _is_built: bool = False)[source]#

Bases: ABC

Abstract differentiator object.

circuit: Optional[Circuit] = None#
decoding: Optional[QuantumDecoding] = None#
_is_built: bool = False#
build(circuit: Circuit, decoding: QuantumDecoding)[source]#

Attach model internals and prepare compiled artifacts.

_on_build() None[source]#
abstract evaluate(parameters: Union[_Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[bool | int | float | complex | str | bytes]], 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#
nparams(wrt_inputs)[source]#
_abc_impl = <_abc._abc_data object>#

qiboml.differentiations.adjoint module#

class qiboml.differentiations.adjoint.Adjoint(circuit: Optional[Circuit] = None, decoding: Optional[QuantumDecoding] = None, _is_built: bool = False)[source]#

Bases: Differentiation

Adjoint differentiation following Algorithm 1 from Ref [1].

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.

References

1. T. Jones and J. Gacon, Efficient calculation of gradients in classical simulations of variational quantum algorithms, arxiv:2009.02823 [quant-ph].

evaluate(parameters: Union[_Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[bool | int | float | complex | str | bytes]], wrt_inputs: bool = False) Union[_Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[bool | int | float | complex | str | bytes]][source]#

Evaluate the gradient of the quantum circuit w.r.t its parameters, i.e. its rotation angles.

Parameters:
  • parameters (List[ArrayLike]) – 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:

ArrayLike

_abc_impl = <_abc._abc_data object>#
_is_built: bool = False#
_on_build() None#
property backend#
build(circuit: Circuit, decoding: QuantumDecoding)#

Attach model internals and prepare compiled artifacts.

circuit: Optional[Circuit] = None#
decoding: Optional[QuantumDecoding] = None#
property non_trainable_gates#
nparams(wrt_inputs)#

qiboml.differentiations.jax module#

class qiboml.differentiations.jax.Jax(circuit: Circuit, decoding: QuantumDecoding)[source]#

Bases: Differentiation

static _run(circuit: Circuit, decoding: QuantumDecoding, *parameters)[source]#
static _run_with_inputs(circuit: Circuit, decoding: QuantumDecoding, *parameters)[source]#
property circuit#
property decoding#
_abc_impl = <_abc._abc_data object>#
_cast_non_trainable_parameters(src_backend: Backend, tgt_backend: Backend)[source]#
_is_built: bool = False#
_on_build() None#
property backend#
build(circuit: Circuit, decoding: QuantumDecoding)#

Attach model internals and prepare compiled artifacts.

property non_trainable_gates#
nparams(wrt_inputs)#
evaluate(parameters: list[Union[numpy._typing._array_like._Buffer, numpy._typing._array_like._SupportsArray[numpy.dtype[Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes]]], 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.

Parameters:
  • parameters (list[ArrayLike]) – the parameters at which to evaluate the circuit, and thus the derivatives.

  • wrt_inputs (bool) – whether to calculate the derivative with respect to, also, inputs (i.e. encoding angles) or not. Defaults to False.

Returns:

the calculated jacobian.

Return type:

ArrayLike

qiboml.differentiations.psr module#

class qiboml.differentiations.psr.PSR(circuit: Optional[Circuit] = None, decoding: Optional[QuantumDecoding] = None, _is_built: bool = False)[source]#

Bases: Differentiation

The Parameter Shift Rule differentiator. Especially useful for non analytical derivative calculation which, thus, makes it hardware compatible.

_on_build()[source]#
evaluate(parameters: Union[_Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[bool | int | float | complex | str | bytes]], 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[ArrayLike] :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: (ArrayLike)

one_parameter_shift(parameters: Union[_Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[bool | int | float | complex | str | bytes]], 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.

static shift_parameter(parameters, i, epsilon, backend)[source]#
_abc_impl = <_abc._abc_data object>#
_is_built: bool = False#
property backend#
build(circuit: Circuit, decoding: QuantumDecoding)#

Attach model internals and prepare compiled artifacts.

circuit: Optional[Circuit] = None#
decoding: Optional[QuantumDecoding] = None#
property non_trainable_gates#
nparams(wrt_inputs)#

qiboml.differentiations.quimb module#

class qiboml.differentiations.quimb.QuimbJax(circuit: Optional[Circuit] = None, decoding: Optional[QuantumDecoding] = None, _is_built: bool = False, **quimb_kwargs)[source]#

Bases: Jax

_compile_jacobians()[source]#
static _run(circuit: Circuit, decoding: QuantumDecoding, *parameters)[source]#
static _run_with_inputs(circuit: Circuit, decoding: QuantumDecoding, *parameters)[source]#
_abc_impl = <_abc._abc_data object>#
_cast_non_trainable_parameters(src_backend: Backend, tgt_backend: Backend)#
_is_built: bool = False#
_on_build() None#
property backend#
build(circuit: Circuit, decoding: QuantumDecoding)#

Attach model internals and prepare compiled artifacts.

property circuit#
property decoding#
evaluate(parameters: list[Union[numpy._typing._array_like._Buffer, numpy._typing._array_like._SupportsArray[numpy.dtype[Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes]]], wrt_inputs: bool = False)#

Evaluate the jacobian of the internal quantum model (circuit + decoding) w.r.t to its parameters, i.e. the parameterized gates in the circuit.

Parameters:
  • parameters (list[ArrayLike]) – the parameters at which to evaluate the circuit, and thus the derivatives.

  • wrt_inputs (bool) – whether to calculate the derivative with respect to, also, inputs (i.e. encoding angles) or not. Defaults to False.

Returns:

the calculated jacobian.

Return type:

ArrayLike

property non_trainable_gates#
nparams(wrt_inputs)#
_jax: Backend#