setup class#
- class pycif.utils.classes.setup.Setup(plg_orig=None, orig_name='', **kwargs)[source]#
Bases:
PluginOrchestrator class that drives a full pyCIF simulation.
Extends
Pluginwith methods to parse YAML configuration files, initialise the plugin tree, check requirements, and hand control to the executionMode. Typically the entry point for running pyCIF.- classmethod run_simu(args)[source]#
Run a simulation from a parsed argument dict (e.g. from the CLI).
Resolves the config file path, loads the YAML, applies CLI overrides (
debug,monitor_memory), then delegates torun_simu_from_dict().- Parameters:
args (dict) – CLI argument dict. Must contain
"def_file"; may also contain"debug"and"monitor_memory"flags.- Returns:
The return value of the execution
Mode, or a(output, setup)tuple ifreturn_configis True in the YAML.- Return type:
Any
- classmethod run_simu_from_dict(config_dict, **kwargs)[source]#
Execute a full simulation from an already-loaded config dict.
Initialises the log, loads the plugin tree, optionally monitors memory, runs the
Mode, and returns its output.- Parameters:
config_dict (dict) – Fully resolved configuration dictionary.
**kwargs – Forwarded to the
Mode.executecall.
- Returns:
The return value of
Mode.execute, or a(output, setup)tuple ifreturn_configis set in the YAML.- Return type:
Any
- classmethod yaml_to_dict(config_file)[source]#
Load a YAML file and its sub-configs into a flat config dict.
Recursively resolves any
file_yamlkeys by merging the referenced YAML files. Optionally pretty-prints the merged dict and exits ifprint_dict_and_leaveis set in the config.- Parameters:
config_file (str) – Absolute path to the YAML configuration file.
- Returns:
Merged configuration dictionary.
- Return type:
OrderedDict
- classmethod dict_to_setup(config_dict)[source]#
Load a config dict into a recursive Setup Plugin object.
- Parameters:
config_dict (dict) – Configuration dictionary to load.
- Returns:
Populated Setup instance ready for
init_config().- Return type:
- classmethod yaml_to_setup(config_file)[source]#
Convenience wrapper: load a YAML file directly to a Setup object.
Combines
yaml_to_dict()anddict_to_setup().- Parameters:
config_file (str) – Path to the YAML configuration file.
- Returns:
Populated Setup instance.
- Return type:
- classmethod init_config(setup)[source]#
Initialise logging, validate mandatory arguments, and log run info.
Creates the log file and working directory, copies the YAML for traceability, checks that all mandatory keys (
datei,datef,workdir,logfile,verbose) are present, and logs the git version and config summary.
- classmethod load_config(setup)[source]#
Initialise config and load the full plugin tree.
Combines
init_config()andload_setup()in one call.
- classmethod load_from_dict(config_dict)[source]#
Load a config dict directly into a Setup and initialise level-1 plugins.
- Parameters:
config_dict (dict) – Configuration dictionary to load.
- Returns:
Setup instance with level-1 plugins loaded.
- Return type:
- classmethod yaml_subconfigs(config_dict)[source]#
Recursively replace
file_yamlkeys with the referenced YAML contents.- Parameters:
config_dict (dict) – Configuration dict that may contain
file_yamlkeys pointing to other YAML files.- Returns:
Configuration dict with all
file_yamlreferences resolved.- Return type:
dict
- Raises:
OSError – If a referenced YAML path is not a valid, existing file.
- classmethod git_info(setup)[source]#
Log and write the current git branch and commit hash to
workdir/VERSION.- Parameters:
setup (Setup) – Setup instance providing
setup.workdir.
- classmethod config_info(setup)[source]#
Log the main simulation parameters (dates, workdir, logfile, YAML path).
- Parameters:
setup (Setup) – Setup instance whose parameters are logged.
- classmethod load_setup(plg, parent_plg_type=None, level=999, tree='', list_levels=None, ignore_parent_type=False, **kwargs)[source]#
Loads a Setup plugin. Loops recursively over all attributes of the setup to load: 1) sub-plugins are initialized as Plugin child-class templates ( Domain, ObsVect, Model, etc); 2) instances are saved to the Plugin class to be accessible for anywhere later one.
This allows modifications of the data of a given plugin at some place of the code to be automatically forwarded to the rest of the code
- Parameters:
self (Setup) – the setup to load
parent_plg_type (str) – the last recognized plugin type that is
children (inherited by)