Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get state dependencies, observed -> SymbolicIndexingInterface #2071

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ function controls(sys::AbstractSystem)
isempty(systems) ? ctrls : [ctrls; reduce(vcat, namespace_controls.(systems))]
end

function observed(sys::AbstractSystem)
function SymbolicIndexingInterface.observed(sys::AbstractSystem)
obs = get_observed(sys)
systems = get_systems(sys)
[obs;
Expand Down Expand Up @@ -638,6 +638,37 @@ function SymbolicIndexingInterface.is_param_sym(sys::AbstractSystem, sym)
!isnothing(SymbolicIndexingInterface.param_sym_to_index(sys, sym))
end

function SymbolicIndexingInterface.observed_sym_to_index(sys::AbstractSystem, sym)
findfirst(isequal(sym), SymbolicIndexingInterface.observed(sys))
end
function SymbolicIndexingInterface.is_observed_sym(sys::AbstractSystem, sym)
!isnothing(SymbolicIndexingInterface.obvserved_sym_to_index(sys, sym))
end

function SymbolicIndexingInterface.get_state_dependencies(sys::AbstractSystem, sym)
obs = observed(sys)
lhss = map(obs) do eq
eq.lhs
end
sts = states(sys)
i = observed_sym_to_index(sys, sym)
if isnothing(i)
return []
end

eq = obs[i]
varss = vars(eq)
out = mapreduce(vcat, varss, init = []) do u
if any(isequal(u), lhss)
get_state_dependencies(sys, u)
else
[u]
end
end |> unique

return filter(x -> any(isequal(x), sts), out)
end

struct AbstractSysToExpr
sys::AbstractSystem
states::Vector
Expand Down
1 change: 1 addition & 0 deletions src/systems/diffeqs/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ function build_explicit_observed_function(sys, ts;

# FIXME: This is a rather rough estimate of dependencies. We assume
# the expression depends on everything before the `maxidx`.
# ?
subs = Dict()
maxidx = 0
for s in dep_vars
Expand Down