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

Support anemoi.graphs #2

Closed
wants to merge 8 commits into from
Closed

Support anemoi.graphs #2

wants to merge 8 commits into from

Conversation

JPXKQX
Copy link
Member

@JPXKQX JPXKQX commented Jun 4, 2024

Description

Support for new graph mappings:

  • Moved from HeteroData objects to Python dictionaries.
  • Build encoder & decoder based on the graph.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation and docstrings to reflect the changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have ensured that the code is still pip-installable after the changes and runs
  • I have not introduced new dependencies in the inference partion of the model
  • I have ran this on single GPU
  • I have ran this on multi-GPU or multi-node
  • I have ran this to work on LUMI (or made sure the changes work independently.)
  • I have ran the Benchmark Profiler against the old version of the code

@FussyDuck
Copy link

FussyDuck commented Jun 4, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@JesperDramsch JesperDramsch left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

I have left some comments below, regarding naming of variables, arranging of code, and to comment and explain some parts of the code.

Additionally, I think, we should be careful with the use of get_attr and set_attr, because they have previously prevented serialisation of the model (and are generally really hard to decipher.)

self._graph_name_hidden = config.graph.hidden
self._graph_name_hidden = config.graphs.hidden_mesh.name
self._graph_mesh_names = [name for name in graph_data if isinstance(name, str)]
self._graph_input_meshes = [
Copy link
Member

Choose a reason for hiding this comment

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

These need a comment to explain what is being done here.

Probably should be a method too that takes graph_data as an input and processes it.

Copy link
Member

Choose a reason for hiding this comment

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

From reading the code all the way to the end, it seems that these are filtering the names / keys of the graphs. This should be reflected in the variable names.

src/anemoi/models/models/encoder_processor_decoder.py Outdated Show resolved Hide resolved
sub_graph=self._graph_data[(self._graph_name_hidden, "to", self._graph_name_hidden)],
src_grid_size=self._hidden_grid_size,
dst_grid_size=self._hidden_grid_size,
sub_graph=self._graph_data.get((self._graph_name_hidden, "to", self._graph_name_hidden), None),
Copy link
Member

Choose a reason for hiding this comment

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

What happens if None is passed to the sub_graph?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will fail unless the TransformerProcessor is specified.

src/anemoi/models/models/encoder_processor_decoder.py Outdated Show resolved Hide resolved
self.trainable_hidden_size = config.model.trainable_parameters.hidden

def _register_latlon(self, name: str, key: str) -> None:
self.num_nodes = {name: self._graph_data[name]["coords"].shape[0] for name in self._graph_mesh_names}
Copy link
Member

Choose a reason for hiding this comment

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

The use of self._graph_mesh_names is redundant here, should probably be something like {name: graph["coords"].shape[0] for name, graph in self._graph_data.items()}.

Copy link
Member Author

Choose a reason for hiding this comment

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

self._graph_data has both nodes (they key is a string) and connections (the key is a tuple of strings) in different items. It would be something like {name: graph["coords"].shape[0] for name, graph in self._graph_data.items() if isinstance(name, str)}. Do you think is it still clearer than with self._graph_mesh_names?

src/anemoi/models/models/encoder_processor_decoder.py Outdated Show resolved Hide resolved
src/anemoi/models/models/encoder_processor_decoder.py Outdated Show resolved Hide resolved
# Register lat/lon
self._register_latlon("data", self._graph_name_data)
self._register_latlon("hidden", self._graph_name_hidden)
for name in self._graph_mesh_names:
Copy link
Member

Choose a reason for hiding this comment

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

This could just be in self._graph_data for simplicity. name should probably be renamed into something like mesh_key or grid_key.

Copy link
Member Author

Choose a reason for hiding this comment

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

and mesh_name? do you think is it a good option?

self._graph_name_data = config.graph.data
self._graph_name_hidden = config.graph.hidden
self._graph_name_hidden = config.graphs.hidden_mesh.name
self._graph_mesh_names = [name for name in graph_data if isinstance(name, str)]
Copy link
Member

Choose a reason for hiding this comment

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

What does this filter for?

@JPXKQX JPXKQX closed this Jul 4, 2024
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.

5 participants