AlgebraicAgents coupling

A ReactionNetworkProblem is an AlgebraicAgents.jl (AA) agent, so a network is a node in a larger heterogeneous AA hierarchy: it can be entangled with sibling agents, expose observables, and read a sibling's output off a wire (with a one-tick Jacobi lag). This page also covers checkpointing a live run.

AA verbs (reexported)

entangle!, add_wire!, and getobservable are AlgebraicAgents functions — getobservable is overloaded by ReactiveDynamics for ReactionNetworkProblem, and all three are reexported (via @reexport using AlgebraicAgents); they are documented in the AlgebraicAgents documentation. entangle!(parent, rd) makes the network a child node of parent; add_wire!(root; from, to, from_var_name, to_var_name) connects one agent's observable to another agent's input port; getobservable(rd, name) reads a network's exported observable by name (or getobservable(rd, i::Int) by canonical index). A cross-agent read is expressed on the RD side with an ExternalRef (see Serialization for its IR docstring): the referenced value resolves one tick late, giving a deterministic Jacobi coupling.

using ReactiveDynamics
using AlgebraicAgents            # reexported by ReactiveDynamics

# rd is a ReactionNetworkProblem; finance is a sibling AA agent under root
entangle!(root, rd)                                                         # AA verb — make rd a node in the hierarchy
add_wire!(root; from = rd, to = finance,                                    # AA verb — wire rd's :cash observable
    from_var_name = "cash", to_var_name = "rd_cash")                        #   into finance's :rd_cash input port
getobservable(rd, :cash)                                                    # AA verb — read the observable by name

Checkpointing

dump_state/restore snapshot and reload a live run through a StateDump; these are ReactiveDynamics exports. (dump_state requires a clean tick boundary.)

ReactiveDynamics.StateDumpType
StateDump

An eval-free, JSON-representable snapshot of a live run at a TICK BOUNDARY (ADR 0007 §C / CONTRACT §10.5), produced by dump_state and consumed by restore. It holds the declarative initial marking (§B) PLUS the dynamic run state: the model hash, the clock (t, tspan, dt), the RNG state (Xoshiro s0..s4), the creation counters and name → creation_index map, the plain-species column vector u, the full token population as (species, name, creation_index, fields, bound) tuples with CURRENT field values, and the once-rule enabled latches. Eval-free by construction: tokens carry field VALUES + a kind NAME resolved through the host registry on restore, never Julia source (§8.4 S4 / ADR 0006 §B). A zero-tick dump with nothing in flight IS an initial marking — the "initial marking = checkpoint" identity (§C).

source
ReactiveDynamics.dump_stateFunction
dump_state(problem) -> StateDump

Serialize a live problem into an eval-free StateDump for halt/resume or the zero-tick "dump == initial marking" identity (ADR 0007 §C / CONTRACT §10.5). Captures the clock, RNG state, creation counters, plain-species u, the token population with each token's CURRENT field values, and the once-rule latches; pair with restore to reconstruct the run.

DELIBERATE DEFERRAL (Milestone-1): dump_state requires a CLEAN TICK BOUNDARY — an empty ongoing transition set — and errors otherwise. Mid-cycle in-flight Transition instances (their frozen sampled-attr dicts and bound-token relink-by-uuid — the §C open question) are NOT serialized; the heavier mid-cycle resume is deferred. Step to a boundary where no instance is mid-cycle (or reinit!) before dumping.

source
ReactiveDynamics.restoreFunction
restore(spec, dump::StateDump; registry = Dict{Symbol, Any}(), kwargs...) -> ReactionNetworkProblem

Reconstruct a live run from a StateDump — construction with overlays (ADR 0007 §C). Builds a fresh ReactionNetworkProblem from spec, then overlays the dumped clock/RNG/creation-counters/u and rebuilds the token population in creation-index order — each token's kind resolved via the registry to a host constructor, its fields set to the dumped literal values (eval-free; no Julia source is carried). Structured u columns are re-derived from the restored population, not copied. Warns on a model-hash mismatch (restoring against a different spec is ill-defined). kwargs are forwarded to the ReactionNetworkProblem constructor.

source