topobench.utils.config_resolvers module#
Configuration resolvers for the topobench package.
- class OmegaConf#
Bases:
objectOmegaConf primary class
- classmethod clear_resolver(name)#
Clear(remove) any resolver only if it exists.
Returns a bool: True if resolver is removed and False if not removed.
- classmethod has_resolver(name)#
- static clear_cache(conf)#
- static clear_resolvers()#
Clear(remove) all OmegaConf resolvers, then re-register OmegaConf’s default resolvers.
- static copy_cache(from_config, to_config)#
- static create(obj=_DEFAULT_MARKER_, parent=None, flags=None)#
- static from_cli(args_list=None)#
- static from_dotlist(dotlist)#
Creates config from the content sys.argv or from the specified args list of not None
- static get_cache(conf)#
- static get_type(obj, key=None)#
- static is_config(obj)#
- static is_dict(obj)#
- static is_interpolation(node, key=None)#
- static is_list(obj)#
- static is_missing(cfg, key)#
- static is_readonly(conf)#
- static is_struct(conf)#
- static legacy_register_resolver(name, resolver)#
- static load(file_)#
- static masked_copy(conf, keys)#
Create a masked copy of of this config that contains a subset of the keys
- Parameters:
conf (DictConfig) – DictConfig object
- Returns:
The masked
DictConfigobject.- Return type:
- static merge(*configs)#
Merge a list of previously created configs into a single one
- static missing_keys(cfg)#
Returns a set of missing keys in a dotlist style.
- Parameters:
cfg (Any) – An
OmegaConf.Container, or a convertible object viaOmegaConf.create(dict, list, …).- Returns:
set of strings of the missing keys.
- Raises:
ValueError – On input not representing a config.
- Return type:
- static register_new_resolver(name, resolver, *, replace=False, use_cache=False)#
Register a resolver.
- Parameters:
name (str) – Name of the resolver.
resolver (Callable[[...], Any]) – Callable whose arguments are provided in the interpolation, e.g., with ${foo:x,0,${y.z}} these arguments are respectively “x” (str), 0 (int) and the value of
y.z.replace (bool) – If set to
False(default), then aValueErroris raised if an existing resolver has already been registered with the same name. If set toTrue, then the new resolver replaces the previous one. NOTE: The cache on existing config objects is not affected, useOmegaConf.clear_cache(cfg)to clear it.use_cache (bool) – Whether the resolver’s outputs should be cached. The cache is based only on the string literals representing the resolver arguments, e.g., ${foo:${bar}} will always return the same value regardless of the value of
barif the cache is enabled forfoo.
- static register_resolver(name, resolver)#
- static resolve(cfg)#
Resolves all interpolations in the given config object in-place.
- Parameters:
cfg (Container) – An OmegaConf container (DictConfig, ListConfig) Raises a ValueError if the input object is not an OmegaConf container.
- static save(config, f, resolve=False)#
Save as configuration object to a file
- static select(cfg, key, *, default=_DEFAULT_MARKER_, throw_on_resolution_failure=True, throw_on_missing=False)#
- Parameters:
cfg (Container) – Config node to select from
key (str) – Key to select
default (Any) – Default value to return if key is not found
throw_on_resolution_failure (bool) – Raise an exception if an interpolation resolution error occurs, otherwise return None
throw_on_missing (bool) – Raise an exception if an attempt to select a missing key (with the value ‘???’) is made, otherwise return None
- Returns:
selected value or None if not found.
- Return type:
- static set_cache(conf, cache)#
- static set_readonly(conf, value)#
- static set_struct(conf, value)#
- static structured(obj, parent=None, flags=None)#
- static to_container(cfg, *, resolve=False, throw_on_missing=False, enum_to_str=False, structured_config_mode=SCMode.DICT)#
Resursively converts an OmegaConf config to a primitive container (dict or list).
- Parameters:
cfg (Any) – the config to convert
resolve (bool) – True to resolve all values
throw_on_missing (bool) – When True, raise MissingMandatoryValue if any missing values are present. When False (the default), replace missing values with the string “???” in the output container.
enum_to_str (bool) – True to convert Enum keys and values to strings
structured_config_mode (SCMode) –
- Specify how Structured Configs (DictConfigs backed by a dataclass) are handled.
By default (
structured_config_mode=SCMode.DICT) structured configs are converted to plain dicts.If
structured_config_mode=SCMode.DICT_CONFIG, structured config nodes will remain as DictConfig.If
structured_config_mode=SCMode.INSTANTIATE, this function will instantiate structured configs (DictConfigs backed by a dataclass), by creating an instance of the underlying dataclass.
See also OmegaConf.to_object.
- Returns:
A dict or a list representing this config as a primitive container.
- Return type:
Dict[str | bytes | int | Enum | float | bool, Any] | List[Any] | None | str | Any
- static to_object(cfg)#
Resursively converts an OmegaConf config to a primitive container (dict or list). Any DictConfig objects backed by dataclasses or attrs classes are instantiated as instances of those backing classes.
- This is an alias for OmegaConf.to_container(…, resolve=True, throw_on_missing=True,
structured_config_mode=SCMode.INSTANTIATE)
- static to_yaml(cfg, *, resolve=False, sort_keys=False)#
returns a yaml dump of this config object.
- Parameters:
- Returns:
A string containing the yaml representation.
- Return type:
- static unsafe_merge(*configs)#
Merge a list of previously created configs into a single one This is much faster than OmegaConf.merge() as the input configs are not copied. However, the input configs must not be used after this operation as will become inconsistent.
- static update(cfg, key, value=None, *, merge=True, force_add=False)#
Updates a dot separated key sequence to a value
- Parameters:
cfg (Container) – input config to update
key (str) – key to update (can be a dot separated path)
value (Any) – value to set, if value if a list or a dict it will be merged or set depending on merge_config_values
merge (bool) – If value is a dict or a list, True (default) to merge into the destination, False to replace the destination.
force_add (bool) – insert the entire path regardless of Struct flag or Structured Config nodes.
- __init__()#
- check_pses_in_transforms(transforms)#
Check if there are positional or structural encodings in the transforms.
- Parameters:
- transformsDictConfig
Configuration parameters for the transforms.
- Returns:
- bool
True if there are positional or structural encodings, False otherwise.
- define_task_level(dataset_task_level, learning_setting)#
Define the task level for a given dataset task level and learning setting.
- Parameters:
- dataset_task_levelstr
Task level defined in the dataset configuration file.
- learning_settingstr
Learning setting defined in the dataset split parameters.
- Returns:
- str
Task level for the model.
- Raises:
- ValueError
If the dataset task level or learning setting is invalid.
- get_default_metrics(task, metrics=None)#
Get default metrics for a given task.
- Parameters:
- taskstr
Task, either “classification” or “regression”.
- metricslist, optional
List of metrics to be used. If None, the default metrics will be used.
- Returns:
- list
List of default metrics.
- Raises:
- ValueError
If the task is invalid.
- get_default_trainer()#
Get default trainer configuration.
- Returns:
- str
Default trainer configuration file name.
- get_default_transform(dataset, model)#
Get default transform for a given data domain and model.
- Parameters:
- datasetstr
Dataset name. Should be in the format “data_domain/name”.
- modelstr
Model name. Should be in the format “model_domain/name”.
- Returns:
- str
Default transform.
- get_flattened_channels(num_nodes, channels)#
Get the output dimension of flattening a feature matrix.
- Parameters:
- num_nodesint
Hidden dimension for the first layer.
- channelsint
Channel dimension.
- Returns:
- int
Flatenned cchannels dimension.
- get_monitor_metric(task, metric)#
Get monitor metric for a given task.
- Parameters:
- taskstr
Task, either “classification” or “regression”.
- metricstr
Name of the metric function.
- Returns:
- str
Monitor metric.
- Raises:
- ValueError
If the task is invalid.
- get_monitor_mode(task)#
Get monitor mode for a given task.
- Parameters:
- taskstr
Task, either “classification” or “regression”.
- Returns:
- str
Monitor mode, either “max” or “min”.
- Raises:
- ValueError
If the task is invalid.
- get_non_relational_out_channels(num_nodes, channels, task_level)#
Get the output dimension for a non-relational model.
- Parameters:
- num_nodesint
Number of nodes in the input graph.
- channelsint
Channel dimension.
- task_levelint
Task level for the model.
- Returns:
- int
Output dimension.
- get_required_lifting(data_domain, model)#
Get required transform for a given data domain and model.
- Parameters:
- data_domainstr
Dataset domain.
- modelstr
Model name. Should be in the format “model_domain/name”.
- Returns:
- str
Required transform.
- infer_in_channels(dataset, transforms)#
Infer the number of input channels for a given dataset.
- Parameters:
- datasetDictConfig
Configuration parameters for the dataset.
- transformsDictConfig
Configuration parameters for the transforms.
- Returns:
- list
List with dimensions of the input channels.
- infer_num_cell_dimensions(selected_dimensions, in_channels)#
Infer the length of a list.
- Parameters:
- selected_dimensionslist
List of selected dimensions. If not None it will be used to infer the length.
- in_channelslist
List of input channels. If selected_dimensions is None, this list will be used to infer the length.
- Returns:
- int
Length of the input list.
- infer_topotune_num_cell_dimensions(neighborhoods)#
Infer the length of a list.
- Parameters:
- neighborhoodslist
List of neighborhoods.
- Returns:
- int
Length of the input list.
- register_all_resolvers()#
Register all custom OmegaConf resolvers.
This centralizes resolver registration to avoid duplication across modules. Should be called before Hydra initialization in any script that uses configs.