agentlib_flexquant.modules package
Submodules
agentlib_flexquant.modules.baseline_mpc module
- class agentlib_flexquant.modules.baseline_mpc.FlexibilityBaselineMINLPMPC(config: dict, agent: Agent)[source]
Bases:
MINLPMPC
agentlib_flexquant.modules.flexibility_indicator module
- class agentlib_flexquant.modules.flexibility_indicator.FlexibilityIndicatorModule(*args, **kwargs)[source]
Bases:
BaseModule
- calc_and_send_offer()[source]
Calculate the flexibility KPIs for current predictions, send the flex offer and set the outputs, write and save the results.
- check_power_end_deviation(tol: float)[source]
calculates the deviation of the final value of the power profiles and warn the user if it exceeds the tolerance
- cleanup_results()[source]
Deletes all files this module created.
Override this method, if your module creates e.g. results files etc.
- data: FlexibilityData
- get_results() DataFrame | None [source]
Opens results file of flexibility_indicator.py results_file defined in __init__
- process()[source]
This abstract method must be implemented in order to sync the module with the other processes of the agent and the whole MAS.
- send_flex_offer(name, base_power_profile: Series, pos_diff_profile: Series, pos_price: float, neg_diff_profile: Series, neg_price: float, timestamp: float = None)[source]
Send a flex offer as an agent Variable. The first offer is dismissed, since the different MPCs need one time step to fully initialize.
Inputs:
name: name of the agent variable indicator_data: the indicator data object timestamp: the time offer was generated
- write_results(df, ts, n)[source]
Write every data of variables in self.var_list in an DataFrame DataFrame will be updated every time step
- Parameters:
df – DataFrame which is initialised as an empty DataFrame with columns according to self.var_list
ts – time step
n – number of time steps during prediction horizon
- Returns:
DataFrame with results of every variable in self.var_list
- pydantic model agentlib_flexquant.modules.flexibility_indicator.FlexibilityIndicatorModuleConfig[source]
Bases:
BaseModuleConfig
- Config:
arbitrary_types_allowed: bool = True
validate_assignment: bool = True
extra: str = forbid
frozen: bool = True
- Fields:
- Validators:
check_results_file_extension
»all fields
check_valid_fields
»shared_variable_fields
- field calculate_costs: InputsForCalculateFlexCosts = InputsForCalculateFlexCosts(use_constant_electricity_price=False, calculate_flex_costs=True, const_electricity_price=nan)
- Validated by:
- field correct_costs: InputsForCorrectFlexCosts = InputsForCorrectFlexCosts(enable_energy_costs_correction=False, absolute_power_deviation_tolerance=0.1, stored_energy_variable='E_stored')
- Validated by:
- field inputs: List[AgentVariable] = [AgentVariable(name='_P_el_base', type='pd.Series', timestamp=None, unit='W', description='The power input to the system', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='_P_el_base', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='_P_el_neg', type='pd.Series', timestamp=None, unit='W', description='The power input to the system', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='_P_el_neg', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='_P_el_pos', type='pd.Series', timestamp=None, unit='W', description='The power input to the system', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='_P_el_pos', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='_E_stored_base', type='pd.Series', timestamp=None, unit='kWh', description='Energy stored in the system w.r.t. 0K', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='_E_stored_base', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='_E_stored_neg', type='pd.Series', timestamp=None, unit='kWh', description='Energy stored in the system w.r.t. 0K', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='_E_stored_neg', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='_E_stored_pos', type='pd.Series', timestamp=None, unit='kWh', description='Energy stored in the system w.r.t. 0K', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='_E_stored_pos', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)]
- Validated by:
- field outputs: List[AgentVariable] = [AgentVariable(name='FlexibilityOffer', type='FlexOffer', timestamp=None, unit='Not defined', description='Not defined', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='FlexibilityOffer', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_power_flex_full', type='pd.Series', timestamp=None, unit='W', description='Negative power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_power_flex_full', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_power_flex_full', type='pd.Series', timestamp=None, unit='W', description='Positive power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_power_flex_full', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_power_flex_offer', type='pd.Series', timestamp=None, unit='W', description='Negative power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_power_flex_offer', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_power_flex_offer', type='pd.Series', timestamp=None, unit='W', description='Positive power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_power_flex_offer', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_power_flex_offer_min', type='float', timestamp=None, unit='W', description='Minimum of negative power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_power_flex_offer_min', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_power_flex_offer_min', type='float', timestamp=None, unit='W', description='Minimum of positive power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_power_flex_offer_min', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_power_flex_offer_max', type='float', timestamp=None, unit='W', description='Maximum of negative power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_power_flex_offer_max', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_power_flex_offer_max', type='float', timestamp=None, unit='W', description='Maximum of positive power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_power_flex_offer_max', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_power_flex_offer_avg', type='float', timestamp=None, unit='W', description='Average of negative power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_power_flex_offer_avg', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_power_flex_offer_avg', type='float', timestamp=None, unit='W', description='Average of positive power flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_power_flex_offer_avg', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_power_flex_within_boundary', type='bool', timestamp=None, unit='-', description='Variable indicating whether the baseline power and flex power align at the horizon end', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_power_flex_within_boundary', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_power_flex_within_boundary', type='bool', timestamp=None, unit='-', description='Variable indicating whether the baseline power and flex power align at the horizon end', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_power_flex_within_boundary', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_energy_flex', type='float', timestamp=None, unit='kWh', description='Negative energy flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_energy_flex', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_energy_flex', type='float', timestamp=None, unit='kWh', description='Positive energy flexibility', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_energy_flex', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_costs', type='float', timestamp=None, unit='ct', description='Saved costs due to baseline', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_costs', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_costs', type='float', timestamp=None, unit='ct', description='Saved costs due to baseline', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_costs', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_corrected_costs', type='float', timestamp=None, unit='ct', description='Corrected saved costs due to baseline', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_corrected_costs', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_corrected_costs', type='float', timestamp=None, unit='ct', description='Corrected saved costs due to baseline', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_corrected_costs', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_costs_rel', type='float', timestamp=None, unit='ct/kWh', description='Saved costs due to baseline', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_costs_rel', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_costs_rel', type='float', timestamp=None, unit='ct/kWh', description='Saved costs due to baseline', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_costs_rel', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='negative_corrected_costs_rel', type='float', timestamp=None, unit='ct/kWh', description='Corrected saved costs per energy due to baseline', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='negative_corrected_costs_rel', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='positive_corrected_costs_rel', type='float', timestamp=None, unit='ct/kWh', description='Corrected saved costs per energy due to baseline', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='positive_corrected_costs_rel', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)]
- Validated by:
- field parameters: List[AgentVariable] = [AgentVariable(name='prep_time', type=None, timestamp=None, unit='s', description='Preparation time', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='prep_time', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='market_time', type=None, timestamp=None, unit='s', description='Market time', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='market_time', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='flex_event_duration', type=None, timestamp=None, unit='s', description='time to switch objective', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='flex_event_duration', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='time_step', type=None, timestamp=None, unit='s', description='timestep of the mpc solution', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='time_step', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='prediction_horizon', type=None, timestamp=None, unit='-', description='prediction horizon of the mpc solution', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='prediction_horizon', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)]
- Validated by:
- field power_unit: str = 'kW'
Unit of the power variable
- Validated by:
- field price_variable: str = 'c_pel'
Name of the price variable sent by a predictor
- Validated by:
- field results_file: Path | None = PosixPath('flexibility_indicator.csv')
User specified results file name
- Validated by:
- field save_results: bool | None = True
- Validated by:
- Validated by:
check_valid_fields
- model_post_init(context: Any, /) None
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
- pydantic model agentlib_flexquant.modules.flexibility_indicator.InputsForCalculateFlexCosts[source]
Bases:
BaseModel
- Fields:
- Validators:
validate_constant_price
»all fields
- field calculate_flex_costs: bool = True
Calculate the flexibility cost
- Validated by:
- field const_electricity_price: float = nan
constant electricity price in ct/kWh
- Validated by:
- field use_constant_electricity_price: bool = False
Use constant electricity price
- Validated by:
- pydantic model agentlib_flexquant.modules.flexibility_indicator.InputsForCorrectFlexCosts[source]
Bases:
BaseModel
- Fields:
- field absolute_power_deviation_tolerance: float = 0.1
Absolute tolerance in kW within which no warning is thrown
- field enable_energy_costs_correction: bool = False
Variable determining whether to correct the costs of the flexible energyDefine the variable for stored electrical energy in the base MPC model and config as output if the correction of costs is enabled
- field stored_energy_variable: str = 'E_stored'
Name of the variable representing the stored electrical energy in the baseline config
agentlib_flexquant.modules.flexibility_market module
- class agentlib_flexquant.modules.flexibility_market.FlexibilityMarketModule(*, config: dict, agent: Agent)[source]
Bases:
BaseModule
Class to emulate flexibility market. Receives flex offers and accepts these.
- cleanup_results()[source]
Deletes all files this module created.
Override this method, if your module creates e.g. results files etc.
- df: DataFrame = None
- dummy_callback(inp, name)[source]
Dummy function, that is included, when market type is not specified
- end: int | float = 0
- get_results() DataFrame | None [source]
Opens results file of flexibilityindicators.py results_file defined in __init__
- process()[source]
This abstract method must be implemented in order to sync the module with the other processes of the agent and the whole MAS.
- random_flexibility_callback(inp, name)[source]
When a flexibility offer is sent this function is called.
- The offer is accepted randomly. The factor self.offer_acceptance_rate determines the
random factor for offer acceptance. self.pos_neg_rate is the random factor for the direction of the flexibility. A higher rate means that more positive offers will be accepted.
- Constraints:
cooldown: during $cooldown steps after a flexibility event no offer is accepted minimum_average_flex: min amount of flexibility to be accepted, to account for the model error
- pydantic model agentlib_flexquant.modules.flexibility_market.FlexibilityMarketModuleConfig[source]
Bases:
BaseModuleConfig
- Config:
arbitrary_types_allowed: bool = True
validate_assignment: bool = True
extra: str = forbid
frozen: bool = True
- Fields:
- Validators:
check_results_file_extension
»all fields
check_valid_fields
»shared_variable_fields
- field inputs: List[AgentVariable] = [AgentVariable(name='FlexibilityOffer', type=None, timestamp=None, unit='Not defined', description='Not defined', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='FlexibilityOffer', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)]
- Validated by:
- field market_specs: MarketSpecifications [Required]
- Validated by:
- field outputs: List[AgentVariable] = [AgentVariable(name='_P_external', type=None, timestamp=None, unit='Not defined', description='External Power IO', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='_P_external', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='rel_start', type=None, timestamp=None, unit='Not defined', description='relative start time of the flexibility event', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='rel_start', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='rel_end', type=None, timestamp=None, unit='Not defined', description='relative end time of the flexibility event', ub=inf, lb=-inf, clip=False, allowed_values=[], value=None, alias='rel_end', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None), AgentVariable(name='in_provision', type=None, timestamp=None, unit='Not defined', description='Set if the system is in provision', ub=inf, lb=-inf, clip=False, allowed_values=[], value=False, alias='in_provision', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)]
- Validated by:
- field results_file: Path | None = PosixPath('flexibility_market.csv')
User specified results file name
- Validated by:
- field save_results: bool | None = True
- Validated by:
- Validated by:
check_valid_fields
- model_post_init(context: Any, /) None
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
agentlib_flexquant.modules.shadow_mpc module
- class agentlib_flexquant.modules.shadow_mpc.FlexibilityShadowMINLPMPC(*args, **kwargs)[source]
Bases:
MINLPMPC
- calc_flex_callback(inp, name)[source]
set the control trajectories before calculating the flexibility offer. self.model should account for flexibility in its cost function
- class agentlib_flexquant.modules.shadow_mpc.FlexibilityShadowMPC(*args, **kwargs)[source]
Bases:
MPC
- calc_flex_callback(inp, name)[source]
set the control trajectories before calculating the flexibility offer. self.model should account for flexibility in its cost function