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

Generating parallel reproducible results #163

Closed taleslimaf closed 1 year ago

taleslimaf commented 3 years ago

To ensure that the seed is assigned during parallelism, I have to change the following class to receive parameters initializer and initargs. That way I can pass a function that instantiates the seed (initializer) and as a parameter which seed I want to use (initargs). This modification does not impact the current code.

class ProcessPoolEvaluator(SubmitEvaluator):

    def __init__(self, processes=None, initializer=None, initargs=()):
        try:
            from concurrent.futures import ProcessPoolExecutor
            self.executor = ProcessPoolExecutor(
                max_workers = processes,
                initializer = initializer, 
                initargs = initargs
            )
            super(ProcessPoolEvaluator, self).__init__(self.executor.submit)
            LOGGER.log(logging.INFO, "Started process pool evaluator")

            if processes:
                LOGGER.log(logging.INFO, "Using user-defined number of processes: %d", processes)
        except ImportError:
            # prevent error from showing in Eclipse if concurrent.futures not available
            raise

    def close(self):
        LOGGER.log(logging.DEBUG, "Closing process pool evaluator")
        self.executor.shutdown()
        LOGGER.log(logging.INFO, "Closed process pool evaluator")
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.