agentlib_flexquant package

agentlib plugin

Subpackages

Submodules

agentlib_flexquant.generate_flex_agents module

class agentlib_flexquant.generate_flex_agents.FlexAgentGenerator(flex_config: str | Path | FlexQuantConfig, mpc_agent_config: str | Path | AgentConfig)[source]

Bases: object

Class for generating the flex agents

orig_mpc_module_config: the config for the original mpc, which has nothing to do with the flexibility quantification baseline_mpc_module_config: the config for the baseline mpc for flexibility quantification pos_flex_mpc_module_config: the config for the positive flexibility mpc for flexibility quantification neg_flex_mpc_module_config: the config for the negative flexibility mpc for flexibility quantification indicator_module_config: the config for the indicator for flexibility quantification market_module_config: the config for the market for flexibility quantification

adapt_indicator_config(module_config: FlexibilityIndicatorModuleConfig) FlexibilityIndicatorModuleConfig[source]

Adapt the indicator module config for automated flexibility quantification.

adapt_market_config(module_config: FlexibilityMarketModuleConfig) FlexibilityMarketModuleConfig[source]

Adapt the market module config for automated flexibility quantification.

adapt_mpc_module_config(module_config: MPCConfig, mpc_dataclass: BaseMPCData) MPCConfig[source]

Adapt the mpc module config for automated flexibility quantification.

Things adapted among others are: - the file name/path of the mpc config file - names of the control variables for the shadow mpcs - reduce communicated variables of shadow mpcs to outputs - add the power variable to the outputs - add parameters for the activation and quantification of flexibility

Parameters:
  • module_config – The module config to be adapted

  • mpc_dataclass – The dataclass corresponding to the type of the MPC module. It contains all the extra data necessary for flexibility quantification, which will be used to update the module_config.

Returns:

The adapted module config

adapt_sim_results_path(simulator_agent_config: str | Path) dict[source]

Optional helper function to adapt file path for simulator results in sim config, so that sim results land in the same results directory as flex results.

Parameters:

simulator_agent_config – Path to the simulator agent config JSON file.

Returns:

The updated simulator config dictionary with the modified result file path.

Raises:

FileNotFoundError – If the specified config file does not exist.

append_module_and_dump_agent(module: BaseModuleConfig, agent: AgentConfig, module_type: str, config_name: str)[source]

Append the given module config to the given agent config and dumps the agent config to a json file.

The json file is named based on the config_name.

Parameters:
  • module – The module config to be appended.

  • agent – The agent config to be updated.

  • module_type – The type of the module

  • config_name – The name of the json file for module config (e.g. baseline.json)

baseline_mpc_module_config: MPCConfig
check_variables_in_casadi_config(config: CasadiModelConfig, expr: str)[source]

Check if all variables in the expression are defined in the config.

Parameters:
  • config – casadi model config.

  • expr – The expression to check.

Raises:

ValueError – If any variable in the expression is not defined in the config.

generate_flex_agents() list[str][source]

Generate the configs and the python module for the flexibility agents.

Returns:

list of the full path for baseline mpc, pos_flex mpc, neg_flex mpc, indicator and market config

get_config_file_paths() List[str][source]

Return a list of paths with the created config files.

indicator_module_config: FlexibilityIndicatorModuleConfig
market_module_config: FlexibilityMarketModuleConfig
neg_flex_mpc_module_config: MPCConfig
orig_mpc_module_config: MPCConfig
pos_flex_mpc_module_config: MPCConfig
run_config_validations()[source]

Function to validate integrity of user-supplied flex config.

The following checks are performed: 1. Ensures the specified power variable exists in the MPC model outputs. 2. Ensures the specified comfort variable exists in the MPC model states. 3. Validates that the stored energy variable exists in MPC outputs if energy cost correction is enabled. 4. Verifies the supported collocation method is used; otherwise, switches to ‘legendre’ and raises a warning. 5. Ensures that the sum of prep time, market time, and flex event duration does not exceed the prediction horizon. 6. Ensures market time equals the MPC model time step if market config is present. 7. Ensures that all flex time values are multiples of the MPC model time step. 8. Checks for mismatches between time-related parameters in the flex/MPC and indicator configs and issues warnings when discrepancies exist, using the flex/MPC config values as the source of truth.