agentlib_flexquant.utils package

Submodules

agentlib_flexquant.utils.config_management module

agentlib_flexquant.utils.config_management.get_class_from_file(file_path, class_name)[source]
agentlib_flexquant.utils.config_management.get_module(config: AgentConfig, module_type: str) T[source]

Extracts a module from a config based on its name

agentlib_flexquant.utils.config_management.get_module_type_matching_dict(dictionary: dict)[source]

Creates two dictionaries, which map the modules types of the agentlib_mpc modules to those of the flexquant modules. This is done by using the MODULE_TYPE_DICT

agentlib_flexquant.utils.config_management.get_orig_module_type(config: AgentConfig)[source]

Returns the config type of the original MPC

agentlib_flexquant.utils.config_management.subtract_relative_path(absolute_path, relative_path)[source]
agentlib_flexquant.utils.config_management.to_dict_and_remove_unnecessary_fields(module: BaseModuleConfig)[source]

Removes unnecessary fields from the module to keep the created json simple

agentlib_flexquant.utils.data_handling module

agentlib_flexquant.utils.data_handling.convert_timescale_of_index(df: DataFrame, from_unit: Literal['seconds', 'minutes', 'hours', 'days'], to_unit: {'seconds': 1, 'minutes': 60, 'hours': 3600, 'days': 86400}) DataFrame[source]

Convert the timescale of a dataframe index (from seconds) to the given time unit

Keyword arguments: results – The dictionary of the results with the dataframes time_unit – The time unit to convert the index to

agentlib_flexquant.utils.data_handling.fill_nans(series: Series, method: Literal['mean', 'interpolate']) Series[source]

Fill NaN values in the series with the given method.

Implemented methods: - mean: fill NaN values with the mean of the following values. - interpolate: interpolate missing values.

agentlib_flexquant.utils.data_handling.strip_multi_index(series: Series) Series[source]

agentlib_flexquant.utils.interactive module

class agentlib_flexquant.utils.interactive.CustomBound(for_variable: str, lb_name: str | None = None, ub_name: str | None = None)[source]

Bases: object

Dataclass to let the user define custom bounds for the mpc variables

var_name – The name of the variable to plot the bounds into lower bound – The lower bound of the variable as the name of the lower bound variable in the MPC upper bound – The upper bound of the variable as the name of the upper bound variable in the MPC

for_variable: str
lower_bound: str | None
upper_bound: str | None
class agentlib_flexquant.utils.interactive.Dashboard(flex_config: str | Annotated[Path, PathType(path_type=file)] | FlexQuantConfig | None = None, simulator_agent_config: str | Annotated[Path, PathType(path_type=file)] | AgentConfig | None = None, generated_flex_files_base_path: str | Annotated[Path, PathType(path_type=file)] | None = None, results: str | Annotated[Path, PathType(path_type=file)] | dict[str, dict[str, DataFrame]] = None, to_timescale: Literal['seconds', 'minutes', 'hours', 'days'] = 'hours', port: int = None)[source]

Bases: Results

Class for the dashboard of flexquant

MPC_ITERATIONS: str = 'iter_count'
bounds_key: str = 'bounds'
characteristic_times_accepted_key: str = 'characteristic_times_accepted'
characteristic_times_current_key: str = 'characteristic_times_current'
custom_bounds: list[CustomBound] = []
label_negative: str = 'negative'
label_positive: str = 'positive'
show(custom_bounds: CustomBound | list[CustomBound] = None)[source]

Shows the dashboard in a web browser containing: – Statistics of the MPCs solver – The states, controls, and the power variable of the MPCs and the simulator – KPIs of the flexibility quantification – Markings of the characteristic flexibility times

Optional arguments to show the comfort bounds: – temperature_var_name: The name of the temperature variable in the MPC to plot the comfort bounds into – ub_comfort_var_name: The name of the upper comfort bound variable in the MPC – lb_comfort_var_name: The name of the lower comfort bound variable in the MPC

agentlib_flexquant.utils.parsing module

class agentlib_flexquant.utils.parsing.SetupSystemModifier(mpc_data: BaseMPCData, controls: List[MPCVariable], binary_controls: List[MPCVariable] | None)[source]

Bases: NodeTransformer

A custom AST transformer for modifying the MPC model file.

This class traverses the AST of the input file, identifies the relevant classes and methods, and performs the necessary modifications.

mpc_data

The new return expression to be used in the setup_system method.

Type:

str

get_leftmost_list(node)[source]

Recursively traverse binary operations to get the leftmost list.

Parameters:

node – An AST node (could be a BinOp or directly a List)

Returns:

The leftmost List node found

modify_config_class_baseline(node)[source]

Modify the config class of the baseline mpc.

Parameters:

node (ast.ClassDef) – The class definition node of the config.

modify_config_class_shadow(node)[source]

Modify the config class of the shadow mpc.

Parameters:

node (ast.ClassDef) – The class definition node of the config.

modify_setup_system_baseline(node)[source]

Modify the setup_system method of the baseline mpc model class.

This method changes the return statement of the setup_system method and adds all necessary new lines of code.

Parameters:

node (ast.FunctionDef) – The function definition node of setup_system.

modify_setup_system_shadow(node)[source]

Modify the setup_system method of the shadow mpc model class.

This method changes the return statement of the setup_system method and adds all necessary new lines of code.

Parameters:

node (ast.FunctionDef) – The function definition node of setup_system.

visit_ClassDef(node)[source]

Visit a class definition in the AST.

This method is called for each class definition in the AST. It identifies the BaselineMPCModelConfig and BaselineMPCModel classes and performs the necessary actions.

Parameters:

node (ast.ClassDef) – The class definition node in the AST.

Returns:

The possibly modified class definition node.

Return type:

ast.ClassDef

visit_Module(module)[source]

Visit a module definition in the AST.

Appends or deletes the import statements at the top of the module.

Parameters:

module (ast.Module) – The module definition node in the AST.

Returns:

The possibly modified module definition node.

Return type:

ast.Module

agentlib_flexquant.utils.parsing.add_import_to_tree(name: str, alias: str, tree: Module)[source]
agentlib_flexquant.utils.parsing.add_input(name, value, unit, description, type)[source]
agentlib_flexquant.utils.parsing.add_output(name, unit, type, value, description)[source]
agentlib_flexquant.utils.parsing.add_parameter(name, value, unit, description)[source]
agentlib_flexquant.utils.parsing.create_ast_element(template_string)[source]
agentlib_flexquant.utils.parsing.remove_all_imports_from_tree(tree: Module)[source]