designspace.unflatten#

designspace.unflatten(flat: dict[str, Any], space: Space) dict[str, Any]#

Rebuild a nested configuration from one keyed by path.

The inverse of ds.flatten(), and the way back from a solver’s flat view to the shape .validate() and .sample_one() speak.

Parameters:
  • flat (dict[str, Any]) – A configuration keyed by path.

  • space (Space) – The space it belongs to, which supplies the structure to rebuild.

Returns:

The configuration in nested form.

Return type:

dict[str, Any]

Examples

>>> s = ds.space(
...     ds.param("opt").choice(sgd=ds.space(ds.param("momentum").real(0, 1))),
...     ds.param("lr").real(0, 1),
... )
>>> flat = {"opt": "sgd", "opt.sgd.momentum": 0.5, "lr": 0.1}
>>> ds.unflatten(flat, s)
{'opt': {'sgd': {'momentum': 0.5}}, 'lr': 0.1}