Backend
CancellationPolicy
¶
Bases: Flag
Policy to use when cancelling futures after exiting an Executor.
Note
Not all backends support all policies.
ATTRIBUTE | DESCRIPTION |
---|---|
NONE |
Do not cancel any futures.
|
PENDING |
Cancel all pending futures, but not running ones.
|
RUNNING |
Cancel all running futures, but not pending ones.
|
ALL |
Cancel all pending and running futures.
|
BaseParallelBackend
¶
Abstract base class for all parallel backends.
executor(max_workers=None, config=ParallelConfig(), cancel_futures=CancellationPolicy.PENDING)
abstractmethod
classmethod
¶
Returns an executor for the parallel backend.
Source code in src/pydvl/parallel/backend.py
init_parallel_backend(config)
¶
Initializes the parallel backend and returns an instance of it.
The following example creates a parallel backend instance with the default configuration, which is a local joblib backend.
To create a parallel backend instance with a different backend, e.g. ray, you can pass the backend name as a string to the constructor of ParallelConfig.
PARAMETER | DESCRIPTION |
---|---|
config |
instance of ParallelConfig with cluster address, number of cpus, etc.
TYPE:
|
Source code in src/pydvl/parallel/backend.py
available_cpus()
¶
Platform-independent count of available cores.
FIXME: do we really need this or is os.cpu_count
enough? Is this portable?
RETURNS | DESCRIPTION |
---|---|
int
|
Number of cores, or 1 if it is not possible to determine. |
Source code in src/pydvl/parallel/backend.py
effective_n_jobs(n_jobs, config=ParallelConfig())
¶
Returns the effective number of jobs.
This number may vary depending on the parallel backend and the resources available.
PARAMETER | DESCRIPTION |
---|---|
n_jobs |
the number of jobs requested. If -1, the number of available CPUs is returned.
TYPE:
|
config |
instance of ParallelConfig with cluster address, number of cpus, etc.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The effective number of jobs, guaranteed to be >= 1. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
if the effective number of jobs returned by the backend is < 1. |
Source code in src/pydvl/parallel/backend.py
Created: 2023-10-14