autopartial
- class autopartial(autofunc, /, *args, **kwds)
A
functools.partial()-like wrapper that acceptsHyperparameterarguments and automatically builds aConfigurationSpacecovering all of them.When called with a SMAC3
Configurationobject (and an optional prefix string), it resolves every hyperparameter to its sampled value and invokes the wrapped callable.- Parameters:
autofunc (callable) – The function or class to wrap. May itself be an
autopartialinstance, in which case configuration spaces are merged.args – Positional hyperparameters — each must be a
Hyperparameteror anautopartialinstance.kwds – Keyword hyperparameters — same constraint as args.
- Raises:
TypeError – If autofunc is not callable.
ValueError – If any argument is not a
Hyperparameterorautopartial.
Usage pattern
from ConfigSpace.hyperparameters import UniformFloatHyperparameter from src.core import autopartial lr_hp = UniformFloatHyperparameter("lr", 1e-4, 0.1, log=True) margin_hp = UniformFloatHyperparameter("margin", 0.5, 1.5) wrapped_optimizer = autopartial(MyOptimizer, lr=lr_hp, margin=margin_hp) # wrapped_optimizer.cs → ConfigurationSpace with lr and margin # Call with a sampled configuration: optimizer = wrapped_optimizer(some_smac_config)
Nesting autopartial instances
autopartialinstances can be nested. The inner configuration spaces are merged into the outer one using a colon-delimited prefix:inner = autopartial(dict, lr=lr_hp) outer = autopartial(MyTrainer, optimizer_kwargs=inner) # outer.cs contains "optimizer_kwargs:lr"
Attributes
Attribute
Description
autofuncThe underlying callable.
argsTuple of positional
Hyperparameter/autopartialobjects.kwdsDict of keyword
Hyperparameter/autopartialobjects.csThe assembled
ConfigurationSpace.Methods
- __call__(space, prefix='')
Resolve all hyperparameters from space and call
autofunc.- Parameters:
space – A SMAC3 / ConfigSpace
Configurationobject.prefix (str) – Namespace prefix used when this instance is nested inside another
autopartial.
- Returns:
The return value of
autofunc(*resolved_args, **resolved_kwds).