trident.utils package¶
Submodules¶
trident.utils.dictlist module¶
- class trident.utils.dictlist.DictList(data=None)[source]¶
Bases:
Generic
[T
]A dictionary-like class that allows access to its items by key or index.
- __getitem__(key
Union[str, int]) -> Any: Get an item by key or index.
- __setitem__(key
str, value: Any) -> None: Set an item by key.
- __delitem__(key
str) -> None: Delete an item by key.
- get(key
str, default: Optional[Any] = None) -> Any: Get an item with a default if the key is not present.
- get(key, default=None)[source]¶
Get an item with a default if the key is not present.
- Return type:
TypeVar
(T
)
trident.utils.enums module¶
trident.utils.logging module¶
trident.utils.runner module¶
- trident.utils.runner.extras(cfg)[source]¶
A couple of optional utilities, controlled by main config file: - disabling warnings - forcing debug friendly configuration - verifying experiment name is set when running in experiment mode
Modifies DictConfig in place.
- Parameters:
config (DictConfig) – Configuration composed by Hydra.
- Return type:
None
- trident.utils.runner.finish(cfg, module, datamodule, trainer, callbacks, logger)[source]¶
Makes sure everything closed properly.
- Return type:
None
- trident.utils.runner.log_hyperparameters(cfg, module, trainer)[source]¶
This method controls which parameters from Hydra config are saved by Lightning loggers.
- Return type:
None
- Additionaly saves:
number of module parameters
- trident.utils.runner.print_config(config, fields=('run', 'trainer', 'module', 'datamodule', 'callbacks', 'logger'), resolve=True)[source]¶
Prints content of DictConfig using Rich library and its tree structure.
- Parameters:
config (DictConfig) – Configuration composed by Hydra.
fields (Sequence[str], optional) – Determines which main fields from config will
order. (be printed and in what)
resolve (bool, optional) – Whether to resolve reference fields of DictConfig.
- Return type:
None
trident.utils.transform module¶
Module contents¶
- trident.utils.deepgetitem(obj, item, default=None)[source]¶
Steps through an item chain to get the ultimate value.
If ultimate value or path to value does not exist, does not raise an exception and instead returns fallback.
Does not work if keys comprise dots.
Credits: https://stackoverflow.com/a/38623359
>>> d = {'snl_final': {'about': {'_icsd': {'icsd_id': 1}}}} >>> deepgetitem(d, 'snl_final.about._icsd.icsd_id') 1 >>> deepgetitem(d, 'snl_final.about._sandbox.sbx_id') >>>