Warning when using "DiffEqFlux.sciml_train" and "ModelingToolkit.structural_simplify"

Hi All,

I want to use “DiffEqFlux.sciml_train” to get parameters after using “ModelingToolkit.structural_simplify”. I’m able to get a reasonable result but have a weird warning:

 Warning: Warning: Unrecognized keyword arguments found. Future versions will error.
│ The only allowed keyword arguments to `solve` are:
│ (:dense, :saveat, :save_idxs, :tstops, :d_discontinuities, :save_everystep, :save_on, :save_start, :save_end, :initialize_save, :adaptive, :abstol, :reltol, :dt, :dtmax, :dtmin, :force_dtmin, :internalnorm, :controller, :gamma, :beta1, :beta2, :qmax, :qmin, :qsteady_min, :qsteady_max, :qoldinit, :failfactor, :calck, :alias_u0, :maxiters, :callback, :isoutofdomain, :unstable_check, :verbose, :merge_callbacks, :progress, :progress_steps, :progress_name, :progress_message, :timeseries_errors, :dense_errors, :calculate_errors, :initializealg, :alg, :save_noise, :delta, :seed, :alg_hints, :kwargshandle, :trajectories, :batch_size, :sensealg, :advance_to_tstop, :stop_at_next_tstop, :default_set, :second_time)
│ See https://diffeq.sciml.ai/stable/basics/common_solver_opts/ for more details.
│ 
│ Set kwargshandle=KeywordArgError for an error message and more details.
│ Set kwargshandle=KeywordArgSilent to ignore this message.
└ @ DiffEqBase C:\Users\mzhen\.julia\packages\DiffEqBase\U3LtB\src\solve.jl:213

The code:

using ModelingToolkit, DifferentialEquations, DiffEqFlux, Plots
using DataFrames, Plots, CSV, Statistics, Zygote

df_obs = DataFrame(CSV.File("data/res5.csv"))
t_save = df_obs.time
obs = Array(df_obs[!, [2:8;]])
tspan = (t_save[1], last(t_save))

@parameters param_c1 param_c2 param_c3 param_c4 param_c5 param_l1 param_l2
@variables t x[1:7](t) z[1:5](t)
D = Differential(t)

u0 = [x[1] => 0.0,
      x[2] => 0.0,
      x[3] => 0.0,
      x[4] => 0.0,
      x[5] => 0.0,
      x[6] => 0.0,
      x[7] => 0.0,
      z[1] => 0.82,
      z[2] => 0.179,
      z[3] => 0.315,
      z[4] => 0.0336,
      z[5] => 0.0336]

eqs = [
      D(x[1]) ~ z[1] / param_c1,
      D(x[2]) ~ z[2] / param_c2,
      D(x[3]) ~ z[3] / param_c3,
      D(x[4]) ~ z[4] / param_c4,
      D(x[5]) ~ z[5] / param_c5,
      D(x[6]) ~ x[2] / param_l1,
      D(x[7]) ~ x[4] / param_l2,
      0 ~ z[3] + z[4] + x[7] - z[2] - x[6],
      0 ~ x[1] - x[3] - x[2],
      0 ~ x[3] - x[5] - x[4],
      0 ~ z[1] + z[2] + x[6] - 1.0 + x[1],
      0 ~ z[4] + x[7] - z[5] - x[5]
]

@named sys = ODESystem(eqs)
sys_low = dae_index_lowering(sys)
simpsys = structural_simplify(sys_low)

params = [param_c1 => 1.0, param_c2 => 1.0, param_c3 => 1.0,
          param_c4 => 1.0, param_c5 => 1.0, param_l1 => 1.0, param_l2 => 1.0]
p_init = [x.second for x in params]

prob = ODAEProblem(simpsys, u0, tspan, params, jac=true)

