Skip to content

The Parser for Configuration File

This module is designed to parse, validate, and structure a JSON configuration file for the co-simulation framework. It ensures that all necessary configurations for GraphEngine, Master DataStreamHandlers, and DataStorages are correctly formatted and ready for execution. Additionally, it performs sanity checks to detect missing keys, redundant endpoints, and orphaned connections.

ConfigParser

ConfigParser(file_path)

Parses and validates JSON configuration files.

This class handles loading, validation, and transformation of configuration data for various components such as the Graph Engine, Master Solver, Data Storages, and Stream Handlers.

ATTRIBUTE DESCRIPTION
file_path

Path to the configuration file. Can also be a dictionary if the user prefers to provide the configuration directly without using a JSON file.

TYPE: Union[str, Dict]

_config_object

The parsed configuration object (type ConfigObject)

TYPE: ConfigObject

graph_config

Configuration for the graph engine.

TYPE: Dict

master_config

Configuration for the master solver.

TYPE: Dict

data_storages

Storage settings for external data.

TYPE: Dict

stream_handlers

Handlers for external data streams.

TYPE: Dict

error_in_config

Indicates whether errors exist in the configuration.

TYPE: bool

Source code in cofmupy/config_parser.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def __init__(self, file_path: Union[str, Dict]) -> None:
    # Arguments
    self.file_path = file_path

    self._config_object: ConfigObject
    self.graph_config: Dict = {}
    self.master_config: Dict = {}
    self.data_storages: Dict = {}
    self.stream_handlers: Dict = {}
    self.error_in_config: bool = False

    # ------------ 1. Load config: self._config_object ------------------
    self._config_object = self._load_config(file_check=True)

    # ------------ 2. Apply defaults and perform validation ------------
    self._validate_configuration()

    # ------------ 3. Build configurations ---------------------------
    self._build_storage_config()
    self._build_master_config()
    self._build_handlers_config()
    self._build_graph_config()

config_dict property

config_dict

Construct and return dict from protected _config_object

RETURNS DESCRIPTION
config

config formatted as a dict

TYPE: dict

fill_data_storage

fill_data_storage(targets, storage_id, storage_title)

Fill data storage with labels and items

Source code in cofmupy/config_parser.py
270
271
272
273
274
275
276
277
278
279
def fill_data_storage(self, targets: list, storage_id: str, storage_title: str):
    """
    Fill data storage with labels and items
    """
    for target2 in targets:
        if isinstance(target2, ConfigConnectionFmu):
            self.data_storages[storage_id]["config"]["labels"].append(storage_title)
            self.data_storages[storage_id]["config"]["items"].append(
                (target2.id, target2.variable)
            )