designspace.is_flat#

designspace.is_flat(config: dict[str, Any], space: Space) bool#

Whether a configuration is already keyed by path.

ds.flatten() refuses a configuration in the form it exists to produce, so this asks that question first. Two marks tell the forms apart, and either one settles it: a key below the top level carries a . or a [, which no parameter name may contain, and a lift’s own entry holds a list nested and that list’s length flat.

A configuration carrying neither mark reads the same in both forms, every value sitting at a bare name, and is reported not flat. ds.flatten() accepts it, returning it unchanged.

Parameters:
  • config (dict[str, Any]) – The configuration to inspect. It is read structurally and is not validated against the space.

  • space (Space) – The space it belongs to, which supplies the parameter kinds.

Returns:

Whether the configuration is keyed by path.

Return type:

bool

Examples

>>> s = ds.space(
...     ds.param("n").integer(0, 3),
...     ds.param("timeouts").integer(1, 60).repeat(ds.param("n")),
... )
>>> config = {"n": 2, "timeouts": [30, 45]}
>>> ds.is_flat(config, s)
False
>>> ds.is_flat(ds.flatten(config, s), s)
True

It reports exactly what ds.flatten() refuses.

>>> ds.flatten(ds.flatten(config, s), s)
Traceback (most recent call last):
    ...
TypeError: flatten(): the configuration is already keyed by path, at ...