SciML / DataDrivenDiffEq.jl

Data driven modeling and automated discovery of dynamical systems for the SciML Scientific Machine Learning organization
https://docs.sciml.ai/DataDrivenDiffEq/stable/
MIT License
405 stars 57 forks source link

Update Symbolics and MTK #287

Closed AlCap23 closed 2 years ago

AlCap23 commented 2 years ago

Fails locally for Michaelis Menten, lets see how its doing here.

AlCap23 commented 2 years ago

Now it does not fail on MM but rather throws a stack trace related to build_function.


ERROR: LoadError: MethodError: no method matching normalize_args(::Term{Real, Nothing})
Closest candidates are:
  normalize_args(::Vector{T} where T) at /Users/juliusmartensen/.julia/packages/RuntimeGeneratedFunctions/KrkGo/src/RuntimeGeneratedFunctions.jl:223
  normalize_args(::Symbol) at /Users/juliusmartensen/.julia/packages/RuntimeGeneratedFunctions/KrkGo/src/RuntimeGeneratedFunctions.jl:224
  normalize_args(::Expr) at /Users/juliusmartensen/.julia/packages/RuntimeGeneratedFunctions/KrkGo/src/RuntimeGeneratedFunctions.jl:225
Stacktrace:
  [1] iterate
    @ ./generator.jl:47 [inlined]
  [2] _collect
    @ ./array.jl:691 [inlined]
  [3] collect_similar
    @ ./array.jl:606 [inlined]
  [4] map
    @ ./abstractarray.jl:2294 [inlined]
  [5] normalize_args(args::Vector{Term{Real, Nothing}})
    @ RuntimeGeneratedFunctions ~/.julia/packages/RuntimeGeneratedFunctions/KrkGo/src/RuntimeGeneratedFunctions.jl:223
  [6] iterate
    @ ./generator.jl:47 [inlined]
  [7] collect_to!(dest::Vector{Symbol}, itr::Base.Generator{Vector{Any}, typeof(RuntimeGeneratedFunctions.normalize_args)}, offs::Int64, st::Int64)
    @ Base ./array.jl:724
  [8] collect_to_with_first!(dest::Vector{Symbol}, v1::Symbol, itr::Base.Generator{Vector{Any}, typeof(RuntimeGeneratedFunctions.normalize_args)}, st::Int64)
    @ Base ./array.jl:702
  [9] _collect(c::Vector{Any}, itr::Base.Generator{Vector{Any}, typeof(RuntimeGeneratedFunctions.normalize_args)}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
    @ Base ./array.jl:696
 [10] collect_similar
    @ ./array.jl:606 [inlined]
 [11] map
    @ ./abstractarray.jl:2294 [inlined]
 [12] normalize_args(args::Vector{Any})
    @ RuntimeGeneratedFunctions ~/.julia/packages/RuntimeGeneratedFunctions/KrkGo/src/RuntimeGeneratedFunctions.jl:223
 [13] RuntimeGeneratedFunctions.RuntimeGeneratedFunction(cache_tag::Type, context_tag::Type, ex::Expr; opaque_closures::Bool)
    @ RuntimeGeneratedFunctions ~/.julia/packages/RuntimeGeneratedFunctions/KrkGo/src/RuntimeGeneratedFunctions.jl:56
 [14] RuntimeGeneratedFunctions.RuntimeGeneratedFunction(cache_tag::Type, context_tag::Type, ex::Expr)
    @ RuntimeGeneratedFunctions ~/.julia/packages/RuntimeGeneratedFunctions/KrkGo/src/RuntimeGeneratedFunctions.jl:55
 [15] _build_and_inject_function(mod::Module, ex::Expr)
    @ Symbolics ~/.julia/packages/Symbolics/mFWWM/src/build_function.jl:140
 [16] _build_function(::Symbolics.JuliaTarget, ::Vector{Num}, ::Vector{Term{Real, Nothing}}, ::Vararg{Any, N} where N; expression::Type, expression_module::Module, checkbounds::Bool, postprocess_fbody::Symbolics.var"#261#265", linenumbers::Bool, outputidxs::Nothing, skipzeros::Bool, wrap_code::Tuple{Nothing, Nothing}, fillzeros::Bool, parallel::Symbolics.SerialForm, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Symbolics ~/.julia/packages/Symbolics/mFWWM/src/build_function.jl:247
 [17] #build_function#241
    @ ~/.julia/packages/Symbolics/mFWWM/src/build_function.jl:52 [inlined]
 [18] _build_ddd_function(rhs::Vector{Num}, states::Vector{Term{Real, Nothing}}, parameters::Vector{Any}, iv::Num, controls::Symbolics.Arr{Term{Real, Nothing}, 1}, eval_expression::Bool)
    @ DataDrivenDiffEq ~/.julia/dev/DataDrivenDiffEq/src/basis/build_function.jl:96
 [19] Basis(eqs::Vector{Equation}, states::Vector{Term{Real, Nothing}}; parameters::Vector{Any}, iv::Num, controls::Symbolics.Arr{Term{Real, Nothing}, 1}, observed::Vector{Any}, name::Symbol, simplify::Bool, linear_independent::Bool, eval_expression::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ DataDrivenDiffEq ~/.julia/dev/DataDrivenDiffEq/src/basis/type.jl:122
 [20] build_solution(prob::DataDrivenProblem{Float64, false, DataDrivenDiffEq.Continuous}, Ξ::Matrix{Float64}, opt::ImplicitOptimizer{Vector{Float64}}, b::Basis, implicits::Vector{Num}; eval_expression::Bool)
    @ DataDrivenDiffEq ~/.julia/dev/DataDrivenDiffEq/src/solution.jl:244
 [21] solve(p::DataDrivenProblem{Float64, false, DataDrivenDiffEq.Continuous}, b::Basis, opt::ImplicitOptimizer{Vector{Float64}}, implicits::Vector{Num}; normalize::Bool, denoise::Bool, maxiter::Int64, eval_expression::Bool, round::Bool, kwargs::Base.Iterators.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:g, :scale_coefficients), Tuple{typeof(ĝ), Bool}}})
    @ DataDrivenDiffEq ~/.julia/dev/DataDrivenDiffEq/src/solve/sindy.jl:123
 [22] top-level scope
    @ ~/.julia/dev/DataDrivenDiffEq/test/sindy/cartpole.jl:68
in expression starting at /Users/juliusmartensen/.julia/dev/DataDrivenDiffEq/test/sindy/cartpole.jl:68

@shashi @YingboMa Do you have any ideas, hints or quick fixes for this ? I would appreciate the help 😄

ChrisRackauckas commented 2 years ago

Looks like a symbolic vector thing. How are your variables being defined?

AlCap23 commented 2 years ago

I didn't change much, even though I reordered the basis files.

I collect the equations of a Basis within the constructor. I overload deleteat for Symbolics.Arr via a wrap. I switched an isempty to lenght(u) < 1 within - the DataDriven function generator.

And the error just occurs in the third SINDy testset. Which is somewhat strange. If it would be a general SINDy problem, it should occur in the first two. If it would be related to Implicit SINDy it should also occur in the Michaelis Menten test.

I will provide better hints in the morning, right now I am on my mobile so sorry for the lack of links.