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

Make save function more universal to accept any number of 1D or 2D node or edge features #31

Merged
merged 5 commits into from
Oct 17, 2024

Conversation

maxiimilian
Copy link
Contributor

@maxiimilian maxiimilian commented Oct 9, 2024

Describe your changes

This pull request contains three changes -- one major and two minor changes.

The major change modifies how edge and node features are converted from pyg.data.Data objects into torch.Tensors before saving. If we assume that all node/edge features (features in the following) are numeric, a conversion to float32 will always work. Further, my proposed change assumes that the features can be either 1D (vector of edge lengths) or 2D (node position, vdiff vector between source and target nodes). Based on this, I propose a universal function that reshapes any 1D vector into a 2D column vector, which allows the concatenation of any number of features in a loop.

Using the new function, we also make the saving of len as edge feature explicit by including it in the default edge_features list.

Two minor bugs are fixed:

Type of change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📖 Documentation (Addition or improvements to documentation)

Checklist before requesting a review

  • My branch is up-to-date with the target branch - if not update your fork with the changes from the target branch (use pull with --rebase option if possible).
  • I have performed a self-review of my code
  • For any new/modified functions/classes I have added docstrings that clearly describe its purpose, expected inputs and returned values
  • I have placed in-line comments to clarify the intent of any hard-to-understand passages of my code
  • I have updated the documentation to cover introduced code changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have given the PR a name that clearly describes the change, written in imperative form (context).
  • I have requested a reviewer and an assignee (assignee is responsible for merging)

Checklist for reviewers

Each PR comes with its own improvements and flaws. The reviewer should check the following:

  • the code is readable
  • the code is well tested
  • the code is documented (including return types and parameters)
  • the code is easy to maintain

Author checklist after completed review

  • I have added a line to the CHANGELOG describing this change, in a section
    reflecting type of change (add section where missing):
    • added: when you have added new functionality
    • changed: when default behaviour of the code has been changed
    • fixes: when your contribution fixes a bug

Checklist for assignee

  • PR is up to date with the base branch
  • the tests pass
  • author has added an entry to the changelog (and designated the change as added, changed or fixed)
  • Once the PR is ready to be merged, squash commits and merge the PR.

@joeloskarsson joeloskarsson self-requested a review October 10, 2024 17:06
@joeloskarsson joeloskarsson self-assigned this Oct 10, 2024
Copy link
Contributor

@joeloskarsson joeloskarsson left a comment

Choose a reason for hiding this comment

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

This is great, thanks a lot for this contribution! 😄

I went over the code and left some small comments. I don't think there is any need for adding additional tests here as

  1. the saving functionality with default feature arguments is already tested in
    def test_save_to_pyg():
  2. we don't have any good functionality to add additional edge/node features that is now saveable with this more universal approach and could be used in a test (as far as I remember, let me know if I am wrong)

There are a couple small additional things that would be good to do before merging this:

  1. The linting seems to fail due to the code formatting. This should be easily fixed by just running the pre-commit hooks once.
  2. Go ahead and add an entry to the changelog! 🙂

src/weather_model_graphs/save.py Show resolved Hide resolved
src/weather_model_graphs/visualise/plot_2d.py Outdated Show resolved Hide resolved
src/weather_model_graphs/save.py Outdated Show resolved Hide resolved
src/weather_model_graphs/save.py Outdated Show resolved Hide resolved
Copy link
Contributor

@joeloskarsson joeloskarsson left a comment

Choose a reason for hiding this comment

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

Tests and linting are all green now 🥳 Just want a small tweak to keep the formatting of the changelog consistent, then this is good to merge!

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Joel Oskarsson <[email protected]>
Copy link
Contributor

@joeloskarsson joeloskarsson left a comment

Choose a reason for hiding this comment

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

Everything good now, I'll merge this in. Thanks again for this contribution!

@joeloskarsson joeloskarsson merged commit d91571a into mllam:main Oct 17, 2024
3 checks passed
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.

2 participants