Authoring
The authoring surface is the @reaction_network DSL and the macros that populate a network with transitions, species, attributes, and the initial-state / parameter / solver metadata a run needs. A network authored here is a pure typed data artifact — no host code is captured — that is later handed to ReactionNetworkProblem for simulation.
ReactiveDynamics.ReactionNetwork — Type
ReactionNetworkThe static network container (ADR 0015: renamed from the ACSets-lineage ReactionNetworkSchema — it is a populated network INSTANCE, not the schema; the type-level object model is const SCHEMA). It is the inert, typed struct-of-columns store an authored model compiles to before it is handed to ReactionNetworkProblem for simulation. counts counts rows per object; columns is the NamedTuple of typed columns in ALLATTRS order; reactants is the promoted ReactantSpec incidence table (ADR 0003 Phase 2), populated lazily/on-merge (empty for a freshly-constructed or not-yet-promoted model — the runtime never reads it).
ReactiveDynamics.@reaction_network — Macro
Macro that takes an expression corresponding to a reaction network and outputs a ReactionNetwork (the static struct-of-columns model), ready to pass to ReactionNetworkProblem for simulation.
Most arrows accepted (both right, left, and bi-drectional arrows). Use 0 or ∅ for annihilation/creation to/from nothing.
Custom functions and sampleable objects can be used as numeric parameters. Note that these have to be accessible from ReactiveDynamics's source code.
Examples
net = @reaction_network begin
1.0, X ⟶ Y
1.0, X ⟶ Y, priority => 6.0, prob => 0.7, capacity => 3.0
1.0, ∅ --> (Poisson(0.3γ)X, Poisson(0.5)Y)
(XY > 100) && (XY -= 1)
end
@push net 1.0 X ⟶ Y
@prob_init net X = 1 Y = 2 XY = α
@prob_params net γ = 1 α = 4ReactiveDynamics.@push — Macro
Add reactions to a network.
Examples
@push sir β * S * I * tdecay(@time()) S + I --> 2I name => SI2I
@push sir begin
ν * I, I --> R, name => I2R
γ, R --> S, name => R2S
endReactiveDynamics.@add_species — Macro
Add new species to a model.
Examples
@add_species net S I RReactiveDynamics.@mode — Macro
Set species modality.
Supported modalities
- nonblock
- conserved
- rate
Examples
@mode net (r"proj\w+", r"experimental\w+") conserved
@mode net (S, I) conserved
@mode net S conservedReactiveDynamics.@aka — Macro
Alias an object name in a network.
Default names
| name | short name |
|---|---|
| species | S |
| transition | T |
| action | A |
| event | E |
| param | P |
| meta | M |
Examples
@aka net species = resource transition = reactionReactiveDynamics.@name_transition — Macro
Set name of a transition in the model.
Examples
@name_transition net 1 = "name"
@name_transition net name = "transition_name"
@name_transition net "name" = "transition_name"ReactiveDynamics.@append_transitions — Macro
@append_transitions net transitionsAppend a runtime-built collection of reaction lines to an existing net. transitions evaluates to a collection of strings, each one reaction line in the @reaction_network surface syntax; they are joined into a single begin…end block, parsed, and handed to @push. Use this when the set of transitions is assembled programmatically (a vector built in a loop, read from a table) rather than written literally — the literal-authoring path is @push.
Examples
lines = ["ν * I, I --> R, name => I2R", "γ, R --> S, name => R2S"]
@append_transitions net linesReactiveDynamics.@cost — Macro
Set cost.
Examples
@cost model experimental1=2 experimental2=3ReactiveDynamics.@reward — Macro
Set reward.
Examples
@reward model experimental1=2 experimental2=3ReactiveDynamics.@valuation — Macro
Set valuation.
Examples
@valuation model experimental1=2 experimental2=3ReactiveDynamics.@prob_init — Macro
Set initial values of species in a network.
Examples
@prob_init net X = 1 Y = 2 Z = h(α)
@prob_init net [1.0, 2.0, 3.0]ReactiveDynamics.@prob_uncertainty — Macro
Set uncertainty in initial values of species in a network (stderr).
Examples
@prob_uncertainty net X = 0.1 Y = 0.2
@prob_uncertainty net [0.1, 0.2]ReactiveDynamics.@prob_params — Macro
Set parameter values in a network.
Examples
@prob_params net α = 1.0 β = 2.0ReactiveDynamics.@prob_meta — Macro
Set model metadata (e.g. solver arguments)
Examples
@prob_meta net tspan = (0, 100.0) schedule = schedule_weighted!
@prob_meta sir tspan = 250 dt = 1 # `tstep` is a deprecated alias for `dt`ReactiveDynamics.@periodic — Macro
Add a periodic callback to a model.
Examples
@periodic net 1.0 X += 1ReactiveDynamics.@jump — Macro
Add a jump process (with specified Poisson intensity per unit time step) to a model.
Examples
@jump net λ Z += rand(state.rng, Poisson(1.0))ReactiveDynamics.@register — Macro
Register a host function/definition into ReactiveDynamics scope so model expressions may call it by name (e.g. a custom rate/guard helper). Evaluates ex at macro-expansion time — an AUTHORING-time escape hatch, distinct from the eval-free runtime; do not use it to inject per-run data.
Examples
@register bool_cond(t) = (100 < t < 200) || (400 < t < 500)
@register tdecay(t) = exp(-t / 10^3)Attributes & shorthands
Common transition attributes. When set inside @reaction_network (or the update macros) they may be referred to by any of their shorthand names.
| attribute | shorthand | interpretation |
|---|---|---|
transPriority | priority | priority of a transition (influences resource allocation) |
transProbOfSuccess | probability prob pos | probability that a transition terminates successfully |
transCapacity | cap capacity | maximum number of concurrent instances of the transition |
transCycleTime | ct cycletime | duration of a transition's instance (adjusted by resource allocation) |
transMaxLifeTime | lifetime maxlifetime maxtime timetolive | maximal duration of a transition's instance |
transPostAction | postAction post | action to be executed once a transition's instance terminates |
transName | name interpretation | name of a transition, either a string or unquoted text |
Common species attributes.
| attribute | shorthand | interpretation |
|---|---|---|
specInitUncertainty | uncertainty stoch stochasticity | uncertainty about a variable's initial state (modelled as a Gaussian standard deviation) |
specInitVal | initial value of a variable |
Rate semantics
The "rate" term of a transition governs how many instances spawn per step. By default a bare numeric rate is a stochastic (Poisson) intensity: at each step n ~ Poisson(rate * dt) instances are spawned. To specify the rate as a cycle time instead, use @ct(cycle_time) — e.g. @ct(ex), A --> B, ..., a shorthand for 1/ex, A --> B, .... For a deterministic "rate", use @deterministic(ex), where ex evaluates to a deterministic count (floored to whole instances) spawned per integrator step. Note that a deterministic count does not scale with the step length.