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

Rework calliope model attributes #625

Closed
wants to merge 0 commits into from
Closed

Conversation

irm-codebase
Copy link
Contributor

@irm-codebase irm-codebase commented Jun 28, 2024

Fixes #619

Summary of changes in this pull request

  • Introduces better handling of Calliope configuration (by differentiating between configuration from files, overrides and runtime).
  • Limits backend access to only things it needs (math, defaults, build config, data)
  • Better data handling to avoid duplicating information between the backend and the model object (unless necessary).
  • Removes unnecessary attributes

See this table: #619 (comment)

Reviewer checklist

  • Test(s) added to cover contribution
  • Documentation updated
  • Changelog updated
  • Coverage maintained or improved

@irm-codebase
Copy link
Contributor Author

@brynpickering first step towards the new attribute setup. This one fixes how math dictionaries are handled.
Some tests related to operate mode seem to be failing... but I thought that feature was not working???

I'll try to debug that before continuing.

@brynpickering
Copy link
Member

operate mode is working (#539)!

self._is_built: bool = False
self._is_solved: bool = False

# new
self.math: AttrDict = AttrDict()
self._math_dir: Path = Path(calliope.__file__).parent / "math"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer importlib.resources.files("calliope")

@@ -504,7 +509,9 @@ def run(self, force_rerun=False, **kwargs):

def to_netcdf(self, path):
"""Save complete model data (inputs and, if available, results) to a NetCDF file at the given `path`."""
io.save_netcdf(self._model_data, path, model=self)
self._model_data.attrs["math"] = self.math
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer this step to be in IO, i.e. pass math to IO

@irm-codebase
Copy link
Contributor Author

@brynpickering this fix is causing some VERY weird behavior on the backend (actually reintroducing #623) and around operate mode.
I will try to re-approach with your suggestions and by first only cleaning model.py. I will only introduce the backend changes after making sure that everything on the front is behaving adequately.

@irm-codebase
Copy link
Contributor Author

operate mode is working (#539)!

In that case, shouldn't we re-activate the tests that check it / remove the unnecessary ones?

@irm-codebase
Copy link
Contributor Author

My approach was incorrect. Retrying!

@irm-codebase irm-codebase deleted the fix-data-config-sync branch July 8, 2024 08:32
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 this pull request may close these issues.

Ensuring data and model configuration remain in sync at all times (model, backend, backendmath)
2 participants