Skip to content

Commit 56329e1

Browse files
committed
Fix observed function generation
1 parent 59963d6 commit 56329e1

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/structural_transformation/symbolics_tearing.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,11 +590,13 @@ function tearing_reassemble(state::TearingState, var_eq_matching; simplify = fal
590590
oldobs[idx] = (lhs ~ neweqs[eqidx].rhs)
591591
end
592592
deleteat!(oldobs, sort!(removed_obs))
593-
@set! sys.observed = [oldobs; subeqs]
594593
@set! sys.substitutions = Substitutions(subeqs, deps)
595594
@set! state.sys = sys
596595
@set! sys.tearing_state = state
597596

597+
der2expr = Dict(eq.lhs => eq.rhs for eq in equations(sys) if isdiffeq(eq))
598+
obs = substitute.([oldobs; subeqs], (der2expr,))
599+
@set! sys.observed = obs
598600
return invalidate_cache!(sys)
599601
end
600602

src/systems/diffeqs/odesystem.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,22 +323,14 @@ function build_explicit_observed_function(sys, ts;
323323
end
324324
ts = map(t -> substitute(t, subs), ts)
325325
obsexprs = []
326-
eqs_cache = Ref{Any}(nothing)
327326
for i in 1:maxidx
328327
eq = obs[i]
329328
lhs = eq.lhs
330329
rhs = eq.rhs
331330
vars!(vars, rhs)
332331
for v in vars
333-
isdifferential(v) || continue
334-
if eqs_cache[] === nothing
335-
eqs_cache[] = Dict(eq.lhs => eq.rhs for eq in equations(sys))
336-
end
337-
eqs_dict = eqs_cache[]
338-
rhs = get(eqs_dict, v, nothing)
339-
if rhs === nothing
340-
error("The observed variable $(eq.lhs) depends on the differentiated variable $v, but it's not explicit solved. Fix file an issue if you are sure that the system is valid.")
341-
end
332+
isdifferential(v) &&
333+
error("Observed `$eq` depends on differentiated variable `$v`. This is not supported.")
342334
end
343335
empty!(vars)
344336
push!(obsexprs, lhs rhs)

0 commit comments

Comments
 (0)