Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an option to load chronics episode by episode when using FromMultiEpisodeData #659

Open
EBoguslawski opened this issue Nov 7, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@EBoguslawski
Copy link
Contributor

Problem description

Hello,

In my code, I create a deterministic environment from previously generated episodes (with a runner) thanks to the FromMultiEpisodeData class.

On my computer, creating such an environment with one year of data on the l2rpn_idf_2023 environment takes 2:36 minutes. It means that I would need around 41 minutes to load all the chronics (16 years).

You can do the test on your computer with the code below, which prints the duration of the environment creation (for one year).

Would it be possible to code an option to load the chronicles as you go along, rather than all at once at the creation?

How to reproduce

import os
import grid2op
from grid2op.Runner import Runner
from grid2op.Agent import RecoPowerlineAgent
from lightsim2grid import LightSimBackend
from grid2op.Chronics import FromMultiEpisodeData
from grid2op.Opponent import FromEpisodeDataOpponent
from grid2op.Episode import EpisodeData
import time

env_name = "l2rpn_idf_2023"
path_save = "./RecoPowerlineAgent_episodes"

## 1. Generating episodes (comment if it is already done)

env = grid2op.make(env_name, backend=LightSimBackend())
param = env.parameters
param.NO_OVERFLOW_DISCONNECTION = True
env.change_parameters(param)
env.reset()

# In our example, we evaluate only the first year
n_chronics = len(os.listdir(env.chronics_handler.path))
n_weeks = n_chronics // 16 # because there is 16 years in our dataset
episode_id = [k*16 for k in range(n_weeks)]
n_episode = len(episode_id)

runner = Runner(**env.get_params_for_runner(),
                agentClass=RecoPowerlineAgent)

res = runner.run(nb_episode=n_episode, pbar=False,
                        episode_id=episode_id, 
                        path_save=path_save,
                        )

## 2. Creating a new environment from generated episodes

li_episode = EpisodeData.list_episode(path_save)
# li_episode = [el for el in li_episode if el[1][-2:] in ["_0"]] # you can filter episodes of year 0 with this line if you evaluated other years

print("Env creation. Loading...")
start = time.time()
env_from_episodes = grid2op.make(env_name,
                   chronics_class=FromMultiEpisodeData,
                   data_feeding_kwargs={"li_ep_data": li_episode},
                   opponent_class=FromEpisodeDataOpponent,
                   backend = LightSimBackend(),
              )
end = time.time()
duration_in_min = (end - start) / 60
print(f"Env created ! It lasted {duration_in_min:.2f} minutes.")
@EBoguslawski EBoguslawski added the enhancement New feature or request label Nov 7, 2024
BDonnot added a commit to BDonnot/Grid2Op that referenced this issue Nov 8, 2024
BDonnot added a commit to BDonnot/Grid2Op that referenced this issue Nov 8, 2024
DEUCE1957 pushed a commit to DEUCE1957/Grid2Op that referenced this issue Nov 8, 2024
DEUCE1957 pushed a commit to DEUCE1957/Grid2Op that referenced this issue Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant