Add create_graph_with_wmg.py CLI using weather-model-graphs#596
Add create_graph_with_wmg.py CLI using weather-model-graphs#596prajwal-tech07 wants to merge 8 commits intomllam:mainfrom
Conversation
Update pyproject.toml to install weather-model-graphs from the issue-384/to-neural-lam branch of the fork, so that CI and reviewers can test the neural-lam side against the unreleased to_neural_lam() changes before wmg PR mllam#123 is merged. Will revert to a versioned PyPI dependency once PR mllam#123 is released.
|
Merged Leif's |
leifdenby
left a comment
There was a problem hiding this comment.
Looking good! A few suggestions for changes 🚀
| } | ||
|
|
||
|
|
||
| def _estimate_mesh_node_distance(xy): |
There was a problem hiding this comment.
maybe we could call this _estimate_grid_node_spacing? And then expose the grid-mesh-spacing ratio as a CLI arg that defaults to 3.0?
There was a problem hiding this comment.
Renamed _estimate_mesh_node_distance → _estimate_grid_node_spacing — it now returns only the average grid spacing. The ×3 multiplier is replaced by a new grid_mesh_ratio parameter (default 3.0) exposed as --grid_mesh_ratio on the CLI.
There was a problem hiding this comment.
looks great, but it would better to name it --grid_mesh_spacing_ratio I think - just be clear about what it is the ratio between :) what do you think?
There was a problem hiding this comment.
--grid_mesh_ratio → --grid_mesh_spacing_ratio
Good call — renamed the CLI arg, function parameter, and docstrings throughout to make it clear it's the ratio between mesh-node and grid-node spacing.
|
|
||
| @pytest.mark.parametrize("archetype", ["keisler", "graphcast", "hierarchical"]) | ||
| @pytest.mark.parametrize("datastore_name", DATASTORES.keys()) | ||
| def test_wmg_graph_creation(datastore_name, archetype): |
There was a problem hiding this comment.
This is great, but we could actually use the testing that #323 introduces. I should try and get that finished so that we can merge both in together :)
There was a problem hiding this comment.
Sounds like a great plan — either way works for me. Happy to adapt the tests to #323's infrastructure once it lands, or merge as-is if this PR is ready
| "plotly>=5.15.0", | ||
| "torch>=2.3.0", | ||
| "torch-geometric==2.3.1", | ||
| "torch-geometric>=2.5.3", |
There was a problem hiding this comment.
Yes, this is necessary. The weather-model-graphs[pytorch] extra requires torch-geometric>=2.5.3 in its own dependencies, so we need to allow at least that version here too.
There was a problem hiding this comment.
ah, in that case I think we maybe should reduce required version number on the weather-model-graphs side, since all we are doing with pytorch-geometric is using it to convert the networkx.DiGraph objects to torch.Tensor objects, and we already do that in the current create_graphs.py code in neural-lam with the older version. So how about we change weather-model-graphs to require torch-geometric==2.3.1 so the two are in sync? Then we don't have to change anything on the neural-lam side
There was a problem hiding this comment.
You're right — wmg only uses from_networkx which works fine with 2.3.1. I've also pushed a commit to the wmg PR branch (prajwal-tech07/weather-model-graphs@d0c693d) pinning it to ==2.3.1 there too, so both repos stay in sync.
There was a problem hiding this comment.
I will make a separate PR for this. I think this is some general CI maintenance that should be merged in before this PR.
There was a problem hiding this comment.
Noted — happy to revert the CI changes from this branch if you'd prefer to handle them in a separate PR.
…sh_ratio, use stacked=True, add return_components comment, add README entry
leifdenby
left a comment
There was a problem hiding this comment.
Thanks for this, I added additional comments on previous review to resolve:
There was a problem hiding this comment.
Ok, the CLI interface looks great now, as do the readme instructions and install works great (just tried locally on my laptop too).
I think we should also change the tests that use graph creation (i.e. the training examples, they all use the create_graph_from_datastore() function in https://github.com/mllam/neural-lam/blob/main/neural_lam/create_graph.py#L540), but I think we should use the new one that you have created that creates a graph with wmg instead.
Migrated all test files that used the old create_graph_from_datastore() from neural_lam.create_graph to use the new wmg-based version from neural_lam.create_graph_with_wmg instead. Changes: - test_datasets.py: Use wmg create_graph_from_datastore with archetype='keisler' - test_clamping.py: Use wmg create_graph_from_datastore with archetype='keisler' - test_plotting.py: Use wmg create_graph_from_datastore with archetype='keisler' - test_training.py: Use wmg create_graph_from_datastore with archetype='keisler' - test_plot_graph.py: Use wmg create_graph_from_datastore with keisler and hierarchical archetypes. Removed multiscale (graphcast) parametrization since the graphcast archetype produces multi-level m2m edges without up/down edges, which is not yet compatible with utils.load_graph(). Graphcast graph creation is separately tested in test_graph_creation.py.
|
Thanks for the suggestion, @leifdenby! Done in 76c7ed7. All test files that used the old
All tests pass locally (55/55 in the modified files, 72/72 in the full suite. |
Follow rename in weather-model-graphs (mllam/weather-model-graphs#123).

Describe your changes
Add a new CLI script
create_graph_with_wmg.pythat delegates graph creationto weather-model-graphs (wmg)
and saves the output using
wmg.save.to_neural_lam()in the tensor-on-diskformat expected by
neural_lam.utils.load_graph().This is the neural-lam side of the bridge described in #384. The wmg side
is mllam/weather-model-graphs#123,
which adds
to_neural_lam()towmg.save.What this PR does:
neural_lam/create_graph_with_wmg.pywith support for all three wmgarchetypes:
keisler(flat single-scale),graphcast(flat multiscale),and
hierarchical(Oskarsson)mesh_node_distancefrom grid spacing when not specified(Nx, Ny, 2)→(N, 2)for wmgcreate_graph.pyCLI pointing usersto the new script
weather-model-graphs[pytorch]>=0.3.0as a dependencytorch-geometricpin from==2.3.1to>=2.5.3(required bywmg's pytorch extra)
create_graph_with_wmgas a console script entry pointDependencies: Requires mllam/weather-model-graphs#123
to be merged and released first (adds
wmg.save.to_neural_lam()).Files changed (4 files, +305 −1):
neural_lam/create_graph_with_wmg.pyneural_lam/create_graph.pypyproject.tomltests/test_graph_creation.pyIssue Link
Solves #384 (neural-lam side)
Type of change
Checklist before requesting a review
pullwith--rebaseoption if possible).Checklist for reviewers
Each PR comes with its own improvements and flaws. The reviewer should check the following:
Author checklist after completed review
reflecting type of change (add section where missing):
Checklist for assignee