Project-Platypus / Platypus

A Free and Open Source Python Library for Multiobjective Optimization
GNU General Public License v3.0
563 stars 153 forks source link

Problem with parallel programming #131

Closed MaximilianNaglUR closed 1 year ago

MaximilianNaglUR commented 4 years ago

Hi!

I am trying to distribute the evaluation of problem statement wit ProcessPoolEvaluator. As a start, I used two tutorial problems. The first code runs perfectly, while the second crashes every time...

The first one:

from platypus import *

if __name__ == "__main__":
    algorithms = [NSGAII, (NSGAIII, {"divisions_outer":12})]
    problems = [DTLZ2(3)]

    with ProcessPoolEvaluator(4) as evaluator:
        results = experiment(algorithms, problems, nfe=1000, evaluator=evaluator)

        hyp = Hypervolume(minimum=[0, 0, 0], maximum=[1, 1, 1])
        hyp_result = calculate(results, hyp, evaluator=evaluator)
        display(hyp_result, ndigits=3)

The secon one:

from platypus import NSGAII, DTLZ2, ProcessPoolEvaluator

#simulate an computationally expensive problem
class DTLZ2_Slow(DTLZ2):

    def evaluate(self, solution):
        sum(range(1000000))
        super(DTLZ2_Slow, self).evaluate(solution)

if __name__ == "__main__":
    # define the problem definition
    problem = DTLZ2_Slow()

    # instantiate the optimization algorithm to run in parallel
    with ProcessPoolEvaluator(4) as evaluator:
        algorithm = NSGAII(problem, evaluator=evaluator)
        algorithm.run(10000)

    # display the results
    for solution in algorithm.result:
        print(solution.objectives)

I get the following error message:

Traceback (most recent call last):

  File "<ipython-input-197-e9efb994a9ba>", line 18, in <module>
    algorithm.run(10000)

  File "C:\Users\Maximilian\Anaconda3\lib\site-packages\platypus\core.py", line 405, in run
    self.step()

  File "C:\Users\Maximilian\Anaconda3\lib\site-packages\platypus\algorithms.py", line 181, in step
    self.initialize()

  File "C:\Users\Maximilian\Anaconda3\lib\site-packages\platypus\algorithms.py", line 191, in initialize
    super(NSGAII, self).initialize()

  File "C:\Users\Maximilian\Anaconda3\lib\site-packages\platypus\algorithms.py", line 72, in initialize
    self.evaluate_all(self.population)

  File "C:\Users\Maximilian\Anaconda3\lib\site-packages\platypus\core.py", line 378, in evaluate_all
    results = self.evaluator.evaluate_all(jobs)

  File "C:\Users\Maximilian\Anaconda3\lib\site-packages\platypus\evaluator.py", line 115, in evaluate_all
    return [f.result() for f in futures]

  File "C:\Users\Maximilian\Anaconda3\lib\site-packages\platypus\evaluator.py", line 115, in <listcomp>
    return [f.result() for f in futures]

  File "C:\Users\Maximilian\Anaconda3\lib\concurrent\futures\_base.py", line 435, in result
    return self.__get_result()

  File "C:\Users\Maximilian\Anaconda3\lib\concurrent\futures\_base.py", line 384, in __get_result
    raise self._exception

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

Has anyone a guess why the second code crashes?

Thanks very much in advance

Max

github-actions[bot] commented 1 year ago

This issue is stale and will be closed soon. If you feel this issue is still relevant, please comment to keep it active. Please also consider working on a fix and submitting a PR.