EquationOfMotion#

class EquationOfMotion(hamiltonian_func, hamiltonian_gradient_func)[source]#

Bases: Differentiable

Represents the equation of motion of a system, assumed to be of the form

\[\frac{d x}{d t} = A(t) x\]

with x a vector or more generally a matrix characterizing the system, and A(t) another time-dependent matrix.

Implementations can for example be the Schrödinger equation for a closed system, Lindbladian for an open system, or Hamilton’s equations for a classical system. As these always involve the definition of a Hamiltonian function this needs to be passed together with a function that returns its gradient. The get_value and get_gradient methods should return the value and the gradient of A(t).

__init__(hamiltonian_func, hamiltonian_gradient_func)[source]#
Parameters:
  • hamiltonian_func (Callable[[Array], Array]) – Function that returns the Hamiltonian at different times.

  • hamiltonian_gradient_func (Callable[[Array], Array]) – Function that returns the gradient of the Hamiltonian at different times.

Methods

__init__(hamiltonian_func, ...)

get_gradient(times)

Calculate the gradient of the object.

get_value(times)

Calculate the value of the object.

get_value_and_gradient(times)

Calculate the value and the gradient of the object.

abstract get_gradient(times)[source]#

Calculate the gradient of the object.

Parameters:

times (Array) – Array of times.

Returns:

The gradient of the object. There are two main cases.

1) The array has dimensions (n_times, n_params, (dimensions_of_object)). If the object is a scalar (1x1 Array) the dimension is just (n_times, n_params).

2) The array has dimension (n_params, (dimensions_of_object)). This is the case for instance of fidelities that are a function of an array of times.

Return type:

Array

abstract get_value(times)[source]#

Calculate the value of the object.

Parameters:

times (Array) – Array of times.

Returns:

The value of the object. If it returns an Array then the value is calculated at the n_times and the dimension should be (n_times, (dimensions_of_object)). If the object is a scalar (1x1 Array) the dimension is just n_times. If it returns a Float for instance it means that the object depends on the whole array of times. This is for instance the case of fidelities that are a function of an array of times.

Return type:

Array | Float

get_value_and_gradient(times)[source]#

Calculate the value and the gradient of the object.

Note

The default implementation here gathers the value and the gradient separately. For cases where the value can be obtained during the gradient calculation, this method is overwritten for efficiency.

Returns:

The value and the gradient of the object.

Return type:

tuple[Array | Float, Array]