I've made an app that performs multivariate constrained optimization using Scipy's minimize() function (using the SLSQP solver). It's working ok, so now I'm looking at improving the performance of it.
The process for calculating my objective value is quite heavy, and takes about a quarter of a second to compute. That doesn't sound like much, but when minimise() does its thing, it does this calculation about 600 times. Additionally, the process for running the constraint function takes about the same time, and is also computed about 600 times during optimisation.
The thing is, the code for calculating the objective value and the constraint value is nearly identical, just the very last bit at the end differs. (My code processes a set of variables, and produces a set of results. Some of those results are relevant for calculating the objective value, while others are relevant for calculating the constraint value).
Is there a way that I can share the bulk of the calculation between the objective value calculation and the constraint value calculation? If this is possible, then I could nearly halve my optimization time.
I've noticed that the constraints dictionary can have extra arguments 'args' passed to it. Perhaps there is a way of passing it the set of 'results' gained during the objective value calculation?
Thanks, Hugh.