Skip to content

Commit

Permalink
fix: allow accessing parameter dependencies via Symbol names
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Sep 23, 2024
1 parent 52a1ebf commit 5e2fee6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/systems/index_cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,16 @@ function IndexCache(sys::AbstractSystem)

dependent_pars = Set{BasicSymbolic}()
for eq in parameter_dependencies(sys)
push!(dependent_pars, eq.lhs)
sym = eq.lhs
ttsym = default_toterm(sym)
rsym = renamespace(sys, sym)
rttsym = renamespace(sys, ttsym)
for s in [sym, ttsym, rsym, rttsym]
push!(dependent_pars, s)
if hasname(s) && (!iscall(s) || operation(s) != getindex)
symbol_to_variable[getname(s)] = sym
end
end
end

return IndexCache(
Expand Down
9 changes: 9 additions & 0 deletions test/symbolic_indexing_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,12 @@ get_dep = @test_nowarn getu(prob, 2p1)
@test getu(prob, p1)(prob) == getu(prob, :p1)(prob)
@test getu(prob, p2)(prob) == getu(prob, :p2)(prob)
end

@testset "Parameter dependencies as symbols" begin
@variables x(t) = 1.0
@parameters a = 1 b
@named model = ODESystem(D(x) ~ x + a - b, t, parameter_dependencies = [b ~ a + 1])
sys = complete(model)
prob = ODEProblem(sys, [], (0.0, 1.0))
@test prob.ps[b] == prob.ps[:b]
end

0 comments on commit 5e2fee6

Please sign in to comment.