calliope-project / calliope

A multi-scale energy systems modelling framework

Home Page:https://www.callio.pe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improving the handling of invalid backends

irm-codebase opened this issue · comments

What can be improved?

Our current implementation of different backends is a bit fickle.

_BACKENDS: dict[str, Callable] = {"pyomo": PyomoBackendModel}
...
backend = self._BACKENDS[backend_name](input, self.math, **updated_build_config)
  • It breaks the linkage between backend versions and language support tools in IDEs (e.g., refactoring won't work properly)
  • If an invalid key is given, it'll return a key error. We probably want to give a more specific message to users.
  • Additional backed-specific parameters are not possible?

I propose changing it to a python match statement with a specific error at the end.
https://docs.python.org/3.10/whatsnew/3.10.html#pep-634-structural-pattern-matching

Version

v0.7

It's a hardcoded dictionary in the source code, so I wouldn't say error management is a massive issue. A user isn't going to be confronted with it. Sure, we can move it to a match-case statement.

RE additional backend-specific parameters not being possible. Yes, that is intended. We want differences between backends to be only in how they implement abstract methods and nothing else. If we allow specific parameters in, backends are liable to deviate further over time which will be a maintenance nightmare. Not to say that it won't already be a maintenance nightmare, ofc. 😅