pybroker.parallel module
Contains parallel execution configuration.
- class ParallelConfig(n_jobs: int | None = -1, backend: str | None = 'loky', parallel: Parallel | None = None)[source]
Bases:
objectConfiguration for parallel execution used by PyBroker.
PyBroker can compute indicators, train models, and run optimizations in parallel using joblib. Optimization trials run on all available cores by default; indicator computation and model training additionally require their
parallel_indicators/parallel_modelsflags. Callset_parallel(n_jobs=1)to run everything sequentially, and read the current configuration withget_parallel_config().- n_jobs
Number of worker jobs.
-1(the default) uses all available cores;1runs sequentially.- Type:
int | None
- backend
joblib backend name.
'loky'(the default) runs work in separate processes. Any backend registered with joblib is also accepted (e.g.'ray'afterray.util.joblib.register_ray()).- Type:
str | None
- parallel
Optional pre-constructed
joblib.Parallelinstance that overridesn_jobsandbackendentirely. When set, PyBroker uses it directly and the caller owns its lifecycle. Defaults toNone.- Type:
joblib.parallel.Parallel | None
- get_parallel_config() ParallelConfig[source]
Returns the current parallel configuration
- set_parallel(n_jobs: int | None = None, backend: str | None = None, parallel: Parallel | None = None) None[source]
Configures parallel execution used by PyBroker.
PyBroker uses all available cores by default; call
set_parallel(n_jobs=1)to run sequentially.- Parameters:
n_jobs – Number of workers.
-1uses all cores (the default);1runs sequentially. Leave asNoneto keep the currently configured value.backend – joblib backend name:
'loky'(default) or any backend registered viajoblib.register_parallel_backend()(e.g.'ray'afterray.util.joblib.register_ray()). The'multiprocessing'backend is rejected because its standard pickle serialization cannot ship PyBroker’s dispatch closures.parallel – Pre-constructed
joblib.Parallelinstance. Mutually exclusive withn_jobs/backend; caller owns its lifecycle.
- Raises:
ValueError – If
parallelis passed together withn_jobsorbackend, ifbackendis not a registered joblib backend or is'multiprocessing', or ifparallelreturns results out of submission order.