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:
listwith string values βCategoricalHyperparameterlistwith numeric values βOrdinalHyperparameter(preserves the exact candidate set defined by the user)scipy.statsfrozen 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
Set to create SMAC's scratch directory under this base and retain it after the run. |
Classes
|
Adapter for SMAC3 |
- 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:
BaseOptimizerAdapterAdapter 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#