feat(state): make pbc a per-system attribute#594
Open
lil-lon wants to merge 5 commits into
Open
Conversation
During __init__ the dataclass assigned pbc before system_idx, so the (3,) to (n_systems, 3) broadcast in __setattr__ could not run at construction time and had to be duplicated in __post_init__. Declaring pbc after system_idx makes n_systems available when pbc is assigned, leaving a single broadcast site in __setattr__ and only shape validation in __post_init__. kw_only=True keeps the public API unchanged.
lil-lon
marked this pull request as draft
July 25, 2026 06:11
lil-lon
marked this pull request as ready for review
July 25, 2026 09:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SimState.pbca per-system attribute of shape(n_systems, 3); a bool,list[bool], or(3,)tensor is broadcast to all systems. Moving it from_global_attributesto_system_attributeslets slicing, splitting, popping, and concatenation handle it likecell.atoms_to_state/structures_to_stateaccept inputs with different pbc instead of raising, andstate_to_atoms/state_to_structures/ trajectory files store each system's own pbc row.require_full_pbc; elastic tensor calculation now rejects systems that are not fully periodic.(3,)row on a shallow copy (_to_legacy_pbc_state) before delegating, because those integrations broadcaststate.pbcthemselves assuming the old shape; mixed-pbc batches raise a clear error there.pbcaftersystem_idxso__setattr__can broadcast a(3,)row already during__init__, leaving a single broadcast site (__post_init__only validates the shape). Simplify pbc handling inautobatchingandionow that pbc is always a tensor.Related issue: #584
Compatibility
Breaking:
get_attrs_for_scope:pbcmoved from"global"to"per-system".Unchanged:
list[bool]/(3,)inputs are still accepted and broadcast to all systems.(3,)pbc array; existing files stay readable.Discussion points
_to_legacy_pbc_statehands third-party forward() a SimState whose pbc temporarily violates the(n_systems, 3)invariant. The preferred fix is upstream support for per-system pbc in the integrations; until then the shim keeps the current orb / NequIP / metatomic releases working unchanged, since they only read plain attributes off the state.state.pbc = <1-D value>after construction broadcasts any length without validation (__post_init__runs only at construction). Missing validation is pre-existing, but should__setattr__enforce a length-3 row?Checklist
Before a pull request can be merged, the following items must be checked: