Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facilitate getting actor type in SIL interface #203

Open
Impelon opened this issue Apr 27, 2024 · 0 comments · May be fixed by #205
Open

Facilitate getting actor type in SIL interface #203

Impelon opened this issue Apr 27, 2024 · 0 comments · May be fixed by #205

Comments

@Impelon
Copy link
Contributor

Impelon commented Apr 27, 2024

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 _ControllerSim somehow. (Adding it to the implementations of Generator and Consumer manually 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.
    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,
                  },
              )
          )
    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_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.

@Impelon Impelon linked a pull request Apr 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant