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

Replay an agent starting at some timestep #136

Open
marota opened this issue Jul 24, 2020 · 1 comment
Open

Replay an agent starting at some timestep #136

marota opened this issue Jul 24, 2020 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed version 2.0 Will be made available in version 2.0 at best

Comments

@marota
Copy link
Contributor

marota commented Jul 24, 2020

Is your feature request related to a problem? Please describe.

When an agent fails at some point, we'd like to replay the timesteps just before and see if we could find a solution to avoid failure. We would like to avoid replaying the whole scenario again with that agent, and for instance inspect manually the state, running some simulations of different actions at that timestep

Describe the solution you'd like

From the logs of the agent, rebuild the environment/observation at the desired timestep of a scenario.

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

This can be useful for debugging as well

@marota marota added the enhancement New feature or request label Jul 24, 2020
@Tezirg
Copy link
Contributor

Tezirg commented Jul 24, 2020

Unfortunately, there is no easy solution for this. The power flow needs to be ran again, with the same actions to get a usable environment.

Assuming the environment at t=0 can be rebuilt; That is, all config is known, including seeds, backend and difficulty:
And, not taking into account a potential Opponent:

import grid2op
from grid2op.Episode import EpisodeData

def resume_timestep(env, agent_path, episode_name, resume_timestep):
    # Build episode to id hash table
    episodes_name_to_id = {}
    for i, ep in enumerate(env.chronics_handle.real_data.subpaths):
        episodes_name_to_id[os.path.basename(ep)] = i

    # Reload previous actions
    epr = EpisodeData.from_disk(agent_path, episode_name)

    # Set env to desired chronics
    env.set_id(episodes_name_to_id[episode_name])
    env.reset()

    # Replay actions up to desired timestep
    for i in range(resume_timestep - 1):
        if env.done:
            raise "Episode game over before resume_timestep: check params"
        o, r, d, i = env.step(epr.actions[i])

    return o,r,d,i

if __name__ == "__main__":
    dataset = "rte_case14_realistic"
    agent_path = "/tmp/agent-logs/"
    episode_name = "0001"
    resume_step = 10

    # Build env
    # Cannot rebuild env from logs.
    # So it needs to be a manual check, for Parameters / seeds / etc..
    env = grid2op.make(dataset)

    obs, reward, done, info = resume_timestep(env,
                                              agent_path,
                                              episode_name,
                                              resume_step)

BDonnot added a commit that referenced this issue May 12, 2021
1.6.0: introduction to alarm feature
@BDonnot BDonnot added help wanted Extra attention is needed version 2.0 Will be made available in version 2.0 at best labels Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed version 2.0 Will be made available in version 2.0 at best
Projects
None yet
Development

No branches or pull requests

3 participants