-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
callbacks: Improve performance of _store_outcomes by ~25x (#232)
* callbacks: Improve performance of _store_outcomes by ~25x On a performance profile of the optimized lake model I noticed that the _store_case function took up a large portion of the runtime (46.4% of 5000 runs, or 9535ms). This commit optimizes the DefaultCallback class by: - Replacing Pandas DataFrames with NumPy structured arrays for faster data access and manipulation. - Using NumPy functions and data structures where possible. - Reducing unnecessary function calls. According to profiles, it speeds up `_store_outcomes` by about 25x. When running a very simple model, the whole workbench is now over 2.5x as fast. **Old** - Profile: Total time 11.172 ms (48.8%), own time 559 ms (2.4%) - Now runs about 15.000 iterations of the [simple Python model](https://emaworkbench.readthedocs.io/en/latest/basic_tutorial.html#a-simple-model-in-python) per second. **New** - Profile: Total time 424 ms (3.7%), own time 90 ms (0.8%). - Now runs about 40.000 iterations of the [simple Python model](https://emaworkbench.readthedocs.io/en/latest/basic_tutorial.html#a-simple-model-in-python) per second. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * callbacks: Return a DataFrame instead of a NumPy array * Return correct DataFrame and update test set Return a correctly indexed DataFrame and make some small adjustments to the test set. Please review carefully. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * callback: Replace NaN with None * callbacks: Update _store_case to ensure order of uncertainties and levers Co-Authored-By: Jan Kwakkel <j.h.kwakkel@tudelft.nl> * Update callbacks.py make dtypes an attribute --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jan Kwakkel <j.h.kwakkel@tudelft.nl>
- Loading branch information
1 parent
081b41f
commit a608a2e
Showing
2 changed files
with
41 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters