Hello,First of all, thank you for making such an excellent tool. It has helped me immensely in my research.I'm currently trying to solve a fitting problem that has both a large parameter space (~1500 parameters) and a long computation time. I have optimized the computation using numba, which requires the use of params['name'].value to properly return a float and not a Parameters object. Now, it appears that the next bottle neck is at parameter.py:745(_getval).
Do you have any suggestions for speeding up the retrieval of parameter values? Is there room for optimization of this portion of code? I would like to give back to the project if possible.
What makes you conclude that `_getval()` is the bottleneck? If each function evaluation is a long running computation time, I would no imagine that getting the parameter values be the slow part.
You decided to not post any code or even to tell us how many of the 1500 parameter were variables. That makes it hard to know what you are doing or give any specific advice. Our request that you include a complete, minimal example is really pretty clear.
I do not know how well any of the fitting algorithms would scale to 1500 variable parameters. I expect that many would start to hit serious problems. You decided to not tell us what solver you are using.
Welll, maybe. If you have constraint expressions, or bounds, or fixed parameters, you might want to refactor your code to use fewer of these. But in the end `_getval()` is a Python function that will be called. So if that really is the bottleneck it might be hopeless.
Then again, if you want to try to see if you can get lmfit Parameters faster, go for it! As you can probably tell, ultimate runtime performance is actually not the highest priority for lmfit. Or python. Or, really, even numba. It is entirely possible that what you really need is Fortran, MPI, and access to a high-performance cluster.
Hi Matt,Thank you for taking the time to provide such an detailed and prompt response!What makes you conclude that `_getval()` is the bottleneck? If each function evaluation is a long running computation time, I would no imagine that getting the parameter values be the slow part.Please see this notebook. It contains a simplified example of the type of optimization problem at hand and the bottleneck is pretty well diagnosed to exist when defining a parameter using `expr`.
You decided to not post any code or even to tell us how many of the 1500 parameter were variables. That makes it hard to know what you are doing or give any specific advice. Our request that you include a complete, minimal example is really pretty clear.I do not understand the differentiation between parameter and variable in this context. Can you please explain the difference?
Sorry about not providing an example in my first message. I cannot share the code for the problem that I'm solving as it is unpublished research. Please see the above notebook for a basic example. Let me know if I can provide any additional information.
I do not know how well any of the fitting algorithms would scale to 1500 variable parameters. I expect that many would start to hit serious problems. You decided to not tell us what solver you are using.I'm currently using the least_squares method, because it provided the best performance for less ambitious version of this optimization problem of the same type.
Welll, maybe. If you have constraint expressions, or bounds, or fixed parameters, you might want to refactor your code to use fewer of these. But in the end `_getval()` is a Python function that will be called. So if that really is the bottleneck it might be hopeless.I came to the same conclusion last night and the above notebook provides some supporting evidence. When using a parameter defined with `expr` it significantly slows down (>5x slow down) retrieval of the value. This does make sense because it needs to evaluate the expression every time which I imagine is a lot slower than retrieving a number. Why does calling `parameter[name].value` take ~10x longer than `parameter[name]`?
Also, if the parameter is defined using `expr`, the slow down becomes ~100x. Do you think that could be accelerated at all?