anyoptimization / pymoo

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

Concurrency safety parallelisation #579

Closed romanovzky closed 6 months ago

romanovzky commented 6 months ago

Hi all,

I have a problem where in order to evaluate an individual I need to write a file to disk, execute a program, and read the file. In order to safely parallelise, I need to be able to write the files with distinct name for each pop individual, i.e. something like this

file_path = f"/tmp/{point_id}"
with(f"{file_path}.in", "w") as f:
   f.write(x)
_ = subprocess.run([mysofware, f"/tmp/{point_id}.in", "f/tmp/{point_id}.out", capture_output=True)
with(f"{file_path}.out","w") as f:
    output = f.read()

however, looking at all possible ways of running pymoo (minimize, ask and tell, etc) I don't seem to have any way of having a (at least per generation) unique identifier of a candidate solution so that file_path is unique and I don't have concurrency issues, and therefore can't parallelise my evaluate.

Am I missing something? Cheers

romanovzky commented 6 months ago

Sorry, just realised that Problem, instead of ElementWiseProblem accepts a whole pop, so I can in principle parallelise inside the _evaluate method. Is this correct?

blankjul commented 6 months ago

yes exactly this is how pymoo is designed!

Please reopen if this does not resolve your issue.