You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hence it should be possible to use env.chronics_handler.get_name() inside a custom reward function, since BaseEnv includes the chronics handler. This is useful for, for instance, fetching the load profiles.
However, this will throw an error if we use obs.simulate():
File ".../L2RPN/Rewards/EnergyNotSuppliedReward.py", line 22, in __call__
ep_id = env.chronics_handler.get_name()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: '_ObsCH' object has no attribute 'get_name'
Since the _ObsEnv class is used in place of the normal BaseEnv, the normal chronics handler does not exist.
In the mean time (the grid2op release with this fix will wait for some other modifications) I suggest you use:
classWeirdReward(BaseReward):
def__init__(self, logger: Logger=None):
super().__init__(logger)
def__call__(self, action: BaseAction, env:BaseEnv, has_error: bool, is_done: bool, is_illegal: bool, is_ambiguous: bool) ->float:
ifself.is_simulated_env(env):
return0.# the data for the simulation does not mean anything, better not use it# now you can use env.chronics_handler.get_name()returnsuper().__call__(action, env, has_error, is_done, is_illegal, is_ambiguous)
Oh and by the way, the "True" chronics will never be fed to "obs.simulate" this is a design choice to ensure that a user cannot access the "future" data, in the same way that accessing a real simulator will not provide you any data about the future.
BDonnot
added a commit
to BDonnot/Grid2Op
that referenced
this issue
Nov 6, 2024
Environment
1.11.0.dev0
ArchLinux
Bug description
A normal, fully initialized, Environment has a chronics_handler - from which you can get the name / ID of the current episode:
The call to the Reward Function has the following signature (from BaseReward):
Hence it should be possible to use
env.chronics_handler.get_name()
inside a custom reward function, since BaseEnv includes the chronics handler. This is useful for, for instance, fetching the load profiles.However, this will throw an error if we use obs.simulate():
Since the _ObsEnv class is used in place of the normal BaseEnv, the normal chronics handler does not exist.
My current workaround is to use:
Minimal Example
The text was updated successfully, but these errors were encountered: