andrewlyden / PyLESA

Python for Local Energy Systems Analysis
MIT License
13 stars 11 forks source link

Performance: added option to move matplotlib figure generation to separate process #12

Closed thisistheplace closed 2 months ago

thisistheplace commented 3 months ago

Hi @andrewlyden,

The matplotlib savefig method is causing a bottleneck in the overall runtime. It takes ~ 1/3 to 1/2 of the overall time when running the fixed order solver. There doesn't seem to be anything that can be done about this within the matplotlib library.

I originally planned on moving the figure writing to a separate thread but matplotlib isn't threadsafe.

Instead I've moved the figure writing to a separate process (compute core) so that it doesn't block the solver from moving onto the next parametric simulation. This can make debugging more tricky but single core processing can be forced by specifying the new --singlecore option.

I've also changed the progress bars to use the tqdm library which is simpler to implement. Log messages mostly get written to the log file with just progress (and warnings/errors!) written to the screen which hopefully makes monitoring the overall run progress a bit clearer.

Thanks,

Ben