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, edge_sep=" -> ", loop_solver="jacobi"
)

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]

edge_sep

Edge separator for connections. Defaults to " -> ".

TYPE: str

loop_solver

Method used to solve algebrauc loops. Defaults to "jacobi".

TYPE: str

config_dict

The parsed configuration dictionary.

TYPE: Dict

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 cofmpy/config_parser.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __init__(
    self,
    file_path: Union[str, Dict],
    edge_sep: str = " -> ",
    loop_solver: str = "jacobi",
) -> None:
    # Arguments
    self.file_path = file_path
    self.loop_solver = loop_solver
    self.edge_sep = edge_sep

    self.config_dict: Dict = {}
    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_dict ------------------
    self.config_dict = self._load_config(file_check=True)

    # ------------ 2. Apply defaults and perform validation ------------
    self._apply_defaults(edge_sep, loop_solver)
    self._validate_configuration()

    # ------------ 3. Prepend 'root' dir to present paths ------------
    self._update_paths_in_dict()

    # ------------ 4. Build configurations ---------------------------
    self._build_master_config()
    self._build_handlers_config()
    self._build_graph_config()