SciML / SciMLBase.jl

The Base interface of the SciML ecosystem
https://docs.sciml.ai/SciMLBase/stable
MIT License
118 stars 91 forks source link

Regression: Cases of indexing on Nonlinear problem's not working #720

Closed TorkelE closed 1 day ago

TorkelE commented 2 weeks ago

MWE:

using ModelingToolkit
using ModelingToolkit: getu

@variables t X(t) Y(t) XY(t)
@parameters kp kd k1 k2
D = Differential(t)
eqs = [
    0 ~ kp - kd*X - k1*X + k2*Y,
    0 ~ k1*X - k2*Y,
    XY ~ X + Y
]
@mtkbuild nsys = NonlinearSystem(eqs)

observed(nsys)
u0 = [X => 1.0, Y => 2.0]
ps = [kp => 1.0, kd => 2.0, k1 => 3.0, k2 => 4.0]
nprob = NonlinearProblem(nsys, u0, ps)

# Scalar inputs.
nprob[XY] # Works
nprob[nsys.XY] # Works
nprob[:XY] # Works
getu(nprob, XY)(nprob) # Works
getu(nprob, nsys.XY)(nprob) # Works
getu(nprob, :XY)(nprob) # Works

# Tuple inputs.
nprob[(XY, X)] # ERROR: Invalid indexing of problem
nprob[(nsys.XY, nsys.X)] # ERROR: Invalid indexing of problem
nprob[(:XY, :X)] # ERROR: Invalid indexing of problem
getu(nprob, (XY, X))(nprob) # Works
getu(nprob, (nsys.XY, nsys.X))(nprob) # Works
getu(nprob, (:XY, :X))(nprob) # ERROR: UndefVarError: `XY` not defined

# Vector inputs.
nprob[[XY, X]] # works
nprob[[nsys.XY, nsys.X]] # works
nprob[[:XY, :X]] # works
getu(nprob, [XY, X])(nprob) # works
getu(nprob, [nsys.XY, nsys.X])(nprob) # works
getu(nprob, [:XY, :X])(nprob) # ERROR: UndefVarError: `XY` not defined

Think some might have been there previously, but a few of these were working but now causes test failures in Catalyst.

AayushSabharwal commented 1 day ago

All of this works with SciMLBase#master, just needs a tag