Skip to content

Convert ts.integrate param units#587

Merged
CompRhys merged 7 commits into
TorchSim:mainfrom
curtischong:fix-579-2
Jul 24, 2026
Merged

Convert ts.integrate param units#587
CompRhys merged 7 commits into
TorchSim:mainfrom
curtischong:fix-579-2

Conversation

@curtischong

@curtischong curtischong commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

We currently are not converting the parameters in ts.integrate (they are supposed to accept normal units)
Note: this is in contrast to the internal api (direct integrator functions like ts.npt_nose_hoover_isotropic_step where they expect the units to already be converted).

This PR goes through all the params and adds a type annotation to these args in the integrator functions to properly convert the units.

Note: additional kwargs like a = kwargs.get("momenta") in https://github.com/TorchSim/torch-sim/blob/main/torch_sim/integrators/nvt.py#L344 and https://github.com/TorchSim/torch-sim/blob/main/torch_sim/integrators/npt.py#L1733 do not have annotated conversion param like the rest. I think this is fine since users are not manually initing the momenta for individual atoms in the ts.integrate api. - they're most likely loaded in from another simulation (so I think they'll have the proper units)

This PR is to fix the issue outlined in #579 where a user was changing the settings for a simulation and since we didn't properly convert the units to internal MetalUnits, their simulation was unstable. This change fixes the issue noticed in their md workflow

Checklist

Before a pull request can be merged, the following items must be checked:

  • Doc strings have been added in the Google docstring format.
  • Run ruff on your code.
  • Tests have been added for any new functionality or bug fixes.

curtischong and others added 3 commits July 3, 2026 11:48
add run cmd

simplify repro

new repro

repro fix

use their model

integrator fixes

revert to sevennet

cleanup

get structures in memory

better integrator definitions

cleanup

better test names

more cleanup

cleanup

more cleanup

cleanup

cleanup

cleanup

delete repro file

fix other params

better name

use constants

cleanup
Comment thread torch_sim/integrators/md.py Outdated
Comment thread torch_sim/runners.py Outdated
@CompRhys

Copy link
Copy Markdown
Member

The alternative here is simply to delete the concept of the unit convertors within TS that this PR attempts to fix and then leave it up to the user to ensure that they're numerically consistent between their model and integration parameters. @abhijeetgangan would you be opposed to that as a lower maintenance and LLOC solution?

@curtischong

Copy link
Copy Markdown
Collaborator Author

I think we need to keep the metalunits bc it does simplify the formulas. here's an example branch where I asked an ai to remove the units main...curtischong:torch-sim:remove-metal-units.

Maybe there's a better way though

@curtischong

Copy link
Copy Markdown
Collaborator Author

I think I'm just hesitant because I'm not familiar with all the units. The diff doesn't look too bad and as long as we tell users the expected units for each param we should be fine (they won't really see all the internal unit conversions anyway). I'll put up a PR so we can run tests on the branch

@CompRhys

Copy link
Copy Markdown
Member

@sek1ro-yuzzz could you test your SevenNet NaN issue on this branch please?

@curtischong

curtischong commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

I tested this PR with this script and it passes on this branch, but fails on main

repro_579.py

@CompRhys

Copy link
Copy Markdown
Member

thanks @curtischong!

@CompRhys
CompRhys merged commit e4a5b8b into TorchSim:main Jul 24, 2026
62 of 64 checks passed
@curtischong curtischong mentioned this pull request Jul 25, 2026
3 tasks
@curtischong
curtischong deleted the fix-579-2 branch July 25, 2026 12:58
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.

Batched MD with SevenNet+D3 can produce NaN trajectories while ASE remains finite

2 participants