-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean nodes after building the graph (#23)
* feat: clean graph of unneeded attributes after creation Co-authored-by: Mario Santa Cruz <[email protected]> Co-authored-by: Helen Theissen <[email protected]> Co-authored-by: Jesper Dramsch <[email protected]>
- Loading branch information
1 parent
d510eb2
commit 7fd9c74
Showing
9 changed files
with
86 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# (C) Copyright 2024 European Centre for Medium-Range Weather Forecasts. | ||
# This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# In applying this licence, ECMWF does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an intergovernmental organisation | ||
# nor does it submit to any jurisdiction. | ||
|
||
|
||
from pathlib import Path | ||
|
||
import torch | ||
from torch_geometric.data import HeteroData | ||
|
||
from anemoi.graphs.create import GraphCreator | ||
|
||
|
||
class TestGraphCreator: | ||
|
||
def test_generate_graph(self, config_file: tuple[Path, str], mock_grids_path: tuple[str, int]): | ||
"""Test GraphCreator workflow.""" | ||
tmp_path, config_name = config_file | ||
graph_path = tmp_path / "graph.pt" | ||
config_path = tmp_path / config_name | ||
|
||
GraphCreator(graph_path, config_path).create() | ||
|
||
graph = torch.load(graph_path) | ||
assert isinstance(graph, HeteroData) | ||
assert "test_nodes" in graph.node_types | ||
assert ("test_nodes", "to", "test_nodes") in graph.edge_types | ||
|
||
for nodes in graph.node_stores: | ||
for node_attr in nodes.node_attrs(): | ||
assert isinstance(nodes[node_attr], torch.Tensor) | ||
assert nodes[node_attr].dtype in [torch.int32, torch.float32] | ||
|
||
for edges in graph.edge_stores: | ||
for edge_attr in edges.edge_attrs(): | ||
assert isinstance(edges[edge_attr], torch.Tensor) | ||
assert edges[edge_attr].dtype in [torch.int32, torch.float32] | ||
|
||
for nodes in graph.node_stores: | ||
for node_attr in nodes.node_attrs(): | ||
assert not node_attr.startswith("_") | ||
for edges in graph.edge_stores: | ||
for edge_attr in edges.edge_attrs(): | ||
assert not edge_attr.startswith("_") |
This file was deleted.
Oops, something went wrong.