Skip to content

Commit e5ade9f

Browse files
fixes initialization, stepping function
- fix support for initial values specified in acs - fix support for custom tsteps - fix req/alloc Signed-off-by: Bíma, Jan <jan.bima@merck.com>
1 parent 6afa807 commit e5ade9f

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

src/interface/create.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ end
147147

148148
function expand_rate(rate)
149149
rate = if !(isexpr(rate, :macrocall) && (macroname(rate) == :per_step))
150-
:(rand(Poisson(max($rate, 0))))
150+
:(rand(Poisson(max(state.dt * $rate, 0))))
151151
else
152152
rate.args[3]
153153
end

src/interface/update.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ Add a jump process (with specified Poisson intensity per unit time step) to a mo
489489
macro jump(acsex, inex, acex)
490490
return push_to_acs!(
491491
acsex,
492-
Expr(:&&, Expr(:call, :rand, :(Poisson(max(@solverarg(:tstep) * $inex, 0)))), acex),
492+
Expr(:&&, Expr(:call, :rand, :(Poisson(max(state.dt * $inex, 0)))), acex),
493493
)
494494
end
495495

src/solvers.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ function get_init_satisfied(allocs, qs, state)
107107
(reqs[tok.index, i] += tok.stoich)
108108
end
109109
end
110+
@show 2 reqs
110111
for i in eachindex(allocs)
111112
allocs[i] = reqs[i] == 0.0 ? Inf : floor(allocs[i] / reqs[i])
112113
end
114+
@show allocs
113115
foreach(i -> qs[i] = min(qs[i], minimum(allocs[:, i])), 1:size(reqs, 2))
114116
foreach(i -> allocs[:, i] .= reqs[:, i] * qs[i], 1:size(reqs, 2))
115117

@@ -133,7 +135,7 @@ function evolve!(state)
133135
qs .= ceil.(Ref(Int), qs)
134136
@show qs
135137
for i = 1:nparts(state, :T)
136-
new_instances = state.dt * qs[i] + state[i, :transToSpawn]
138+
new_instances = qs[i] + state[i, :transToSpawn]
137139
capacity =
138140
state[i, :transCapacity] -
139141
count(t -> t[:transHash] == state[i, :transHash], state.ongoing_transitions)
@@ -165,7 +167,7 @@ function evolve!(state)
165167
for i = 1:nparts(state, :T)
166168
qs[i] != 0 && push!(
167169
state.ongoing_transitions,
168-
Transition(state[i, :transName] * "_@$(state.t)", get_sampled_transition(state, i), state.t, qs[i], 0.0),
170+
Transition(string(state[i, :transName]) * "_@$(state.t)", get_sampled_transition(state, i), state.t, qs[i], 0.0),
169171
)
170172
end
171173

@@ -258,11 +260,13 @@ function finish!(state)
258260
(in(:rate, tok.modality) ? trans_[:transCycleTime] : 1)
259261
)
260262
end
263+
261264
q = if trans_.state >= trans_[:transCycleTime]
262265
rand(Distributions.Binomial(Int(trans_.q), trans_[:transProbOfSuccess]))
263266
else
264267
0
265268
end
269+
266270
foreach(
267271
tok -> (state.u[tok.index] += q * tok.stoich;
268272
val_reward += state[tok.index, :specReward] * q * tok.stoich),
@@ -378,26 +382,20 @@ function ReactiveNetwork(
378382
end
379383

380384
function AlgebraicAgents.step!(state::ReactiveNetwork)
381-
#du = copy(state.u)
382385
free_blocked_species!(state)
383-
#du .= state.u
384386
update_observables(state)
385387
sample_transitions!(state)
386388
evolve!(state)
387389
finish!(state)
388-
#update_u!(state, u)
389390
event_action!(state)
390391

391392
push!(
392393
state.log,
393394
(:valuation, state.t, state.u' * [state[i, :specValuation] for i = 1:nparts(state, :S)]),
394395
)
395396

396-
#update_u!(state, du)
397397
save!(state)
398-
399-
#state.u .= du
400-
state.t += state.dt
398+
return state.t += state.dt
401399
end
402400

403401
function AlgebraicAgents._projected_to(state::ReactiveNetwork)

src/state.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ end
217217
## query the state
218218

219219
t(state::ReactiveNetwork) = state.t
220-
solverarg(state::ReactiveNetwork, arg) = state.solverargs[arg]
220+
solverarg(state::ReactiveNetwork, arg) = state.p[arg]
221221
take(state::ReactiveNetwork, pcs::Symbol) = state.observables[pcs].sampled
222222
log(state::ReactiveNetwork, msg) = (println(msg); push!(state.log, (:log, msg)))
223223
state(state::ReactiveNetwork) = state

tutorial/basics.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ end
1010

1111
@prob_init acs X = 10 Y = 20
1212
@prob_params acs
13-
@prob_meta acs tspan = 250 dt = 0.1
13+
@prob_meta acs tspan = 250 dt = 0.11
1414

1515

1616
# sol = ReactiveDynamics.solve(prob)
@@ -23,6 +23,9 @@ for i in 1:30
2323
AlgebraicAgents.step!(prob)
2424
end
2525
prob.history_u
26+
27+
28+
2629
using Plots
2730

2831
@plot sol plot_type = summary

0 commit comments

Comments
 (0)