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

Consistently use NumPy's default random number generator to avoid RAM usage issues from legacy call #536

Closed
rhugonnet opened this issue Apr 22, 2024 · 0 comments · Fixed by #538
Labels
performance Related to computational performance priority

Comments

@rhugonnet
Copy link
Contributor

Turns out using the legacy NumPy random generator

x = np.random.choice()

or its equivalent for consistency in the random output:

rnd = np.random.RandomState(np.random.MT19937(np.random.SeedSequence(random_state)))
rnd.choice()

and without replacement (replace=False) is leaking RAM usage by creating in memory an array the size of the sample size requested, which is not cleared after the function call. So, for instance, asking for 100 random points with a value between 0 and 1 billion, without replacement, will create an array of size 1 billion in memory which stays for a while. See numpy/numpy#14169 and GlacioHack/xdem#501 (reply in thread).
And we are currently doing this everywhere 😱

We need to replace everywhere in GeoUtils and xDEM by:

rnd = np.random.default_rng(seed=random_state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Related to computational performance priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant