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 #470 non adapted sample indices in gradients during sorting #480

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

agoscinski
Copy link
Contributor

@agoscinski agoscinski commented Feb 2, 2024

Fixes #470

  • Splitting sorted tensors into an ascending and descending so the fix can be more robustly tested
  • Adding dispatched arange_like to create inverse mapping for reasigning samples in gradients

Waiting till #479 is merged to also add finite difference test

Contributor (creator of pull-request) checklist

  • Tests updated (for new features and bugfixes)?
  • Documentation updated (for new features)?
  • Issue referenced (for PRs that solve an issue)?

Reviewer checklist

  • CHANGELOG updated with public API or any other important changes?

📚 Documentation preview 📚: https://metatensor--480.org.readthedocs.build/en/480/

Copy link

github-actions bot commented Feb 2, 2024

Here is a pre-built version of the code in this pull request: wheels.zip, you can install it locally by unzipping wheels.zip and using pip to install the file matching your system

@agoscinski agoscinski force-pushed the sort-gradfix branch 3 times, most recently from 7dbd0ed to a553a3d Compare February 6, 2024 15:27
descending: bool,
) -> TensorBlock:
"""
Sorts a single TensorBlock without the user input checking and sorting of gradients
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Sorts a single TensorBlock without the user input checking and sorting of gradients
Sorts a single gradient TensorBlock. This is different from `_sort_single_block` because we need to update the sample differently (since gradient samples are pointers into the values samples)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated this doc and embedded suggested change into it

python/metatensor-operations/tests/sort.py Show resolved Hide resolved
python/metatensor-operations/tests/sort.py Show resolved Hide resolved
properties=Labels(["p"], np.array([[1], [0]])),
)

# fmt: off
Copy link
Member

Choose a reason for hiding this comment

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

this should not be needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed but black makes this really hard to read so I turned it off

Copy link
Member

Choose a reason for hiding this comment

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

I partially agree with you that black is not ideal here, but I would prefer not to start adding fmt: off or # noqa too often in the code. I would rather live with slightly worst formatting but have it consistent everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This have strong feelings on. This sort test is already hard to understand as it is, and the black formatting made it much harder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unlike other tests, the order must be much easier to read so one can follow what is how moved. I added comments why it is turned off.

@agoscinski
Copy link
Contributor Author

Added commit with changes from review suggestions

- Splitting sorted tensors into an ascending and descending so the fix can
be more robustly tested
- Adding dispatched arange_like to create inverse mapping for reasigning
samples in gradients
@Luthaf Luthaf merged commit 278cb32 into master Feb 7, 2024
28 checks passed
@Luthaf Luthaf deleted the sort-gradfix branch February 7, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants