rubem.configuration.model_configuration.ModelConfiguration

class ModelConfiguration(config_input, validate_input=True, base_dir=None, allow_blocking_problems=False)[source]

Bases: object

Represents the configuration settings for the model.

The ModelConfiguration class is responsible for loading and storing the configuration settings required for running the model. It supports loading configuration from either a dictionary or a JSON file.

Parameters:
  • config_input (dict | str | PathLike[str] | bytes) – The configuration input: a dictionary with the legacy sections, or the path of a legacy JSON file. A dictionary is copied, so changing it after the load does not change the loaded configuration.

  • validate_input (bool) – Whether to validate the input files and their content. Defaults to True.

  • base_dir (str | PathLike[str] | bytes | None) – Directory the relative paths of the configuration are anchored on. Defaults to the directory of the JSON file, or to None (paths kept as given) for a dictionary.

  • allow_blocking_problems (bool) – Whether to keep going when the inputs carry blocking problems: the checks still run and every problem is kept in problems, the blocking ones are logged as errors and the configuration loads instead of raising ConfigurationError. Defaults to False.

Raises:
  • FileNotFoundError – If the specified config file is not found.

  • ValueError – If the config file type is not supported, or a setting is missing or invalid (pydantic.ValidationError is a ValueError).

  • json.JSONDecodeError – If the JSON file is not valid.

  • ConfigurationError – If the inputs carry blocking problems, unless allow_blocking_problems is set.

Methods

load

Load a legacy configuration from a dictionary or a JSON file.

write_metadata

Write metadata.json next to the outputs of a format 1.0 run.

classmethod load(config_input, validate_input=True, base_dir=None, allow_blocking_problems=False)[source]

Load a legacy configuration from a dictionary or a JSON file.

Relative paths are anchored on the directory of the JSON file, or on base_dir when given (a dictionary has no anchor unless base_dir is passed). allow_blocking_problems is passed through to the constructor.

Return type:

ModelConfiguration

write_metadata()[source]

Write metadata.json next to the outputs of a format 1.0 run.

A no-op for a legacy configuration, which has no metadata section. Intended to be called once the run has finished successfully (after every other output has been written): it is not called while loading or validating the configuration, so a configuration that fails validation never touches an existing metadata.json. The write itself is atomic (a temporary file, replaced onto the target), so a failure while writing leaves an existing metadata.json untouched.

Return type:

None