guofei9987 / scikit-opt

Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Optimization Algorithm,Immune Algorithm, Artificial Fish Swarm Algorithm, Differential Evolution and TSP(Traveling salesman)
https://scikit-opt.github.io/scikit-opt/#/en/
MIT License
5.3k stars 989 forks source link

Fix RuntimeError: context has already been set #223

Closed JesseSenior closed 5 months ago

JesseSenior commented 11 months ago

After invoking torch.multiprocessing.set_start_method, importing sko will result in "RuntimeError: context has already been set". Here is a simple code to reproduce it(to be run in a non-win32 environment).

import torch.multiprocessing as mp
mp.set_start_method("spawn")

import sko # <-- RuntimeError occurs.

This pull request should fix it. (Reference: https://github.com/pytorch/pytorch/issues/3492#issuecomment-392977006) Possible related Issue: #146

emil-peters commented 10 months ago

I had the same issue on my system. Could we look into solving it or accept this fix?

guofei9987 commented 5 months ago

thank you!