API Documentation

Create a model

ReactiveDynamics.@ReactionNetworkMacro

Macro that takes an expression corresponding to a reaction network and outputs an instance of TheoryReactionNetwork that can be converted to a DiscreteProblem or solved directly.

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

acs = @ReactionNetwork begin
    1.0, X ⟶ Y
    1.0, X ⟶ Y, priority=>6., prob=>.7, capacity=>3.
    1.0, ∅ --> (Poisson(.3γ)X, Poisson(.5)Y)
    (XY > 100) && (XY -= 1)
end
@push acs 1.0 X ⟶ Y 
@prob_init acs X=1 Y=2 XY=α
@prob_params acs γ=1 α=4
@solve_and_plot acs

Modify a model

We list common transition attributes:

attributeinterpretation
transPrioritypriority of a transition (influences resource allocation)
transProbOfSuccessprobability that a transition terminates successfully
transCapacitymaximum number of concurrent instances of the transition
transCycleTimeduration of a transition's instance (adjusted by resource allocation)
transMaxLifeTimemaximal duration of a transition's instance
transPostActionaction to be executed once a transition's instance terminates
transNamename of a transition

We list common species attributes:

attributeinterpretation
specInitUncertaintyuncertainty about variable's initial state (modelled as Gaussian standard deviation)
specInitValinitial value of a variable

Moreover, it is possible to specify the semantics of the "rate" term. By default, at each time step n ~ Poisson(rate * dt) instances of a given transition will be spawned. If you want to specify the rate in terms of a cycle time, you may want to use @ct(cycle_time), e.g., @ct(ex), A --> B, .... This is a shorthand for 1/ex, A --> B, ....

For deterministic "rates", use @per_step(ex). Here, ex evaluates to a deterministic number (ceiled to the nearest integer) of a transition's instances to spawn per a single integrator's step. However, note that in this case, the number doesn't scale with the step length! Moreover

ReactiveDynamics.@akaMacro

Alias object name in an acs.

Default names

nameshort name
speciesS
transitionT
actionA
eventE
paramP
metaM

Examples

@aka acs species=resource transition=reaction
ReactiveDynamics.@modeMacro

Set species modality.

Supported modalities

  • nonblock
  • conserved
  • rate

Examples

@mode acs (r"proj\w+", r"experimental\w+") conserved
@mode acs (S, I) conserved
@mode acs S conserved
ReactiveDynamics.@name_transitionMacro

Set name of a transition in the model.

Examples

@name_transition acs 1="name"
@name_transition acs name="transition_name"
@name_transition acs "name"="transition_name"

Resource costs

Add reactions

ReactiveDynamics.@pushMacro

Add reactions to an acset.

Examples

@push sir_acs β*S*I*tdecay(@time()) S+I --> 2I name=>SI2I
@push sir_acs begin 
    ν*I, I --> R, name=>I2R
    γ, R --> S, name=>R2S
end
ReactiveDynamics.@jumpMacro

Add a jump process (with specified Poisson intensity per unit time step) to a model.

Examples

@jump acs λ Z += rand(Poisson(1.))

Set initial values, uncertainty, and solver arguments

ReactiveDynamics.@prob_initMacro

Set initial values of species in an acset.

Examples

@prob_init acs X=1 Y=2 Z=h(α)
@prob_init acs [1., 2., 3.]
ReactiveDynamics.@prob_uncertaintyMacro

Set uncertainty in initial values of species in an acset (stderr).

Examples

@prob_uncertainty acs X=.1 Y=.2
@prob_uncertainty acs [.1, .2,]
ReactiveDynamics.@prob_metaMacro

Set model metadata (e.g. solver arguments)

Examples

@prob_meta acs tspan=(0, 100.) schedule=schedule_weighted!
@prob_meta sir_acs tspan=250 tstep=1

Model unions

ReactiveDynamics.@joinMacro
@join models... [equalize...]

Performs join of models and identifies model variables, as specified.

Model variables / parameter values and metadata are propagated; the last model takes precedence.

Examples

@join acs1 acs2 @catchall(A)=acs2.Z @catchall(XY) @catchall(B)

Model import and export

Solution import and export

ReactiveDynamics.@import_solutionMacro
@import_solution "sol.jld2"
@import_solution "sol.jld2" sol

Import a solution from a file.

Examples

@import_solution "sir_acs_sol/serialized/sol.jld2"
ReactiveDynamics.@export_csvMacro
@export_csv sol
@export_csv sol "sol.csv"

Export a solution to a file.

Examples

@export_csv sol "sol.csv"

Problematize,sSolve, and plot

ReactiveDynamics.@problematizeMacro

Convert a model to a DiscreteProblem. If passed a problem instance, return the instance.

Examples

@problematize acs tspan=1:100
ReactiveDynamics.@solveMacro

Solve the problem. Solverargs passed at the calltime take precedence.

Examples

@solve prob
@solve prob tspan=1:100
@solve prob tspan=100 trajectories=20
ReactiveDynamics.@plotMacro

Plot the solution (summary).

Examples

@plot sol plot_type=summary
@plot sol plot_type=allocation # not supported for ensemble solutions!
@plot sol plot_type=valuations # not supported for ensemble solutions!
@plot sol plot_type=new_transitions # not supported for ensemble solutions!

Optimization and fitting

ReactiveDynamics.@optimizeMacro
@optimize acset objective <free_var=[init_val]>... <free_prm=[init_val]>... opts...

Take an acset and optimize given functional.

Objective is an expression which may reference the model's variables and parameters, i.e., A+β. The values to optimized are listed using their symbolic names; unless specified, the initial value is inferred from the model. The vector of free variables passed to the NLopt solver has the form [free_vars; free_params]; order of vars and params, respectively, is preserved.

By default, the functional is minimized. Specify objective=max to perform maximization.

Propagates NLopt solver arguments; see NLopt documentation.

Examples

@optimize acs abs(A-B) A B=20. α=2. lower_bounds=0 upper_bounds=100
@optimize acss abs(A-B) A B=20. α=2. upper_bounds=[200,300,400] maxeval=200 objective=min
ReactiveDynamics.@fitMacro
@fit acset data_points time_steps empiric_variables <free_var=[init_val]>... <free_prm=[init_val]>... opts...

Take an acset and fit initial values and parameters to empirical data.

The values to optimized are listed using their symbolic names; unless specified, the initial value is inferred from the model. The vector of free variables passed to the NLopt solver has the form [free_vars; free_params]; order of vars and params, respectively, is preserved.

Propagates NLopt solver arguments; see NLopt documentation.

Examples

t = [1, 50, 100]
data = [80 30 20]
@fit acs data t vars=A B=20 A α # fit B, A, α; empirical data is for variable A
ReactiveDynamics.@fit_and_plotMacro
@fit acset data_points time_steps empiric_variables <free_var=[init_val]>... <free_prm=[init_val]>... opts...

Take an acset, fit initial values and parameters to empirical data, and plot the result.

The values to optimized are listed using their symbolic names; unless specified, the initial value is inferred from the model. The vector of free variables passed to the NLopt solver has the form [free_vars; free_params]; order of vars and params, respectively, is preserved.

Propagates NLopt solver arguments; see NLopt documentation.

Examples

t = [1, 50, 100]
data = [80 30 20]
@fit acs data t vars=A B=20 A α # fit B, A, α; empirical data is for variable A
ReactiveDynamics.@build_solverMacro
@build_solver acset <free_var=[init_val]>... <free_prm=[init_val]>... opts...

Take an acset and export a solution as a function of free vars and free parameters.

Examples

solver = @build_solver acs S α β # function of variable S and parameters α, β
solver([S, α, β])