You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using ModelingToolkit, OrdinaryDiffEq
@variables t u(t)[1:10] =1
u =collect(u)
eqs =Differential(t).(u) .~ (1:length(u))
@named sys =ODESystem(eqs,t,u,[]; tspan=(0, 10))
prob =ODEProblem(sys)
sol =solve(prob, Tsit5(), tstops=range(prob.tspan...; length=10000))
using BenchmarkTools
@btimegetindex($sol, $u);
# 1.649 s (12584906 allocations: 1.47 GiB)
Seems to scale roughly linearly with the length of the solution
sol =solve(prob, Tsit5(), tstops=range(prob.tspan...; length=100))
@btimegetindex($sol, $u);
# 15.070 ms (124909 allocations: 15.01 MiB)
Indexing the solution with 10 separate scalar symbols is reasonably fast. Not exactly a 1:1 comparison, but this should give a reasonable order of magnitude for the expected speed.
I think this is because of sym_to_index, which is a search through the states of the system, if there is no ordering here this would have to be an O(n) operation.
I've noticed that unsurprisingly a hashmap (Dict) indexed with symbols is faster for even a low number of states, though if you try to index with more complex expressions this becomes a trade off at low n as the hashing cost increases, we should probably be creating index maps to levarage this.
I add a sym_map that can do this in #2071, once this is merged we can move to using this by default.
Seems to scale roughly linearly with the length of the solution
Indexing the solution with 10 separate scalar symbols is reasonably fast. Not exactly a 1:1 comparison, but this should give a reasonable order of magnitude for the expected speed.
The text was updated successfully, but these errors were encountered: