# Library Reference

## Resource Sharers and Machines

`AlgebraicDynamics.UWDDynam.AbstractResourceSharer`

— TypeAn undirected open dynamical system operating on information of type `T`

.

A resource sharer `r`

has signature `r.nports`

.

`AlgebraicDynamics.UWDDynam.ContinuousResourceSharer`

— TypeAn undirected open continuous system. The dynamics function `f`

defines an ODE $\dot u(t) = f(u(t),p,t)$.

`AlgebraicDynamics.UWDDynam.DiscreteResourceSharer`

— TypeAn undirected open discrete system. The dynamics function `f`

defines a discrete update rule $u_{n+1} = f(u_n, p, t)$.

`AlgebraicDynamics.DWDDynam.AbstractMachine`

— TypeA directed open dynamical system operating on information fo type `T`

. A machine `m`

has type signature (`m.ninputs`

, `m.outputs`

).

`AlgebraicDynamics.DWDDynam.ContinuousMachine`

— TypeAn undirected open continuous system. The dynamics function `f`

defines an ODE $\dot u(t) = f(u(t),x(t),p,t)$ where $u$ is the state and $x$ captures the exogenous variables.

The readout function may only depend on the state, so it must be of the form $r(u(t))$.

`AlgebraicDynamics.DWDDynam.DiscreteMachine`

— TypeA directed open discrete dynamical system. The dynamics function `f`

defines a discrete update rule $u_{n+1} = f(u_n, x_n, p, t)$ where $u_n$ is the state and $x_n$ is the value of the exogenous variables at the $n$th time step.

The readout function may only depend on the state, so it must be of the form $r(u_n)$.

`AlgebraicDynamics.UWDDynam.eval_dynamics`

— Function`eval_dynamics(r::AbstractResourceSharer, u::AbstractVector, p, t)`

Evaluates the dynamics of the resource sharer `r`

at state `u`

, parameters `p`

, and time `t`

.

Omitting `t`

and `p`

is allowed if the dynamics of `r`

does not depend on them.

`eval_dynamics(m::AbstractMachine, u::AbstractVector, xs::AbstractVector, p, t)`

Evaluates the dynamics of the machine `m`

at state `u`

, parameters `p`

, and time `t`

. The exogenous variables are set by `xs`

which may either be a collection of functions $x(t)$ or a collection of constant values.

The length of `xs`

must equal the number of inputs to `m`

.

`AlgebraicDynamics.UWDDynam.euler_approx`

— Function`euler_approx(r::ContinuousResourceSharer, h)`

Transforms a continuous resource sharer `r`

into a discrete resource sharer via Euler's method with step size `h`

. If the dynamics of `r`

is given by $\dot{u}(t) = f(u(t),p,t)$ the the dynamics of the new discrete system is given by the update rule $u_{n+1} = u_n + h f(u_n, p, t)$.

`euler_approx(r::ContinuousResourceSharer)`

Transforms a continuous resource sharer `r`

into a discrete resource sharer via Euler's method where the step size is introduced as a new parameter, the last in the list of parameters.

`euler_approx(m::ContinuousMachine, h)`

Transforms a continuous machine `m`

into a discrete machine via Euler's method with step size `h`

. If the dynamics of `m`

is given by $\dot{u}(t) = f(u(t),x(t),p,t)$ the the dynamics of the new discrete system is given by the update rule $u_{n+1} = u_n + h f(u_n, x_n, p, t)$.

`euler_approx(m::ContinuousMachine)`

Transforms a continuous machine `m`

into a discrete machine via Euler's method where the step size is introduced as a new parameter, the last in the list of parameters.

`oapply`

`AlgebraicDynamics.UWDDynam.fills`

— Function`fills(r::AbstractResourceSharer, d::AbstractUWD, b::Int)`

Checks if `r`

is of the correct signature to fill box `b`

of the undirected wiring diagram `d`

.

`Catlab.WiringDiagrams.WiringDiagramAlgebras.oapply`

— Function` oapply(d::AbstractUWD, rs::Vector)`

Implements the operad algebras for undirected composition of dynamical systems given a composition pattern (implemented by an undirected wiring diagram `d`

) and primitive systems (implemented by a collection of resource sharers `rs`

). Returns the composite resource sharer.

Each box of `d`

must be filled by a resource sharer of the appropriate type signature.

`oapply(d::AbstractUWD, r::AbstractResourceSharer)`

A version of `oapply`

where each box of `d`

is filled with the resource sharer `r`

.

` oapply(d::AbstractUWD, generators::Dict)`

A version of `oapply`

where `generators`

is a dictionary mapping the name of each box to its corresponding resource sharer.

`oapply(d::OpenCPortGraph, ms::Vector)`

Implements the operad algebras for directed composition of dynamical systems given a composition pattern (implemented by an open circular port graph `d`

) and primitive systems (implemented by a collection of machines `ms`

).

Each box of the composition pattern `d`

is filled by a machine with the appropriate type signature. Returns the composite machine.

`oapply(d::OpenCPortGraph, m::AbstractMachine)`

A version of `oapply`

where each box of `d`

is filled with the machine `m`

.

`oapply(d::WiringDiagram, ms::Vector)`

Implements the operad algebras for directed composition of dynamical systems given a composition pattern (implemented by a directed wiring diagram `d`

) and primitive systems (implemented by a collection of machines `ms`

).

Each box of the composition pattern `d`

is filled by a machine with the appropriate type signature. Returns the composite machine.

`oapply(d::WiringDiagram, m::AbstractMachine)`

A version of `oapply`

where each box of `d`

is filled with the machine `m`

.

`oapply(d::WiringDiagram, generators::Dict)`

A version of `oapply`

where `generators`

is a dictionary mapping the name of each box to its corresponding machine.

## Integration with OrdinaryDiffEq.jl and DynamicalSystems.jl

`SciMLBase.ODEProblem`

— Type`ODEProblem(r::ContinuousResourceSharer, u0::Vector, tspan)`

Constructs an ODEProblem from the vector field defined by `r.dynamics(u,p,t)`

.

`ODEProblem(m::ContinuousMachine, xs::Vector, u0::Vector, tspan)`

Constructs an ODEProblem from the vector field defined by `(u,p,t) -> m.dynamics(u, x, p, t)`

. The exogenous variables are determined by `xs`

.

`DynamicalSystemsBase.DiscreteDynamicalSystem`

— Type`DiscreteDynamicalSystem(r::DiscreteResourceSharer, u0::Vector, p)`

Constructs a DiscreteDynamicalSystem from the equation of motion `r.dynamics(u,p,t)`

. Pass `nothing`

in place of `p`

if your system does not have parameters.

`DiscreteDynamicalSystem(m::DiscreteMachine, xs::Vector, u0::Vector, p)`

Constructs an DiscreteDynamicalSystem from the equation of motion defined by `(u,p,t) -> m.dynamics(u, x, p, t)`

. The exogenous variables are determined by `xs`

. Pass `nothing`

in place of `p`

if your system does not have parameters.

`DynamicalSystemsBase.trajectory`

— Function`trajectory(r::DiscreteResourceSharer, u0::AbstractVector, p, nsteps::Int; dt::Int = 1)`

Evolves the resouce sharer `r`

for `nsteps`

times with step size `dt`

, initial condition `u0`

, and parameters `p`

.

`trajectory(m::DiscreteMachine, u0::AbstractVector, xs::AbstractVector, p, nsteps::Int; dt::Int = 1)`

Evolves the machine `m`

for `nsteps`

times with step size `dt`

, initial condition `u0`

, and parameters `p`

. Any inputs to `m`

are determied by `xs`

. If `m`

has no inputs then you can omit `xs`

.