SciML / ModelingToolkit.jl

An acausal modeling framework for automatically parallelized scientific machine learning (SciML) in Julia. A computer algebra system for integrated symbolics for physics-informed machine learning and automated transformations of differential equations
https://mtk.sciml.ai/dev/
Other
1.43k stars 209 forks source link

Sensitivity and Vector Parameters Symbolic probems #2097

Closed GuidoBallabio closed 1 year ago

GuidoBallabio commented 1 year ago

While I was trying to implement sensitivity analysis and neuralODEs on a MTK model I noticed a few issues;

  1. As known vector parameters are not ready (#1271) last example say they work while slow, but not anymore)
  2. the remake function suggested in the FAQ to avoid symbolic processing in the optimization function actually calls symbolis and not differentiable function resulting in errors.
  3. I tried working around it declaring tha parameter as scala and then pass it a vector, and it works for ODEProblem! But then it crashes on optimization, even patching my way through the remake function and passing non-symbolic args to it, because the sensitivity code expects a scalar parameter reasonably.

Here an MWE of a vector parameters problem that was working at the time of #1271 :

using ModelingToolkit
@parameters p[1:61]
test_fun(x, p) = x + sum(p)
@register_symbolic test_fun(x, p)
println(test_fun(0, p))
println(test_fun(0, p[1]))

output:

Symbolics._mapreduce(identity, +, p, Colon(), (:init => false,))
test_fun(0, p[1])

It should be:

test_fun(0, p)
test_fun(0, p[1])

as far as I am concerned, register symbolic should let parse inside the function.

I would love to be able to do something as in #1271, that used to work even if slow because not vectorized. I accept workarounds, and thanks for your lovely work and libraries!

ChrisRackauckas commented 1 year ago

the remake function suggested in the FAQ to avoid symbolic processing in the optimization function actually calls symbolis and not differentiable function resulting in errors.

I tried working around it declaring tha parameter as scala and then pass it a vector, and it works for ODEProblem! But then it crashes on optimization, even patching my way through the remake function and passing non-symbolic args to it, because the sensitivity code expects a scalar parameter reasonably.

That's https://github.com/SciML/SciMLSensitivity.jl/issues/760.

So closing because it's a duplicate, and better tracked at the sensitivity analysis AD level. But yes, it's on our minds.