MCPcopy Create free account
hub / github.com/ahalev/python-microgrid / state_dict

Method state_dict

src/pymgrid/microgrid/microgrid.py:739–773  ·  view source on GitHub ↗

State of the microgrid as a dict. Keys are module names and values are lists of state dicts for all modules with said name. Parameters ---------- normalized : bool, default False Whether to return a dict of normalized values. as_run_out

(self, normalized=False, as_run_output=False, _initial=None)

Source from the content-addressed store, hash-verified

737 return self._modules
738
739 def state_dict(self, normalized=False, as_run_output=False, _initial=None):
740 """
741 State of the microgrid as a dict.
742
743 Keys are module names and values are lists of state dicts for all modules with said name.
744
745 Parameters
746 ----------
747 normalized : bool, default False
748 Whether to return a dict of normalized values.
749
750 as_run_output : bool, default False
751 Whether to return output in the same format as the output of :meth:`Microgrid.run`.
752 Inner values are numpy arrays and not dict in this case.
753
754 _initial : dict or None
755 Internal parameter, do not use.
756
757 Returns
758 -------
759 state_dict : dict[str, list[dict]] or dict[str[list[np.ndarray]]]
760 State of the microgrid as a nested dict.
761
762 """
763 def as_run_output_f(state_dict):
764 if as_run_output:
765 return np.array(list(state_dict.values()))
766 return state_dict
767
768 state_dict = _initial or dict()
769
770 for name, modules in self._modules.iterdict():
771 state_dict[name] = [as_run_output_f(module.state_dict(normalized=normalized)) for module in modules]
772
773 return state_dict
774
775 @property
776 def log(self):

Calls 1

iterdictMethod · 0.80