nqs_sdk.core.config module

class nqs_sdk.core.config.ConfigLoader[source]

Bases: object

Utility class for loading and processing simulation configuration files

This class provides static methods for handling different configuration formats (JSON, YAML) and sources (files, strings, dictionaries). It includes validation and format detection capabilities to ensure robust configuration loading

The loader supports both file-based and string-based configurations, with automatic format detection based on content or file extensions

static load(config)[source]

Load configuration from various sources and return standardized format

This method handles multiple input types and automatically detects the configuration format, returning a tuple of (content, format_type)

Parameters:

config (Union[str, dict, Path]) – Configuration source, can be: - dict: Configuration dictionary (converted to JSON) - str: JSON string, YAML string, or file path - Path: Path object pointing to configuration file

Returns:

  • content_string: String representation of the configuration

  • format_type: Either “json” or “yaml”

Return type:

Tuple of (content_string, format_type) where

Raises:
  • FileNotFoundError – If file path doesn’t exist

  • ValueError – If string appears to be malformed JSON or unsupported format

Example

>>> content, fmt = ConfigLoader.load({"agents": [], "protocols": {}})
>>> content, fmt = ConfigLoader.load("config.yaml")
>>> content, fmt = ConfigLoader.load('{"simulation": {"blocks": 1000}}')
static merge_configs(base_config, update_config)[source]

Recursively merge two configuration dictionaries

Performs a deep merge where nested dictionaries are merged recursively, and non-dictionary values in update_config override those in base_config

Parameters:
  • base_config (Dict[str, Any]) – Base configuration dictionary

  • update_config (Dict[str, Any]) – Configuration updates to apply

Return type:

Dict[str, Any]

Returns:

New dictionary containing the merged configuration

Example

>>> base = {"simulation": {"blocks": 1000}, "agents": []}
>>> update = {"simulation": {"timestep": 12}, "protocols": {}}
>>> merged = ConfigLoader.merge_configs(base, update)
>>> # Result: {"simulation": {"blocks": 1000, "timestep": 12},
>>> #          "agents": [], "protocols": {}}