ModiaSim / Modia.jl

Modeling and simulation of multidomain engineering systems
MIT License
319 stars 37 forks source link

issue with new version of Sundials v4.20.1 #169

Closed johhell closed 5 months ago

johhell commented 8 months ago

description

Modia precompilation error after system update. New version of Sundials was installed - with some changes: https://github.com/SciML/Sundials.jl/commit/ffbfee42900ca9d2697d681946ff40ca723d1962

workaround

switch back to v4.20.0

ChrisRackauckas commented 8 months ago

Do you have a standard install of Julia from Julialang.org?

johhell commented 8 months ago

Yes. julia: v1.9.2 Modia: 0.12.0 Error occurrence when called simulate! in SnoopPrecompile.@precompile_all_call and using Sundials@4.20.1 This works: ] status

(Modia) pkg> st
Project Modia v0.12.0
Status `~/Projekte/Modia/Modia.jl/Project.toml`
  [a93c6f00] DataFrames v1.6.1
  [2b5f629d] DiffEqBase v6.135.0
  [0c46a032] DifferentialEquations v7.11.0
  [6a86dc24] FiniteDiff v2.21.1
  [f6369f11] ForwardDiff v0.10.36
  [682c06a0] JSON v0.21.4
  [eff96d63] Measurements v2.10.0
  [ec7bf1ca] ModiaBase v0.11.1
  [0987c9cc] MonteCarloMeasurements v1.1.6
  [bac558e1] OrderedCollections v1.6.2
  [f2c3362d] RecursiveFactorization v0.2.20
  [189a3867] Reexport v1.2.2
  [3201582d] SignalTables v0.4.2
  [66db9d55] SnoopPrecompile v1.0.3
  [90137ffa] StaticArrays v1.6.5
⌃ [c3572dad] Sundials v4.20.0              <<<<<=======
  [a759f4b9] TimerOutputs v0.5.23
  [1986cc42] Unitful v1.17.0
  [b77e0a4c] InteractiveUtils
  [37e2e46d] LinearAlgebra
  [de0858da] Printf
  [8dfed614] Test
Info Packages marked with ⌃ have new versions available and may be upgradable.
ChrisRackauckas commented 8 months ago

What was the error?

johhell commented 8 months ago

reproducing the error

=> Sundials@4.20.1

(Modia) pkg> add Sundials@4.20.1
   Resolving package versions...
    Updating `~/Projekte/Modia/Modia.jl/Project.toml`
  [c3572dad] ↑ Sundials v4.20.0 ⇒ v4.20.1
    Updating `~/Projekte/Modia/Modia.jl/Manifest.toml`
  [c3572dad] ↑ Sundials v4.20.0 ⇒ v4.20.1
Precompiling project...
  ✗ Modia
  2 dependencies successfully precompiled in 36 seconds. 196 already precompiled.
  1 dependency errored. To see a full report either run `import Pkg; Pkg.precompile()` or load the package

status

Status `~/Projekte/Modia/Modia.jl/Project.toml`
  [a93c6f00] DataFrames v1.6.1
  [2b5f629d] DiffEqBase v6.135.0
  [0c46a032] DifferentialEquations v7.11.0
  [6a86dc24] FiniteDiff v2.21.1
  [f6369f11] ForwardDiff v0.10.36
  [682c06a0] JSON v0.21.4
  [eff96d63] Measurements v2.10.0
  [ec7bf1ca] ModiaBase v0.11.1
  [0987c9cc] MonteCarloMeasurements v1.1.6
  [bac558e1] OrderedCollections v1.6.2
  [f2c3362d] RecursiveFactorization v0.2.20
  [189a3867] Reexport v1.2.2
  [3201582d] SignalTables v0.4.2
  [66db9d55] SnoopPrecompile v1.0.3
  [90137ffa] StaticArrays v1.6.5
  [c3572dad] Sundials v4.20.1        <<<<<---------------------------------
  [a759f4b9] TimerOutputs v0.5.23
  [1986cc42] Unitful v1.17.0
  [b77e0a4c] InteractiveUtils
  [37e2e46d] LinearAlgebra
  [de0858da] Printf
  [8dfed614] Test

compile Modia

