pydvl.parallel.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.
|
ParallelBackend
¶
Abstract base class for all parallel backends.
executor
abstractmethod
classmethod
¶
executor(
max_workers: int | None = None,
*,
config: ParallelConfig | None = None,
cancel_futures: CancellationPolicy | bool = CancellationPolicy.PENDING
) -> Executor
Returns a futures executor for the parallel backend.
Source code in src/pydvl/parallel/backend.py
init_parallel_backend
¶
init_parallel_backend(
config: ParallelConfig | None = None, backend_name: str | None = None
) -> ParallelBackend
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.
If you don't pass any arguments, then by default it will instantiate the JoblibParallelBackend:
To create a parallel backend instance with for example ray
as a backend,
you can pass the backend name as a string:.
The following is an example of the deprecated way for instantiating a parallel backend:
PARAMETER | DESCRIPTION |
---|---|
backend_name |
Name of the backend to instantiate.
TYPE:
|
config |
(DEPRECATED) Object configuring parallel computation, with cluster address, number of cpus, etc.
TYPE:
|
Source code in src/pydvl/parallel/backend.py
available_cpus
¶
available_cpus() -> int
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. |