anyoptimization / pymoo

NSGA2, NSGA3, R-NSGA3, MOEAD, Genetic Algorithms (GA), Differential Evolution (DE), CMAES, PSO
https://pymoo.org
Apache License 2.0
2.28k stars 390 forks source link

Update pymoo code to use Generators rather than setting global seeds. #469

Open CompRhys opened 1 year ago

CompRhys commented 1 year ago
# if a seed is set, then use it to call the random number generators
if seed is not None:
    import random
    random.seed(seed)
    np.random.seed(seed)

Currently pymoo sets global seeds that mean that it can interfere with intended functionality outside it's own scope. I would propose that we update pymoo to use the best practice of numpy Generators and then fork the seed into everywhere where a seed is used.

blankjul commented 1 year ago

This is related to #413.

I would be happy to look at a PR. But I also know that this requires touching many places in the framework. Ideally, each algorithm has a RandomState object (or maybe even operators have their own). Additionally, the implementation should be thread-safe which it currently is not.

jacktang commented 1 year ago

@blankjul I'd like to fix it.