pymgrid.modules.BatteryModule#
- class pymgrid.modules.BatteryModule(min_capacity, max_capacity, max_charge, max_discharge, efficiency, battery_cost_cycle=0.0, battery_transition_model=None, init_charge=None, init_soc=None, initial_step=0, normalized_action_bounds=(0, 1), raise_errors=False)[source]#
A battery module.
Battery modules are fixed: when calling
Microgrid.run, you must pass a control for batteries.Parameters#
- min_capacityfloat
Minimum energy that must be contained in the battery.
- max_capacityfloat
Maximum energy that can be contained in the battery. If
soc=1, capacity is at this maximum.- max_chargefloat
Maximum amount the battery can be charged in one step.
Warning
This amount is the maximum the battery can be charged internally, dependent on the
battery_transition_model. The amount the battery can be charged externally (e.g. the amount of energy the battery can absorb) is defined as the negative ofmin_act.- max_dischargefloat
Maximum amount the battery can be discharged in one step.
Warning
This amount is the maximum the battery can be discharged internally, dependent on the
battery_transition_model. The amount the battery can be discharged externally (e.g. the amount of energy the battery can provide) is defined asmax_act.- efficiencyfloat
Efficiency of the battery. See
BatteryModule.model_transition()for details.- battery_cost_cyclefloat, default 0.0
Marginal cost of charging and discharging.
- battery_transition_modelcallable or None, default None
Function to model the battery’s transition. If None,
BatteryTransitionModelis used.Note
If you define a battery_transition_model, it must be YAML-serializable if you plan to serialize your battery module or any microgrid containing your battery.
For example, you can define it as a class with a
__call__method andyaml.YAMLObjectas its metaclass. See the PyYAML documentation for details andBatteryTransitionModelfor an example.- init_chargefloat or None, default None
Initial charge of the battery. One of
init_chargeorinit_socmust be passed, else an exception is raised. If both are passed,init_socis ignored andinit_chargeis used.- init_socfloat or None, default None
Initial state of charge of the battery. One of
init_chargeorinit_socmust be passed, else an exception is raised. If both are passed,init_socis ignored andinit_chargeis used.- 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_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.
An action space bounded by the current step's maximum consumption and production.
from_normalized(value[, act, obs])Un-normalize an action or observation.
get_cost(energy_change)Get the cost of charging or discharging.
load(stream)Load a module from yaml representation.
log_dict()Module's log as a dict.
Module's log as a DataFrame.
model_transition(energy)Convert an external energy request to a change in internal energy.
reset()Reset the module to step zero and flush the log.
sample_action([strict_bound])Sample an action from the module's action space.
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
actionamount of energy.to_normalized(value[, act, obs])Normalize an action or observation.
Values passed to transition models.
update(external_energy_change[, as_source, ...])Update the state of the module given an energy request.
verbose_eq(other[, indent])Attributes
Expected marginal cost of energy absorption.
Action spaces of the module.
Battery charge.
Current step of the module.
Whether the module is a sink.
Whether the module is a source.
Module's log as a DataFrame.
The module's logger.
The most recent entry in the log.
Average marginal cost of producing with the module.
Maximum action that the module allows.
Maximum amount of consumption at the current time step.
Maximum amount of energy the battery can absorb when charging.
Maximum amount of energy the battery can provide when discharging.
Maximum observation that the module gives.
Maximum amount of production at the current time step.
Minimum action that the module allows.
Minimum observation that the module gives.
Minimum amount of production at the current time step.
Type of the module.
Observation space of the module.
Expected marginal cost of energy production.
Battery state of charge.
Current state of the module as a vector.
Tag used for yaml serialization.