platypus.evaluator module
- class ApplyEvaluator(apply_func)
Bases:
EvaluatorEvaluates jobs using a given apply function.
An apply function is a form of asynchronous computing that takes a callable and a input, asynchronously evaluates the function on that input, and returns a future to await the result.
Thus, the apply function should satisfy this signature:
def apply(func: Callable[[T], R], input: T) -> Future[R]: ...
where
functakes input of typeTand returns a result of typeR. In the context of anEvaluator, both types will beJob.Thus, the main difference between a submit and an apply function is whether it accepts a single input or a list of inputs.
For an example, see the
multiprocessingmodule and, in particular, thePoolclass, which provides bothapplyandmapfunctions.Parameters
- apply_funcCallable
The apply function.
- class Evaluator
Bases:
objectAbstract class for evaluators.
- class Job
Bases:
objectAbstract class for implementing a distributable job.
The job should capture any inputs required by
run()along with any outputs produced by the job as attributes.Also be aware that the specific
Evaluatorused to run the jobs might mandate additional requirements. For instance, evaluators that distribute jobs across processes or machines typically need to serialize or pickle Python objects to transmit them over a network.- abstract run()
Executes the job.
- class MapEvaluator(map_func=<class 'map'>)
Bases:
EvaluatorEvaluates jobs using a given map-like function.
A map-like function takes a callable and a list of inputs, applies the function to each input, and returns a list of results. The most common example is the built-in
map()function.However, to be formal, a map function must satisfy the signature:
def map(func: Callable[[T], R], inputs: list[T]) -> list[R]: ...
where
functakes input of typeTand returns a result of typeR. In the context of anEvaluator, both types will beJob.Parameters
- map_funcCallable
The map-like function.
- class MultiprocessingEvaluator(processes=None)
Bases:
PoolEvaluatorEvaluator using Python’s multiprocessing library.
Parallelization is provided by spawning multiple Python processes. Refer to the
multiprocessingmodule andPoolfor any additional requirements.Parameters
- processesint
The number of processes to spawn. If
None, will use the number of available CPUs.
- class PoolEvaluator(pool)
Bases:
MapEvaluatorEvaluates jobs using a pool.
The two most common pool implementations are
MPIPool, which is included with Platypus, andSchwimmbad. In order to be considered a pool, the implementation must:Provide the
mapattribute with a map-like function for submitting jobs to the pool.Provide a
close()method that stops accepting new jobs and begins shutting down the pool.As jobs can continue running after closing a pool, optionally provide a
join()method to wait for the completion of all jobs.
Parameters
- poolAny
The pool.
- class ProcessPoolEvaluator(processes=None)
Bases:
SubmitEvaluatorEvaluator using Python’s ProcessPoolExecutor.
Refer to the
concurrent.futuresmodule andProcessPoolExecutorfor any additional requirements.Parameters
- processesint
The size of the process pool. If
None, will use the number of available CPUs.
- class SubmitEvaluator(submit_func)
Bases:
EvaluatorEvaluates jobs using a given submit function.
A submit function is a form of asynchronous computing that takes a callable and a list of inputs, asynchronously evaluates the function on each input, and returns a list of futures to await the results.
Thus, the submit function should satisfy this signature:
def submit(func: Callable[[T], R], inputs: list[T]) -> list[Future[R]]: ...
where
functakes input of typeTand returns a result of typeR. In the context of anEvaluator, both types will beJob.For more information, see the
concurrent.futuresmodule and, in particular, theExecutorclass.Parameters
- submit_funcCallable
The submit function.