Skip to content

Commit 949eca7

Browse files
Merge pull request #3070 from AayushSabharwal/as/dep-param-name
fix: allow accessing parameter dependencies via `Symbol` names
2 parents 52a1ebf + efca396 commit 949eca7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/systems/index_cache.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,16 @@ function IndexCache(sys::AbstractSystem)
277277

278278
dependent_pars = Set{BasicSymbolic}()
279279
for eq in parameter_dependencies(sys)
280-
push!(dependent_pars, eq.lhs)
280+
sym = eq.lhs
281+
ttsym = default_toterm(sym)
282+
rsym = renamespace(sys, sym)
283+
rttsym = renamespace(sys, ttsym)
284+
for s in [sym, ttsym, rsym, rttsym]
285+
push!(dependent_pars, s)
286+
if hasname(s) && (!iscall(s) || operation(s) != getindex)
287+
symbol_to_variable[getname(s)] = sym
288+
end
289+
end
281290
end
282291

283292
return IndexCache(

test/symbolic_indexing_interface.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,12 @@ get_dep = @test_nowarn getu(prob, 2p1)
185185
@test getu(prob, p1)(prob) == getu(prob, :p1)(prob)
186186
@test getu(prob, p2)(prob) == getu(prob, :p2)(prob)
187187
end
188+
189+
@testset "Parameter dependencies as symbols" begin
190+
@variables x(t) = 1.0
191+
@parameters a=1 b
192+
@named model = ODESystem(D(x) ~ x + a - b, t, parameter_dependencies = [b ~ a + 1])
193+
sys = complete(model)
194+
prob = ODEProblem(sys, [], (0.0, 1.0))
195+
@test prob.ps[b] == prob.ps[:b]
196+
end

0 commit comments

Comments
 (0)