platypus.evaluator module

class platypus.evaluator.ApplyEvaluator(apply_func)

Evaluates 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 func takes input of type T and returns a result of type R. In the context of an Evaluator, both types will be Job.

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 multiprocessing module and, in particular, the Pool class, which provides both apply and map functions.

Parameters

apply_funcCallable

The apply function.

evaluate_all(jobs, **kwargs)

Evaluates all of the jobs.

Parameters

jobsiterable of Job

The jobs to execute.

kwargs :

Any additional arguments passed on to the evaluator.

Returns

The evaluated jobs.

class platypus.evaluator.Evaluator

Abstract class for evaluators.

abstract evaluate_all(jobs, **kwargs)

Evaluates all of the jobs.

Parameters

jobsiterable of Job

The jobs to execute.

kwargs :

Any additional arguments passed on to the evaluator.

Returns

The evaluated jobs.

class platypus.evaluator.Job

Abstract 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 Evaluator used 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 platypus.evaluator.MapEvaluator(map_func=<class 'map'>)

Evaluates 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 func takes input of type T and returns a result of type R. In the context of an Evaluator, both types will be Job.

Parameters

map_funcCallable

The map-like function.

evaluate_all(jobs, **kwargs)

Evaluates all of the jobs.

Parameters

jobsiterable of Job

The jobs to execute.

kwargs :

Any additional arguments passed on to the evaluator.

Returns

The evaluated jobs.

class platypus.evaluator.MultiprocessingEvaluator(processes=None)

Evaluator using Python’s multiprocessing library.

Parallelization is provided by spawning multiple Python processes. Refer to the multiprocessing module and Pool for any additional requirements.

Parameters

processesint

The number of processes to spawn. If None, will use the number of available CPUs.

class platypus.evaluator.PoolEvaluator(pool)

Evaluates jobs using a pool.

The two most common pool implementations are MPIPool, which is included with Platypus, and Schwimmbad. In order to be considered a pool, the implementation must:

  1. Provide the map attribute with a map-like function for submitting jobs to the pool.

  2. Provide a close() method that stops accepting new jobs and begins shutting down the pool.

  3. 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 platypus.evaluator.ProcessPoolEvaluator(processes=None)

Evaluator using Python’s ProcessPoolExecutor.

Refer to the concurrent.futures module and ProcessPoolExecutor for any additional requirements.

Parameters

processesint

The size of the process pool. If None, will use the number of available CPUs.

class platypus.evaluator.SubmitEvaluator(submit_func)

Evaluates 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 func takes input of type T and returns a result of type R. In the context of an Evaluator, both types will be Job.

For more information, see the concurrent.futures module and, in particular, the Executor class.

Parameters

submit_funcCallable

The submit function.

evaluate_all(jobs, **kwargs)

Evaluates all of the jobs.

Parameters

jobsiterable of Job

The jobs to execute.

kwargs :

Any additional arguments passed on to the evaluator.

Returns

The evaluated jobs.