Feature: in-place solvers#665
Conversation
|
@cako I understand if you are busy and have no time for this, but if you can and are interested I'd appreciate any feedback (see https://github.com/PyLops/pylops_inplacesolvers for comparison with current solvers and in particular https://github.com/PyLops/pylops_inplacesolvers/blob/main/notebooks/Visualize.ipynb for some visualization of timings) |
|
Had a cursory look, and everything looked good. I did have a couple questions regarding intended use. Seems like preallocating is slower? And it doesnt change the memory consumption? If so, is there any reason to doing it? Regarding the memory usage computation, I think it's very useful. |
When preallocate=False is selected, all solvers behave equivalently to the current solvers without performing any operation in-place.
Thanks @cako! Mmh not sure where you see that Regarding memory, yes I do not expect the peak memory to change with pre-allocation as anyways the same variables are either created in the step method over and over again (current behavior) or upfront and filled (new behavior)... In general, after some thinking, I decided to modify a bit the inner working of all the solvers when |
|
@cako just checking you saw my reply? |
|
Yup! Sorry forgot to reply. But yes, your answer makes sense. |
Great, I am going to do one last look and polishing and then I will merge 😄 |
… into feat-inplacesolvers

This PR introduces two new functionalities to all of the solvers in the
optimizationmodule, namely:memory_usagethat can be used before running thesetupandstepmethods to get an approximate estimate of the memory usage of the solver.preallocatethat modifies the behavior of the solver compared to the current one, by preallocating all of the arrays in thesetupmethod and performing all operations on arrays in-place (note that this does not apply to theOp.matvec/Op.rmatvecoperations as those are currently not implemented in-place)*approximate refers to the fact that the memory usage is calculated taking into account only the main variables of the solvers (ND-arrays of the size of either the model or the data) and not additional lists or arrays that store losses or other metrics.