ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
Homogenize parameters by default
By default, we have something like Vector{Union{Int, Float64, Vector{Float64}, Vector{Int}}}
which results in excessive compilation time. We should homogenize it to Tuple{Vector{Int}, Vector{Float64}, Vector{Vector{Float64}}, Vector{Vector{Int}}}}
.
I wrote a script here as a prototype https://gist.github.com/YingboMa/72198a5cbb5db17b7e681ffad244b72a
@shashi do you have time to handle this?
CC: @bradcarman
Is this related to another issue?
Yes, the problem this solves is Julia can fail to compile a jacobian function which is built with a mixed Union type parameter vector. Julia needs to go thru every element of the parameter vector, determine it's type and compile the expression. With a Tuple that is split into N variables, julia then only needs to compile the N variable types in the jacobian expression. The following folder contains examples, jac3.jl will cause Julia to stall in precompilation, whereas jac3_mod.jl with a single type parameter vector compiles and executes very quickly.
Would this change mean that parameter tuples mixing floats and parameters get promoted to all Float64
internally? That would be undesirable, and I think potentially break, some Catalyst models.
Or is the idea to convert mixed-type parameter vector/tuples into a tuple with the mixed types separated into vector components?
Yes, split into vector components of like types
Would this just be applied to parameter vectors, or to mixed-type parameter tuples too?