Skip to content

Remove StateDict type and ensure_sim_state helper#487

Open
orionarcher wants to merge 2 commits intomainfrom
remove-state-dict
Open

Remove StateDict type and ensure_sim_state helper#487
orionarcher wants to merge 2 commits intomainfrom
remove-state-dict

Conversation

@orionarcher
Copy link
Collaborator

@orionarcher orionarcher commented Mar 2, 2026

Orion Summary

state: SimState | StateDict is a longstanding compromise in the function signature. As we add more robust typing, I think it's time to fully embrace SimState as the core object. This PR swaps from state: SimState | StateDict to state: SimState across the board. (already got agreement from @abhijeetgangan)

Upstream Nequip issue fixed here. Fairchem issue is a flake.

Claude Summary

  • Removes StateDict = dict type alias and StateKey from torch_sim/typing.py — these were the only remaining artifacts of the dict-as-state pattern
  • Removes the ensure_sim_state conversion helper from torch_sim/state.py — it's now a pure no-op since all callers pass a SimState
  • Simplifies state: SimState | StateDictstate: SimState across all integrators (NVE, NVT, NPT), optimizers (FIRE, BFGS, L-BFGS, gradient descent), models (MACE, ORB, SevenNet, FairChem, FairChem legacy, soft sphere, GraphPES, Morse, LJ, particle life, metatomic, MatterSim), and the ModelInterface ABC
  • Updates two test functions that explicitly tested dict-as-state to pass SimState directly instead
  • Updates the introduction example script to construct ts.SimState(...) instead of raw dict(...)

Test plan

  • All pre-commit hooks pass (ruff, codespell, ty)
  • grep -r "StateDict|ensure_sim_state" torch_sim/ tests/ returns no matches
  • Full test suite passes: 656 passed, 3 skipped

🤖 Generated with Claude Code

StateDict = dict was a type alias allowing raw dicts to be passed as state
to integrators, optimizers, and models. All callers now pass a proper
SimState, so remove the alias, the ensure_sim_state conversion helper, and
all StateDict | SimState union annotations across integrators, optimizers,
models, the interface ABC, tests, and examples.
@orionarcher orionarcher added breaking Breaking changes api API design discussions labels Mar 2, 2026
@CompRhys
Copy link
Member

CompRhys commented Mar 2, 2026

this is a pain point of moving to externalize, the upstream nequip has a dep on StateDict which causes the tests to fail.

This will impact Nequip, SevenNet and Orb (@cw-tan, @YutackPark, @vsimkus) which have already been externalized. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API design discussions breaking Breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants