toruseo / UXsim

Vehicular traffic flow simulator in road network, written in pure Python
https://toruseo.jp/UXsim/docs/
MIT License
138 stars 61 forks source link

Optimize memory usage in `homogeneous_DUO_update` via in-place update #144

Closed EwoutH closed 1 month ago

EwoutH commented 2 months ago

This commit resolves a memory consumption issue in the homogeneous_DUO_update method by replacing the previous array reallocation with an in-place update using np.place. The old implementation created new NumPy arrays in each update cycle, leading to unnecessary memory overhead.

With the in-place update, total memory usage was reduced from 1189 MB to 471 MB.

Changes

Part of https://github.com/toruseo/UXsim/issues/143.

EwoutH commented 2 months ago

@toruseo The failure values look very small, could it be that just some rounding error and the tolerances are a bit tight?

toruseo commented 2 months ago

The diff is not small. I guess (I dont fully understand the vectorizatoin technique used here) the modification broke the route choice logic.

EwoutH commented 2 months ago

Yes, took a look again, you’re right.

I will try a few other approaches, and also investigate dist_record. Could it be that s.route_pref is copied somewhere and/or pointed to from other entities?

toruseo commented 1 month ago

Closing, as better one is implemented by https://github.com/toruseo/UXsim/pull/146