perf(state): derive n_systems from cell shape to avoid GPU-CPU sync

Merged
LI
1mo ago
+27-6

Summary

  • Derive SimState.n_systems from the leading dimension of cell instead of torch.unique on system_idx, so reading it no longer forces a GPU-CPU sync.
  • Use state.n_systems in the FIRE steps, as discussed in #609.
  • Validate constraints after __post_init__ batches the cell, so system constraint bounds are checked against the correct n_systems when a (3, 3) cell is passed. Add a test for this case.

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.