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

[feature] support post-processors #71

Merged
merged 25 commits into from
Nov 22, 2024
Merged

Conversation

JPXKQX
Copy link
Member

@JPXKQX JPXKQX commented Oct 25, 2024

This PR allows the user to create their own post-processors for the graph. In particular, we provide an implementation of RemoveUnconnectedNodes which may be useful for LAM, where we want to remove the nodes far from the area of interest.

The post-processors are included in the recipe as follows:

nodes:
   ...
edges:
   ...

post_processors:
  - _target_: anemoi.graphs.processors.RemoveUnconnectedNodes
    nodes_name: data
    ignore: cutout_mask # optional
    save_mask_indices_to_attr: indices_connected_nodes # optional

Here, we have 2 optional arguments:

  • ignore: It allows the user to ignore some nodes based on an existing attribute. For example, do not drop nodes from inside the limited area, even if they are not connected.
  • save_mask_indices_to_attr: It allows the user to store the indices to mask the nodes from the previous graph to the processed graph as an attribute. This may be needed for training/inference using only the points of interest.

@JPXKQX JPXKQX added the enhancement New feature or request label Oct 25, 2024
@JPXKQX JPXKQX self-assigned this Oct 25, 2024
@JPXKQX JPXKQX marked this pull request as ready for review October 28, 2024 08:17
src/anemoi/graphs/create.py Show resolved Hide resolved
src/anemoi/graphs/processors/__init__.py Outdated Show resolved Hide resolved
@JPXKQX JPXKQX requested a review from HCookie November 6, 2024 10:47
HCookie
HCookie previously approved these changes Nov 8, 2024
HCookie
HCookie previously approved these changes Nov 11, 2024
Copy link
Contributor

@dietervdb-meteo dietervdb-meteo left a comment

Choose a reason for hiding this comment

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

There is a bug in GraphDescriptor if one drops unconnected nodes from the graph. In its function get_node_summary() please change

attributes.remove("x")

to

exclude = ["x","indices_connected_nodes"]
attributes = [a for a in attributes if a not in exclude]

Edit: Actually the above is not a proper fix, since "indices_connected_nodes" is a name specified in the config. So it should be replaced with the corresponding config entry or another [more robust?] solution needs to be found.

Copy link
Contributor

@dietervdb-meteo dietervdb-meteo left a comment

Choose a reason for hiding this comment

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

Similarly to the bug in GraphDescriptor there is one in plotting.prepare.py. In the function get_node_attribute_dims please change

attr_dims = {}
for nodes in graph.node_stores:
    for attr in nodes.node_attrs():
        if attr == "x" or not isinstance(nodes[attr], torch.Tensor):
            continue

to

attr_dims = {}
exclude = ["x","indices_connected_nodes"]
for nodes in graph.node_stores:
    for attr in nodes.node_attrs():
        if attr in exclude or not isinstance(nodes[attr], torch.Tensor):
            continue

Edit: Actually the above is not a proper fix, since "indices_connected_nodes" is a name specified in the config. So it should be replaced with the corresponding config entry or another [more robust?] solution needs to be found.

Copy link
Contributor

@dietervdb-meteo dietervdb-meteo left a comment

Choose a reason for hiding this comment

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

Could be nicer if in BaseMaskingProcessor the mask is stored as self.mask rather than passed along as an argument between each of the routines. The compute_mask function of subclasses could then set that mask attribute.

Copy link
Contributor

@dietervdb-meteo dietervdb-meteo left a comment

Choose a reason for hiding this comment

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

Looks good to me now. Thanks Mario!

@JPXKQX JPXKQX merged commit 85c9c74 into develop Nov 22, 2024
121 checks passed
@JPXKQX JPXKQX deleted the feature/remove-unconnected-nodes branch November 22, 2024 13:30
@JPXKQX JPXKQX mentioned this pull request Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants