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
Julia Version 1.10.4
Commit 48d4fd4843 (2024-06-04 10:41 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 4 × Intel(R) Core(TM) i3-8130U CPU @ 2.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =
Additional context
When an ODESystem is used to construct a BifurcationProblem, only the equations, parameters and unknowns are included. If an observed variable, with its own equations, if used in the RHS of any of the ODEs, then it will be undefined in the resulting NonlinearSystem.
The following code provides a workaround by ensuring ALL observed variables and equations are included in the NonlinearSystem (and skipping the ODESystem conversion step). This also requires including initial guesses for the observed variables.
using ModelingToolkit
using BifurcationKit
using ModelingToolkit: t_nounits as t, D_nounits as D
@mtkmodel FOL begin
@parameters begin
τ # parameters
end
@variables begin
x(t) # dependent variables
RHS(t)
end
@equations begin
RHS ~ (1 - x) / τ
D(x) ~ RHS
end
end
@mtkbuild fol = FOL()
par = [fol.τ => 1.]
u0 = [fol.x => 1.]
prob = ODEProblem(fol, u0, (0.0, 1.), par)
bif_par = fol.τ
# Define the NonlinearSystem to include observed variables
nsys = NonlinearSystem([[0 ~ eq.rhs for eq in equations(fol)]; [eq for eq in observed(fol)]],
[unknowns(fol); [eq.lhs for eq in observed(fol)]],
parameters(fol);
name = nameof(fol))
# This means observed variables are now unknowns and so need initial guesses
u0 = [u0; [fol.RHS => (1 - 1.) / 1.]]
bp = BifurcationProblem(complete(nsys), u0, par, bif_par)
opts_br = ContinuationPar(p_min = 0.5,
p_max = 2.)
bf = bifurcationdiagram(bp, PALC(), 2, opts_br)
Not sure if its best to have a system like this (where observed variables and their equations are included separately), but with a check to make sure the observed variables actually need including. Or if its better to unfurl any observed variables that are used in the RHS.
Describe the bug 🐞
Using observed variables in the RHS of an ODESystem leads to errors when computing bifurcation diagrams.
Expected behavior
A bifurcation diagram should be plotted, instead an error is thrown because the observed variable is not defined.
Minimal Reproducible Example 👇
Error & Stacktrace ⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
Additional context
When an ODESystem is used to construct a BifurcationProblem, only the equations, parameters and unknowns are included. If an observed variable, with its own equations, if used in the RHS of any of the ODEs, then it will be undefined in the resulting NonlinearSystem.
The following code provides a workaround by ensuring ALL observed variables and equations are included in the NonlinearSystem (and skipping the ODESystem conversion step). This also requires including initial guesses for the observed variables.
Not sure if its best to have a system like this (where observed variables and their equations are included separately), but with a check to make sure the observed variables actually need including. Or if its better to unfurl any observed variables that are used in the RHS.