Skip to content

Commit ad6d50e

Browse files
fix plotting, solution, log
1 parent 97c7c74 commit ad6d50e

File tree

13 files changed

+113
-408
lines changed

13 files changed

+113
-408
lines changed

src/ReactiveDynamics.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ end
7474

7575
@acset_type FoldedReactionNetworkType(TheoryReactionNetwork)
7676

77-
const ReactionNetwork = FoldedReactionNetworkType{
77+
const ReactionNetworkSchema = FoldedReactionNetworkType{
7878
Symbol,
7979
Union{String,Symbol,Missing},
8080
SampleableValues,
@@ -131,11 +131,11 @@ defargs = Dict(
131131
)
132132

133133
compilable_attrs =
134-
filter(attr -> eltype(attr) == SampleableValues, propertynames(ReactionNetwork()))
134+
filter(attr -> eltype(attr) == SampleableValues, propertynames(ReactionNetworkSchema()))
135135

136136
species_modalities = [:nonblock, :conserved, :rate]
137137

138-
function assign_defaults!(acs::ReactionNetwork)
138+
function assign_defaults!(acs::ReactionNetworkSchema)
139139
for (_, v_) in defargs, (k, v) in v_
140140
for i = 1:length(subpart(acs, k))
141141
isnothing(acs[i, k]) && (subpart(acs, k)[i] = v)
@@ -160,12 +160,12 @@ function assign_defaults!(acs::ReactionNetwork)
160160
return acs
161161
end
162162

163-
function ReactionNetwork(transitions, reactants, obs, events)
164-
return merge_acs!(ReactionNetwork(), transitions, reactants, obs, events)
163+
function ReactionNetworkSchema(transitions, reactants, obs, events)
164+
return merge_acs!(ReactionNetworkSchema(), transitions, reactants, obs, events)
165165
end
166166

167-
function ReactionNetwork(transitions, reactants, obs)
168-
return merge_acs!(ReactionNetwork(), transitions, reactants, obs, [])
167+
function ReactionNetworkSchema(transitions, reactants, obs)
168+
return merge_acs!(ReactionNetworkSchema(), transitions, reactants, obs, [])
169169
end
170170

171171
function add_obs!(acs, obs)
@@ -194,7 +194,7 @@ function add_obs!(acs, obs)
194194
return acs
195195
end
196196

197-
function merge_acs!(acs::ReactionNetwork, transitions, reactants, obs, events)
197+
function merge_acs!(acs::ReactionNetworkSchema, transitions, reactants, obs, events)
198198
foreach(
199199
t -> add_part!(acs, :T; trans = t[1][2], transRate = t[1][1], t[2]...),
200200
transitions,

src/compilers.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ function wrap_expr(fex, species_names, prm_names, varmap)
112112
)
113113
push!(letex.args[2].args, fex)
114114

115-
# the function shall be a function of the dynamic ReactiveNetwork structure: letex -> :(state -> $letex)
115+
# the function shall be a function of the dynamic ReactionNetworkSchema structure: letex -> :(state -> $letex)
116116
# eval the expression to a Julia function, save that function into the "compiled" acset
117117
return eval(:(state -> $letex))
118118
end
119119

120-
function get_wrap_fun(acs::ReactionNetwork)
120+
function get_wrap_fun(acs::ReactionNetworkSchema)
121121
species_names = collect(acs[:, :specName])
122122
prm_names = collect(acs[:, :prmName])
123123
varmap = Dict([name => :(state.u[$i]) for (i, name) in enumerate(species_names)])
@@ -133,7 +133,7 @@ function skip_compile(attr)
133133
(string(attr) == "trans")
134134
end
135135

136-
function compile_attrs(acs::ReactionNetwork)
136+
function compile_attrs(acs::ReactionNetworkSchema)
137137
species_names = collect(acs[:, :specName])
138138
prm_names = collect(acs[:, :prmName])
139139
varmap = Dict([name => :(state.u[$i]) for (i, name) in enumerate(species_names)])
@@ -169,7 +169,7 @@ function compile_attrs(acs::ReactionNetwork)
169169
return attrs, transitions, wrap_fun
170170
end
171171

172-
function remove_choose(acs::ReactionNetwork)
172+
function remove_choose(acs::ReactionNetworkSchema)
173173
acs = deepcopy(acs)
174174
pcs = []
175175
for attr in propertynames(acs.subparts)

src/interface/create.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# reaction network DSL: CREATE part; reaction line and event parsing
22

3-
export @ReactionNetwork
3+
export @ReactionNetworkSchema
44

55
using MacroTools: prewalk, postwalk, striplines, isexpr
66
using Symbolics: build_function, get_variables
@@ -45,7 +45,7 @@ Custom functions and sampleable objects can be used as numeric parameters. Note
4545
# Examples
4646
4747
```julia
48-
acs = @ReactionNetwork begin
48+
acs = @ReactionNetworkSchema begin
4949
1.0, X ⟶ Y
5050
1.0, X ⟶ Y, priority => 6.0, prob => 0.7, capacity => 3.0
5151
1.0, ∅ --> (Poisson(0.3γ)X, Poisson(0.5)Y)
@@ -57,17 +57,17 @@ end
5757
@solve_and_plot acs
5858
```
5959
"""
60-
macro ReactionNetwork end
60+
macro ReactionNetworkSchema end
6161

62-
macro ReactionNetwork()
62+
macro ReactionNetworkSchema()
6363
return make_ReactionNetwork(:())
6464
end
6565

66-
macro ReactionNetwork(ex)
66+
macro ReactionNetworkSchema(ex)
6767
return make_ReactionNetwork(ex; eval_module = __module__)
6868
end
6969

70-
macro ReactionNetwork(ex, args...)
70+
macro ReactionNetworkSchema(ex, args...)
7171
return make_ReactionNetwork(
7272
generate(Expr(:braces, ex, args...); eval_module = __module__);
7373
eval_module = __module__,
@@ -78,7 +78,7 @@ function make_ReactionNetwork(ex::Expr; eval_module = @__MODULE__)
7878
blockex = generate(ex; eval_module)
7979
blockex = unblock_shallow!(blockex)
8080

81-
return :(ReactionNetwork(get_data($(QuoteNode(blockex)))...))
81+
return :(ReactionNetworkSchema(get_data($(QuoteNode(blockex)))...))
8282
end
8383

8484
### Functions that process the input and rephrase it as a reaction system ###

src/interface/plots.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Plots
2+
3+
function plot_df(df::DataFrames.DataFrame, t_ix = 1)
4+
data = Matrix(df)
5+
t = @view data[:, t_ix]
6+
data_ = @view data[:, setdiff(1:size(data, 2), (t_ix,))]
7+
colnames = reshape(DataFrames.names(df)[setdiff(1:size(data, 2), (t_ix,))], 1, :)
8+
9+
Plots.plot(t, data_, labels = colnames, xlabel = "t")
10+
end
11+
12+
# plot reduction
13+
function AlgebraicAgents._draw(prob::ReactionNetworkProblem, vars = string.(prob.acs[:, :specName]); kwargs...)
14+
p = plot()
15+
for var in vars
16+
p = plot!(p, prob.sol[!, "t"], prob.sol[!, var]; label="$var", xlabel="time", ylabel="quantity", kwargs...)
17+
end
18+
p
19+
end

src/interface/reaction_parser.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function recursively_choose(r_line, state)
2929
end
3030
end
3131

32-
function extract_reactants(r_line, state::ReactiveNetwork)
32+
function extract_reactants(r_line, state::ReactionNetworkProblem)
3333
r_line = recursively_choose(r_line, state)
3434

3535
return recursive_find_reactants!(

src/interface/solve.jl

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,8 @@
1-
export @agentize, @solve, @plot
2-
export @optimize, @fit, @fit_and_plot, @build_solver
1+
export @agentize
32

43
import MacroTools
54
import Plots
65

7-
"""
8-
Convert a model to a `ReactiveNetwork`. If passed a problem instance, return the instance.
9-
10-
# Examples
11-
12-
```julia
13-
@agentize acs tspan = 1:100
14-
```
15-
"""
16-
macro agentize(acsex, args...)
17-
args, kwargs = args_kwargs(args)
18-
quote
19-
if $(esc(acsex)) isa ReactiveNetwork
20-
$(esc(acsex))
21-
else
22-
ReactiveNetwork($(esc(acsex)), $(args...); $(kwargs...))
23-
end
24-
end
25-
end
26-
27-
"""
28-
Solve the problem. Solverargs passed at the calltime take precedence.
29-
30-
# Examples
31-
32-
```julia
33-
@solve prob
34-
@solve prob tspan = 1:100
35-
@solve prob tspan = 100
36-
```
37-
"""
38-
macro solve(probex, args...)
39-
args, kwargs = args_kwargs(args)
40-
mode = find_kwargex_delete!(kwargs, :mode, nothing)
41-
!isnothing(findfirst(el -> el.args[1] == :trajectories, kwargs)) && (mode = :ensemble)
42-
43-
quote
44-
prob = if $(esc(probex)) isa ReactiveNetwork
45-
$(esc(probex))
46-
else
47-
ReactiveNetwork($(esc(probex)), $(args...); $(kwargs...))
48-
end
49-
50-
simulate(prob)
51-
end
52-
end
53-
546
# auxiliary plotting functions
557
function plot_summary(s, labels, ixs; kwargs...)
568
isempty(ixs) && return @warn "Set of species to plot must be non-empty!"

src/loadsave.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ const objects_aliases = Dict(
1616
:obs => "obs",
1717
)
1818

19-
const RN_attrs = string.(propertynames(ReactionNetwork().subparts))
19+
const RN_attrs = string.(propertynames(ReactionNetworkSchema().subparts))
2020

2121
function get_attrs(object)
2222
object = object isa Symbol ? objects_aliases[object] : object
2323

2424
return filter(x -> occursin(object, x), RN_attrs)
2525
end
2626

27-
function export_network(acs::ReactionNetwork)
27+
function export_network(acs::ReactionNetworkSchema)
2828
dict = Dict()
2929
for (key, val) in objects_aliases
3030
push!(dict, val => [])
@@ -113,7 +113,7 @@ function import_network(path::AbstractString)
113113
end
114114
end
115115

116-
function export_network(acs::ReactionNetwork, path::AbstractString)
116+
function export_network(acs::ReactionNetworkSchema, path::AbstractString)
117117
if splitext(path)[2] == ".csv"
118118
exported_network = export_network(acs)
119119
paths = DataFrame(; type = [], path = [])

src/operators/equalize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function get_eqs_ff(eq)
2121
end
2222
end
2323

24-
function equalize!(acs::ReactionNetwork, eqs = [])
24+
function equalize!(acs::ReactionNetworkSchema, eqs = [])
2525
specmap = Dict()
2626
for block in eqs
2727
block_alias = findfirst(e -> e[1] == :alias, block)

src/operators/joins.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ end
5959
"""
6060
Prepend species names with a model identifier (unless a global species name).
6161
"""
62-
function prepend!(acs::ReactionNetwork, name = gensym("acs"), eqs = [])
62+
function prepend!(acs::ReactionNetworkSchema, name = gensym("acs"), eqs = [])
6363
specmap = Dict()
6464
for i = 1:nparts(acs, :S)
6565
new_name = normalize_name(name, i, acs[i, :specName], eqs)
@@ -199,7 +199,7 @@ Model variables / parameter values and metadata are propagated; the last model t
199199
macro join(exs...)
200200
callex = :(
201201
begin
202-
acs_new = ReactionNetwork()
202+
acs_new = ReactionNetworkSchema()
203203
end
204204
)
205205
exs = collect(exs)

0 commit comments

Comments
 (0)