quri_parts.core.utils.differentiation module#

OperatorGenerator#

Represents a function that generates Operator from given parameters, e.g. generates molecular Hamiltonian from coordinates of atoms.

alias of Callable[[Sequence[float]], Operator]

OperatorGradientCalculator#

Represents a function that calculates the gradients of an operator at given parameters.

alias of Callable[[Sequence[float], Callable[[Sequence[float]], Operator]], Sequence[Operator]]

OperatorHessianCalculator#

Represents a function that calculates the hessian of an operator at given parameters.

alias of Callable[[Sequence[float], Callable[[Sequence[float]], Operator]], Sequence[Sequence[Operator]]]

class DifferentiableObjectProtocol(*args, **kwargs)#

Bases: Protocol

abstract __add__(other)#
Parameters:
  • self (_T) –

  • other (_T) –

Return type:

_T

abstract __sub__(other)#
Parameters:
  • self (_T) –

  • other (_T) –

Return type:

_T

abstract __truediv__(other)#
Parameters:
  • self (_T) –

  • other (int | float | complex) –

Return type:

_T

forward_difference_gradient_formula(f, params, step=1e-05)#

Returns the gradient of a passed function from params with two-point forward-difference formula.

Parameters:
  • f (Callable[[Sequence[float]], T]) –

  • params (Sequence[float]) –

  • step (float) –

Return type:

Sequence[T]

backward_difference_gradient_formula(f, params, step=1e-05)#

Returns the gradient of a passed function from params with two-point backward-difference formula.

Parameters:
  • f (Callable[[Sequence[float]], T]) –

  • params (Sequence[float]) –

  • step (float) –

Return type:

Sequence[T]

central_difference_gradient_formula(f, params, step=1e-05)#

Returns the gradient of a passed function from params with central- difference formula.

Parameters:
  • f (Callable[[Sequence[float]], T]) –

  • params (Sequence[float]) –

  • step (float) –

Return type:

Sequence[T]

forward_difference_hessian_formula(f, params, step=1e-05)#

Returns the hessian of a passed function from params with forward- difference formula.

Parameters:
  • f (Callable[[Sequence[float]], T]) –

  • params (Sequence[float]) –

  • step (float) –

Return type:

Sequence[Sequence[T]]

backward_difference_hessian_formula(f, params, step=1e-05)#

Returns the hessian of a passed function from params with backward- difference formula.

Parameters:
  • f (Callable[[Sequence[float]], T]) –

  • params (Sequence[float]) –

  • step (float) –

Return type:

Sequence[Sequence[T]]

central_difference_hessian_formula(f, params, step=1e-05)#

Returns the hessian of a passed function from params with central- difference formula.

Parameters:
  • f (Callable[[Sequence[float]], T]) –

  • params (Sequence[float]) –

  • step (float) –

Return type:

Sequence[Sequence[T]]

gradient(f, params, step=1e-05)#

Returns the gradient of a passed function from params with central- difference formula.

Parameters:
  • f (Callable[[Sequence[float]], T]) –

  • params (Sequence[float]) –

  • step (float) –

Return type:

Sequence[T]

hessian(f, params, step=1e-05)#

Returns the hessian of a passed function from params with central- difference formula.

Parameters:
  • f (Callable[[Sequence[float]], T]) –

  • params (Sequence[float]) –

  • step (float) –

Return type:

Sequence[Sequence[T]]

numerical_operator_gradient(params, operator_generator, difference_formula=<function central_difference_gradient_formula>, step=1e-05, atol=1e-08)#

Function that returns the numerical gradient of an Operator with respect to the operator parameters.

Parameters:
  • params (Sequence[float]) – Parameters at which the gradient is calculated.

  • operator_generator (core.utils.differentiation.OperatorGenerator) – OperatorGenerator.

  • difference_formula (Callable[[Callable[[Sequence[float]], Operator], Sequence[float], float], Sequence[Operator]]) – Method to calculate gradients.

  • step (float) – Step size for difference_formula.

  • atol (float) – Absolute tolerance. Terms whose coefficients are smaller than atol will be ignored.

Return type:

Sequence[Operator]

numerical_operator_hessian(params, operator_generator, difference_formula=<function central_difference_hessian_formula>, step=1e-05, atol=1e-08)#

Function that returns the numerical hessian of an Operator with respect to the operator parameters.

Parameters:
  • params (Sequence[float]) – Parameters at which the hessian is calculated.

  • operator_generator (core.utils.differentiation.OperatorGenerator) – OperatorGenerator.

  • difference_formula (Callable[[Callable[[Sequence[float]], Operator], Sequence[float], float], Sequence[Sequence[Operator]]]) – Method to calculate hessian.

  • step (float) – Step size for difference_formula.

  • atol (float) – Absolute tolerance. Terms whose coefficients are smaller than atol will be ignored.

Return type:

Sequence[Sequence[Operator]]