From b3ce93e01dad51f71909dab20bb7f69e599e5f6e Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Mon, 4 Dec 2023 10:44:52 -0500 Subject: [PATCH] ode.observables is not a required field (#145) --- src/operations.jl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/operations.jl b/src/operations.jl index 5d2396b..c03cb5c 100644 --- a/src/operations.jl +++ b/src/operations.jl @@ -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] @@ -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] @@ -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 \ No newline at end of file +end