List of batch evaluators#

Batch evaluators implemented in Python#

class pygmo.mp_bfe(chunksize=None)#

Multiprocessing batch fitness evaluator.

New in version 2.13.

This user-defined batch fitness evaluator (UDBFE) will dispatch the fitness evaluation in batch mode of a set of decision vectors to a process pool created and managed via the facilities of the standard Python multiprocessing module.

The evaluations of the decision vectors are dispatched to the processes of a global pool shared between different instances of mp_bfe. The pool is created either implicitly by the construction of the first mp_bfe object or explicitly via the init_pool() static method. The default number of processes in the pool is equal to the number of logical CPUs on the current machine. The pool’s size can be queried via get_pool_size(), and changed via resize_pool(). The pool can be stopped via shutdown_pool().

Note

Due to certain implementation details of CPython, it is not possible to initialise, resize or shutdown the pool from a thread different from the main one. Normally this is not a problem, but, for instance, if the first mp_bfe instance is created in a thread different from the main one, an error will be raised. In such a situation, the user should ensure to call init_pool() from the main thread before spawning the secondary thread.

Warning

Due to internal limitations of CPython, sending an interrupt signal (e.g., by pressing Ctrl+C in an interactive Python session) while an mp_bfe is running might end up sending an interrupt signal also to the external process(es). This can lead to unpredictable runtime behaviour (e.g., the session may hang). Although pygmo tries hard to limit as much as possible the chances of this occurrence, it cannot eliminate them completely. Users are thus advised to tread carefully with interrupt signals (especially in interactive sessions) when using mp_bfe.

Warning

Due to an upstream bug, when using Python 3.8 the multiprocessing machinery may lead to a hangup when exiting a Python session. As a workaround until the bug is resolved, users are advised to explicitly call shutdown_pool() before exiting a Python session.

Parameters

chunksize (int or None) – if not None, this positive integral represents the approximate number of decision vectors that are processed by each task submitted to the process pool by the call operator

Raises
  • TypeError – if chunksize is neither None nor a value of an integral type

  • ValueError – if chunksize is not strictly positive

  • unspecified – any exception thrown by init_pool()

get_extra_info()#

Extra info for this evaluator.

If the process pool was previously shut down via shutdown_pool(), invoking this function will trigger the creation of a new pool.

Returns

a string containing information about the number of processes in the pool

Return type

str

Raises

unspecified – any exception thrown by get_pool_size()

get_name()#

Name of this evaluator.

Returns

"Multiprocessing batch fitness evaluator"

Return type

str

static get_pool_size()#

Get the size of the process pool.

If the process pool was previously shut down via shutdown_pool(), invoking this function will trigger the creation of a new pool.

Returns

the current size of the pool

Return type

int

Raises

unspecified – any exception thrown by init_pool()

static init_pool(processes=None)#

Initialise the process pool.

This method will initialise the process pool backing mp_bfe, if the pool has not been initialised yet or if the pool was previously shut down via shutdown_pool(). Otherwise, this method will have no effects.

Parameters

processes (None or an int) – the size of the pool (if None, the size of the pool will be equal to the number of logical CPUs on the system)

Raises
  • ValueError – if the pool does not exist yet and the function is being called from a thread different from the main one, or if processes is a non-positive value

  • TypeError – if processes is not None and not an int

static resize_pool(processes)#

Resize pool.

This method will resize the process pool backing mp_bfe.

If the process pool was previously shut down via shutdown_pool(), invoking this function will trigger the creation of a new pool.

Parameters

processes (int) – the desired number of processes in the pool

Raises
  • TypeError – if the processes argument is not an int

  • ValueError – if the processes argument is not strictly positive

  • unspecified – any exception thrown by init_pool()

static shutdown_pool()#

Shutdown pool.

This method will shut down the process pool backing mp_bfe, after all pending tasks in the pool have completed.

After the process pool has been shut down, attempting to use the evaluator will raise an error. A new process pool can be created via an explicit call to init_pool() or one of the methods of the public API of mp_bfe which trigger the creation of a new process pool.

class pygmo.ipyparallel_bfe#

Ipyparallel batch fitness evaluator.

New in version 2.13.

This user-defined batch fitness evaluator (UDBFE) will dispatch the fitness evaluation in batch mode of a set of decision vectors to an ipyparallel cluster. The communication with the cluster is managed via an ipyparallel.LoadBalancedView instance which is created either implicitly when the first fitness evaluation is run, or explicitly via the init_view() method. The LoadBalancedView instance is a global object shared among all the ipyparallel batch fitness evaluators.

get_extra_info()#

Extra info for this evaluator.

Returns

a string with extra information about the status of the evaluator

Return type

str

get_name()#

Name of the evaluator.

Returns

"Ipyparallel batch fitness evaluator"

Return type

str

static init_view(client_args=[], client_kwargs={}, view_args=[], view_kwargs={})#

Init the ipyparallel view.

This method will initialise the ipyparallel.LoadBalancedView which is used by all ipyparallel evaluators to submit the evaluation tasks to an ipyparallel cluster. If the ipyparallel.LoadBalancedView has already been created, this method will perform no action.

The input arguments client_args and client_kwargs are forwarded as positional and keyword arguments to the construction of an ipyparallel.Client instance. From the constructed client, an ipyparallel.LoadBalancedView instance is then created via the ipyparallel.Client.load_balanced_view() method, to which the positional and keyword arguments view_args and view_kwargs are passed.

Note that usually it is not necessary to explicitly invoke this method: an ipyparallel.LoadBalancedView is automatically constructed with default settings the first time a batch evaluation task is submitted to an ipyparallel evaluator. This method should be used only if it is necessary to pass custom arguments to the construction of the ipyparallel.Client or ipyparallel.LoadBalancedView objects.

Parameters
  • client_args (list) – the positional arguments used for the construction of the client

  • client_kwargs (dict) – the keyword arguments used for the construction of the client

  • view_args (list) – the positional arguments used for the construction of the view

  • view_kwargs (dict) – the keyword arguments used for the construction of the view

Raises

unspecified – any exception thrown by the constructor of ipyparallel.Client or by the ipyparallel.Client.load_balanced_view() method

static shutdown_view()#

Destroy the ipyparallel view.

This method will destroy the ipyparallel.LoadBalancedView currently being used by the ipyparallel evaluators for submitting evaluation tasks to an ipyparallel cluster. The view can be re-inited implicitly by submitting a new evaluation task, or by invoking the init_view() method.

Batch evaluators exposed from C++#

class pygmo.default_bfe#

Default UDBFE.

This class is a user-defined batch fitness evaluator (UDBFE) that can be used to construct a bfe.

default_bfe is the default UDBFE used by bfe, and, depending on the properties of the input problem, it will delegate the implementation of its call operator to another UDBFE. Specifically:

See also the docs of the C++ class pagmo::default_bfe.


class pygmo.thread_bfe#

Threaded UDBFE.

This class is a user-defined batch fitness evaluator (UDBFE) that can be used to construct a bfe.

thread_bfe will use multiple threads of execution to parallelise the evaluation of the fitnesses of a batch of input decision vectors.

See also the docs of the C++ class pagmo::thread_bfe.


class pygmo.member_bfe#

Member UDBFE.

This class is a user-defined batch fitness evaluator (UDBFE) that can be used to construct a bfe.

member_bfe is a simple wrapper which delegates batch fitness evaluations to the input problem’s pygmo.problem.batch_fitness() method.

See also the docs of the C++ class pagmo::member_bfe.