setup class#

class pycif.utils.classes.setup.Setup(plg_orig=None, orig_name='', **kwargs)[source]#

Bases: Plugin

Orchestrator class that drives a full pyCIF simulation.

Extends Plugin with methods to parse YAML configuration files, initialise the plugin tree, check requirements, and hand control to the execution Mode. 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 to run_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 if return_config is 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.execute call.

Returns:

The return value of Mode.execute, or a (output, setup) tuple if return_config is 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_yaml keys by merging the referenced YAML files. Optionally pretty-prints the merged dict and exits if print_dict_and_leave is 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:

Setup

classmethod yaml_to_setup(config_file)[source]#

Convenience wrapper: load a YAML file directly to a Setup object.

Combines yaml_to_dict() and dict_to_setup().

Parameters:

config_file (str) – Path to the YAML configuration file.

Returns:

Populated Setup instance.

Return type:

Setup

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.

Parameters:

setup (Setup) – Setup instance to initialise.

Returns:

The same instance with logfile and workdir updated to their absolute paths.

Return type:

Setup

Raises:

Exception – If mandatory YAML keys are missing or the simulation period is void (datei == datef).

classmethod load_config(setup)[source]#

Initialise config and load the full plugin tree.

Combines init_config() and load_setup() in one call.

Parameters:

setup (Setup) – Setup instance to initialise and load.

Returns:

Fully initialised and loaded Setup instance.

Return type:

Setup

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:

Setup

classmethod yaml_subconfigs(config_dict)[source]#

Recursively replace file_yaml keys with the referenced YAML contents.

Parameters:

config_dict (dict) – Configuration dict that may contain file_yaml keys pointing to other YAML files.

Returns:

Configuration dict with all file_yaml references 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)