ugr-sail / sinergym

Gym environment for building simulation and control using reinforcement learning
https://ugr-sail.github.io/sinergym/
MIT License
133 stars 35 forks source link

[Question] Runperiod Year in Simulation set wrong #359

Closed mrks-g closed 1 year ago

mrks-g commented 1 year ago

Question ❓

I am setting the runperiod of the environment using with day, month and year but the simulation observations returns a wrong year (2008 instead of 2018). I do not understand this beahavior, especially since month and day work correctly. @AlejandroCN7

Additional context

I m using v3.

in sinergym.config.modeling.py:

in self.model.adapt_building_to_config() the runperiod is set correctly.

save_building_model works correct as well.

BUT

in sinergym.envs.eplus_env.py after

self.energyplus_simulator.start(
    building_path=eplus_working_building_path,
    weather_path=eplus_working_weather_path,
    output_path=eplus_working_out_path)

The year is set wrong (2008). I checked with:

self.energyplus_simulator.exchange.year(self.energyplus_simulator.energyplus_state)

Day and Month are correct.

Other supporting but more high level information::

The runperiod in the environment returned by gym.make is returned as: environment.unwrapped.runperiod {'start_day': 3, 'start_month': 10, 'start_year': 2018, 'end_day': 14, 'end_month': 10, 'end_year': 2018, 'start_weekday': 1, 'n_steps_per_hour': 4}

The runperiod in the environment returned by env.step is returned as: env.unwrapped.runperiod {'start_day': 1, 'start_month': 10, 'start_year': 2018, 'end_day': 31, 'end_month': 5, 'end_year': 2019, 'start_weekday': 1, 'n_steps_per_hour': 4}

But the observation variables returned by env.step are:

image

where 5 denotes the oberserved year (!).

additional the time variables:

DEFAULT_TIME_VARIABLES = ['year', 'month', 'day_of_month', 'hour', 'minutes']

and the default observation wrapper:

`class ObservationWrapper(gym.ObservationWrapper): """wrapper that narrows down the observation space and fills it with useful information like the current average indoor room temperature and the current setpoint temperature"""

def __init__(self, env: gym.Env, setpoint: float) -> None:
    """create the wrapper and initialize the members"""
    super().__init__(env)
    self._setpoint = setpoint
    if not isinstance(self.env.observation_space, gym.spaces.Box):
        raise ValueError
    self.observation_space = gym.spaces.Box(
        low=self.env.observation_space.low[0],
        high=self.env.observation_space.high[0],
        shape=(5,),
        dtype=self.env.observation_space.dtype
    )
    self._observation_variable_order = get_observation_variable_names(self.env)
    self._temperature_variables = get_room_temperature_variable_names(
        get_building_file_abbreviation(self.env.unwrapped.building_file))

def observation(self, obs: np.array) -> np.array:
    """only supply the most needed observation variables"""
    obs_dict = {x: y for x, y in zip(self._observation_variable_order, obs)}
    average_temperature_value = get_average_room_temperature(obs_dict, self._temperature_variables)
    return np.array([average_temperature_value,
                     self._setpoint,
                     obs_dict[get_default_outdoor_temperature_name()],
                     obs_dict[get_default_diffuse_solar_radiation_name()],
                     obs_dict[get_default_direct_solar_radiation_name()],
                     *[obs_dict[x] for x in DEFAULT_TIME_VARIABLES]])`

Checklist

AlejandroCN7 commented 1 year ago

Hi @mrks-g,

I also noticed this problem recently and was checking the case similarly as you show here. However, I believe that this is not a Sinergym bug. I simply believe that the Energyplus API does not return the correct value for the set runperiod for some reason. I think you should open the issue to them. (here)

Thank you very much for opening this issue and for being so complete in the information given. I am closing this issue, but feel free to reopen if you need anything else.

Regards.