hydra_zen.wrapper.default_to_config#

hydra_zen.wrapper.default_to_config(target, CustomBuildsFn=<class 'hydra_zen.structured_configs._implementations.DefaultBuilds'>, **kw)[source]#

Creates a config that describes target.

This function is designed to selectively apply hydra_zen.builds or hydra_zen.just in a way that permits maximum compatibility with common inputs to hydra_zen.ZenStore. It behavior can be summarized based on the type of target

  • OmegaConf containers and dataclass instances are returned unchanged

  • A dataclass type is processed as builds(target, **kw, populate_full_signature=True, builds_bases=(target,))

  • Lists and dictionaries are processed by hydra_zen.just

  • All other inputs are processed as builds(target, **kw, populate_full_signature=True)

Parameters:
targetCallable[…, Any] | DataClass | Type[DataClass] | list | dict
CustomBuildsFnType[BuildsFn[Any]], optional (default=DefaultBuilds)

Provides the config-creation functions (builds, just) used by this function.

**kwAny

Keyword arguments to be passed to builds.

Returns:
target_configDataClass | Type[DataClass] | list | dict

Examples

Lists and dictionaries

>>> from hydra_zen.wrapper import default_to_config
>>> default_to_config([1, {"z": 2+2j}])
[1, {'z': ConfigComplex(real=2.0, imag=2.0, _target_='builtins.complex')}]

Dataclass types

>>> from dataclasses import dataclass
>>>
>>> @dataclass
... class A:
...     x: int
...     y: int
>>> Builds_A = default_to_config(A, y=22)
>>> Builds_A(x=1)
Builds_A(x=1, y=22, _target_='__main__.A')
>>> issubclass(Builds_A, A)
True

A function

>>> from hydra_zen import to_yaml
>>> def func(x: int, y: int): ...
>>> print(to_yaml(default_to_config(func)))
_target_: __main__.func
x: ???
'y': ???