pymgrid.modules.GridModule#

class pymgrid.modules.GridModule(max_import, max_export, time_series, forecaster=None, forecast_horizon=23, forecaster_increase_uncertainty=False, forecaster_relative_noise=False, initial_step=0, final_step=-1, cost_per_unit_co2=0.0, normalized_action_bounds=(0, 1), raise_errors=False)[source]#

An electrical grid module.

By default, GridModule is a fixed module; it can be transformed to a flex module with GridModule.as_flex. GridModule is the only built-in module that can be both a fixed and flex module.

Parameters#

max_importfloat

Maximum import at any time step.

max_exportfloat

Maximum export at any time step.

time_seriesarray-like, shape (n_features, n_steps), n_features = {3, 4}

If n_features=3, time series of (import_price, export_price, co2_per_kwH) in each column, respectively. Grid is assumed to have no outages. If n_features=4, time series of (import_price, export_price, co2_per_kwH, grid_status) in each column, respectively. time_series[:, -1] – the grid status – must be binary.

forecastercallable, float, “oracle”, None, default None.

Function that gives a forecast n-steps ahead.

  • If callable, must take as arguments (val_c: float, val_{c+n}: float, n: int), where

    • val_c is the current value in the time series: self.time_series[self.current_step]

    • val_{c+n} is the value in the time series n steps in the future

    • n is the number of steps in the future at which we are forecasting.

    The output forecast = forecaster(val_c, val_{c+n}, n) must have the same sign as the inputs val_c and val_{c+n}.

  • If float, serves as a standard deviation for a mean-zero gaussian noise function that is added to the true value.

  • If "oracle", gives a perfect forecast.

  • If None, no forecast.

forecast_horizonint.

Number of steps in the future to forecast. If forecaster is None, ignored and 0 is returned.

forecaster_increase_uncertaintybool, default False

Whether to increase uncertainty for farther-out dates if using a GaussianNoiseForecaster. Ignored otherwise.

cost_per_unit_co2float, default 0.0

Marginal cost of grid co2 production.

normalized_action_boundstuple of int or float, default (0, 1).

Bounds of normalized actions. Change to (-1, 1) for e.g. an RL policy with a Tanh output activation.

raise_errorsbool, default False

Whether to raise errors if bounds are exceeded in an action. If False, actions are clipped to the limit possible.

Methods

as_fixed()

Convert the module to a fixed module.

as_flex()

Convert the module to a flex module.

as_sink(energy_excess)

Act as an energy sink to the microgrid.

as_source(energy_demand)

Act as an energy source to the microgrid.

dump([stream])

Save a module to a YAML buffer.

dynamic_action_space()

An action space bounded by the current step's maximum consumption and production.

forecast()

Forecast the module's time series from the current state.

from_normalized(value[, act, obs])

Un-normalize an action or observation.

get_co2_cost(import_export, as_source, as_sink)

Current cost of the carbon dioxide production of the grid's usage.

get_co2_production(import_export, as_source, ...)

Current carbon dioxide production of the grid's usage.

get_cost(import_export, as_source, as_sink)

Current cost of the grid's usage.

load(stream)

Load a module from yaml representation.

log_dict()

Module's log as a dict.

log_frame()

Module's log as a DataFrame.

reset()

Reset the module to step zero and flush the log.

sample_action([strict_bound])

Sample an action from the module's action space.

serializable_state_attributes()

Return the attributes of the module that represent the module's current state for serialization.

serialize(dumper_stream)

Serialize module.

set_forecaster(forecaster[, ...])

Set the forecaster for this module.

state_dict([normalized])

Current state of the module as a dictionary.

step(action[, normalized])

Take one step in the module, attempting to draw or send action amount of energy.

to_normalized(value[, act, obs])

Normalize an action or observation.

update(external_energy_change[, as_source, ...])

Update the state of the module given an energy request.

verbose_eq(other[, indent])

Attributes

absorption_marginal_cost

Expected marginal cost of energy absorption.

action_space

Action spaces of the module.

co2_per_kwh

Current and forecasted carbon dioxide production per kWh.

current_obs

Current observation.

current_status

Current status of the grid.

current_step

Current step of the module.

export_price

Current and forecasted export prices.

final_step

forecast_horizon

The number of steps until which the module forecasts.

forecaster

View of the forecaster.

forecaster_increase_uncertainty

View of GaussianNoiseForecaster.increase_uncertainty.

forecaster_relative_noise

View of GaussianNoiseForecaster.relative_noise.

grid_status

Current and forecasted grid status.

import_price

Current and forecasted import prices.

is_sink

Whether the module is a sink.

is_source

Whether the module is a source.

log

Module's log as a DataFrame.

logger

The module's logger.

logger_last

The most recent entry in the log.

marginal_cost

Average marginal cost of producing with the module.

max_act

Maximum action that the module allows.

max_consumption

Maximum amount of consumption at the current time step.

max_obs

Maximum observation that the module gives.

max_production

Maximum amount of production at the current time step.

min_act

Minimum action that the module allows.

min_obs

Minimum observation that the module gives.

min_production

Minimum amount of production at the current time step.

module_type

Type of the module.

observation_space

Observation space of the module.

production_marginal_cost

Expected marginal cost of energy production.

state

Current state of the module as a vector.

state_components

Labels of the components of each entry in the module's time series.

time_series

View of the module's time series.

weak_grid

Whether the grid has outages or not.

yaml_tag

Tag used for yaml serialization.