Integrations
How integrations are loaded
Integrations with DifferentialEquations.jl, Agents.jl, and AlgebraicDynamics.jl are provided as Julia package extensions (see Conditional loading of code in packages). Each third-party package is declared under [weakdeps] in AlgebraicAgents's Project.toml and paired with an extension module under [extensions]. An extension is loaded automatically once all of its trigger packages have been loaded in the current session.
using AlgebraicAgents, DifferentialEquations
wrap_system("my_model", ODEProblem((u, p, t) -> 1.01*u, [0.5], (0.0, 10.0)))The agent types (DiffEqAgent, ABMAgent/AAgent, GraphicalAgent) are exported from the main module, so they can be referenced as field types or in method dispatch even before the corresponding extension is loaded. Their constructors and stepping logic become available once the relevant extension is active. Plotting follows the same pattern: once Plots is loaded (along with DataFrames where applicable), draw can be used to produce figures.
Some functionality requires multiple trigger packages. For example, converting an AlgebraicDynamics GraphicalAgent into a DiffEqAgent requires both AlgebraicDynamics and DifferentialEquations, and @draw_df requires both DataFrames and Plots. The complete list of triggers for each extension is given by the [extensions] table in the package's Project.toml.
SciML Integration
Agent Constructors
AlgebraicAgents.DiffEqAgent — TypeDiffEqAgent(name, problem[, alg]; observables=nothing, kwargs...)Initialize DE problem algebraic wrap.
Keywords
observables: eithernothingor a dictionary which maps keys to observable's positional index inu,- other kwargs will be passed to the integrator during initialization step.
The fully-typed constructor is provided by the AlgebraicAgentsSciMLExt package extension, which is loaded automatically once DifferentialEquations.jl is available in the current environment.
AlgebraicDynamics.jl Integration
Agent Constructors
AlgebraicAgents.GraphicalAgent — TypeGraphicalAgent(name, model)Initialize algebraic wrap of either an AbstractResourceSharer or a AbstractMachine.
The wrapped AbstractResourceSharer or AbstractMachine is stored as the property system.
The constructor that accepts an AlgebraicDynamics model and the associated oapply-based composition operators are provided by the AlgebraicAgentsAlgebraicDynamicsExt package extension, which is loaded automatically once AlgebraicDynamics.jl is available in the current environment.
Examples
GraphicalAgent("rabbit", ContinuousMachine{Float64}(1,1,1, dotr, (u, p, t) -> u))Conversion to DiffEqAgent
AlgebraicAgents.DiffEqAgent — MethodDiffEqAgent(agent::GraphicalAgent, u0, tspan, p; alg, kwargs...)Infer a problem type parametrized by agent.system, and create an appropriate DEProblem. Moreover, wrap this problem as an instance of DiffEqAgent; this contains agent's inner hierarchy.
Examples
DiffEqAgent(system, u0, tspan, params)
DiffEqAgent(system, u0, tspan, params; alg=Tsit5())Sums
AlgebraicAgents.:⊕ — Method⊕(models::Vararg{AbstractAlgebraicAgent, N}; name)Algebraic sum of algebraic models. Optionally specify resulting model's name.
By default, outputs an instance of FreeAgent.
Examples
⊕(m1, m2; name="diagram1") ⊕ ⊕(m3, m4; name="diagram2");Agents.jl Integration
The integration can be loaded as:
Agent Constructors
AlgebraicAgents.ABMAgent — TypeABMAgent(name, abm; kwargs...)Initialize ABMAgent, incl. hierarchy of ABM's agents.
Configure the evolutionary step, logging, and step size by keyword arguments below.
Arguments
- any kwarg accepted by `Agents.run!`, incl. `adata`, `mdata`
- `when`, `when_model`: when to collect agents data, model data
true by default, and performs data collection at every step
if an `AbstractVector`, checks if `t ∈ when`; otherwise a function (model, t) -> ::Bool
- `step_size`: how far the step advances, either a float or a function (model, t) -> size::Float64
- `tspan`: solution horizon, defaults to `(0., Inf)`The fully-typed constructor and stepping logic are provided by the AlgebraicAgentsAgentsExt package extension, which is loaded automatically once Agents.jl is available in the current environment.
AlgebraicAgents.AAgent — TypeAlgebraic wrap for Agents.AbstractAgent.
Bindings
AlgebraicAgents.@a — Macro@a operationAlgebraic extension of add_agent!, kill_agent!.
Requires the AlgebraicAgentsAgentsExt extension (i.e. Agents.jl loaded).
Examples
@a add_agent!(model, 0.5)
@a disentangle!(agent, model)