qumin.utils package¶
Submodules¶
qumin.utils.metadata module¶
- class qumin.utils.metadata.Metadata(path=None, cfg=None, rundir_path=None)[source]¶
Bases:
objectMetadata manager for Qumin scripts. Wrapper around the Frictionless Package class.
Basic usage :
Register Metadata manager;
Get an absolute path to the metadata folder;
Write to that path;
After writing a file, register it and set metadata (description, custom dict);
Export the JSON descriptor.
The Metadata class can easily be used in scripts that reuse Qumin results. In that case, one must pass a value to runtime_path, if hydra is not set (which is very likely if you write a simple script).
Examples
import omegaconf cfg = omegaconf.dictconfig.DictConfig({data="myparalex/package.json"}) md = Metadata(cfg=cfg, path="myprevious_run/metadata.json") name = 'path/myfile.txt' filename = md.get_path(name) # Open an IO stream and write to ``filename``. md.register_file(name, description="My nice file", custom={"property": "value"}) md.save_metadata(path)
- Variables:
start (datetime) – timestamp at the beginning of the run.
prefix (Path) – normalized prefix for the output files
cfg (OmegaConf) – all arguments passed to the python script
paralex (frictionless.Package) – a frictionless Package representing a dataset.
- get_paradigm_conf(cfg)[source]¶
Load paradigm creation keywords from previous run.
A few security checks are performed to ensure the user didn’t pass contradictory arguments. If this is the case, a warning is thrown and old arguments are kept.
Under some conditions, arguments can be overwritten (e.g. cells list).
- Parameters:
cfg (OmegaConf.dictconfig.DictConfig) – Arguments passed to the current run. These arguments might override arguments from the previous run, under specific conditions.
- get_paradigms(md, **kwargs)[source]¶
Creates paradigms with a stable config strategy.
- Parameters:
md (qumin.utils.metadata.Metadata) – Metadata handler of the current run.
kwargs (dict) – Additional keyword arguments are passed to qumin.representations.paradigms.Paradigms.
- get_path(rel_path)[source]¶
Return an absolute path to a file and create parent directories.
- Parameters:
rel_path (str) – relative path to the file or folder.
- Returns:
absolute path to the file or folder.
- Return type:
- get_pattern_conf()[source]¶
Load pattern creation keywords from previous run. No security checks: all relevant arguments have already been tested when loading the paradigms.
- get_patterns(paradigms, **kwargs)[source]¶
Creates patterns with a stable config strategy.
- Parameters:
paradigms (qumin.representations.paradigms.Paradigms) – Paradigms representation.
kwargs (dict) – Additional keyword arguments are passed patterns.from_file().
- get_resource_path(resource)[source]¶
Return the full path to a resource
- Parameters:
resource (str) – A resource name
- Returns:
a path to the resource.
- Return type:
- register_file(rel_path, name=None, custom=None, override=False, **kwargs)[source]¶
Add a file as a frictionless resource.
- Parameters:
rel_path (str or pathlib.Path) – the relative path to the file.
name (str) – name of the resource. By default, this will be the name of the file without the extension.
override (bool) – Whether to override an existing resource.
custom (dict) – Custom properties to save.
**kwargs (dict) – Optional keyword arguments passed to Resource, e.g. description.
Module contents¶
qumin.utils.metadata module¶
- class qumin.utils.metadata.Metadata(path=None, cfg=None, rundir_path=None)[source]¶
Bases:
objectMetadata manager for Qumin scripts. Wrapper around the Frictionless Package class.
Basic usage :
Register Metadata manager;
Get an absolute path to the metadata folder;
Write to that path;
After writing a file, register it and set metadata (description, custom dict);
Export the JSON descriptor.
The Metadata class can easily be used in scripts that reuse Qumin results. In that case, one must pass a value to runtime_path, if hydra is not set (which is very likely if you write a simple script).
Examples
import omegaconf cfg = omegaconf.dictconfig.DictConfig({data="myparalex/package.json"}) md = Metadata(cfg=cfg, path="myprevious_run/metadata.json") name = 'path/myfile.txt' filename = md.get_path(name) # Open an IO stream and write to ``filename``. md.register_file(name, description="My nice file", custom={"property": "value"}) md.save_metadata(path)
- Variables:
start (datetime) – timestamp at the beginning of the run.
prefix (Path) – normalized prefix for the output files
cfg (OmegaConf) – all arguments passed to the python script
paralex (frictionless.Package) – a frictionless Package representing a dataset.
- get_paradigm_conf(cfg)[source]¶
Load paradigm creation keywords from previous run.
A few security checks are performed to ensure the user didn’t pass contradictory arguments. If this is the case, a warning is thrown and old arguments are kept.
Under some conditions, arguments can be overwritten (e.g. cells list).
- Parameters:
cfg (OmegaConf.dictconfig.DictConfig) – Arguments passed to the current run. These arguments might override arguments from the previous run, under specific conditions.
- get_paradigms(md, **kwargs)[source]¶
Creates paradigms with a stable config strategy.
- Parameters:
md (qumin.utils.metadata.Metadata) – Metadata handler of the current run.
kwargs (dict) – Additional keyword arguments are passed to qumin.representations.paradigms.Paradigms.
- get_path(rel_path)[source]¶
Return an absolute path to a file and create parent directories.
- Parameters:
rel_path (str) – relative path to the file or folder.
- Returns:
absolute path to the file or folder.
- Return type:
- get_pattern_conf()[source]¶
Load pattern creation keywords from previous run. No security checks: all relevant arguments have already been tested when loading the paradigms.
- get_patterns(paradigms, **kwargs)[source]¶
Creates patterns with a stable config strategy.
- Parameters:
paradigms (qumin.representations.paradigms.Paradigms) – Paradigms representation.
kwargs (dict) – Additional keyword arguments are passed patterns.from_file().
- get_resource_path(resource)[source]¶
Return the full path to a resource
- Parameters:
resource (str) – A resource name
- Returns:
a path to the resource.
- Return type:
- register_file(rel_path, name=None, custom=None, override=False, **kwargs)[source]¶
Add a file as a frictionless resource.
- Parameters:
rel_path (str or pathlib.Path) – the relative path to the file.
name (str) – name of the resource. By default, this will be the name of the file without the extension.
override (bool) – Whether to override an existing resource.
custom (dict) – Custom properties to save.
**kwargs (dict) – Optional keyword arguments passed to Resource, e.g. description.