Run the microgrid for a single step. Parameters ---------- control : dict[str, list[float]] Actions to pass to each fixed module. normalized : bool, default True Whether ``control`` is a normalized value or not. If not, each module d
(self, control, normalized=True)
| 231 | pass |
| 232 | |
| 233 | def step(self, control, normalized=True): |
| 234 | """ |
| 235 | |
| 236 | Run the microgrid for a single step. |
| 237 | |
| 238 | Parameters |
| 239 | ---------- |
| 240 | control : dict[str, list[float]] |
| 241 | Actions to pass to each fixed module. |
| 242 | normalized : bool, default True |
| 243 | Whether ``control`` is a normalized value or not. If not, each module de-normalizes its respective action. |
| 244 | |
| 245 | Returns |
| 246 | ------- |
| 247 | observation : dict[str, list[float]] |
| 248 | Observations of each module after using the passed ``control``. |
| 249 | reward : float |
| 250 | Reward/cost of running the microgrid. A positive value implies revenue while a negative |
| 251 | value is a cost. |
| 252 | done : bool |
| 253 | Whether the microgrid terminates. |
| 254 | info : dict |
| 255 | Additional information from this step. |
| 256 | |
| 257 | """ |
| 258 | control_copy = control.copy() |
| 259 | microgrid_step = MicrogridStep(reward_shaping_func=self.reward_shaping_func, cost_info=self.get_cost_info()) |
| 260 | |
| 261 | for name, modules in self.fixed.iterdict(): |
| 262 | for module in modules: |
| 263 | microgrid_step.append(name, *module.step(0.0, normalized=False)) |
| 264 | |
| 265 | fixed_provided, fixed_consumed, _, _ = microgrid_step.balance() |
| 266 | log_dict = self._get_log_dict(fixed_provided, fixed_consumed, prefix='fixed') |
| 267 | |
| 268 | for name, modules in self.controllable.iterdict(): |
| 269 | try: |
| 270 | module_controls = control_copy.pop(name) |
| 271 | except KeyError: |
| 272 | raise ValueError(f'Control for module "{name}" not found. Available controls:\n\t{control.keys()}') |
| 273 | else: |
| 274 | try: |
| 275 | _zip = zip(modules, module_controls) |
| 276 | except TypeError: |
| 277 | _zip = zip(modules, [module_controls]) |
| 278 | |
| 279 | for module, _control in _zip: |
| 280 | module_step = module.step(_control, normalized=normalized) # obs, reward, done, info. |
| 281 | microgrid_step.append(name, *module_step) |
| 282 | |
| 283 | controllable_fixed_provided, controllable_fixed_consumed, _, _ = microgrid_step.balance() |
| 284 | difference = controllable_fixed_provided - controllable_fixed_consumed |
| 285 | |
| 286 | log_dict = self._get_log_dict( |
| 287 | controllable_fixed_provided-fixed_provided, |
| 288 | controllable_fixed_consumed-fixed_consumed, |
| 289 | log_dict=log_dict, |
| 290 | prefix='controllable' |