dynax.system

Classes representing dynamical systems.

Functions

boxed_field(lower, upper, **kwargs)

Mark an attribute value as trainable and box-constrained on [lower, upper].

field(**kwargs)

Mark an attribute value as trainable and unconstrained.

non_negative_field([min_val])

Mark an attribute value as trainable and non-negative.

static_field(**kwargs)

Mark an attribute value as non-trainable.

Classes

AbstractControlAffine()

Base class for control-affine dynamical systems.

AbstractSystem()

Base class for dynamical systems.

DynamicStateFeedbackSystem(sys1, sys2, v)

System with dynamic state-feedback.

FeedbackSystem(sys1, sys2)

Two systems connected via feedback.

LinearSystem(A, B, C, D[, initial_state])

A linear, time-invariant dynamical system.

SeriesSystem(sys1, sys2)

Two systems in series.

StaticStateFeedbackSystem(sys, v)

System with static state-feedback.

dynax.system.field(**kwargs)[source]

Mark an attribute value as trainable and unconstrained.

Parameters:

**kwargs (Any) – Keyword arguments passed to dataclasses.field().

Return type:

Any

dynax.system.static_field(**kwargs)[source]

Mark an attribute value as non-trainable.

Like equinox.field(), but marks the field as unconstrained and converts JAX arrays to NumPy arrays so the value is treated as a static constant.

Parameters:

**kwargs (Any) – Keyword arguments passed to eqx.field().

Return type:

Any

dynax.system.boxed_field(lower, upper, **kwargs)[source]

Mark an attribute value as trainable and box-constrained on [lower, upper].

Parameters:
Return type:

Any

dynax.system.non_negative_field(min_val=0.0, **kwargs)[source]

Mark an attribute value as trainable and non-negative.

Parameters:
Return type:

Any

class dynax.system.AbstractSystem[source]

Bases: Module

Base class for dynamical systems.

Any dynamical system in Dynax must inherit from this class. Subclasses can define continuous-time

\[\begin{split}ẋ &= f(x, u, t) \\ y &= h(x, u, t)\end{split}\]

or discrete-time

\[\begin{split}x_{k+1} &= f(x_k, u_k, t) \\ y_k &= h(x_k, u_k, t)\end{split}\]

system. The distinction between the two is only made when instances of subclasses are passed to objects such as dynax.evolution.Flow, dynax.evolution.Map, dynax.linearize.input_output_linearize, or dynax.linearize.discrete_input_output_linearize.

Subclasses must set values for the n_inputs, and initial_state attributes and implement the vector_field method. The output method describes the measurement equations. By default, the full state vector is returned as output.

Example:

class IntegratorAndGain(AbstractSystem):
    n_states = 1
    n_inputs = "scalar"
    gain: float

    def vector_field(self, x, u, t):
        dx = u
        return dx

    def output(self, x, u, t):
        return self.gain*x

AbstractSystem is a dataclass and as such defines a default constructor which can make it necessary to implement a custom __init__ method.

initial_state: AbstractVar[Array | ndarray]

Initial state vector.

n_inputs: AbstractVar[int | Literal['scalar']]

Number of inputs.

abstractmethod vector_field(x, u=None, t=None)[source]

Compute state derivative.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – State derivative.

output(x, u=None, t=None)[source]

Compute output.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – System output.

property n_outputs: int | Literal['scalar']

The size of the output vector.

linearize(x0=None, u0=None, t0=None)[source]

Compute the Jacobian linearization around a point.

Parameters:
  • x0 (Array | None) – State at which to linearize. Defaults to initial_state.

  • u0 (Array | None) – Input at which to linearize. Defaults to zero input.

  • t – Time at which to linearize.

Returns:

LinearSystem – Linearized system.

pretty()[source]

Return a pretty formatted string representation.

The string includes the constrains of all trainable parameters and the values of all parameters.

Return type:

str

class dynax.system.AbstractControlAffine[source]

Bases: AbstractSystem

Base class for control-affine dynamical systems.

Both in continuous-time

\[\begin{split}ẋ &= f(x) + g(x)u \\ y &= h(x) + i(x)u\end{split}\]

or the discrete-time equivalent.

Subclasses must implement the f and g methods that characterize the vector field. Optionally, the h and i methods can be implemented to describe the measurement equations. By default, the full state vector is returned as output.

abstractmethod f(x)[source]

The constant-input part of the vector field.

Return type:

Array

abstractmethod g(x)[source]

The input-proportional part of the vector field.

Return type:

Array

h(x)[source]

The constant-input part of the output equation.

Return type:

Array

i(x)[source]

The input-proportional part of the output equation.

Return type:

Array

vector_field(x, u=None, t=None)[source]

Compute state derivative.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – State derivative.

output(x, u=None, t=None)[source]

Compute output.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – System output.

class dynax.system.LinearSystem(A, B, C, D, initial_state=None)[source]

Bases: AbstractControlAffine

A linear, time-invariant dynamical system.

\[\begin{split}ẋ &= Ax + Bu \\ y &= Cx + Du\end{split}\]
Parameters:
  • A (Array) – System matrices of appropriate shape.

  • B (Array) – System matrices of appropriate shape.

  • C (Array) – System matrices of appropriate shape.

  • D (Array) – System matrices of appropriate shape.

A: Array

State matrix.

B: Array

Input matrix.

C: Array

Output matrix.

D: Array

Feedthrough matrix.

initial_state: Array = None

Initial state vector.

n_inputs: int | Literal['scalar'] = None

Number of inputs.

f(x)[source]

The constant-input part of the vector field.

Return type:

Array

g(x)[source]

The input-proportional part of the vector field.

Return type:

Array

h(x)[source]

The constant-input part of the output equation.

Return type:

Array

i(x)[source]

The input-proportional part of the output equation.

Return type:

Array

class dynax.system.SeriesSystem(sys1, sys2)[source]

Bases: AbstractSystem, _CoupledSystemMixin

Two systems in series.

\[\begin{split}ẋ_1 &= f_1(x_1, u, t) \\ y_1 &= h_1(x_1, u, t) \\ ẋ_2 &= f_2(x_2, y1, t) \\ y_2 &= h_2(x_2, y1, t)\end{split}\]
../_images/aafig-90f9eec314560b6611d3f295d5c062cb8a2b41c4.svg
Parameters:
initial_state: Array

Initial state vector.

n_inputs: int | Literal['scalar']

Number of inputs.

vector_field(x, u=None, t=None)[source]

Compute state derivative.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – State derivative.

output(x, u=None, t=None)[source]

Compute output.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – System output.

class dynax.system.FeedbackSystem(sys1, sys2)[source]

Bases: AbstractSystem, _CoupledSystemMixin

Two systems connected via feedback.

\[\begin{split}ẋ_1 &= f_1(x_1, u + y_2, t) \\ y_1 &= h_1(x_1, t) \\ ẋ_2 &= f_2(x_2, y_1, t) \\ y_2 &= h_2(x_2, y_1, t)\end{split}\]
../_images/aafig-c62612fd2c4255a5b3307995889f230976e05acb.svg
Parameters:
initial_state: Array

Initial state vector.

n_inputs: int | Literal['scalar']

Number of inputs.

vector_field(x, u=None, t=None)[source]

Compute state derivative.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – State derivative.

output(x, u=None, t=None)[source]

Compute output.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – System output.

class dynax.system.StaticStateFeedbackSystem(sys, v)[source]

Bases: AbstractSystem

System with static state-feedback.

\[\begin{split}ẋ &= f(x, v(x), t) \\ y &= h(x, u, t)\end{split}\]
../_images/aafig-c59c4bc9502f9a8b03cad5f138d3a82aed2de276.svg
Parameters:
  • sys (AbstractSystem) – System with vector field \(f\) and output \(h\).

  • v (Callable[[Array], Array]) – Static feedback law \(v\).

initial_state: Array

Initial state vector.

n_inputs: int | Literal['scalar']

Number of inputs.

vector_field(x, u=None, t=None)[source]

Compute state derivative.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – State derivative.

output(x, u=None, t=None)[source]

Compute output.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – System output.

class dynax.system.DynamicStateFeedbackSystem(sys1, sys2, v)[source]

Bases: AbstractSystem, _CoupledSystemMixin

System with dynamic state-feedback.

\[\begin{split}ẋ_1 &= f_1(x_1, v(x_1, x_2, u), t) \\ ẋ_2 &= f_2(x_2, u, t) \\ y &= h_1(x_1, u, t)\end{split}\]
../_images/aafig-64a24bd2367b5e9afe60e621e7d20f398ec20d4b.svg
Parameters:
  • sys1 (AbstractSystem) – System with vector field \(f_1\) and output \(h\).

  • sys2 (AbstractSystem) – System with vector field \(f_2\).

  • v (Callable[[Array, Array, Array | float], Array]) – dynamic feedback law \(v\).

initial_state: Array

Initial state vector.

n_inputs: int | Literal['scalar']

Number of inputs.

vector_field(x, u=None, t=None)[source]

Compute state derivative.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – State derivative.

output(x, u=None, t=None)[source]

Compute output.

Parameters:
  • x (Array) – State vector.

  • u (Array | None) – Optional input vector.

  • t (float | None) – Optional time.

Returns:

Array – System output.