API Reference

Module main

IDR-IISIM Compiler main

main.main()[source]

Main program entry point.

The program iterates over all industries found in the specified source folder, processing each industry to generate its corresponding model.

Return type:

None

Raises:

Exception: If there is an error during the processing of the industries.

main.process_industry(name, industry_path)[source]

Process and generate code for a specified industry.

This function validates and processes all YAML files in the given industry path, generating a Python script for the industry based on the loaded configurations.

Return type:

None

Args:

name (str): The name of the industry to be processed. industry_path (str): The path where the YAML files of the industry are stored.

Raises:

Exception: If there are issues in processing the industry files.

Package idr_iisim

This package provides the functionalities to load and validate the YAML files, load the templates that define the script code format and compile the loaded models into these templates.

Module idr_iisim.models

models.model

Module to parse industry’s processes

class idr_iisim.models.model.FunctionsMapType[source]

Bases: TypedDict

Type definition for FunctionsMap.

Attributes:

function (Callable[…, Any]): The function to be called. args (list[dict[str, Any]]): List of arguments for the function. expression (str): The expression associated with this function. description (str): Description of the function.

args: list[dict[str, Any]]
description: str
expression: str
function: Callable[..., Any]
class idr_iisim.models.model.Model(path)[source]

Bases: ABC

Abstract base class representing a model in the system.

It contains the model configuration, functions map, results, and external inputs.

Attributes:

directory (str): Directory of the model file. inputs (dict[str, InputStruct]): Dictionary holding input structures. outputs (dict[str, OutputStruct]): Dictionary holding output structures. constants (dict[str, ConstantStruct]): Dictionary holding constant structures. functions_map (dict[str, FunctionsMapType]): Map of functions. config (Union[ModelStruct, MetaStruct]): Configuration of the model.

constants_generator()[source]

Generate code for constants defined in the model configuration.

Return type:

str

Returns:

str: The generated code for constants, or an empty string if none are defined.

abstractmethod get_getter_items()[source]

Generate items’ descriptions to configure as getters.

Return type:

list[tuple[str, str]]

Returns:

list[tuple[str, str]]: A list of tuples containing variable names and their descriptions.

getters_generator()[source]

Generate getter methods for the model.

Return type:

str

Returns:

str: The generated getter methods as string.

process_config(items, config)[source]

Process configuration elements and initialize model attributes.

Return type:

None

Args:

items (list[ItemStruct]): Items to process for configuration. config (ModelStruct): The model configuration structure.

Raises:

ValueError: If any constant or input value is out of its valid range.

models.meta

Module to process the meta.yaml, the industry’s configuration

class idr_iisim.models.meta.Meta(yaml_data, path)[source]

Bases: Model

Meta class to handle parsing and managing meta data configurations.

Attributes:

outcome (dict[str, OutcomeStruct]): A dictionary holding outcomes. demands (dict[str, DemandStruct]): A dictionary holding demands. meta_demands (dict[str, MetaDemandStruct]): A dictionary holding meta-demands. config (MetaStruct): Parsed configuration data.

constructor_post_generator()[source]

Generate initialization code for meta-demands and outputs.

Return type:

str

Returns:

str: The generated initialization code as a string.

constructor_pre_generator(process)[source]

Generate initialization code for demands used in a specified process.

Return type:

str

Args:

process (str): The name of the process for which initializations are generated.

Returns:

str: The generated initialization code as a string.

get_getter_items()[source]

Generate a list of item descriptions for getter configuration.

Return type:

list[tuple[str, str]]

Returns:

list[tuple[str, str]]: A list of tuples containing variable names and their descriptions.

get_units()[source]

Get the units of demands and outputs.

Return type:

dict[str, str]

Returns:

dict[str, str]: A dictionary mapping variable names to their units.

models.meta

Module to parse industry’s processes

class idr_iisim.models.process.Process(yaml_data, path)[source]

Bases: Model

Process class that represents a model in the system.

It contains the model configuration, functions map, results, and external inputs.

Attributes:

config (ModelStruct): Holds the parsed model configuration.

get_getter_items()[source]

Generate items’ descriptions to configure as getters.

Return type:

list[tuple[str, str]]

Returns:

list[tuple[str, str]]: A list of tuples containing variable names and their descriptions.

operations_generator()[source]

Generate operations methods for the model.

Return type:

str

Returns:

str: The generated operations as a string.

process_call_method_generator()[source]

Generate the code to call the different methods.

Return type:

str

Returns:

str: The generated method call as a string.

process_methods_generator()[source]

Generate the methods for the industry’s class.

Return type:

str

Returns:

str: The generated methods as a formatted string.

idr_iisim.utils

utils.models_dict

Industry

class idr_iisim.utils.models_dict.Industry(meta=None)[source]

Bases: object

Industry class

add_process(key, process)[source]

add model to the industry

Return type:

None

check_types()[source]

check types among processes

This method checks if the types of the different inputs and demands are consistent between the different processes.

Return type:

None

generate_execution_queue()[source]

Generate the correct execution queue of the processes

This method generate the execution queue in the correct order taking into account the correct flow to based on the dependencies between the different processes of the industry.

Return type:

list[str]

script_generator()[source]

Generator of the script

This method generates the model (the Python class) of the industry

Return type:

str

set_meta(meta)[source]

set or update the meta of this industry

Return type:

None

idr_iisim.utils.models_dict.load_yaml(path)[source]

load industry’s yaml file

Parameters:

path (str) – path of the YAML file to be loaded.

Return type:

dict[str, Any]

utils.schema

Schema Validator

class idr_iisim.utils.schema.Validator[source]

Bases: object

The Validator class responsible for validating data against schemas defined in the config schema files.

Attributes:

industry_validator (dict[str, Any]): Schema loaded from config/industry.yaml. process_validator (dict[str, Any]): Schema loaded from config/process.yaml.

industry_validator: dict[str, Any]
print_industry_schema()[source]

print current validation schema

Return type:

None

print_process_schema()[source]

print current validation schema

Return type:

None

process_validator: dict[str, Any]
validate(data)[source]

Validate the provided data against the appropriate schema.

This method checks if the given dictionary data conforms to a schema loaded from the corresponding YAML file.

Return type:

None

Args:

data (dict[str, Any]): The dictionary containing data to be validated.

Raises:

ValueError: If the data is missing a type field or has an invalid type. Exception: If the validation process fails.

utils.structs

types definition

class idr_iisim.utils.structs.BaseStruct(name, description, units)[source]

Bases: object

Base structure that aggregates common attributes.

Attributes:

name (str): The name of the item description (str): A description of the item. units (str): Measurement units associated with the item.

description: str
name: str
units: str
class idr_iisim.utils.structs.ConstantStruct(name, description, units, citation, source, value, range=None)[source]

Bases: BaseStruct

Structure for constants used in the model.

Attributes:

citation (str): Citation source (str): Source from which the constant is derived. value (float): The constant value. range (Optional[list[float]]): Optional range of valid values for the constant.

citation: str
range: Optional[list[float]] = None
source: str
value: float
class idr_iisim.utils.structs.DemandStruct(name, description, units, args, operation, tests=None, *, used, meta=None)[source]

Bases: ItemStruct

Structure for demands in the model.

Attributes:

used (str): The process that is using the demand. meta (Optional[str]): Optional metadata associated with the demand.

meta: Optional[str] = None
used: str
class idr_iisim.utils.structs.InputStruct(name, description, units, value, input_from, range=None)[source]

Bases: BaseStruct

Structure for inputs in the model.

Attributes:

value (list[float]): List of input values. input_from (str): The source of the input, using ‘from’ as a JSON key. range (Optional[list[float]]): Optional range of valid values for the input.

input_from: str
range: Optional[list[float]] = None
value: list[float]
class idr_iisim.utils.structs.ItemStruct(name, description, units, args, operation, tests=None)[source]

Bases: BaseStruct

Structure for items used in demand, meta-demand, and output.

Attributes:

args (list[dict[str, Any]]): Arguments associated with the item. operation (str): The operation to be performed on the item. tests (Optional[list[float]]): Optional tests associated with the item.

args: list[dict[str, Any]]
operation: str
tests: Optional[list[float]] = None
class idr_iisim.utils.structs.MetaDemandStruct(name, description, units, args, operation, tests=None)[source]

Bases: ItemStruct

Structure for meta-demands in the model.

This inherits from ItemStruct.

class idr_iisim.utils.structs.MetaStruct(name, short_name, id, category, description, version, debug, constants, inputs, outputs, outcome, demands, meta)[source]

Bases: ModelStruct

Structure for meta models.

Attributes:

outcome (OutcomeStruct): The expected outcome of the model. demands (list[DemandStruct]): List of demands associated with the model. meta (list[MetaDemandStruct]): List of meta-demands associated with the model.

demands: list[DemandStruct]
meta: list[MetaDemandStruct]
outcome: OutcomeStruct
class idr_iisim.utils.structs.ModelStruct(name, short_name, id, category, description, version, debug, constants, inputs, outputs)[source]

Bases: object

Structure for the model configuration.

Attributes:

name (str): The name of the model. short_name (str): A short name for the model. id (str): Unique identifier for the model. category (str): The category of the model. description (str): A description of the model. version (str): Version information for the model. debug (str): Debugging information. constants (list[ConstantStruct]): List of constants used in the model. inputs (list[InputStruct]): List of inputs for the model. outputs (list[OutputStruct]): List of outputs for the model.

category: str
constants: list[ConstantStruct]
debug: str
description: str
id: str
inputs: list[InputStruct]
name: str
outputs: list[OutputStruct]
short_name: str
version: str
class idr_iisim.utils.structs.OutcomeStruct(name, description, units, same_result, range=None, tests=None)[source]

Bases: BaseStruct

Structure for outcomes in the model.

Attributes:

same_result (str): The expected outcome description. range (Optional[list[float]]): Optional range of values for the outcome. tests (Optional[list[float]]): Optional tests associated with the outcome.

range: Optional[list[float]] = None
same_result: str
tests: Optional[list[float]] = None
class idr_iisim.utils.structs.OutputStruct(name, description, units, args, operation, tests=None, value=None, range=None)[source]

Bases: ItemStruct

Structure for outputs in the model.

Attributes:

value (Optional[float]): Optional output value. range (Optional[list[float]]): Optional range of valid values for the output.

range: Optional[list[float]] = None
value: Optional[float] = None
idr_iisim.utils.structs.json_to_meta_struct(data)[source]

Parse the JSON object and transform it into a MetaStruct object.

This function takes a JSON dictionary representation of a meta model and constructs a MetaStruct object, extracting all necessary fields, including constants, inputs, and outputs.

Return type:

MetaStruct

Args:
data (dict[str, Any]): JSON data representing the meta model. Must include

‘constants’, ‘outcome’, ‘inputs’, ‘outputs’, ‘demands’, and other required attributes.

Returns:

MetaStruct: An instance of MetaStruct filled with the parsed data.

Example:

meta_struct = json_to_meta_struct(json_meta_data)

idr_iisim.utils.structs.json_to_model_struct(data)[source]

Parse the JSON object and transform it into a ModelStruct object.

This function takes a JSON dictionary representation of a model and constructs a ModelStruct object, extracting the necessary fields.

Return type:

ModelStruct

Args:
data (dict[str, Any]): JSON data representing the model. Must include

‘constants’, ‘inputs’, ‘outputs’, and other required attributes.

Returns:

ModelStruct: An instance of ModelStruct filled with the parsed data.

Example:

model_struct = json_to_model_struct(json_data)

templates

module to load templates

idr_iisim.templates.load_template(template_path)[source]

Load a template from the specified file path.

This function reads the content of the given template file and returns a Template object that can be used for string substitution.

Return type:

Template

Args:

template_path (str): Path to the template file to be loaded.

Returns:

Template: A Template object containing the loaded template content.

Raises:

FileNotFoundError: If the specified template file does not exist. Exception: If there is an error reading the template file (e.g., encoding issues).