calliope-project / calliope

A multi-scale energy systems modelling framework
https://www.callio.pe
Apache License 2.0
276 stars 89 forks source link

Improving the handling of invalid backends #624

Closed irm-codebase closed 2 days ago

irm-codebase commented 6 days ago

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)

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

brynpickering commented 3 days ago

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. 😅