Common components and methods#
Submodules#
assume.common.base module#
- class assume.common.base.BaseStrategy(*args, **kwargs)#
Bases:
objectA base class for a bidding strategy.
- calculate_bids(unit: BaseUnit, market_config: MarketConfig, product_tuples: list[Product], **kwargs) list[Order]#
Calculates the bids for the next time step.
- Parameters:
unit (BaseUnit) – The unit.
market_config (MarketConfig) – The market configuration.
- Returns:
The bids.
- Return type:
Orderbook
- calculate_reward(unit: BaseUnit, marketconfig: MarketConfig, orderbook: list[Order])#
Calculates the reward for the given unit.
- Parameters:
unit (BaseUnit) – The unit.
marketconfig (MarketConfig) – The market configuration.
orderbook (Orderbook) – The orderbook.
- class assume.common.base.BaseUnit(id: str, unit_operator: str, technology: str, bidding_strategies: dict[str, BaseStrategy], forecaster: UnitForecaster, node: str = 'node0', location: tuple[float, float] = (0.0, 0.0), **kwargs)#
Bases:
objectA base class for a unit. This class is used as a foundation for all units.
- Parameters:
id (str) – The ID of the unit.
unit_operator (str) – The operator of the unit.
technology (str) – The technology of the unit.
bidding_strategies (dict[str, BaseStrategy]) – The bidding strategies of the unit.
index (FastIndex) – The index of the unit.
node (str, optional) – The node of the unit. Defaults to “”.
forecaster (Forecaster, optional) – The forecast of the unit. Defaults to None.
location (tuple[float, float], optional) – The location of the unit. Defaults to (0.0, 0.0).
**kwargs – Additional keyword arguments.
- as_dict() dict[str, str | int]#
Returns a dictionary representation of the unit.
- Returns:
A dictionary representation of the unit.
- calculate_bids(market_config: MarketConfig, product_tuples: list[tuple]) list[Order]#
Calculates the bids for the next time step.
- Parameters:
market_config (MarketConfig) – The market configuration.
- Returns:
The bids.
- Return type:
Orderbook
- Raises:
KeyError – If the product type is not found in the bidding strategies.
- calculate_cashflow(product_type: str, orderbook: list[Order])#
Calculates the cashflow for the given product type.
- Parameters:
product_type – The product type.
orderbook – The orderbook.
- calculate_cashflow_and_reward(marketconfig: MarketConfig, orderbook: list[Order]) None#
Calculates the cashflow and the reward for the given unit.
- Parameters:
marketconfig (MarketConfig) – The market configuration.
orderbook (Orderbook) – The orderbook.
- calculate_generation_cost(start: datetime, end: datetime, product_type: str) None#
Calculates the generation cost for a specific product type within the given time range, but only if the end is the last index in the time series.
- Parameters:
start (datetime.datetime) – The start time for the calculation.
end (datetime.datetime) – The end time for the calculation.
product_type (str) – The type of product for which the generation cost is to be calculated.
- calculate_marginal_cost(start: datetime, power: float) float#
Calculates the marginal cost for the given power.`
- Parameters:
start (datetime.datetime) – The start time of the dispatch.
power (float) – The power output of the unit.
- Returns:
The marginal cost for the given power.
- Return type:
- execute_current_dispatch(start: datetime, end: datetime) ndarray#
Checks if the total dispatch plan is feasible.
This method checks if the market feedback is feasible for the given unit and sets the closest dispatch if not. The end parameter should be inclusive.
- Parameters:
start – The start time of the dispatch.
end – The end time of the dispatch.
- Returns:
The volume of the unit within the given time range.
- get_output_before(dt: datetime, product_type: str = 'energy') float#
Returns output before the given datetime.
If the datetime is before the start of the index, 0 is returned.
- Parameters:
dt – The datetime.
product_type – The product type (default is “energy”).
- Returns:
The output before the given datetime.
- get_starting_costs(op_time: int) float#
Returns the costs if start-up is planned.
- Parameters:
op_time – Operation time in hours running from get_operation_time.
- Returns:
Start-up costs.
- set_dispatch_plan(marketconfig: MarketConfig, orderbook: list[Order]) None#
Iterates through the orderbook, adding the accepted volumes to the corresponding time slots in the dispatch plan.
- Parameters:
marketconfig (MarketConfig) – The market configuration.
orderbook (Orderbook) – The orderbook.
- class assume.common.base.ExchangeStrategy(*args, **kwargs)#
Bases:
BaseStrategy
- class assume.common.base.LearningConfig(learning_mode: bool = False, evaluation_mode: bool = False, continue_learning: bool = False, trained_policies_save_path: str | None = None, trained_policies_load_path: str | None = None, min_bid_price: float | None = -100.0, max_bid_price: float | None = 100.0, device: str = 'cpu', episodes_collecting_initial_experience: int = 5, exploration_noise_std: float = 0.2, training_episodes: int = 100, validation_episodes_interval: int = 5, train_freq: str = '24h', batch_size: int = 128, gradient_steps: int = 100, learning_rate: float = 0.001, learning_rate_schedule: str | None = None, early_stopping_steps: int | None = None, early_stopping_threshold: float = 0.05, algorithm: str = 'matd3', replay_buffer_size: int = 50000, gamma: float = 0.99, actor_architecture: str = 'mlp', policy_delay: int = 2, noise_sigma: float = 0.1, noise_scale: int = 1, noise_dt: int = 1, action_noise_schedule: str | None = None, tau: float = 0.005, target_policy_noise: float = 0.2, target_noise_clip: float = 0.5)#
Bases:
objectA class for the learning configuration.
- Parameters:
learning_mode (bool) – Should we use learning mode at all? If False, the learning bidding strategy is loaded from trained_policies_load_path and no training occurs. Default is False.
evaluation_mode (bool) – This setting is modified internally. Whether to run in evaluation mode. If True, the agent uses the learned policy without exploration noise and no training updates occur. Default is False.
continue_learning (bool) – Whether to use pre-learned strategies and then continue learning. If True, loads existing policies from trained_policies_load_path and continues training. Default is False.
trained_policies_save_path (str | None) – The directory path - relative to the scenario’s inputs_path - where newly trained RL policies (actor and critic networks) will be saved. Only needed when learning_mode is True. Value is set in setup_world(). Defaults to None.
trained_policies_load_path (str | None) – The directory path - relative to the scenario’s inputs_path - from which pre-trained policies should be loaded. Needed when continue_learning is True or using pre-trained strategies. Default is None.
min_bid_price (float | None) – The minimum bid price which limits the action of the actor to this price. Used to constrain the actor’s output to a realistic price range. Default is -100.0.
max_bid_price (float | None) – The maximum bid price which limits the action of the actor to this price. Used to constrain the actor’s output to a realistic price range. Default is 100.0.
device (str) – The device to use for PyTorch computations. Options include “cpu”, “cuda”, or specific CUDA devices like “cuda:0”. Default is “cpu”.
episodes_collecting_initial_experience (int) – The number of episodes at the start during which random actions are chosen instead of using the actor network. This helps populate the replay buffer with diverse experiences. Default is 5.
exploration_noise_std (float) – The standard deviation of Gaussian noise added to actions during exploration in the environment. Higher values encourage more exploration. Default is 0.2.
training_episodes (int) – The number of training episodes, where one episode is the entire simulation horizon specified in the general config. Default is 100.
validation_episodes_interval (int) – The interval (in episodes) at which validation episodes are run to evaluate the current policy’s performance without training updates. Default is 5.
train_freq (str) – Defines the frequency in time steps at which the actor and critic networks are updated. Accepts time strings like “24h” for 24 hours or “1d” for 1 day. Default is “24h”.
batch_size (int) – The batch size of experiences sampled from the replay buffer for each training update. Larger batches provide more stable gradients but require more memory. In environments with many leanring agents we advise small batch sizes. Default is 128.
gradient_steps (int) – The number of gradient descent steps performed during each training update. More steps can lead to better learning but increase computation time. Default is 100.
learning_rate (float) – The learning rate (step size) for the optimizer, which controls how much the policy and value networks are updated during training. Default is 0.001.
learning_rate_schedule (str | None) – Which learning rate decay schedule to use. Currently only “linear” decay is available, which linearly decreases the learning rate over time. Default is None (constant learning rate).
early_stopping_steps (int | None) – The number of validation steps over which the moving average reward is calculated for early stopping. If the reward doesn’t change by early_stopping_threshold over this many steps, training stops. If None, defaults to training_episodes / validation_episodes_interval + 1.
early_stopping_threshold (float) – The minimum improvement in moving average reward required to avoid early stopping. If the reward improvement is less than this threshold over early_stopping_steps, training is terminated early. Default is 0.05.
algorithm (str) – Specifies which reinforcement learning algorithm to use. Currently, only “matd3” (Multi-Agent Twin Delayed Deep Deterministic Policy Gradient) is implemented. Default is “matd3”.
replay_buffer_size (int) – The maximum number of transitions stored in the replay buffer for experience replay. Larger buffers allow for more diverse training samples. Default is 500000.
gamma (float) – The discount factor for future rewards, ranging from 0 to 1. Higher values give more weight to long-term rewards in decision-making. Default is 0.99.
actor_architecture (str) – The architecture of the neural networks used for the actors. Options include “mlp” (Multi-Layer Perceptron) and “lstm” (Long Short-Term Memory). Default is “mlp”.
policy_delay (int) – The frequency (in gradient steps) at which the actor policy is updated. TD3 updates the critic more frequently than the actor to stabilize training. Default is 2.
noise_sigma (float) – The standard deviation of the Ornstein-Uhlenbeck or Gaussian noise distribution used to generate exploration noise added to actions. Default is 0.1.
noise_scale (int) – The scale factor multiplied by the noise drawn from the distribution. Larger values increase exploration. Default is 1.
noise_dt (int) – The time step parameter for the Ornstein-Uhlenbeck process, which determines how quickly the noise decays over time. Used for noise scheduling. Default is 1.
action_noise_schedule (str | None) – Which action noise decay schedule to use. Currently only “linear” decay is available, which linearly decreases exploration noise over training. Default is “linear”.
tau (float) – The soft update coefficient for updating target networks. Controls how slowly target networks track the main networks. Smaller values mean slower updates. Default is 0.005.
target_policy_noise (float) – The standard deviation of noise added to target policy actions during critic updates. This smoothing helps prevent overfitting to narrow policy peaks. Default is 0.2.
target_noise_clip (float) – The maximum absolute value for clipping the target policy noise. Prevents the noise from being too large. Default is 0.5.
- class assume.common.base.LearningStrategy(learning_role, foresight: int, act_dim: int, unique_obs_dim: int, num_timeseries_obs_dim: int = 3, *args, **kwargs)#
Bases:
BaseStrategyA strategy which provides learning functionality, has a method to calculate the reward.
It is important to keep in mind, that the DRL method and the centralized critic relies on unique observations of individual units. The algorithm is designed in such a way, that the unique observations are always placed at the end of the observation space. Please follow this convention when designing your create_observation method and the observation space.
- class assume.common.base.MinMaxChargeStrategy(*args, **kwargs)#
Bases:
BaseStrategy
- class assume.common.base.MinMaxStrategy(*args, **kwargs)#
Bases:
BaseStrategy
- class assume.common.base.SupportsMinMax(**kwargs)#
Bases:
BaseUnitBase class used for units supporting continuous dispatch and without energy storage. This class is best to be used as foundation for classes of power plants and similar units.
- calculate_min_max_power(start: datetime, end: datetime, product_type: str = 'energy') tuple[ndarray, ndarray]#
Calculates the min and max power for the given time period.
- Parameters:
start (datetime.datetime) – The start time of the dispatch.
end (datetime.datetime) – The end time of the dispatch.
product_type (str) – The product type of the unit.
- Returns:
The min and max power for the given time period.
- Return type:
tuple[np.ndarray, np.ndarray]
- calculate_ramp(op_time: int, previous_power: float, power: float, current_power: float = 0) float#
Corrects the possible power to offer according to ramping restrictions.
- Parameters:
- Returns:
The corrected possible power to offer according to ramping restrictions.
- Return type:
- get_operation_time(start: datetime) int#
Returns the time the unit is operating (positive) or shut down (negative).
- Parameters:
start (datetime.datetime) – The start time.
- Returns:
The operation time as a positive integer if operating, or negative if shut down.
- Return type:
- get_starting_costs(op_time: int) float#
Returns the start-up cost for the given operation time. If operation time is positive, the unit is running, so no start-up costs are returned. If operation time is negative, the unit is not running, so start-up costs are returned according to the start-up costs of the unit and the hot/warm/cold start times.
- class assume.common.base.SupportsMinMaxCharge(**kwargs)#
Bases:
BaseUnitBase Class used for units with energy storage.
The volume is always the amount of energy which is put on (if positive) the market or (if negative) taken from the market. A demand does always have a negative volume - as it buys/consumes energy . A powerplant does always have a positive volume - as it produces energy.
All charging related params are negative, as charging is a demand. This is special for SupportsMinMaxCharge as both charge and discharge is available.
- calculate_min_max_charge(start: datetime, end: datetime, soc: float = None) tuple[ndarray, ndarray]#
Calculates the min and max charging power for the given time period.
- Parameters:
start (datetime.datetime) – The start time of the dispatch.
end (datetime.datetime) – The end time of the dispatch.
soc (float, optional) – The current state-of-charge (between 0 and 1). Defaults to None.
- Returns:
The min and max charging power for the given time period.
- Return type:
tuple[np.ndarray, np.ndarray]
- calculate_min_max_discharge(start: datetime, end: datetime, soc: float = None) tuple[ndarray, ndarray]#
Calculates the min and max discharging power for the given time period.
- Parameters:
start (datetime.datetime) – The start time of the dispatch.
end (datetime.datetime) – The end time of the dispatch.
soc (float, optional) – The current state-of-charge (between 0 and 1). Defaults to None.
- Returns:
The min and max discharging power for the given time period.
- Return type:
tuple[np.ndarray, np.ndarray]
- calculate_ramp_charge(previous_power: float, power_charge: float, current_power: float = 0) float#
Adjusts the charging power to the ramping constraints.
- Parameters:
- Returns:
The charging power adjusted to the ramping constraints.
- Return type:
- calculate_ramp_discharge(previous_power: float, power_discharge: float, current_power: float = 0) float#
Adjusts the discharging power to the ramping constraints. Given previous_power in the step before, we want to offer power_discharge (positive) to some market, while we already sold current_power on some other market.
power_discharge is a power delta to our current output, this function checks if this amount is still feasible to sell.
- Parameters:
- Returns:
The discharging power adjusted to the ramping constraints.
- Return type:
- set_dispatch_plan(marketconfig: MarketConfig, orderbook: list[Order]) None#
Updates the SOC for storage units.
assume.common.exceptions module#
- exception assume.common.exceptions.InvalidTypeException#
Bases:
AssumeException
assume.common.mango_serializer module#
- assume.common.mango_serializer.datetime_json_serializer()#
- assume.common.mango_serializer.generic_json_serializer()#
- assume.common.mango_serializer.generic_pb_serializer()#
- assume.common.mango_serializer.mango_codec_factory()#
assume.common.market_objects module#
- class assume.common.market_objects.ClearingMessage#
Bases:
TypedDictMessage which is sent from the market to agents to clear a market.
- Parameters:
- class assume.common.market_objects.DataRequestMessage#
Bases:
TypedDictMessage for requesting data from a market.
- Parameters:
context (str) – the context of the message
market_id (str) – the id of the market
metric (str) – the specific metric being requested
start_time (datetime.datetime) – the start time of the data request
end_time (datetime.datetime) – the end time of the data request
- class assume.common.market_objects.MarketConfig(market_id: str = 'market', opening_hours: ~dateutil.rrule.rrule = <dateutil.rrule.rrule object>, opening_duration: ~datetime.timedelta = datetime.timedelta(seconds=3600), market_mechanism: str = 'pay_as_clear', market_products: list[~assume.common.market_objects.MarketProduct] = <factory>, product_type: str = 'energy', maximum_bid_volume: float | None = 2000.0, maximum_bid_price: float | None = 3000.0, minimum_bid_price: float = -500.0, maximum_gradient: float | None = None, additional_fields: list[str] = <factory>, volume_unit: str = 'MW', volume_tick: float | None = None, price_unit: str = '€/MWh', price_tick: float | None = None, supports_get_unmatched: bool = False, eligible_obligations_lambda: ~collections.abc.Callable[[~mango.agent.core.Agent], bool] = <function MarketConfig.<lambda>>, param_dict: dict = <factory>, addr: ~mango.messages.message.AgentAddress | None = None)#
Bases:
objectDescribes the configuration of a market.
- Parameters:
market_id (str) – the ID of the market
opening_hours (dateutil.rrule.rrule) – the opening hours of the market
opening_duration (datetime.timedelta) – the duration of the opening hours
market_mechanism (str) – name of method used for clearing
market_products (list[MarketProduct]) – list of available products to be traded at the market
product_type (str) – energy or capacity or heat
maximum_bid_volume (float | None) – the maximum valid bid volume of the market
maximum_bid_price (float | None) – the maximum bid price of the market
minimum_bid_price (float) – the minimum bid price of the market
maximum_gradient (float | None) – max allowed change between bids
additional_fields (list[str]) – additional fields of the market
volume_unit (str) – the volume unit of the market (e.g. MW)
volume_tick (float | None) – step increments of volume (e.g. 0.1)
price_unit (str) – the price unit of the market (e.g. €/MWh)
price_tick (float | None) – step increments of price (e.g. 0.1)
supports_get_unmatched (bool) – whether the market supports get unmatched
eligible_obligations_lambda (eligible_lambda) – lambda function which determines if an agent is eligible to trade this product
param_dict (dict) – dict which can have additional params for the used clearing_mechanism
addr (str) – the address of the market
aid (str) – automatic id of the market
- addr: AgentAddress | None = None#
- eligible_obligations_lambda()#
- market_products: list[MarketProduct]#
- class assume.common.market_objects.MarketProduct(duration: relativedelta | rrule, count: int, first_delivery: relativedelta = relativedelta(), only_hours: OnlyHours | None = None, eligible_lambda_function: Callable[[Agent], bool] | None = None)#
Bases:
objectDescribes the configuration of a market product which is available at a market.
- Parameters:
duration (dateutil.relativedelta.relativedelta | dateutil.rrule.rrule) – the duration of the product
count (int) – how many future durations can be traded, must be >= 1
first_delivery (dateutil.relativedelta.relativedelta) – when does the first delivery begin, in relation to market start
only_hours (OnlyHours | None) – tuple of hours from which this order is available, on multi day products
eligible_lambda_function (eligible_lambda | None) – lambda function which determines if an agent is eligible to trade this product
- duration: relativedelta | rrule#
- first_delivery: relativedelta = relativedelta()#
- class assume.common.market_objects.MetaDict#
Bases:
TypedDictMessage Meta of a FIPA ACL Message.
- Parameters:
sender_id (str) – the id of the sender
reply_to (str) – to which agent follow up messages should be sent
conversation_id (str) – the id of the conversation
performative (str) – the performative of the message
protocol (str) – the protocol used
language (str) – the language used
encoding (str) – the encoding used
ontology (str) – the ontology used
reply_with (str) – what the answer should contain as in_reply_to
in_reply_to (str) – str used to reference an earlier action
reply_by (str) – latest time to accept replies
- class assume.common.market_objects.OnlyHours(begin_hour: int, end_hour: int)#
Bases:
NamedTupleUsed for peak and off-peak bids. Allows to set a begin and hour of the peak.
For example OnlyHours(8,16) would be used to have a bid which is valid for every day from 8 to 16 a clock.
- class assume.common.market_objects.OpeningMessage#
Bases:
TypedDictMessage which is sent from the market to participating agent to open a market.
- Parameters:
- class assume.common.market_objects.Order#
Bases:
TypedDictDescribes an order which can be either generation (volume > 0) or demand (volume < 0)
- Parameters:
bid_id (str) – the id of the bid
start_time (datetime.datetime) – the start time of the order
end_time (datetime.datetime) – the end time of the order
volume (Number | dict[datetime, Number]) – the volume of the order (positive if generation)
accepted_volume (Number | dict[datetime, Number]) – the accepted volume of the order
price (Number) – the price of the order
accepted_price (Number | dict[datetime, Number]) – the accepted price of the order
agent_addr (str) – the address of the agent
node (str) – the node of market where the order is placed
only_hours (OnlyHours | None) – tuple of hours from which this order is available, on multi day products
- class assume.common.market_objects.OrderBookMessage#
Bases:
TypedDictMessage containing the order book of a market.
- Parameters:
- class assume.common.market_objects.Product(start: datetime, end: datetime, only_hours: OnlyHours | None = None)#
Bases:
NamedTupleAn actual product with start and end.
- Parameters:
start (datetime.datetime) – the start time of the product
end (datetime.datetime) – the end time of the product
only_hours (OnlyHours | None) – tuple of hours from which this order is available, on multi day products
- class assume.common.market_objects.RegistrationMessage#
Bases:
TypedDictMessage for agent registration at a market.
- Parameters:
- class assume.common.market_objects.RegistrationReplyMessage#
Bases:
TypedDictReply message for agent registration at a market.
- Parameters:
- assume.common.market_objects.only_co2emissionless(unit)#
same as only_renewables plus nuclear
- assume.common.market_objects.only_renewables(unit)#
check that technology is renewable. This allows all names containing wind, solar, bio or demand
- assume.common.market_objects.power_plant_not_negative(unit)#
assume.common.outputs module#
- class assume.common.outputs.DatabaseMaintenance(db_uri: str)#
Bases:
objectA utility class for managing simulation data stored in a database.
- This class creates a database engine from a provided URI and offers methods to:
Retrieve a list of unique simulation IDs across all tables.
Delete specific simulations from every table.
Delete all simulations, or all except those specified, across every table.
It assumes that each table (except for system tables like “spatial_ref_sys”) contains a column named ‘simulation’ that uniquely identifies the simulation.
- Parameters:
db_uri (str) – The URI of the database engine used to create a SQLAlchemy engine.
- delete_all_simulations(exclude: list[str] = None) None#
Deletes all simulation records from every table, with an option to exclude specific simulations.
If an exclusion list is provided, simulations with those IDs will not be deleted. Otherwise, all simulation records are removed from all tables (excluding system tables).
- delete_simulations(simulation_ids: list[str]) None#
Deletes specific simulation records from all tables.
This method deletes rows from every table where the ‘simulation’ column matches any of the provided simulation IDs. An index is created on the simulation column to optimize the deletion, if one does not already exist.
- class assume.common.outputs.WriteOutput(simulation_id: str, start: datetime, end: datetime, save_frequency_hours, db_uri='', export_csv_path: str = '', outputs_buffer_size_mb: int = 300, learning_mode: bool = False, evaluation_mode: bool = False, episode: int = None, eval_episode: int = None, additional_kpis: dict[str, OutputDef] = {})#
Bases:
RoleInitializes an instance of the WriteOutput class.
- Parameters:
simulation_id (str) – The ID of the simulation as a unique classifier.
start (datetime.datetime) – The start datetime of the simulation run.
end (datetime.datetime) – The end datetime of the simulation run.
save_frequency_hours (int) – The frequency in hours for storing data in the db and/or csv files.
db_uri – The uri of the database engine. Defaults to ‘’.
export_csv_path (str, optional) – The path for exporting CSV files, no path results in not writing the csv. Defaults to “”.
outputs_buffer_size_mb (int, optional) – The maximum storage size (in MB) for storing output data before saving it. Defaults to 300 MB.
learning_mode (bool, optional) – Indicates if the simulation is in learning mode. Defaults to False.
evaluation_mode (bool, optional) – Indicates if the simulation is in evaluation mode. Defaults to False.
additional_kpis (dict[str, OutputDef], optional) – makes it possible to define additional kpis evaluated
- check_columns(table: str, df: DataFrame, index: bool = True)#
Checks and adds columns to the database table if necessary.
- Parameters:
table (str) – The name of the database table.
df (pandas.DataFrame) – The DataFrame to be checked.
- convert_flows(data: dict[tuple[datetime, str], float])#
Convert the flows of the grid results into a dataframe.
- Parameters:
data – The records to be put into the table. Formatted like, “(datetime, line), flow” if generated by pyomo or df if it comes from pypsa.
- convert_market_dispatch(market_dispatch: list[dict])#
Convert the planned dispatch of the units to a DataFrame.
- Parameters:
data (any) – The records to be put into the table. Formatted like, “datetime, power, market_id, unit_id”.
- convert_market_orders(market_orders: any, market_id: str)#
Convert market orders to a dataframe.
- Parameters:
market_orders (any) – The market orders.
market_id (str) – The id of the market.
- convert_market_results(market_results: list[dict])#
Convert market results to a dataframe.
- Parameters:
market_meta (dict) – The market metadata, which includes the clearing price and volume.
- convert_rl_grad_params(rl_grad_params: list[dict])#
Convert the RL (actor-critic) parameters for each gradient step to a dataframe.
- Parameters:
rl_grad_params (dict) – The RL parameters per gradient step.
- convert_rl_params(rl_params: list[dict])#
Convert the RL parameters such as reward, regret, and profit to a dataframe.
- Parameters:
rl_params (dict) – The RL parameters.
- convert_unit_dispatch(unit_dispatch: list[dict])#
Convert the actual dispatch of the units to a DataFrame.
- Parameters:
unit_dispatch (list) – A list of dictionaries containing unit dispatch data. Each dictionary includes arrays for multiple values (e.g., power, costs) and other metadata.
- convert_units_definition(unit_info: dict)#
Convert unit definitions to a dataframe.
- Parameters:
unit_info (dict) – The unit information.
- delete_db_scenario(simulation_id: str)#
Deletes all data from the database for the given simulation id.
- Parameters:
simulation_id (str) – The ID of the simulation as a unique classifier.
- get_sum_reward(episode: int, evaluation_mode=True)#
Retrieves the total reward for each learning unit.
- Returns:
The total reward for each learning unit.
- Return type:
np.ndarray
- handle_output_message(content: dict, meta: MetaDict)#
Handles the incoming messages and performs corresponding actions.
- on_ready()#
Called after the start of all container using activate
- async on_stop()#
This function makes it possible to calculate Key Performance Indicators. It is called when the simulation is finished. It collects average price, total cost, total volume and capacity factors and uses them to calculate the KPIs. The KPIs are then stored in the database and CSV files.
- setup()#
Sets up the WriteOutput instance by subscribing to messages and scheduling recurrent tasks of storing the data.
- async store_dfs()#
Stores the data frames to CSV files and the database. Is scheduled as a recurrent task based on the frequency.
assume.common.units_operator module#
- class assume.common.units_operator.UnitsOperator(available_markets: list[MarketConfig], portfolio_strategies: dict[str, UnitOperatorStrategy] = {})#
Bases:
RoleThe UnitsOperator is the agent that manages the units. It receives the opening hours of the market and sends back the bids for the market.
- available_markets#
The available markets.
- Type:
- registered_markets#
The registered markets.
- Type:
- portfolio_strategies#
The portfolio strategy.
- Type:
- valid_orders#
The valid orders.
- Type:
defaultdict
- context#
The context of the agent.
- Type:
Context
- Parameters:
available_markets (list[MarketConfig]) – The available markets.
portfolio_strategies (dict[str, UnitOperatorStrategy], optional) – Optimized portfolio strategy. Defaults to an empty dict.
- calculate_unit_cashflow_and_reward(orderbook: list[Order], marketconfig: MarketConfig) None#
Feeds the current market result back to the units.
- Parameters:
orderbook (Orderbook) – The orderbook of the market.
marketconfig (MarketConfig) – The market configuration.
- get_actual_dispatch(product_type: str, last: datetime) tuple[list[tuple[datetime, float, str, str]], list[dict]]#
Retrieves the actual dispatch since the last dispatch and commits it in the unit. We calculate the series of the actual market results dataframe with accepted bids. And the unit_dispatch for all units taken care of in the UnitsOperator.
- handle_data_request(content: DataRequestMessage, meta: MetaDict) None#
Handles the data request received from other agents.
- Parameters:
content (DataRequestMessage) – The content of the data request message.
meta (MetaDict) – The meta data of the market.
- handle_market_feedback(content: ClearingMessage, meta: MetaDict) None#
Handles the feedback which is received from a market we did bid at.
- Parameters:
content (ClearingMessage) – The content of the clearing message.
meta (MetaDict) – The meta data of the market.
- handle_opening(opening: OpeningMessage, meta: MetaDict) None#
When we receive an opening from the market, we schedule sending back our list of orders as a response.
- Parameters:
opening (OpeningMessage) – The opening message.
meta (MetaDict) – The meta data of the market.
- handle_registration_feedback(content: RegistrationMessage, meta: MetaDict) None#
Handles the feedback received from a market regarding registration.
- Parameters:
content (RegistrationMessage) – The content of the registration message.
meta (MetaDict) – The meta data of the market.
- on_ready()#
Called after the start of all container using activate
- participate(market: MarketConfig) bool#
Method which decides if we want to participate on a given Market. This always returns true for now.
- Parameters:
market (MarketConfig) – The market to participate in.
- Returns:
True if participate, False otherwise.
- Return type:
- async register_market(market: MarketConfig) None#
Register a market.
- Parameters:
market (MarketConfig) – The market to register.
- set_unit_dispatch(orderbook: list[Order], marketconfig: MarketConfig) None#
Feeds the current market result back to the units.
- Parameters:
orderbook (Orderbook) – The orderbook of the market.
marketconfig (MarketConfig) – The market configuration.
- setup()#
Lifecycle hook in, which will be called on adding the role to agent. The role context is known from hereon.
- async submit_bids(opening: OpeningMessage, meta: MetaDict) None#
Formulates an orderbook and sends it to the market.
- Parameters:
opening (OpeningMessage) – The opening message.
meta (MetaDict) – The meta data of the market.
assume.common.utils module#
- assume.common.utils.adjust_unit_operator_for_learning(bidding_strategies: dict[str, str], world_bidding_strategies: dict[str, BaseStrategy], unit_operator_id: str)#
Check if any of the bidding strategies are learning strategies. And change the unit operator to RL if learning strategies are found.
- Parameters:
- Returns:
The corrected unit operator identifier.
- Return type:
- assume.common.utils.aggregate_step_amount(orderbook: list[Order], begin=None, end=None, groupby=None)#
Step function with bought volume, allows setting timeframe through begin and end, and group by columns in groupby.
- Parameters:
- Returns:
The aggregated orderbook timeseries.
- Return type:
Examples
If called without groupby, this returns the aggregated orderbook timeseries
- assume.common.utils.calculate_content_size(content: list | dict) int#
Calculate the size of a content in bytes.
- assume.common.utils.confirm_learning_save_path(save_path: str, continue_learning: bool) None#
Check save_path and ask user how to proceed if it exists. Raises AssumeException if user declines to proceed.
- assume.common.utils.convert_tensors(data)#
Recursively checks if the data contains PyTorch tensors and converts them to native Python types (floats, ints, lists).
Supports: - pandas.Series (vectorized for efficiency) - Lists of dictionaries (including nested structures) - Any nested list/dict structure
- Parameters:
data (pandas.Series, list, dict, or other Python data types)
- Returns:
The data with all tensors converted to Python-native types.
- assume.common.utils.convert_to_rrule_freq(string: str) tuple[int, int]#
Convert a string to a rrule frequency and interval.
- assume.common.utils.create_incidence_matrix(lines, buses, zones_id=None)#
- assume.common.utils.create_rrule(start, end, freq)#
- assume.common.utils.get_available_products(market_products: list[MarketProduct], startdate: datetime)#
Get all available products for a given startdate.
- Parameters:
market_products (list[MarketProduct]) – List of market products.
startdate (datetime.datetime) – The startdate.
- Returns:
List of available products.
- Return type:
- assume.common.utils.get_products_index(orderbook: list[Order]) DatetimeIndex#
Creates an index containing all start times of orders in orderbook and all between.
- Parameters:
orderbook (Orderbook) – The orderbook.
- Returns:
The index containing all start times of orders in orderbook and all between.
- Return type:
pd.DatetimeIndex
- assume.common.utils.initializer(func)#
Automatically assigns the parameters.
- Parameters:
func (callable) – The function to be initialized.
- Returns:
The wrapper function.
- Return type:
callable
Examples
>>> class process: ... @initializer ... def __init__(self, cmd, reachable=False, user='root'): ... pass >>> p = process('halt', True) >>> p.cmd, p.reachable, p.user ('halt', True, 'root')
- assume.common.utils.min_max_scale(x, min_val: float, max_val: float)#
Min-Max scaling of a value x to the range [0, 1]
- Parameters:
x – value(s) to scale
min_val – minimum value of the parameter
max_val – maximum value of the parameter
- assume.common.utils.normalize_availability(powerplants_df, availability_df)#
- assume.common.utils.parse_duration(duration_str)#
- assume.common.utils.plot_orderbook(orderbook: list[Order], results: list[dict])#
Plot the merit order of bids for each node in a separate subplot.
- assume.common.utils.rename_study_case(path: str, old_key: str, new_key: str)#
Rename key in config file and save changes.
This function makes changes to the config file. Background is so that study cases can be simulated multiple times under different names with the same configuration.
- assume.common.utils.separate_orders(orderbook: list[Order])#
Separate orders with several hours into single hour orders.
- Parameters:
orderbook (Orderbook) – The orderbook.
- Returns:
The updated orderbook.
- Return type:
Note
This function separates orders with several hours into single hour orders and modifies the orderbook in place.
- assume.common.utils.str_to_bool(val)#
Convert a string representation of truth to True or False.
True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’. Raises ValueError if ‘val’ is anything else.
assume.common.grid_utils module#
- assume.common.grid_utils.add_backup_generators(network: Network, backup_marginal_cost: float = 100000.0) None#
Add generators normally to the grid
- Parameters:
network (pypsa.Network) – the pypsa network to which the generators are
generators (pandas.DataFrame) – the generators dataframe
- assume.common.grid_utils.add_generators(network: Network, generators: DataFrame) None#
Add generators normally to the grid
- Parameters:
network (pypsa.Network) – the pypsa network to which the generators are
generators (pandas.DataFrame) – the generators dataframe
- assume.common.grid_utils.add_loads(network: Network, loads: DataFrame) None#
Add loads normally to the grid
- Parameters:
network (pypsa.Network) – the pypsa network to which the loads are
loads (pandas.DataFrame) – the loads dataframe
- assume.common.grid_utils.add_nodal_loads(network: Network, loads: DataFrame) None#
This adds loads to the nodal PyPSA network with respective bus data to which they are connected. The loads are added as generators with negative sign so their dispatch can be also curtailed, since regular load in PyPSA represents only an inelastic demand.
- assume.common.grid_utils.add_redispatch_generators(network: Network, generators: DataFrame, backup_marginal_cost: float = 100000.0) None#
Adds the given generators for redispatch. This includes functions to optimize up as well as down and adds backup capacities of powerplants to be able to adjust accordingly when a congestion happens.
- Parameters:
network (pypsa.Network) – the pypsa network to which the generators are
generators (pandas.DataFrame) – the generators dataframe
backup_marginal_cost (float, optional) – The cost of dispatching the backup units in [€/MW]. Defaults to 1e5.
- assume.common.grid_utils.add_redispatch_loads(network: Network, loads: DataFrame) None#
This adds loads to the redispatch PyPSA network with respective bus data to which they are connected
- assume.common.grid_utils.calculate_network_meta(network, product: MarketProduct, i: int)#
This function calculates the meta data such as supply and demand volumes, and nodal prices.
- Parameters:
product (MarketProduct) – The product for which clearing happens.
i (int) – The index of the product in the market products list.
- Returns:
The meta data.
- Return type:
- assume.common.grid_utils.read_pypsa_grid(network: Network, grid_dict: dict[str, DataFrame])#
Generates the pypsa grid from a grid dictionary. Does not add the generators, as they are added in different ways, depending on whether redispatch is used.
- Parameters:
network (pypsa.Network) – the pypsa network to which the components will be added
grid_dict (dict[str, pd.DataFrame]) – the dictionary containing dataframes for generators, loads, buses and links