Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOPTEST slows down over the course of a simulation #520

Closed
kbenne opened this issue Feb 27, 2023 · 4 comments
Closed

BOPTEST slows down over the course of a simulation #520

kbenne opened this issue Feb 27, 2023 · 4 comments
Assignees
Milestone

Comments

@kbenne
Copy link
Contributor

kbenne commented Feb 27, 2023

We have noticed that the time required to step the simulation increases (about linearly) during a simulation. This isn't as noticable for two week test scenarios, but if you perform an annual run then it becomes more significant. We are seeing almost a four fold increase in step time by the end of an annual simulation.

After some investigation it appears like the problem is related to the y_store and u_store data structures, which hold the historical simulation data and grow over the simulation time. The problem is that these structures are copied on every step in the process appending (they are numpy arrays).

Here is a graph of the simulation step time over the course of an annual simulation.

Screen Shot 2023-02-27 at 9 22 00 AM

This issue relates to #240 which resulted in numpy array being introduced, because it is more memory efficient compared to Python List. The problem we are seeing now is that numpy array results in copies which are computationally expensive.

The solution may be to use Python Array https://docs.python.org/3/library/array.html which should offer efficient storage of numerical values and be computationally efficient. (avoid copy on each step)

@dhblum
Copy link
Collaborator

dhblum commented Feb 27, 2023

Thanks @kbenne for reporting. I've done some memory and simulation time profiling with the following case:

Ubuntu 18.04 VM
Test Case: bestest_hydronic
Simulation period: 180 days starting from 0.
"master" = current master branch using numpy arrays and append
"list" = version using python lists and append
"parray" = version using python arrays and append
"3600s" = 3600 second advance step size
"60s" = 60 second advance step size

Below is a plot of computer memory use over time to complete the simulation period (memory recorded every 1s of real time) given the different arrangements described above. Note the reduction in memory consumption and total simulation time provided by use of python arrays instead of numpy arrays or python lists for the data appending and storing.

Figure_1-4

I therefore propose changing the implementation to use python arrays for data storage instead of the current approach of numpy arrays.

Above plot created using the attached python script and development on this branch: https://github.com/ibpsa/project1-boptest/tree/issue520_arrayAppend. Latest commit on that uses python arrays. Remaining to-do I see there is adjust numerical differences in unit test results and review.
memory_test.txt

@dhblum
Copy link
Collaborator

dhblum commented Feb 27, 2023

Here's a benchmark plot for multizone_office_simple_air, a more complex test case with more points being stored. Benchmark settings same as previous comment. Python arrays seem to provide memory efficiency here as well.

Figure_1-5

@dhblum dhblum added this to the v0.4.0 milestone Feb 27, 2023
@dhblum
Copy link
Collaborator

dhblum commented Mar 1, 2023

See discussion also with regards to single or double float precision here: #521 (comment).

@dhblum
Copy link
Collaborator

dhblum commented Mar 2, 2023

Clsed by #522.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants