SciML / ModelingToolkit.jl

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
https://mtk.sciml.ai/dev/
Other
1.41k stars 205 forks source link

Error when creating JumpProblem from a ReactionSystem with keyword arguments #1042

Closed manuel-rhdt closed 3 years ago

manuel-rhdt commented 3 years ago

After I updated to the newest version of ModelingToolkit, my previously working code broke.

I am creating a JumpProblem from a ReactionSystem using the following code:

# rs::ReactionSystem = [...]
aggregator = Direct()
dprob = DiscreteProblem(rs, u0, tspan, p)
jprob = JumpProblem(rs, dprob, aggregator, save_positions=(false, false))

which gives an error in the last line with the following backtrace

LoadError: MethodError: no method matching JumpSystem(::RecursiveArrayTools.ArrayPartition{Any, Tuple{Vector{MassActionJump}, Vector{ConstantRateJump}, Vector{VariableRateJump}}}, ::Sym{Real, Base.ImmutableDict{DataType, Any}}, ::Vector{Any}, ::Vector{Any}; name=Symbol("##ReactionSystem#265"), systems=Any[], save_positions=(false, false))
  Closest candidates are:
    JumpSystem(::U, ::Any, ::Vector{T} where T, ::Vector{T} where T, ::Vector{Equation}, ::Symbol, ::Vector{JumpSystem}, ::Dict, ::Any) where U<:RecursiveArrayTools.ArrayPartition at /Users/mr/.julia/packages/ModelingToolkit/6NE0T/src/systems/jumps/jumpsystem.jl:29 got unsupported keyword arguments "name", "systems", "save_positions"
    JumpSystem(::Any, ::Any, ::Any, ::Any; observed, systems, default_u0, default_p, defaults, name, connection_type) at /Users/mr/.julia/packages/ModelingToolkit/6NE0T/src/systems/jumps/jumpsystem.jl:56 got unsupported keyword argument "save_positions"
  Stacktrace:
    [1] kwerr(::NamedTuple{(:name, :systems, :save_positions), Tuple{Symbol, Vector{Any}, Tuple{Bool, Bool}}}, ::Type, ::RecursiveArrayTools.ArrayPartition{Any, Tuple{Vector{MassActionJump}, Vector{ConstantRateJump}, Vector{VariableRateJump}}}, ::Sym{Real, Base.ImmutableDict{DataType, Any}}, ::Vector{Any}, ::Vector{Any})
      @ Base ./error.jl:157
    [2] convert(::Type{JumpSystem}, rs::ReactionSystem; name::Symbol, combinatoric_ratelaws::Bool, kwargs::Base.Iterators.Pairs{Symbol, Tuple{Bool, Bool}, Tuple{Symbol}, NamedTuple{(:save_positions,), Tuple{Tuple{Bool, Bool}}}})
      @ ModelingToolkit ~/.julia/packages/ModelingToolkit/6NE0T/src/systems/reaction/reactionsystem.jl:503
    [3] JumpProblem(::ReactionSystem, ::DiscreteProblem{SVector{6, Int64}, Tuple{Float64, Float64}, true, Vector{Float64}, SciMLBase.DiscreteFunction{true, SciMLBase.DiscreteFunction{true, SciMLBase.var"#158#159", Nothing, Nothing}, Nothing, Vector{Symbol}}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::Direct; kwargs::Base.Iterators.Pairs{Symbol, Tuple{Bool, Bool}, Tuple{Symbol}, NamedTuple{(:save_positions,), Tuple{Tuple{Bool, Bool}}}})
      @ ModelingToolkit ~/.julia/packages/ModelingToolkit/6NE0T/src/systems/reaction/reactionsystem.jl:535

The error claims that the keyword argument save_positions is not supported. However, this keyword argument is in fact supported for a JumpProblem constructor. The problem is, that this keyword argument gets passed to the convert(::Type{JumpSystem}, rs::ReactionSystem, …) call as well, whereas it should only be passed to the JumpProblem constructor. Therefore, I think the problem is the following code.

https://github.com/SciML/ModelingToolkit.jl/blob/31883c39ce682942a472445a2b741bf03e5d8bed/src/systems/reaction/reactionsystem.jl#L535

ChrisRackauckas commented 3 years ago

What's the result of ]st -m?

manuel-rhdt commented 3 years ago

The installed versions are the following

(GaussianMcmc) pkg> st
     Project GaussianMcmc v0.1.0
      Status `~/Git/GaussianMcmc/Project.toml`
  [c7e460c6] ArgParse v1.1.4
  [479239e8] Catalyst v6.13.0
  [a93c6f00] DataFrames v1.1.1
  [2b5f629d] DiffEqBase v6.62.2
  [c894b116] DiffEqJump v6.14.2
  [31c24e10] Distributions v0.25.3
  [634d3b9d] DrWatson v1.18.3
  [442a2c76] FastGaussQuadrature v0.4.7
  [5789e2e9] FileIO v1.9.1
  [f67ccb44] HDF5 v0.14.3
  [682c06a0] JSON v0.21.1
  [961ee093] ModelingToolkit v5.19.0
  [3cdcf5f2] RecipesBase v1.1.1
  [90137ffa] StaticArrays v1.2.2
  [2913bbd2] StatsBase v0.33.8
  [4c63d2b9] StatsFuns v0.9.8
  [28d57a85] Transducers v0.4.65
  [8ba89e20] Distributed
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [9a3f8284] Random
  [10745b16] Statistics
manuel-rhdt commented 3 years ago

The full output of ]st -m:

(GaussianMcmc) pkg> st -m
     Project GaussianMcmc v0.1.0
      Status `~/Git/GaussianMcmc/Manifest.toml`
  [c3fe647b] AbstractAlgebra v0.17.1
  [1520ce14] AbstractTrees v0.3.4
  [79e6a3ab] Adapt v3.3.1
  [dce04be8] ArgCheck v2.1.0
  [c7e460c6] ArgParse v1.1.4
  [ec485272] ArnoldiMethod v0.1.0
  [4fba245c] ArrayInterface v3.1.17
  [198e06fe] BangBang v0.3.30
  [9718e550] Baselet v0.1.1
  [a74b3585] Blosc v0.7.0
  [00ebfdb7] CSTParser v2.5.0
  [479239e8] Catalyst v6.13.0
  [d360d2e6] ChainRulesCore v0.9.45
  [861a8166] Combinatorics v1.0.2
  [a80b9123] CommonMark v0.8.1
  [38540f10] CommonSolve v0.2.0
  [bbf7d656] CommonSubexpressions v0.3.0
  [34da2185] Compat v3.30.0
  [b152e2b5] CompositeTypes v0.1.2
  [a33af91c] CompositionsBase v0.1.0
  [187b0558] ConstructionBase v1.2.1
  [a8cc5b0e] Crayons v4.0.4
  [9a962f9c] DataAPI v1.6.0
  [a93c6f00] DataFrames v1.1.1
  [864edb3b] DataStructures v0.18.9
  [e2d170a0] DataValueInterfaces v1.0.0
  [244e2a9f] DefineSingletons v0.1.1
  [2b5f629d] DiffEqBase v6.62.2
  [c894b116] DiffEqJump v6.14.2
  [163ba53b] DiffResults v1.0.3
  [b552c78f] DiffRules v1.0.2
  [31c24e10] Distributions v0.25.3
  [ffbed154] DocStringExtensions v0.8.5
  [e30172f5] Documenter v0.26.3
  [5b8099bc] DomainSets v0.5.2
  [634d3b9d] DrWatson v1.18.3
  [da5c29d0] EllipsisNotation v1.1.0
  [e2ba6199] ExprTools v0.1.3
  [7034ab61] FastBroadcast v0.1.8
  [442a2c76] FastGaussQuadrature v0.4.7
  [5789e2e9] FileIO v1.9.1
  [1a297f60] FillArrays v0.11.7
  [6a86dc24] FiniteDiff v2.8.0
  [59287772] Formatting v0.4.2
  [f6369f11] ForwardDiff v0.10.18
  [069b7b12] FunctionWrappers v1.1.2
  [f67ccb44] HDF5 v0.14.3
  [0e44f5e4] Hwloc v2.0.0
  [b5f81e59] IOCapture v0.1.1
  [615f187c] IfElse v0.1.0
  [d25df0c9] Inflate v0.1.2
  [22cec73e] InitialValues v0.2.10
  [8197267c] IntervalSets v0.5.3
  [41ab1584] InvertedIndices v1.0.0
  [42fd0dbc] IterativeSolvers v0.9.1
  [82899510] IteratorInterfaceExtensions v1.0.0
  [692b3bcd] JLLWrappers v1.3.0
  [682c06a0] JSON v0.21.1
  [98e50ef6] JuliaFormatter v0.13.7
  [b964fa9f] LaTeXStrings v1.2.1
  [2ee39098] LabelledArrays v1.6.1
  [23fbe1c1] Latexify v0.15.6
  [093fc24a] LightGraphs v1.3.5
  [2ab3a3ac] LogExpFunctions v0.2.4
  [bdcacae8] LoopVectorization v0.12.36
  [1914dd2f] MacroTools v0.5.6
  [128add7d] MicroCollections v0.1.0
  [e1d29d7a] Missings v1.0.0
  [961ee093] ModelingToolkit v5.19.0
  [46d2c3a1] MuladdMacro v0.2.2
  [77ba4419] NaNMath v0.3.5
  [8913a72c] NonlinearSolve v0.3.8
  [6fe1bfb0] OffsetArrays v1.9.2
  [bac558e1] OrderedCollections v1.4.1
  [90014a1f] PDMats v0.11.1
  [d96e819e] Parameters v0.12.2
  [69de0a69] Parsers v1.1.0
  [e409e4f3] PoissonRandom v0.4.0
  [f517fe37] Polyester v0.3.1
  [2dfb63ee] PooledArrays v1.2.1
  [21216c6a] Preferences v1.2.2
  [08abe8d2] PrettyTables v1.1.0
  [1fd47b50] QuadGK v2.4.1
  [fb686558] RandomExtensions v0.4.3
  [e6cf234a] RandomNumbers v1.4.0
  [3cdcf5f2] RecipesBase v1.1.1
  [731186ca] RecursiveArrayTools v2.11.4
  [f2c3362d] RecursiveFactorization v0.1.12
  [189a3867] Reexport v1.1.0
  [ae029012] Requires v1.1.3
  [79098fc4] Rmath v0.7.0
  [7e49a35a] RuntimeGeneratedFunctions v0.5.2
  [476501e8] SLEEFPirates v0.6.21
  [1bc83da4] SafeTestsets v0.0.1
  [0bca4576] SciMLBase v1.13.4
  [efcf1570] Setfield v0.7.0
  [699a6c99] SimpleTraits v0.9.3
  [a2af1166] SortingAlgorithms v1.0.0
  [276daf66] SpecialFunctions v1.5.1
  [171d559e] SplittablesBase v0.1.13
  [aedffcd0] Static v0.2.5
  [90137ffa] StaticArrays v1.2.2
  [82ae8749] StatsAPI v1.0.0
  [2913bbd2] StatsBase v0.33.8
  [4c63d2b9] StatsFuns v0.9.8
  [7792a7ef] StrideArraysCore v0.1.13
  [d1185830] SymbolicUtils v0.11.3
  [0c5d862f] Symbolics v0.1.32
  [3783bdb8] TableTraits v1.0.1
  [bd369af6] Tables v1.4.3
  [b718987f] TextWrap v1.0.1
  [8290d209] ThreadingUtilities v0.4.4
  [a759f4b9] TimerOutputs v0.5.9
  [0796e94c] Tokenize v0.5.16
  [28d57a85] Transducers v0.4.65
  [a2a6695c] TreeViews v0.3.0
  [5c2747f8] URIs v1.3.0
  [3a884ed6] UnPack v1.0.2
  [1986cc42] Unitful v1.8.0
  [3d5dd08c] VectorizationBase v0.20.16
  [700de1a5] ZygoteRules v0.2.1
  [0b7ba130] Blosc_jll v1.21.0+0
  [0234f1f7] HDF5_jll v1.12.0+1
  [e33a78d0] Hwloc_jll v2.4.1+0
  [5ced341a] Lz4_jll v1.9.3+0
  [458c3c95] OpenSSL_jll v1.1.10+0
  [efe28fd5] OpenSpecFun_jll v0.5.5+0
  [f50d1b31] Rmath_jll v0.3.0+0
  [3161d3a3] Zstd_jll v1.5.0+0
  [0dad84c5] ArgTools
  [56f22d72] Artifacts
  [2a0f44e3] Base64
  [ade2ca70] Dates
  [8bb1440f] DelimitedFiles
  [8ba89e20] Distributed
  [f43a241f] Downloads
  [9fa8497b] Future
  [b77e0a4c] InteractiveUtils
  [b27032c2] LibCURL
  [76f85450] LibGit2
  [8f399da3] Libdl
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [d6f4376e] Markdown
  [a63ad114] Mmap
  [ca575930] NetworkOptions
  [44cfe95a] Pkg
  [de0858da] Printf
  [3fa0cd96] REPL
  [9a3f8284] Random
  [ea8e919c] SHA
  [9e88b42a] Serialization
  [1a1011a3] SharedArrays
  [6462fe0b] Sockets
  [2f01184e] SparseArrays
  [10745b16] Statistics
  [4607b0f0] SuiteSparse
  [fa267f1f] TOML
  [a4e569a6] Tar
  [8dfed614] Test
  [cf7118a7] UUIDs
  [4ec0a83e] Unicode
  [e66e0078] CompilerSupportLibraries_jll
  [deac9b47] LibCURL_jll
  [29816b5a] LibSSH2_jll
  [c8ffd9c3] MbedTLS_jll
  [14a3606d] MozillaCACerts_jll
  [83775a58] Zlib_jll
  [8e850ede] nghttp2_jll
  [3f19e933] p7zip_jll
isaacsas commented 3 years ago

I think the issue is that JumpSystem's constructor needs to accept arbitrary kwargs.

isaacsas commented 3 years ago

I'll try to put in a PR for this tonight.

isaacsas commented 3 years ago

@manuel-rhdt should be fixed now on master.