Facilitate getting actor type in SIL interface
Working with the new interface, I now notice a shortcoming of removing the actors from the pickled Microgrid representation:
From the broker, it is practically impossible to know which actor state comes from which type of actor (e.g. Generator vs Consumer); before you would have been able to differentiate it from the actors attribute of the pickled Microgrid object.
From what I can tell, there is no good way of doing this anymore, right?
Knowing what kind of actor produced the actor state is pretty important to be able to interpret its contents/semantics. I can come up with 2 somewhat elegant solutions (but surely there is more):
- Include the actor type into the actor state by default by implementing it in the
_ControllerSimsomehow. (Adding it to the implementations ofGeneratorandConsumermanually would be an easy fix, but I find that quite inconsistent, because according to the docs, an Actor can return any dict as a state...) - Pass the actor types along with the states to the
Broker- e.g.
Or maybe like this:class SilController(Controller): # [...] def step(self, time: datetime, p_delta: float, e_delta: float, actor_infos: dict) -> None: assert self.microgrid is not None actor_types = {actor.name: type(actor) for actor in self.microgrid.actors} self.data_pipe_in.send( ( time, { "microgrid": self.microgrid, "actor_infos": actor_infos, "actor_types": actor_types, "p_delta": p_delta, "e_delta": e_delta, }, ) )class SilController(Controller): # [...] def step(self, time: datetime, p_delta: float, e_delta: float, actor_infos: dict) -> None: assert self.microgrid is not None actor_infos = actor_infos.copy() for actor in self.microgrid.actors: state = actor_infos[actor.name] actor_infos[actor.name] = (type(actor), state) ## Or perhaps: # actor_infos[actor.name] = { # "type": type(actor), # "state": state, # } self.data_pipe_in.send( ( time, { "microgrid": self.microgrid, "actor_infos": actor_infos, "p_delta": p_delta, "e_delta": e_delta, }, ) )
It should be noted that other Controller's are not affected by this because they could access the actors through the Microgrid object directly, which the Broker instance cannot.