Local sensitivity analysis with SciMLSensitivity
The docs and paper mention that SciMLSensitivity can be used for local sensitivity analysis, though the two are not compatible in a neat way.
For example, one would expect the following to work
using Catalyst
using DifferentialEquations
using SciMLSensitivity
brusselator = @reaction_network begin
A, ∅ → X
1, 2X + Y → 3X
B, X → Y
1, X → ∅
end
p = [:A => 1., :B => 2.]
u0 = [:X => 1.0, :Y => 1.0]
tspan = (0.0, 30.0)
prob = ODEForwardSensitivityProblem(brusselator, u0, tspan, p)
solve(prob)
Yet, it doesn't because ODEForwardSensitivityProblem requires a function, not a system. Is there a correct way of doing this (I would love to add this to the docs) or is there some kind of form you have to give the system.
Relatedly, is there a way to linearized a reaction network using linearization of ModelingToolkit?
I found it, based on the explanation in the bifurcation settings. My solution was (for a slightly different system):
prob_sens = ODEForwardSensitivityProblem(oprob.f, [0.0, 0.1], tspan, [1.7, 29, 50, 10, 100])
sol_sens = solve(prob_sens)
u, dp = extract_local_sensitivities(sol_sens)
dC = dp[3] # C is the third parameter
plot(sol_sens.t, dC', title="Sensitivity on the ingoing concentration", label=["dS/dt" "dX/dt"])
Should this be added to the docs?
We should probably get ModelingToolkit to add a dispatch so that the following works:
osys = convert(ODESystem, brusselator)
ODEForwardSensitivityProblem(osys, u0, tspan, p)
Then we can add a dispatch here to make
ODEForwardSensitivityProblem(brusselator, u0, tspan, p)
work.
I believe @TorkelE was planning to add a tutorial on sensitivity analysis via Catalyst. I don't know if he has started on it yet.
It would probably make sense to just add a SciMLSensitivity extension to ModelingToolkit to define that dispatch, hopefully it could reuse most of the current ODEFunction and ODEProblem code there to work.
It looks like ODEForwardSensitivityFunction is itself missing needed fields for symbolic indexing and such to work too: https://github.com/SciML/SciMLSensitivity.jl/blob/fde15237adef794d3b544fb62d80db3188abbdf6/src/forward_sensitivity.jl#L10-L37
Just confirming that a tutorial and some additional helper functions for the context of Catalyst is in the works.