nat.data_models.optimizable#

Attributes#

T

Classes#

_TrialLike

Base class for protocol classes.

SearchSpace

OptimizableMixin

Functions#

OptimizableField([default, space, merge_conflict])

Module Contents#

T#
class _TrialLike#

Bases: Protocol

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...
suggest_categorical(
name: str,
choices: collections.abc.Sequence[Any],
) Any#
suggest_int(
name: str,
low: int,
high: int,
*,
log: bool = False,
step: Any = None,
) int#
suggest_float(
name: str,
low: float,
high: float,
*,
log: bool = False,
step: Any = None,
) float#
class SearchSpace(/, **data: Any)#

Bases: pydantic.BaseModel, Generic[T]

values: collections.abc.Sequence[T] | None = None#
low: T | None = None#
high: T | None = None#
log: bool = False#
step: float | None = None#
is_prompt: bool = False#
prompt: str | None = None#
prompt_purpose: str | None = None#
prompt_format: Literal['f-string', 'jinja2', 'mustache'] | None = None#
model_config#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

validate_search_space_parameters()#

Validate SearchSpace configuration.

suggest(trial: _TrialLike, name: str)#
to_grid_values() list[Any]#

Convert SearchSpace to a list of values for GridSampler.

Grid search requires explicit values. This can be provided in two ways: 1. Explicit values: SearchSpace(values=[0.1, 0.5, 0.9]) 2. Range with step: SearchSpace(low=0.1, high=0.9, step=0.2)

For ranges, step is required (no default will be applied) to avoid unintentional combinatorial explosion.

OptimizableField(
default: Any = PydanticUndefined,
*,
space: SearchSpace | None = None,
merge_conflict: str = 'overwrite',
**fld_kw,
)#
class OptimizableMixin(/, **data: Any)#

Bases: pydantic.BaseModel

optimizable_params: list[str] = None#
search_space: dict[str, SearchSpace] = None#