Environment¶
-
class
grid2op.Environment.
Environment
(init_grid_path: str, chronics_handler, backend, parameters, names_chronics_to_backend=None, actionClass=<class 'grid2op.Action.TopologyAction.TopologyAction'>, observationClass=<class 'grid2op.Observation.CompleteObservation.CompleteObservation'>, rewardClass=<class 'grid2op.Reward.FlatReward.FlatReward'>, legalActClass=<class 'grid2op.Rules.AlwaysLegal.AlwaysLegal'>, voltagecontrolerClass=<class 'grid2op.VoltageControler.ControlVoltageFromFile.ControlVoltageFromFile'>, other_rewards={}, thermal_limit_a=None, epsilon_poly=0.01, tol_poly=1e-06, opponent_action_class=<class 'grid2op.Action.DontAct.DontAct'>, opponent_class=<class 'grid2op.Opponent.BaseOpponent.BaseOpponent'>, opponent_init_budget=0)[source]¶ -
logger
¶ Use to store some information (currently in beta status)
- Type
logger
-
time_stamp
¶ Current time of the chronics
- Type
datetime.time
-
nb_time_step
¶ Number of time steps played this episode
- Type
int
-
parameters
¶ Parameters used for the game
-
rewardClass
¶ Type of reward used. Should be a subclass of
grid2op.BaseReward.BaseReward
- Type
type
-
init_grid_path
¶ The path where the description of the powergrid is located.
- Type
str
-
backend
¶ The backend used to compute powerflows and cascading failures.
-
game_rules
¶ The rules of the game (define which actions are legal and which are not)
- Type
grid2op.GameRules.RulesChecker
-
helper_action_player
¶ Helper used to manipulate more easily the actions given to / provided by the
grid2op.BaseAgent
(player)
-
helper_action_env
¶ Helper used to manipulate more easily the actions given to / provided by the environment to the backend.
-
helper_observation
¶ Helper used to generate the observation that will be given to the
grid2op.BaseAgent
-
current_obs
¶ The current observation (or None if it’s not intialized)
- Type
grid2op.Observation.Observation
-
no_overflow_disconnection
¶ Whether or not cascading failures are computed or not (TRUE = the powerlines above their thermal limits will not be disconnected). This is initialized based on the attribute
grid2op.Parameters.Parameters.NO_OVERFLOW_DISCONNECTION
.- Type
bool
-
timestep_overflow
¶ Number of consecutive timesteps each powerline has been on overflow.
- Type
numpy.ndarray
, dtype: int
-
nb_timestep_overflow_allowed
¶ Number of consecutive timestep each powerline can be on overflow. It is usually read from
grid2op.Parameters.Parameters.NB_TIMESTEP_POWERFLOW_ALLOWED
.- Type
numpy.ndarray
, dtype: int
-
hard_overflow_threshold
¶ Number of timestep before an
grid2op.BaseAgent.BaseAgent
can reconnet a powerline that has been disconnected by the environment due to an overflow.- Type
float
-
env_dc
¶ Whether the environment computes the powerflow using the DC approximation or not. It is usually read from
grid2op.Parameters.Parameters.ENV_DC
.- Type
bool
-
chronics_handler
¶ Helper to get the modification of each time step during the episode.
- Type
grid2op.ChronicsHandler.ChronicsHandler
-
names_chronics_to_backend
¶ Configuration file used to associated the name of the objects in the backend (both extremities of powerlines, load or production for example) with the same object in the data (
Environment.chronics_handler
). The idea is that, usually data generation comes from a different software that does not take into account the powergrid infrastructure. Hence, the same “object” can have a different name. This mapping is present to avoid the need to rename the “object” when providing data. A more detailed description is available atgrid2op.ChronicsHandler.GridValue.initialize()
.- Type
dict
-
reward_helper
¶ Helper that is called to compute the reward at each time step.
- Type
grid2p.BaseReward.RewardHelper
-
action_space
¶ Another name for
Environment.helper_action_player
for gym compatibility.
-
observation_space
¶ Another name for
Environment.helper_observation
for gym compatibility.
-
reward_range
¶ The range of the reward function
- Type
(float, float)
-
metadata
¶ For gym compatibility, do not use
- Type
dict
-
spec
¶ For Gym compatibility, do not use
- Type
None
-
viewer
¶ Used to display the powergrid. Currently not supported.
- Type
object
-
env_modification
¶ Representation of the actions of the environment for the modification of the powergrid.
-
current_reward
¶ The reward of the current time step
- Type
float
-
TODO update with maintenance, hazards etc. see below
-
# store actions "cooldown"
-
times_before_line_status_actionable
¶
-
max_timestep_line_status_deactivated
¶
-
times_before_topology_actionable
¶
-
max_timestep_topology_deactivated
¶
-
time_next_maintenance
¶
-
duration_next_maintenance
¶
-
hard_overflow_threshold
¶
-
time_remaining_before_reconnection
¶
-
# redispacthing
-
target_dispatch
¶
-
actual_dispatch
¶
-
gen_activeprod_t
¶ Should be initialized at 0. for “step” to properly recognize it’s the first time step of the game
-
other_rewards
¶ Dictionnary with key being the name (identifier) and value being some RewardHelper. At each time step, all the values will be computed by the
Environment
and the information about it will be returned in the “reward” key of the “info” dictionnary of theEnvironment.step()
.- Type
dict
-
add_text_logger
(logger=None)[source]¶ Add a text logger to this
Environment
Logging is for now an incomplete feature. It will get improved :param logger: The logger to use
-
get_kwargs
()[source]¶ This function allows to make another Environment with the same parameters as the one that have been used to make this one.
This is usefull especially in cases where Environment is not pickable (for example if some non pickable c++ code are used) but you still want to make parallel processing using “MultiProcessing” module. In that case, you can send this dictionnary to each child process, and have each child process make a copy of
self
- Returns
res – A dictionnary that helps build an environment like
self
- Return type
dict
Examples
It should be used as follow:
import grid2op from grid2op.Environment import Environment env = grid2op.make() # create the environment of your choice copy_of_env = Environment(**env.get_kwargs()) # And you can use this one as you would any other environment.
-
get_params_for_runner
()[source]¶ This method is used to initialize a proper
grid2op.Runner.Runner
to use this specific environment.Examples
It should be used as followed:
import grid2op from grid2op.Runner import Runner env = grid2op.make() # create the environment of your choice agent = DoNothingAgent(env.actoin_space) # create the proper runner runner = Runner(**env.get_params_for_runner(), agentClass=DoNothingAgent) # now you can run runner.run(nb_episode=1) # run for 1 episode
-
reset
()[source]¶ Reset the environment to a clean state. It will reload the next chronics if any. And reset the grid to a clean state.
This triggers a full reloading of both the chronics (if they are stored as files) and of the powergrid, to ensure the episode is fully over.
This method should be called only at the end of an episode.
-
reset_grid
()[source]¶ Reset the backend to a clean state by reloading the powergrid from the hard drive. This might takes some time.
If the thermal has been modified, it also modify them into the new backend.
-
seed
(seed=None)[source]¶ Set the seed of this
Environment
for a better control and to ease reproducible experiments.This is not supported yet.
- Parameters
seed (
int
) – The seed to set.
-
set_chunk_size
(new_chunk_size)[source]¶ For an efficient data pipeline, it can be usefull to not read all part of the input data (for example for load_p, prod_p, load_q, prod_v). Grid2Op support the reading of large chronics by “chunk” of given size.
Reading data in chunk can also reduce the memory footprint, useful in case of multiprocessing environment while large chronics.
It is critical to set a small chunk_size in case of training machine learning algorithm (reinforcement learning agent) at the beginning when the agent performs poorly, the software might spend most of its time loading the data.
NB this has no effect if the chronics does not support this feature. TODO see xxx for more information
NB The environment need to be reset for this to take effect (it won’t affect the chronics already loaded)
- Parameters
new_chunk_size (
int
orNone
) – The new chunk size (positive integer)
-
set_id
(id_)[source]¶ Set the id that will be used at the next call to
Environment.reset()
.NB this has no effect if the chronics does not support this feature. TODO see xxx for more information
NB The environment need to be reset for this to take effect.
- Parameters
id (
int
) – the id of the chronics used.
Examples
Here an example that will loop 10 times through the same chronics (always using the same injection then):
import grid2op from grid2op import make from grid2op.BaseAgent import DoNothingAgent env = make("case14_redisp") # create an environment agent = DoNothingAgent(env.action_space) # create an BaseAgent for i in range(10): env.set_id(0) # tell the environment you simply want to use the chronics with ID 0 obs = env.reset() # it is necessary to perform a reset reward = env.reward_range[0] done = False while not done: act = agent.act(obs, reward, done) obs, reward, done, info = env.step(act)
-
If you still can’t find what you’re looking for, try in one of the following pages: