Accelerating the compilation time of optimisation problem

6 views (last 30 days)
I am running a optimization problem in simulink. Its a constrained non-linear optimization with fmincon solver. The issue i am facing is the larger runtime for the problem due to larger compilation time at each iteration. I have a model with large no of thermal masses. When i simplyfy the model with less number of thermal networks and elements, the model is running faster. I need to know what can be done to improve this compilation time when i have large thermal masses for a model.
  1 Comment
Walter Roberson
Walter Roberson on 27 Jul 2022
fmincon() only "compiles" the function in any sense the first time the function is parsed. And technically speaking if you use something like
fmincon(@obj, ....)
then obj will be parsed before fmincon is even started.
If you have code that uses mcc to compile an .exe for each iteration, then you would need to have a very good reason to do that.
In some cases, it occasionally makes sense to build a Symbolic expression, and then have MATLAB convert the symbolic expression to matlab code using matlabFunction() or odeFunction() . There is a sense in which that could be called "compiling". That process can take a fair while for complicated expressions, especially if you told it to save the result to file and you did not remember to tell it to turn optimization off.
But... for most people, MATLAB parses the objective function once, usually before fmincon starts, and after that it is a matter of executing the function, not of "compiling" it.

Sign in to comment.

Answers (1)

Andy Bartlett
Andy Bartlett on 27 Jul 2022
Edited: Andy Bartlett on 27 Jul 2022
You can get dramatic speed-ups across multiple simulation by using Simulink's Fast Restart and several related features. See this Youtube on Simulink Fast Restart. You may also wish to explore accelerator and rapid accelerator. The key thing for this to work is that your optimization search is only making "tunable" changes such as adjusting the value of tunable model parameters and possibly externally fed input signals.
If you are rewiring blocks, replacing blocks, changing data types, dimensions, complexity, ..., then a full re-compile of the Simulink model will be needed after each "structural" change. But between each "structural" change, you can still leverage all the speed-up opportunities to explore "tunable" changes.
There is also a product Simulink Design Optimization dedicated to this type of optimzation loops wrapped around a Simulink model. That product is aware of and designed to leverage speed-up opportunities. For example, watch Youtube on Fast Restart for Simulink Design Optimization.


Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by