Closed glolichen closed 4 months ago
If you are using CleanRL, one trick that worked for me is to
obs_vars = envs.envs[0].get_wrapper_attr("observation_variables") # Before you start training
# In the training loop
next_obs, reward, terminated, truncated, infos = envs.step(
action.cpu().numpy()
)
outdoor_temp = observation[self.obs_variables.index("outdoor_temperature")]
indoor_temp = observation[self.obs_variables.index("air_temperature")]
Hi @glolichen!
That is correct! Thank you @kad99kev.
Indeed, in the environment, you have both the variables that make up your observation (attribute observation_variables
) and the observation space, with which both the step
and reset
methods return an array that constitutes the observation (variables obs
or next_obs
, as you prefer to call it). The values of this numpy array come in the same order as determined in the observation variables. If you want, you can create a dictionary with the observation to access the data more easily as follows:
obs_dict = dict(zip(self.env.get_wrapper_attr('observation_variables'), obs))
print(obs_dict['outdoor_temperature'])
print(obs_dict['air_temperature'])
# Or observation variable you want to see
I hope this is helpful to you, and thank you very much for using Sinergym.
Update: You can also access to environment attribute called last_obs
. This attribute has the obs from last reset or step call with the dictionary made already. For example:
env.reset()
print(env.get_wrapper_attr('last_obs'))
After initializing the environment and calling env.reset(), how to access data on the current environment, such as outside temperature and inside temperature? I tried to use env.var_handlers but that stays the same throughout the loop. Thanks.
:pencil: Please, don't forget to include more labels besides
question
if it is necessary.