Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
thevolatilebit committed Sep 16, 2023
1 parent 4e93e19 commit aec5820
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
20 changes: 16 additions & 4 deletions src/interface/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ function plot_df(df::DataFrames.DataFrame, t_ix = 1)
data_ = @view data[:, setdiff(1:size(data, 2), (t_ix,))]
colnames = reshape(DataFrames.names(df)[setdiff(1:size(data, 2), (t_ix,))], 1, :)

Plots.plot(t, data_, labels = colnames, xlabel = "t")
return Plots.plot(t, data_; labels = colnames, xlabel = "t")
end

# plot reduction
function AlgebraicAgents._draw(prob::ReactionNetworkProblem, vars = string.(prob.acs[:, :specName]); kwargs...)
function AlgebraicAgents._draw(
prob::ReactionNetworkProblem,
vars = string.(prob.acs[:, :specName]);
kwargs...,
)
p = plot()
for var in vars
p = plot!(p, prob.sol[!, "t"], prob.sol[!, var]; label="$var", xlabel="time", ylabel="quantity", kwargs...)
p = plot!(
p,
prob.sol[!, "t"],
prob.sol[!, var];
label = "$var",
xlabel = "time",
ylabel = "quantity",
kwargs...,
)
end
p
return p
end
2 changes: 1 addition & 1 deletion src/interface/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ function plot_from_log(state, record_type, ixs; kwargs...)
label = reshape(label, 1, :),
kwargs...,
)
end
end
41 changes: 24 additions & 17 deletions src/solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ function evolve!(state)

reqs = get_reqs_init!(reqs, qs, state)

allocs =
get_allocs!(reqs, state.u, state, state[:, :transPriority], state.p[:strategy])
allocs = get_allocs!(reqs, state.u, state, state[:, :transPriority], state.p[:strategy])

qs .= get_init_satisfied(allocs, qs, state)

Expand All @@ -168,7 +167,13 @@ function evolve!(state)
for i = 1:nparts(state, :T)
qs[i] != 0 && push!(
state.ongoing_transitions,
Transition(string(state[i, :transName]) * "_@$(state.t)", get_sampled_transition(state, i), state.t, qs[i], 0.0),
Transition(
string(state[i, :transName]) * "_@$(state.t)",
get_sampled_transition(state, i),
state.t,
qs[i],
0.0,
),
)
end

Expand Down Expand Up @@ -332,7 +337,7 @@ function ReactionNetworkProblem(
transition_recipes = transitions
u0_init = zeros(nparts(acs, :S))

for i in 1:nparts(acs, :S)
for i = 1:nparts(acs, :S)
if !isnothing(acs[i, :specName]) && haskey(u0, acs[i, :specName])
u0_init[i] = u0[acs[i, :specName]]
else
Expand All @@ -350,19 +355,17 @@ function ReactionNetworkProblem(
) [:transLHS, :transRHS, :transToSpawn, :transHash]
transitions = Dict{Symbol,Vector}(a => [] for a in transitions_attrs)

sol = DataFrame("t" => Float64[], (string(name) => Float64[] for name in acs[:, :specName])...)
sol = DataFrame(
"t" => Float64[],
(string(name) => Float64[] for name in acs[:, :specName])...,
)
network = ReactionNetworkProblem(
name,
acs,
attrs,
transition_recipes,
u0_init,
merge(
p,
Dict(
:strategy => get(keywords, :alloc_strategy, :weighted),
),
),
u0_init,
merge(p, Dict(:strategy => get(keywords, :alloc_strategy, :weighted))),
keywords[:tspan][1],
keywords[:tspan],
get(keywords, :tstep, 1),
Expand All @@ -371,7 +374,7 @@ function ReactionNetworkProblem(
log,
observables,
wrap_fun,
sol
sol,
)

save!(network)
Expand All @@ -387,7 +390,7 @@ function AlgebraicAgents._reinit!(state::ReactionNetworkProblem)
state.observables = compile_observables(state.acs)
empty!(state.sol)

state
return state
end

function AlgebraicAgents._step!(state::ReactionNetworkProblem)
Expand All @@ -400,20 +403,24 @@ function AlgebraicAgents._step!(state::ReactionNetworkProblem)

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

save!(state)
return state.t += state.dt
end

function AlgebraicAgents._projected_to(state::ReactionNetworkProblem)
state.t > state.tspan[2] ? true : state.t
return state.t > state.tspan[2] ? true : state.t
end

function fetch_params(acs::ReactionNetworkSchema)
return Dict{Symbol,Any}((
acs[i, :prmName] => acs[i, :prmVal] for
i in Iterators.filter(i -> !isnothing(acs[i, :prmVal]), 1:nparts(acs, :P))
))
end
end
6 changes: 2 additions & 4 deletions src/state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ function init_u!(state::ReactionNetworkProblem)
foreach(i -> u[i] = state[i, :specInitVal], 1:nparts(state, :S));
state.u = u)
end
function save!(state::ReactionNetworkProblem)
return push!(state.sol, (state.t, state.u[:]...))
end
save!(state::ReactionNetworkProblem) = push!(state.sol, (state.t, state.u[:]...))

function compile_observables(acs::ReactionNetworkSchema)
observables = Dict{Symbol,Observable}()
Expand Down Expand Up @@ -224,4 +222,4 @@ set_params(state::ReactionNetworkProblem, vals...) =
function add_to_spawn!(state::ReactionNetworkProblem, hash, n)
ix = findfirst(ix -> state.transition_recipes[:transHash][ix] == hash)
return !isnothing(ix) && (state.transition_recipes[:transHash][ix] += n)
end
end
1 change: 1 addition & 0 deletions tutorial/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ simulate(prob)
# access solution
prob.sol

# plot solution
draw(prob)

0 comments on commit aec5820

Please sign in to comment.