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 ofmp_bfe
. The pool is created either implicitly by the construction of the firstmp_bfe
object or explicitly via theinit_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 viaget_pool_size()
, and changed viaresize_pool()
. The pool can be stopped viashutdown_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 callinit_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 anmp_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 usingmp_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
orNone
) – if notNone
, 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 typeValueError – 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
- Raises
unspecified – any exception thrown by
get_pool_size()
- get_name()#
Name of this evaluator.
- Returns
"Multiprocessing batch fitness evaluator"
- Return type
- 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
- 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 viashutdown_pool()
. Otherwise, this method will have no effects.- Parameters
processes (
None
or anint
) – the size of the pool (ifNone
, 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
- 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
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 ofmp_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 theinit_view()
method. TheLoadBalancedView
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
- 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 theipyparallel.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, anipyparallel.LoadBalancedView
instance is then created via theipyparallel.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 theipyparallel.Client
oripyparallel.LoadBalancedView
objects.- Parameters
client_args (
list
) – the positional arguments used for the construction of the clientclient_kwargs (
dict
) – the keyword arguments used for the construction of the clientview_args (
list
) – the positional arguments used for the construction of the viewview_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 theipyparallel.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 theinit_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 bybfe
, and, depending on the properties of the inputproblem
, it will delegate the implementation of its call operator to another UDBFE. Specifically:if the input problem provides a batch fitness member function (as established by
pygmo.problem.has_batch_fitness()
), then amember_bfe
will be constructed and invoked to produce the return value; otherwise,if the input problem provides at least the
basic
thread_safety
guarantee (as established bypygmo.problem.get_thread_safety()
), then apygmo.thread_bfe
will be constructed and invoked to produce the return value; otherwise,a
pygmo.mp_bfe
will be constructed and invoked to produce the return value.
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’spygmo.problem.batch_fitness()
method.See also the docs of the C++ class
pagmo::member_bfe
.