SciML / SciMLSensitivity.jl

A component of the DiffEq ecosystem for enabling sensitivity analysis for scientific machine learning (SciML). Optimize-then-discretize, discretize-then-optimize, adjoint methods, and more for ODEs, SDEs, DDEs, DAEs, etc.
https://docs.sciml.ai/SciMLSensitivity/stable/
Other
330 stars 71 forks source link

ODELocalSensitivityProblem() for singular mass matrix problems #225

Open omalleyc opened 4 years ago

omalleyc commented 4 years ago

Hi, I am trying to use the new functionality to obtain local sensitivities from DAE models. @ChrisRackauckas was able to show me an example using the adjoint_sensitivity() but when I tried using the ODELocalSensitivityProblem for the same problem I get an error regarding a DimensionMismatch for the mass matrix. See the MWE below:

using DifferentialEquations, DiffEqSensitivity
using ForwardDiff

function rober(du,u,p,t)
y₁,y₂,y₃ = u
k₁,k₂,k₃ = p
du[1] = -k₁*y₁+k₃*y₂*y₃
du[2] = k₁*y₁-k₂*y₂^2-k₃*y₂*y₃
du[3] = y₁ + y₂ + y₃ - 1
nothing
end

M = [1. 0 0; 0 1. 0;0 0 0]
p = [0.04,3e7,1e4]
u0=[1.0,0.0,0.0]
tspan=(0.0,100)

f = ODEFunction(rober,mass_matrix=M)

prob_singular_mm_fs=ODEForwardSensitivityProblem(f,u0, tspan,p,sensealg = ForwardDiffSensitivity();)
prob_singular_mm = solve(prob_singular_mm_fs,Rodas5(autodiff=false),reltol=1e-8,abstol=1e-8)
ArnoStrouwen commented 2 years ago

You should not use sensealg as a keyword, try: prob_singular_mm_fs=ODEForwardSensitivityProblem(f,u0, tspan,p,ForwardDiffSensitivity();)

The way you use it it defaults to ForwardSensitivity(), which does not handle mass matrices correctly, I think.