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

Time alignment inconsistencies when chaining simulations #651

Closed
marota opened this issue Oct 17, 2024 · 2 comments
Closed

Time alignment inconsistencies when chaining simulations #651

marota opened this issue Oct 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@marota
Copy link
Contributor

marota commented Oct 17, 2024

Environment

  • Grid2op version: 1.10.4
  • System: `Ubuntu 20.04.3 LTS

Bug description

When chaining simulations, that is reapplying simulate on a simulated observation, time alignment look inconsistent, which results in simulations on other timesteps.

We assume in obs.simulate(act,timestep) that timestep is the number of timestep ahead from the timestamp of the observation we are simulating on.

When doing a second chained simulate on the current grid state (timestep=0), the simulation is actually done on timestep=1

When doing a second chained simulation on the currently simulated grid state, the simulation is actually done on timestep=1 (=in the past)

Chaining simulations is of interest for instance for exploring the combination of several actions through simulation

How to reproduce

Command line

# command line used if any 

Code snippet

import grid2op

env=grid2op.make("l2rpn_idf_2023")

obs=env.reset()
do_nothing_act=env.action_space({})
print("obs timestamp"+str(obs.get_time_stamp()))

#chained simulation on timestep 0
obs_simu_0,*_=obs.simulate(do_nothing_act,time_step=0)
print("obs_simu_0 timestamp"+str(obs_simu_0.get_time_stamp()))

obs_simu_0_simu,*_=obs_simu_0.simulate(do_nothing_act,time_step=0)
print("obs_simu_0_simu timestamp"+str(obs_simu_0_simu.get_time_stamp()))

#chained simulation on forecasted timestep 5
obs_simu_5,*_=obs.simulate(do_nothing_act,time_step=5)
print("obs_simu_5 timestamp"+str(obs_simu_5.get_time_stamp()))

#here we start from this forecasted observation of timestamp=5, and we want to simulate on its timestamp, so 0 timestep ahead.
obs_simu_5_simu,*_=obs_simu_5.simulate(do_nothing_act,time_step=0)
print("obs_simu_5_simu timestamp"+str(obs_simu_5_simu.get_time_stamp()))

assert(obs_simu_0.get_time_stamp()==obs_simu_0_simu.get_time_stamp())
assert(obs_simu_5_simu.get_time_stamp()==obs_simu_5.get_time_stamp())

Current output

obs timestamp 2035-01-01 00:00:00
obs_simu_0 timestamp 2035-01-01 00:00:00
obs_simu_0_simu timestamp 2035-01-01 00:05:00
obs_simu_5 timestamp 2035-01-01 00:25:00
obs_simu_5_simu timestamp 2035-01-01 00:05:00

Expected output

obs timestamp 2035-01-01 00:00:00
obs_simu_0 timestamp 2035-01-01 00:00:00
obs_simu_0_simu timestamp 2035-01-01 **00:00:00**
obs_simu_5 timestamp 2035-01-01 00:25:00
obs_simu_5_simu timestamp 2035-01-01 **00:25:00**
@marota marota added the bug Something isn't working label Oct 17, 2024
@BDonnot
Copy link
Collaborator

BDonnot commented Oct 17, 2024

Hello,

This is not a problem of the "simulate" nor the "chain of simulate" . For example:

import grid2op

env=grid2op.make("l2rpn_idf_2023")

obs=env.reset()
do_nothing_act=env.action_space({})
print(f"real obs timestamp {obs.get_time_stamp()}")

#chained simulation on timestep 0
obs_simu_1,*_=obs.simulate(do_nothing_act,time_step=1)
print(f"obs_simu_1 (simulate with time_step=1) timestamp {obs_simu_1.get_time_stamp()}")

obs_simu_1_simu,*_=obs_simu_1.simulate(do_nothing_act,time_step=1)
print(f"obs_simu_1_simu (chain 2 simulates with time_step=1) {obs_simu_1_simu.get_time_stamp()}")

gives the correct expected output:

real obs timestamp 2035-01-01 00:00:00
obs_simu_1 (simulate with time_step=1) timestamp 2035-01-01 00:05:00
obs_simu_1_simu (chain 2 simulates with time_step=1) 2035-01-01 00:10:00

This is rather a problem with "time_step=0" which has already been posted in issue #598 for which still no clear and consistent model has been proposed (see #598 (comment))

I'm closing this one and will write something there to keep track of this other issue with "simulate for time_step=0"

@marota
Copy link
Contributor Author

marota commented Oct 18, 2024

obs_simu_5,*_=obs.simulate(do_nothing_act,time_step=5)
print("obs_simu_5 timestamp "+str(obs_simu_5.get_time_stamp()))

obs_simu_5_simu,*_=obs_simu_5.simulate(do_nothing_act,time_step=1)
print("obs_simu_5_simu timestamp "+str(obs_simu_5_simu.get_time_stamp()))

Outputs:
obs_simu_5 timestamp 2035-01-01 00:25:00
obs_simu_5_simu timestamp 2035-01-01 00:10:00

The second case is still an issue for time_step!=0 (here time_step=1 and you can try others). We "return" to the past.
See if you want to reopen this issue for this, or extend the other issue.

The problem might be related to the "current_step" variable
obs_simu_5.current_step=1 (should probably be 5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants