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, 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.
- max_dischargefloat
Maximum amount the battery can be discharged in one step.
- 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,
BatteryModule.default_transition_model()is 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.- 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.- 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.
A simple battery transition model.
dump([stream])Save a module to a YAML buffer.
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.
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.
Attributes
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 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.
Battery state of charge.
Current state of the module as a vector.
Current state of the module as a dictionary.
Tag used for yaml serialization.