Open valentinsulzer opened 2 years ago
From the casadi documentation i found: Concatenation means stacking matrices horizontally or vertically. Due to the column-major way of storing elements in CasADi, it is most efficient to stack matrices horizontally. Also someone in this forum gave a suggestion in his second point about a possible acceleration instead of using vercat. I have no experience with casadi whatsoever.
@dion-w I don't really understand the solutions above ...
One idea I had is to create an object pybamm.no_memory_vertcat(a,b)
which stores the two vectors and then can be indexed as needed, taking the relevant index from a
or b
(shifted) as needed
@MarcBerliner is this still a bottleneck? not sure if your recent changes cover this? or if it will be fixed when we switch to IDAKLU
as the default
is this still a bottleneck? not sure if your recent changes cover this? or if it will be fixed when we switch to
IDAKLU
as the default
@rtimms the timings still look about the same for the CasadiSolver
, but this is not an issue with the IDAKLUSolver
since we store everything directly as numpy arrays, which handle concatenation better. Here's the IDAKLUSolver
timings:
Set-up time: 43.910 ms, Solve time: 126.159 ms (of which integration time: 125.623 ms), Total time: 170.069 ms
Updated code for timing IDAKLUSolver
:
solver = pybamm.IDAKLUSolver()
simulation = pybamm.Simulation(model, parameter_values=param, solver=solver)
t_max = 60*60*10
t_eval = np.linspace(0, t_max, num=(t_max//2))
simulation.solve([0, t_max], t_interp=t_eval)
great, thanks! i’ll leave this open for now but not a priority since we will eventually drop the casadi solver anyway
great, thanks! i’ll leave this open for now but not a priority since we will eventually drop the casadi solver anyway
Sure. I don't think it's a difficult fix if we ever want/need to patch this.
If using many time steps, it doesn't take too long to integrate the model, but it takes a long time to create the solution:
Timings are as follows:
Most of the additional solve time is being spent in this vertcat https://github.com/pybamm-team/PyBaMM/blob/23157aebce218444edc83b525dfb2c7fc8637598/pybamm/solvers/casadi_solver.py#L697
It's strange because the solution arrays are being created by the solver really fast, but then just vertcat takes a long time. Maybe there is a faster way to do vertcat?