martius-lab / cluster_utils

https://cluster-utils.readthedocs.io/stable/
Other
12 stars 0 forks source link

Support NumPy 2 & enable ruff NPY warnings #126

Open luator opened 3 weeks ago

luator commented 3 weeks ago

Not too long ago, NumPy 2.0 got released. cluster_utils didn't work with it out of the box, so we restricted the dependency to numpy<2.

Looking into it now, it seems the only actual problem was in the Discrete distribution when using booleans: Using NumPy's choice() converted the list of native bools to an array of np.bool. Later one, this clashed when passing the parameters to the job script, where they are parsed with ast.literal_eval(). Simply converting back to list with .tolist() seems to be enough to fix this.

I also enabled the NPY warnings of ruff, which can aid migration. The only warnings it showed where related to usage of np.random (it's preferred to use a different rng nowadays), though. While this might not be an issue for Numpy 2, I still changed to using a random generator created with np.random.default_rng() and added a utility function to easily access it thoughout the project.

Closes #112