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

Fix type error when calling create_dataarray_from_tensor #106

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

observingClouds
Copy link
Contributor

@observingClouds observingClouds commented Jan 26, 2025

Describe your changes

The create_dataarray_from_tensor is now called with the expected type (tensor instead of numpy array).

Issue Link

< Link to the relevant issue or task. > (e.g. closes #00 or solves #00)

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 README 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). This applies only if you have write access to the repo, otherwise feel free to tag a maintainer to add a reviewer and assignee.

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
Copy link
Collaborator

Thanks for fixing this! I wonder why this was not caught by any tests? Maybe something to try to also change here to avoid similar bugs in the future. We have a test that should run an epoch or so of training on the example data. I wonder if we have managed to configure that one so that it will not run validation. Because this bug should have crashed the validation step I think, making any test including that fail.

@leifdenby
Copy link
Member

I wonder why this was not caught by any tests?

I think because the tests don't run through the cli interface, but instead create a Trainer object directly. The cli interface code needs refactoring so that it can be called directly when a list of arguments to be treated as argv from the command line. I think the tests should call the cli interface though, that would be better.

@observingClouds
Copy link
Contributor Author

My idea was also to use mypy typing checks which could be able to detect that too.

@leifdenby
Copy link
Member

My idea was also to use mypy typing checks which could be able to detect that too.

Interesting! I hadn't thought of that :) If you have time and inclination I would review a PR on that. But maybe not a priority for now? What do you think?

@joeloskarsson
Copy link
Collaborator

Another simple temporary fix to the tests for this is to just specify options to the instantiated pl.Trainer so that it actually runs one validation step.

@observingClouds
Copy link
Contributor Author

Interesting! I hadn't thought of that :) If you have time and inclination I would review a PR on that. But maybe not a priority for now? What do you think?

I have included mypy now and fixed all the issues that were raised (~40). It is not in strict mode yet as many functions are not yet typed in neural-lam and since this results in about 460 issues, I will not attempt that now 😄

@observingClouds observingClouds marked this pull request as ready for review January 27, 2025 13:39
@sadamov
Copy link
Collaborator

sadamov commented Jan 27, 2025

Whenever we talk about static typing and/or CLI I like to mention this library that elegantly combines both: https://typer.tiangolo.com/

@observingClouds
Copy link
Contributor Author

To keep this PR rather clean, I reverted the mypy test and additional type annotations now.

@observingClouds observingClouds mentioned this pull request Feb 4, 2025
20 tasks
Copy link
Member

@leifdenby leifdenby left a comment

Choose a reason for hiding this comment

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

Perfect! Thanks for fixing this.

@leifdenby leifdenby merged commit 82939a2 into mllam:main Feb 6, 2025
8 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.

4 participants