pymgrid.envs.ContinuousMicrogridEnv#
- class pymgrid.envs.ContinuousMicrogridEnv(modules, add_unbalanced_module=True, loss_load_cost=10, overgeneration_cost=2, reward_shaping_func=None, trajectory_func=None, flat_spaces=True, observation_keys=())[source]#
Microgrid environment with a continuous action space.
Implements the OpenAI Gym API for a microgrid; inherits from both
Microgridandgym.Env.Parameters#
- moduleslist, Microgrid, NonModularMicrogrid, or int.
The constructor can be called in three ways:
Passing a list of microgrid modules. This is identical to the
Microgridconstructor.Passing a
MicrogridorNonModularMicrogridinstance. This will effectively wrap the microgrid instance with the Gym API.Passing an integer in [0, 25). This will be result in loading the corresponding pymgrid25 benchmark microgrids.
- add_unbalanced_modulebool, default True.
Whether to add an unbalanced energy module to your microgrid. Such a module computes and attributes costs to any excess supply or demand. Set to True unless
modulescontains anUnbalancedEnergyModule.- loss_load_costfloat, default 10.0
Cost per unit of unmet demand. Ignored if
add_unbalanced_module=False.- overgeneration_costfloat, default 2.0
Cost per unit of excess generation. Ignored if
add_unbalanced_module=False.- flat_spacesbool, default True
Whether the environment’s spaces should be flat.
If True, all continuous spaces are
gym.spaces.Box.Otherwise, they are nested
gym.spaces.Dictofgym.spaces.Tupleofgym.spaces.Box, corresponding to the structure of thecontrolarg ofMicrogrid.run().- trajectory_funccallable or None, default None
Callable that sets an initial and final step for an episode.
trajectory_funcmust take two inputs:initial_stepandfinal_step, and return two integers: the initial and final step for that particular episode, respectively. This function will be called every timereset()is called.If None,
initial_stepandfinal_stepare used to define every episode.
Methods
close()Override close in your subclass to perform any necessary cleanup.
dump([stream])Save a microgrid to a YAML buffer.
from_microgrid(microgrid, **kwargs)Construct an RL environment from a microgrid.
from_nonmodular(nonmodular, **kwargs)Convert to Microgrid from old-style NonModularMicrogrid.
from_normalized(data_dict[, act, obs])De-normalize an action or observation.
from_scenario([microgrid_number])Load one of the pymgrid25 benchmark microgrids.
get_empty_action([sample_flex_modules])Get an action for the microgrid with no values set.
Get the forecast horizon of timeseries modules contained in the microgrid.
get_log([as_frame, drop_singleton_key])Collect a log of controls and responses of the microgrid.
load(stream)Load a microgrid from a yaml buffer.
reset()Reset the microgrid and flush the log.
run(action[, normalized])Run the microgrid for a single step.
sample_action([strict_bound, ...])Get a random action within the microgrid's action space.
set_forecaster(forecaster[, ...])Set the forecaster for timeseries modules in the microgrid.
set_module_attr(attr_name, value)Set the value of an attribute in all modules containing that attribute.
state_dict([normalized])State of the microgrid as a dict.
state_series([normalized])State of the microgrid as a pandas Series.
step(action)Run one timestep of the environment's dynamics.
Convert Microgrid to old-style NonModularMicrogrid.
to_normalized(data_dict[, act, obs])Normalize an action or observation.
Attributes
Space object corresponding to valid actions.
List of all controllable modules in the microgrid.
Current step of underlying modules.
Final step of underlying timeseries data.
List of all fixed modules in the microgrid.
Whether the environment's spaces are flat.
List of all flex modules in the microgrid.
Initial step at which to start underlying timeseries data.
Microgrid's log as a DataFrame.
List of all modules in the microgrid.
View of the module container.
Number of modules in the microgrid.
Returns the environment's internal
_np_randomthat if not set will initialise with a random seed.Space object corresponding to valid observations.
Tag used for yaml serialization.