rte-france / Grid2Op

Grid2Op a testbed platform to model sequential decision making in power systems.

Home Page:https://grid2op.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does Action objects have a unique id?

AvisP opened this issue · comments

Does the action object have a unique action id? I am trying to find out the most frequent actions taken by a trained agent. I was doing something like this. In the last for loop I would like to do a count of the which action was taken and how many times. I checked the imapct_on_object() function and it provides detail on station number, line id etc but not sure how to come up with unique id based on that.

Kindly suggest a possible way to do it.

import grid2op
from lightsim2grid import LightSimBackend  # highly recommended !
from grid2op.Agent import RandomAgent

 env_name = "l2rpn_case14_sandbox"
 env = grid2op.make(env_name,
                        backend=LightSimBackend()
                        )


runner_params = env.get_params_for_runner()
runner = Runner(**runner_params,
                    agentClass=None,
                    agentInstance=grid2op_agent)

res = runner.run(path_save=“./logs/RandomAgent/,
                     nb_episode=10,
                     nb_process=1)

from grid2op.Episode import EpisodeData

li_episode = EpisodeData.list_episode("./logs/RandomAgent/”)

full_path, episode_studied = li_episode[0]

for act in this_episode.actions:
    print(act)

Hello,

Please read again the notebook "study your agent" it should have a way to do this if I remember correctly.

The issue you face is I checked the imapct_on_object() function and it provides detail on station number, line id etc but not sure how to come up with unique id based on that. What do you want to be unique ? How you define exactly a "unique" action ?

grid2op action defines the == operator so you can check that if you want. If you want actions to be hashable it's not possible (and will never be by default) as actions are mutable (and it's far from recommended to make something mutable hashable according to python doc).

So i'm not exactly sure what you want to do exactly. Because, as actions often have a continuous part it does not really make sense to use the == on curtailment, storage or redispatching as the probablity that two actions will be equal is 0. in most cases.

My suggestion would be: define first exactly what you want to do. Then try to look for solution in grid2op.

Hi Benjamin,

Thanks for your detailed response.

I looked at the notebook and yes there is a section which shows an example of how many times a line was acted on by an agent. I am actually looking for an example which states how times of same action an agent took over the course of a scenario.

I should have started off by mentioning that I am dealing with discrete actions only i.e. line and bus switching only. As you mentioned there is no point in comparing continuous actions. There is the IdtoAct class that converts a gym action action space to grid2op. I was looking for something that does the opposite, grid2op action space to gym action space. So in this case each grid2op action space will get a unique number in gym action space. Alternatively, having it hashable would have helped but I see now why it is not possible.

But for some reason I wasn't aware there was a __eq__() defined and I can just do a comparison of two different action using == operator. I think I can write some script based on that and compare the frequency of individual actions being taken.

Hello

If I understood correctly the "==" suits your needs. So i'm closing the issue. Do not hesitate to open it again if there is still a problem.

Yes thanks the "==" sufficed.