Skip to content

Conversation

@shantanusharma
Copy link

This PR addresses a type mismatch bug in eigenvalue merging and improves numerical stability in Lennard-Jones force calculations.

Key changes:
- In `torch_sim/math.py`: Fixed a `TypeError` in `_determine_eigenvalue_case` where boolean masks were incorrectly combined with integer tensors. Added proper device handling for `torch.arange`.
- In `tests/test_math.py`: Added comprehensive tests for `_determine_eigenvalue_case` and `_matrix_log_33` with numerically close eigenvalues to prevent regressions.
- In `torch_sim/models/lennard_jones.py`: Implemented safe division in `unbatched_forward` to avoid division by zero when particles overlap (distances = 0).
- In `torch_sim/transforms.py`: Added a check to `inverse_box` to raise a `ValueError` if the box contains zero values, preventing division by zero.

Checklist:
- [x] Doc strings have been added in the Google docstring format.
- [x] Run ruff on your code.
- [x] Tests have been added for any new functionality or bug fixes.

The tests specifically target the scenario where eigenvalues are numerically close (within tolerance 1e-16), which triggers the merging logic that contained the bug.
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.

1 participant