pdmlabs.optimization.smac_adapter#

SMAC3 optimizer adapter for PdMLabs.

All smac and ConfigSpace imports are lazy (inside method bodies) so this module is importable even when smac is not installed.

Install SMAC3 support with:

pip install pdmlabs[smac]

The adapter uses HyperparameterOptimizationFacade as the single entry point. Hyperparameter space conversion rules:

  • list with string values β†’ CategoricalHyperparameter

  • list with numeric values β†’ OrdinalHyperparameter (preserves the exact candidate set defined by the user)

  • scipy.stats frozen dist β†’ UniformFloatHyperparameter

SMAC needs a scratch directory to run. It is created under $TMPDIR (never in the caller’s working directory) and removed when the run ends – on success, on exception and on KeyboardInterrupt alike. mkdtemp makes it unique against every process on the machine, so parallel or repeated runs cannot collide.

Set PDMLABS_SMAC_OUTPUT_DIR to create that directory under a base of your choosing and keep it after the run, when you need SMAC’s runhistory.json and scenario.json to debug a bad optimization. Since deletion makes the location irrelevant, one variable controls both.

Requires smac >= 2.4.1: SMAC 2.4.0 and older import DTYPE from sklearn.tree._tree, which scikit-learn 1.9 removed, and scikit-survival pins scikit-learn to >=1.9,<1.10.

Module Attributes

OUTPUT_DIR_ENV_VAR

Set to create SMAC's scratch directory under this base and retain it after the run.

Classes

SMAC3Adapter([random_state])

Adapter for SMAC3 HyperparameterOptimizationFacade.

pdmlabs.optimization.smac_adapter.OUTPUT_DIR_ENV_VAR = 'PDMLABS_SMAC_OUTPUT_DIR'#

Set to create SMAC’s scratch directory under this base and retain it after the run.

class pdmlabs.optimization.smac_adapter.SMAC3Adapter(random_state: int = 42)#

Bases: BaseOptimizerAdapter

Adapter for SMAC3 HyperparameterOptimizationFacade.

Requires smac >= 2.0.0 (pip install pdmlabs[smac]).

maximize(param_space: dict, objective_fn, n_iterations: int, n_jobs: int, initial_random: int, constraint_fn=None) → dict#

Maximize objective_fn using SMAC3.

SMAC3 minimises internally; the objective is negated so SMAC effectively maximises. Results are negated back before returning.

minimize(param_space: dict, objective_fn, n_iterations: int, n_jobs: int, initial_random: int, constraint_fn=None) → dict#

Minimise objective_fn using SMAC3 directly (no negation).

supports_categorical: bool = True#