loss = function(p)
  pred_sol = solve(prob, Tsit5(), p=p, saveat=t_save)
  pred = Array(pred_sol')
  mse = mean((pred - obs).^2)
  return mse
end

callback = function (p, l)
  println(l, " ", p)
  return false
end

result = DiffEqFlux.sciml_train(loss, p_init, ADAM(0.1), cb = callback, maxiters = 100)

Any idea how to fix it?

Thanks!

What version? MTK had a stint of passing an argument it should not have been

https://github.com/SciML/ModelingToolkit.jl/pull/1584

so make sure you’re on the latest MTK as that was only a few days ago.

@ChrisRackauckas
I’ve updated all packages, the current version of MTK is the latest one.

[[deps.ModelingToolkit]]
deps = ["AbstractTrees", "ArrayInterface", "Combinatorics", "ConstructionBase", "DataStructures", "DiffEqBase", "DiffEqCallbacks", "DiffEqJump", "DiffRules", "Distributed", "Distributions", "DocStringExtensions", "DomainSets", "Graphs", "IfElse", "InteractiveUtils", "JuliaFormatter", "LabelledArrays", "Latexify", "Libdl", "LinearAlgebra", "MacroTools", "NaNMath", "NonlinearSolve", "RecursiveArrayTools", "Reexport", "Requires", "RuntimeGeneratedFunctions", "SciMLBase", "Serialization", "Setfield", "SparseArrays", "SpecialFunctions", "StaticArrays", "SymbolicUtils", "Symbolics", "UnPack", "Unitful"]
git-tree-sha1 = "1c03e55aef5bd3b8b8caa34704eebe2bf581a444"
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
version = "8.11.6"

But I still have the same issue…

Solve with kwargshandle=KeywordArgError. What does it say?

I tried both kwargshandle=KeywordArgError and kwargshandle=KeywordArgSilent, but no effect—the same output.

If you change it to error, it will be an error instead of a warning and it will print the name of the kwarg that is bad. Can you share that message?

@ChrisRackauckas
I run the next command:

result = DiffEqFlux.sciml_train(loss, p_init, ADAM(0.1), kwargshandle=KeywordArgError, cb = callback, maxiters = 2)

The output is:

┌ Warning: Unrecognized keyword arguments found. Future versions will error.
│ The only allowed keyword arguments to `solve` are:
│ (:dense, :saveat, :save_idxs, :tstops, :d_discontinuities, :save_everystep, :save_on, :save_start, :save_end, :initialize_save, :adaptive, :abstol, :reltol, :dt, :dtmax, :dtmin, :force_dtmin, :internalnorm, :controller, :gamma, :beta1, :beta2, :qmax, :qmin, :qsteady_min, :qsteady_max, :qoldinit, :failfactor, :calck, :alias_u0, :maxiters, :callback, :isoutofdomain, :unstable_check, :verbose, :merge_callbacks, :progress, :progress_steps, :progress_name, :progress_message, :timeseries_errors, :dense_errors, :calculate_errors, :initializealg, :alg, :save_noise, :delta, :seed, :alg_hints, :kwargshandle, :trajectories, :batch_size, :sensealg, :advance_to_tstop, :stop_at_next_tstop, :default_set, :second_time)
│ See https://diffeq.sciml.ai/stable/basics/common_solver_opts/ for more details.
│ 
│ Set kwargshandle=KeywordArgError for an error message and more details.
│ Set kwargshandle=KeywordArgSilent to ignore this message.
└ @ DiffEqBase C:\Users\mzhen\.julia\packages\DiffEqBase\nxrbH\src\solve.jl:346

this output is repeated many times (>10) even if I have “maxiters = 2”

(optim) pkg> status ModelingToolkit
      Status `D:\Projects\playground\optimization_julia\optim\Project.toml`
  [961ee093] ModelingToolkit v8.11.6

No, add it to the solve call

Thank you @ChrisRackauckas !
Done.
The problem was jac=true in the prob = ODAEProblem(simpsys, u0, tspan, params, jac=true)