Time alignment inconsistencies when chaining simulations
Closed this issue · 2 comments
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**
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"
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)