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
I get a TypeError when trying to use DiscreteMicrogridEnv.to_normalized in a simple env like the one explained in the Quick Start part of the documentation.
Here the code I am using.
import numpy as np
import pandas as pd
np.random.seed(0)
from pymgrid import Microgrid
from pymgrid.modules import (
BatteryModule,
LoadModule,
RenewableModule,
GridModule)
small_battery = BatteryModule(min_capacity=10,
max_capacity=100,
max_charge=50,
max_discharge=50,
efficiency=0.9,
init_soc=0.2)
large_battery = BatteryModule(min_capacity=10,
max_capacity=1000,
max_charge=10,
max_discharge=10,
efficiency=0.7,
init_soc=0.2)
load_ts = 100+100*np.random.rand(24*90) # random load data in the range [100, 200].
pv_ts = 200*np.random.rand(24*90) # random pv data in the range [0, 200].
load = LoadModule(time_series=load_ts)
pv = RenewableModule(time_series=pv_ts)
grid_ts = [0.2, 0.1, 0.5] * np.ones((24*90, 3))
grid = GridModule(max_import=100,
max_export=100,
time_series=grid_ts)
modules = [
small_battery,
large_battery,
('pv', pv),
load,
grid]
microgrid = Microgrid(modules)
# Copy-pasted from QuickStart documentation until here
discrete_env = DiscreteMicrogridEnv.from_microgrid(microgrid)
discrete_env.reset()
discrete_env.to_normalized(discrete_env.state_dict(), act=False, obs=True)
As the documentation suggests, I am using a dictionary parameter where "dictionary keys are names of the modules while dictionary values are lists containing an action corresponding to all modules with that name".
File /opt/conda/lib/python3.10/site-packages/pymgrid/microgrid/microgrid.py:424, in Microgrid.to_normalized(self, data_dict, act, obs)
405 """
406 Normalize an action or observation.
407
(...)
421 Normalized action.
422 """
423 assert act + obs == 1, 'One of act or obs must be True but not both.'
--> 424 return {module_name: [module.to_normalized(value, act=act, obs=obs) for module, value in zip(module_list, data_dict[module_name])]
425 for module_name, module_list in self._modules.iterdict() if module_name in data_dict}
File /opt/conda/lib/python3.10/site-packages/pymgrid/microgrid/microgrid.py:424, in (.0)
405 """
406 Normalize an action or observation.
407
(...)
421 Normalized action.
422 """
423 assert act + obs == 1, 'One of act or obs must be True but not both.'
--> 424 return {module_name: [module.to_normalized(value, act=act, obs=obs) for module, value in zip(module_list, data_dict[module_name])]
425 for module_name, module_list in self._modules.iterdict() if module_name in data_dict}
File /opt/conda/lib/python3.10/site-packages/pymgrid/microgrid/microgrid.py:424, in (.0)
405 """
406 Normalize an action or observation.
407
(...)
421 Normalized action.
422 """
423 assert act + obs == 1, 'One of act or obs must be True but not both.'
--> 424 return {module_name: [module.to_normalized(value, act=act, obs=obs) for module, value in zip(module_list, data_dict[module_name])]
425 for module_name, module_list in self._modules.iterdict() if module_name in data_dict}
File /opt/conda/lib/python3.10/site-packages/pymgrid/utils/space/space.py:356, in ModuleSpace._bounds_check(self, val, low, high)
355 def _bounds_check(self, val, low, high):
--> 356 clipped = np.clip(val, low, high)
358 if self.verbose or not self.clip_vals and (clipped != val).any():
359 warnings.warn(f'Value {val} resides out of expected bounds of value to be normalized: [{low}, {high}].')
File <array_function internals>:180, in clip(*args, **kwargs)
I get a TypeError when trying to use DiscreteMicrogridEnv.to_normalized in a simple env like the one explained in the Quick Start part of the documentation.
Here the code I am using.
As the documentation suggests, I am using a dictionary parameter where "dictionary keys are names of the modules while dictionary values are lists containing an action corresponding to all modules with that name".
And here the error trace:
The text was updated successfully, but these errors were encountered: