Support NumPy 2 & enable ruff NPY warnings #126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'schoice()
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 withast.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 ofnp.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 withnp.random.default_rng()
and added a utility function to easily access it thoughout the project.Closes #112