gemseo.core.parallel_execution.disc_parallel_linearization module#

Parallel execution of linearized disciplines.

class DiscParallelLinearization(disciplines, n_processes=2, use_threading=False, wait_time_between_fork=0.0, exceptions_to_re_raise=(), execute=True)[source]#

Bases: CallableParallelExecution[Mapping[str, Any], _WorkerData]

Linearize disciplines in parallel.

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • disciplines (Sequence[Discipline]) -- The disciplines to execute.

  • n_processes (int) --

    The maximum simultaneous number of threads, if use_threading is True, or processes otherwise, used to parallelize the execution.

    By default it is set to 2.

  • use_threading (bool) --

    Whether to use threads instead of processes to parallelize the execution. Multiprocessing will copy (serialize) all the disciplines, while threading will share all the memory. This is important to note if you want to execute the same discipline multiple times, in which case you shall use multiprocessing.

    By default it is set to False.

  • wait_time_between_fork (float) --

    The time to wait between two forks of the process/thread.

    By default it is set to 0.0.

  • exceptions_to_re_raise (Sequence[type[Exception]]) --

    The exceptions that should be raised again when caught inside a worker. If None, all exceptions coming from workers are caught and the execution is allowed to continue.

    By default it is set to ().

  • execute (bool) --

    Whether to start by executing the discipline with the input data for which to compute the Jacobian; this allows to ensure that the discipline was executed with the right input data; it can be almost free if the corresponding output data have been stored in the cache.

    By default it is set to True.

Raises:

ValueError -- If there are duplicated workers in workers when using multithreading.

execute(inputs, exec_callback=(), task_submitted_callback=None)[source]#

Execute all the processes.

Parameters:
  • inputs (Sequence[StrKeyMapping]) -- The input values.

  • exec_callback (CallbackType | Iterable[CallbackType]) --

    Callback functions called with the pair (index, outputs) as arguments when an item is retrieved from the processing. Index is the associated index in inputs of the input used to compute the outputs. If empty, no function is called.

    By default it is set to ().

  • task_submitted_callback (Callable[[], None] | None) -- A callback function called when all the tasks are submitted, but not done yet. If None, no function is called.

Returns:

The computed outputs.

Return type:

list[JacobianData | None]

Warning

This class relies on multiprocessing features, it is therefore necessary to protect its execution with an if __name__ == '__main__': statement when working on Windows.