From c56e511f527eb5bacc04bca227c4985acae67d79 Mon Sep 17 00:00:00 2001 From: osten-antonio Date: Sun, 1 Mar 2026 21:58:53 +0700 Subject: [PATCH 1/3] test: add edge count consistency check to graph creation tests --- tests/test_graph_creation.py | 37 +++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/tests/test_graph_creation.py b/tests/test_graph_creation.py index 93a7a55f4..e75be36ed 100644 --- a/tests/test_graph_creation.py +++ b/tests/test_graph_creation.py @@ -50,6 +50,14 @@ def test_graph_creation(datastore_name, graph_name): "m2g_features.pt", "mesh_features.pt", ] + + # index-feature pair to check if edge is consistent across files + edge_index_feature_pairs = [ + ("g2m_edge_index", "g2m_features"), + ("m2g_edge_index", "m2g_features"), + ("m2m_edge_index", "m2m_features"), + ] + if hierarchical: required_graph_files.extend( [ @@ -59,11 +67,17 @@ def test_graph_creation(datastore_name, graph_name): "mesh_down_features.pt", ] ) + edge_index_feature_pairs.extend( + [ + ("mesh_up_edge_index", "mesh_up_features"), + ("mesh_down_edge_index", "mesh_down_features"), + ] + ) - # TODO: check that the number of edges is consistent over the files, for - # now we just check the number of features + # check that the number of edges is consistent over the files d_features = 3 d_mesh_static = 2 + edge_counts = {} with tempfile.TemporaryDirectory() as tmpdir: graph_dir_path = Path(tmpdir) / "graph" / graph_name @@ -74,7 +88,6 @@ def test_graph_creation(datastore_name, graph_name): hierarchical=hierarchical, n_max_levels=n_max_levels, ) - assert graph_dir_path.exists() # check that all the required files are present @@ -85,16 +98,16 @@ def test_graph_creation(datastore_name, graph_name): for file_name in required_graph_files: file_id = Path(file_name).stem # remove the extension result = torch.load(graph_dir_path / file_name) - if file_id.startswith("g2m") or file_id.startswith("m2g"): assert isinstance(result, torch.Tensor) - if file_id.endswith("_index"): assert ( result.shape[0] == 2 ) # adjacency matrix uses two rows + edge_counts[file_id] = result.shape[1] elif file_id.endswith("_features"): assert result.shape[1] == d_features + edge_counts[file_id] = result.shape[0] elif file_id.startswith("m2m") or file_id.startswith("mesh"): assert isinstance(result, list) @@ -117,3 +130,17 @@ def test_graph_creation(datastore_name, graph_name): assert r.shape[0] == 2 # adjacency matrix uses two rows elif file_id.endswith("_features"): assert r.shape[1] == d_features + + if file_id.endswith("_index"): + edge_counts[file_id] = [r.shape[1] for r in result] + elif ( + file_id.endswith("_features") and file_id != "mesh_features" + ): + edge_counts[file_id] = [r.shape[0] for r in result] + + # loop through index-feature pair to check consistency + for index_id, features_id in edge_index_feature_pairs: + assert edge_counts[index_id] == edge_counts[features_id], ( + f"Edge count mismatch: {index_id} has {edge_counts[index_id]} edges" + f" but {features_id} has {edge_counts[features_id]} rows" + ) From 7f37dfb2f62eebfd28f409a847ba1a222a5dd696 Mon Sep 17 00:00:00 2001 From: osten-antonio Date: Mon, 23 Mar 2026 01:58:16 +0700 Subject: [PATCH 2/3] docs: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8be292acd..e72e17382 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Migrated build backend from PDM to Hatchling with hatch-vcs and added uv build in deploy CI +- Updated `test_graph_creation` to add edge count consistency check [#301](https://github.com/mllam/neural-lam/pull/301) @osten-antonio + ## [v0.5.0](https://github.com/mllam/neural-lam/releases/tag/v0.5.0) This release contains maintenance and fixes, preventing some unexpected crashes and improving CICD and testing. From a74a2a553b0ed8912fe031786b5bc69bf9e73513 Mon Sep 17 00:00:00 2001 From: osten-antonio Date: Fri, 12 Jun 2026 22:46:49 +0700 Subject: [PATCH 3/3] Fix linting --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b6c83058..90b467231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -432,4 +432,4 @@ This release introduces Datastores to represent input data from different source ## [v0.1.0](https://github.com/mllam/neural-lam/releases/tag/v0.1.0) First tagged release of `neural-lam`, matching Oskarsson et al 2023 publication -() \ No newline at end of file +()