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

Replace RandomState with Generator #166

Open
leonlan opened this issue Sep 1, 2023 · 2 comments
Open

Replace RandomState with Generator #166

leonlan opened this issue Sep 1, 2023 · 2 comments
Assignees
Labels
maintenance Maintenance chore

Comments

@leonlan
Copy link
Collaborator

leonlan commented Sep 1, 2023

Is your feature request related to a problem? Please describe

The ALNS library currently uses numpy.random's RandomState for random number generation. But this object is considered legacy and no longer receives updates from Numpy 1.16 onwards.

The main problem happens when users pass their own rng to ALNS. The current default RNG from numpy is Generator, but it has a different interface than RandomState (e.g., integers vs. randint). Since we implement some acceptance criteria/operator selection schemes assuming that the RNG is a RandomState object, users that use Generator object will run into problems.

Describe the solution you'd like

We should replace RandomState with Generator.

Describe alternatives you have considered

N/A

Additional context

N/A

@leonlan leonlan added the enhancement New feature or request label Sep 1, 2023
@N-Wouda
Copy link
Owner

N-Wouda commented Sep 1, 2023

I think I worked around this a few years ago in SimulatedAnnealing (but might've been somewhere else). Back then the generator interface was quite new, so I hadn't wanted to move over yet. By now I think we can just port.

@leonlan
Copy link
Collaborator Author

leonlan commented Sep 1, 2023

Yup, here:

# TODO deprecate RandomState in favour of Generator - which uses
# random(), rather than random_sample().
try:
return probability >= rnd.random()
except AttributeError:
return probability >= rnd.random_sample()

I initially thought of supporting both RandomState and Generator like this, but since RandomState is legacy we should just replace it entirely.

@leonlan leonlan added maintenance Maintenance chore and removed enhancement New feature or request labels Sep 1, 2023
@leonlan leonlan self-assigned this Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance chore
Projects
None yet
Development

No branches or pull requests

2 participants