-
-
Couldn't load subscription status.
- Fork 114
Open
Description
Description
When using symbolic indexing with a DAEProblem, the getters (prob[x], prob[y]) return values from the wrong indices in the underlying u0 array. The setters work correctly, but the getters are swapped.
Minimal Working Example
using ModelingToolkit, SciMLBase
using ModelingToolkit: t_nounits as t, D_nounits as D
@variables x(t) [guess = 1.0] y(t) [guess = 1.0]
@parameters p = missing [guess = 1.0] q = missing [guess = 1.0]
@mtkbuild sys = ODESystem([D(x) ~ p * y + q * t, x^3 + y^3 ~ 5], t;
initialization_eqs = [p^2 + q^2 ~ 3])
# Create the DAE problem
prob = DAEProblem{true}(sys, [D(x) => cbrt(4), D(y) => -1 / cbrt(4), p => 1.0], (0.0, 0.4))
println("Initial state:")
println(" unknowns(sys) = ", unknowns(sys)) # [y(t), x(t)] - note the order
println(" prob.u0 = ", prob.u0) # [1.0, 1.0]
println(" prob[x] = ", prob[x]) # 1.0
println(" prob[y] = ", prob[y]) # 1.0
# Set values using symbolic indexing
prob[x] = 1.0
prob[y] = cbrt(4) # β 1.587
println("\nAfter setting prob[x]=1.0 and prob[y]=cbrt(4):")
println(" prob[x] = ", prob[x]) # Returns 1.0 (expected: 1.0) β
println(" prob[y] = ", prob[y]) # Returns 1.587... (expected: 1.587...) β
println(" prob.u0 = ", prob.u0) # [1.587..., 1.0]
println("\nπ΄ BUG: The values are swapped in u0!")
println(" prob.u0[1] = ", prob.u0[1], " (should be y = ", prob[y], ")")
println(" prob.u0[2] = ", prob.u0[2], " (should be x = ", prob[x], ")")Analysis
The unknowns are ordered as [y(t), x(t)] in the system, so:
u0[1]corresponds toy(t)u0[2]corresponds tox(t)
When we set values:
prob[x] = 1.0correctly setsu0[2] = 1.0βprob[y] = cbrt(4)correctly setsu0[1] = cbrt(4)β
But when we get values:
prob[x]incorrectly returnsu0[1]instead ofu0[2]βprob[y]incorrectly returnsu0[2]instead ofu0[1]β
Impact
This bug causes test failures in Sundials.jl when using CheckInit with DAEProblems, as the initialization checks read the wrong values through symbolic indexing.
Environment
- Julia: 1.11.6
- ModelingToolkit.jl: 10.22.0
- SciMLBase.jl: 2.119.0
- SymbolicIndexingInterface.jl: 0.3.43
Related
This was discovered while working on SciML/Sundials.jl#503
Metadata
Metadata
Assignees
Labels
No labels