designspace.config_hash#

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

A stable digest identifying one configuration.

The key to use for an experiment record, a results cache, or deduplicating trials: two configurations hash the same exactly when they are the same configuration, regardless of dict ordering. Values are type-tagged, so 1 and 1.0 are distinct.

The hash is exact. A configuration that has been through a representation’s encode/decode may differ in the last bits of a float and therefore hash differently, so key your observations on the configuration you hold, not on a round-tripped copy.

The configuration is not validated first.

Parameters:
  • config (dict[str, Any]) – A configuration, in nested form.

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

Returns:

The digest.

Return type:

str

Examples

>>> s = ds.space(
...     ds.param("algo").categorical("greedy", "exact"),
...     ds.param("depth").integer(1, 4),
... )
>>> a = {"algo": "greedy", "depth": 2}
>>> b = {"depth": 2, "algo": "greedy"}
>>> ds.config_hash(a, s) == ds.config_hash(b, s)
True
>>> ds.config_hash({"algo": "exact", "depth": 2}, s) == ds.config_hash(a, s)
False