Skip to content

Commit

Permalink
ode.observables is not a required field (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwdchang authored Dec 4, 2023
1 parent a55c374 commit b3ce93e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ function amr_get(amr::JSON3.Object, ::Type{ODESystem})
statenames = [Symbol(s.id) for s in model.states]
statevars = [only(@variables $s) for s in statenames]
statefuncs = [only(@variables $s(t)) for s in statenames]
obsnames = [Symbol(o.id) for o in ode.observables]
obsnames = []
if haskey(ode, "observables")
obsnames = [Symbol(o.id) for o in ode.observables]
end
obsvars = [only(@variables $o) for o in obsnames]
obsfuncs = [only(@variables $o(t)) for o in obsnames]
allvars = [statevars; obsvars]
Expand Down Expand Up @@ -48,9 +51,11 @@ function amr_get(amr::JSON3.Object, ::Type{ODESystem})
subst = merge!(Dict(allvars .=> allfuncs), Dict(paramvars .=> paramvars))
eqs = [D(statef) ~ substitute(eqs[state], subst) for (state, statef) in (statenames .=> statefuncs)]

for (o, ofunc) in zip(ode.observables, obsfuncs)
expr = substitute(MathML.parse_str(o.expression_mathml), subst)
push!(eqs, ofunc ~ expr)
if haskey(ode, "observables")
for (o, ofunc) in zip(ode.observables, obsfuncs)
expr = substitute(MathML.parse_str(o.expression_mathml), subst)
push!(eqs, ofunc ~ expr)
end
end

defaults = [statefuncs .=> initial_vals; sym_defs]
Expand Down Expand Up @@ -397,4 +402,4 @@ function sciml_service_l2loss(pvals, (prob, pkeys, data)::Tuple{Vararg{Any, 3}})
tot_loss += sum((sol(ts[i]; idxs = datakeys[i]) .- timeseries[i]) .^ 2)
end
return tot_loss, sol, ts
end
end

0 comments on commit b3ce93e

Please sign in to comment.