julia> using Modia
[ Info: Precompiling Modia [cb905087-75eb-5f27-8515-1ce0ec8e839e]

Welcome to Modia - Dynamic Modeling and Simulation with Julia
Version 0.12.0 (2023-06-04)
ERROR: LoadError: MethodError: no method matching append!(::Tuple{Float64}, ::Vector{Float64})

Closest candidates are:
  append!(::DataStructures.MutableLinkedList, ::Any...)
   @ DataStructures ~/.julia192/packages/DataStructures/MKv4P/src/mutable_list.jl:160
  append!(::OffsetArrays.OffsetVector{T} where T, ::Any)
   @ OffsetArrays ~/.julia192/packages/OffsetArrays/0MOrf/src/OffsetArrays.jl:604
  append!(::StatsBase.AbstractHistogram{T, 1}, ::AbstractVector) where T
   @ StatsBase ~/.julia192/packages/StatsBase/WLz8A/src/hist.jl:295
  ...

Stacktrace:
  [1] __init(prob::SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Modia.InstantiatedModel{Float64, Float64}, SciMLBase.ODEFunction{true, SciMLBase.FullSpecialize, typeof(Modia.derivatives!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::Sundials.CVODE_BDF{:Newton, :Dense, Nothing, Nothing}, timeseries::Vector{Any}, ts::Vector{Any}, ks::Vector{Any}; verbose::Bool, callback::SciMLBase.CallbackSet{Tuple{}, Tuple{SciMLBase.DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{typeof(Modia.outputs!), DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(SciMLBase.FINALIZE_DEFAULT)}, SciMLBase.DiscreteCallback{typeof(Modia.timeEventCondition!), typeof(Modia.affectTimeEvent!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}}}, abstol::Float64, reltol::Float64, saveat::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, d_discontinuities::Vector{Float64}, tstops::Tuple{Float64}, maxiters::Int64, dt::Nothing, dtmin::Float64, dtmax::Float64, timeseries_errors::Bool, dense_errors::Bool, save_everystep::Bool, save_idxs::Nothing, save_on::Bool, save_start::Bool, save_end::Bool, dense::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), progress_id::Symbol, save_timeseries::Nothing, advance_to_tstop::Bool, stop_at_next_tstop::Bool, userdata::Nothing, alias_u0::Bool, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:adaptive, :initializealg), Tuple{Bool, SciMLBase.NoInit}}})
    @ Sundials ~/.julia192/packages/Sundials/vGumE/src/common_interface/solve.jl:138
  [2] __solve(prob::SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Modia.InstantiatedModel{Float64, Float64}, SciMLBase.ODEFunction{true, SciMLBase.FullSpecialize, typeof(Modia.derivatives!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::Sundials.CVODE_BDF{:Newton, :Dense, Nothing, Nothing}, timeseries::Vector{Any}, ts::Vector{Any}, ks::Vector{Any}, recompile::Type{Val{true}}; calculate_error::Bool, kwargs::Base.Pairs{Symbol, Any, NTuple{10, Symbol}, NamedTuple{(:reltol, :abstol, :save_everystep, :callback, :adaptive, :saveat, :dtmax, :maxiters, :tstops, :initializealg), Tuple{Float64, Float64, Bool, SciMLBase.CallbackSet{Tuple{}, Tuple{SciMLBase.DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{typeof(Modia.outputs!), DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(SciMLBase.FINALIZE_DEFAULT)}, SciMLBase.DiscreteCallback{typeof(Modia.timeEventCondition!), typeof(Modia.affectTimeEvent!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}}}, Bool, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Float64, Int64, Tuple{Float64}, SciMLBase.NoInit}}})
    @ Sundials ~/.julia192/packages/Sundials/vGumE/src/common_interface/solve.jl:15
  [3] solve_call(_prob::SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Modia.InstantiatedModel{Float64, Float64}, SciMLBase.ODEFunction{true, SciMLBase.FullSpecialize, typeof(Modia.derivatives!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, args::Sundials.CVODE_BDF{:Newton, :Dense, Nothing, Nothing}; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::Base.Pairs{Symbol, Any, NTuple{10, Symbol}, NamedTuple{(:reltol, :abstol, :save_everystep, :callback, :adaptive, :saveat, :dtmax, :maxiters, :tstops, :initializealg), Tuple{Float64, Float64, Bool, SciMLBase.CallbackSet{Tuple{}, Tuple{SciMLBase.DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{typeof(Modia.outputs!), DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(SciMLBase.FINALIZE_DEFAULT)}, SciMLBase.DiscreteCallback{typeof(Modia.timeEventCondition!), typeof(Modia.affectTimeEvent!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}}}, Bool, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Float64, Int64, Tuple{Float64}, SciMLBase.NoInit}}})
    @ DiffEqBase ~/.julia192/packages/DiffEqBase/rf4hJ/src/solve.jl:557
  [4] solve_up(prob::SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Modia.InstantiatedModel{Float64, Float64}, SciMLBase.ODEFunction{true, SciMLBase.FullSpecialize, typeof(Modia.derivatives!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, sensealg::Nothing, u0::Vector{Float64}, p::Modia.InstantiatedModel{Float64, Float64}, args::Sundials.CVODE_BDF{:Newton, :Dense, Nothing, Nothing}; kwargs::Base.Pairs{Symbol, Any, NTuple{10, Symbol}, NamedTuple{(:reltol, :abstol, :save_everystep, :callback, :adaptive, :saveat, :dtmax, :maxiters, :tstops, :initializealg), Tuple{Float64, Float64, Bool, SciMLBase.CallbackSet{Tuple{}, Tuple{SciMLBase.DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{typeof(Modia.outputs!), DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(SciMLBase.FINALIZE_DEFAULT)}, SciMLBase.DiscreteCallback{typeof(Modia.timeEventCondition!), typeof(Modia.affectTimeEvent!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}}}, Bool, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Float64, Int64, Tuple{Float64}, SciMLBase.NoInit}}})
    @ DiffEqBase ~/.julia192/packages/DiffEqBase/rf4hJ/src/solve.jl:1006
  [5] solve(prob::SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Modia.InstantiatedModel{Float64, Float64}, SciMLBase.ODEFunction{true, SciMLBase.FullSpecialize, typeof(Modia.derivatives!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, args::Sundials.CVODE_BDF{:Newton, :Dense, Nothing, Nothing}; sensealg::Nothing, u0::Nothing, p::Nothing, wrap::Val{true}, kwargs::Base.Pairs{Symbol, Any, NTuple{10, Symbol}, NamedTuple{(:reltol, :abstol, :save_everystep, :callback, :adaptive, :saveat, :dtmax, :maxiters, :tstops, :initializealg), Tuple{Float64, Float64, Bool, SciMLBase.CallbackSet{Tuple{}, Tuple{SciMLBase.DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{typeof(Modia.outputs!), DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(SciMLBase.FINALIZE_DEFAULT)}, SciMLBase.DiscreteCallback{typeof(Modia.timeEventCondition!), typeof(Modia.affectTimeEvent!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}}}, Bool, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Float64, Int64, Tuple{Float64}, SciMLBase.NoInit}}})
    @ DiffEqBase ~/.julia192/packages/DiffEqBase/rf4hJ/src/solve.jl:929
  [6] macro expansion
    @ ~/.julia192/packages/TimerOutputs/RsWnF/src/TimerOutput.jl:237 [inlined]
  [7] simulateSegment!(m::Modia.InstantiatedModel{Float64, Float64}, algorithm::Sundials.CVODE_BDF{:Newton, :Dense, Nothing, Nothing}; kwargs::Base.Pairs{Symbol, Real, Tuple{Symbol, Symbol}, NamedTuple{(:stopTime, :useRecursiveFactorizationUptoSize), Tuple{Float64, Int64}}})
    @ Modia ~/Projekte/Modia/Modia.jl/src/SimulateAndPlot.jl:548
  [8] simulateSegment!
    @ ~/Projekte/Modia/Modia.jl/src/SimulateAndPlot.jl:388 [inlined]
  [9] macro expansion
    @ ~/Projekte/Modia/Modia.jl/src/SimulateAndPlot.jl:234 [inlined]
 [10] macro expansion
    @ ~/.julia192/packages/TimerOutputs/RsWnF/src/TimerOutput.jl:237 [inlined]
 [11] simulate!(m::Modia.InstantiatedModel{Float64, Float64}, algorithm::Missing; merge::Nothing, kwargs::Base.Pairs{Symbol, Real, Tuple{Symbol, Symbol}, NamedTuple{(:stopTime, :useRecursiveFactorizationUptoSize), Tuple{Float64, Int64}}})
    @ Modia ~/Projekte/Modia/Modia.jl/src/SimulateAndPlot.jl:233
 [12] simulate!
    @ ~/Projekte/Modia/Modia.jl/src/SimulateAndPlot.jl:187 [inlined]
 [13] macro expansion
    @ ~/Projekte/Modia/Modia.jl/src/Modia.jl:272 [inlined]
 [14] top-level scope
    @ ~/.julia192/packages/SnoopPrecompile/1XXT1/src/SnoopPrecompile.jl:62
 [15] include
    @ ./Base.jl:457 [inlined]
 [16] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
    @ Base ./loading.jl:2049
 [17] top-level scope
    @ stdin:3
in expression starting at /home/hans/Projekte/Modia/Modia.jl/src/Modia.jl:1
in expression starting at stdin:3
ERROR: Failed to precompile Modia [cb905087-75eb-5f27-8515-1ce0ec8e839e] to "/home/hans/.julia192/compiled/v1.9/Modia/jl_wcEWye".
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
   @ Base ./loading.jl:2300
 [3] compilecache
   @ ./loading.jl:2167 [inlined]
 [4] _require(pkg::Base.PkgId, env::String)
   @ Base ./loading.jl:1805
 [5] _require_prelocked(uuidkey::Base.PkgId, env::String)
   @ Base ./loading.jl:1660
 [6] macro expansion
   @ ./loading.jl:1648 [inlined]
 [7] macro expansion
   @ ./lock.jl:267 [inlined]
 [8] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1611
ChrisRackauckas commented 8 months ago

Is Modia declaring tstops as a tuple? That's odd but could probably be supported.

johhell commented 8 months ago

Thx for support tstop was defined as Tuple . Now modified to Vector and simulation works with Sundials@4.20.0 and Sundials@4.20.1 PR follows.

johhell commented 8 months ago

PR : https://github.com/ModiaSim/Modia.jl/pull/170

MartinOtter commented 8 months ago

Is Modia declaring tstops as a tuple? That's odd but could probably be supported.

I don't know why tstops was declared as tuple. Note, this definition is present in Modia since many years and it is odd that it worked until now (tstops as vector is of course the right approach). It might be that in some cases the definition with a vector did not work in the past, but with tuple it did, and that therefore I used the implementation with a tuple - or I just made a mistake at that time and by accident this just worked until now. Anyway, I have accepted the pull request to change this in Modia to a vector