pybroker.parallel module

Contains parallel execution configuration.

class ParallelConfig(n_jobs: int | None = -1, backend: str | None = 'loky', parallel: Parallel | None = None)[source]

Bases: object

Configuration 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_models flags. Call set_parallel(n_jobs=1) to run everything sequentially, and read the current configuration with get_parallel_config().

n_jobs

Number of worker jobs. -1 (the default) uses all available cores; 1 runs 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' after ray.util.joblib.register_ray()).

Type:

str | None

parallel

Optional pre-constructed joblib.Parallel instance that overrides n_jobs and backend entirely. When set, PyBroker uses it directly and the caller owns its lifecycle. Defaults to None.

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. -1 uses all cores (the default); 1 runs sequentially. Leave as None to keep the currently configured value.

  • backend – joblib backend name: 'loky' (default) or any backend registered via joblib.register_parallel_backend() (e.g. 'ray' after ray.util.joblib.register_ray()). The 'multiprocessing' backend is rejected because its standard pickle serialization cannot ship PyBroker’s dispatch closures.

  • parallel – Pre-constructed joblib.Parallel instance. Mutually exclusive with n_jobs/backend; caller owns its lifecycle.

Raises:

ValueError – If parallel is passed together with n_jobs or backend, if backend is not a registered joblib backend or is 'multiprocessing', or if parallel returns results out of submission order.