Skip to content

Why checking for only single system when providing system list in initialize_state #485

@thomasloux

Description

@thomasloux
def initialize_state(  # noqa: C901, PLR0911
    system: StateLike,
    device: torch.device | None = None,
    dtype: torch.dtype | None = None,
) -> SimState:
    # TODO: create a way to pass velocities from pmg and ase

    if isinstance(system, SimState):
        return system.clone().to(device, dtype)

    if isinstance(system, list | tuple):
        if len(system) == 0:
            raise ValueError("Cannot initialize state from an empty list.")
        states = [s for s in system if isinstance(s, SimState)]
        **if len(states) == len(system) and not all(s.n_systems == 1 for s in states):
            raise ValueError(
                "When providing a list of states, to the initialize_state function, "
                "all states must have n_systems == 1. To fix this, you can split the "
                "states into individual states with the split_state function."
            )**
        if len(states) == len(system):
            return ts.concatenate_states(states)

Why does this function impose this constraint? Not sure it's a problem for anyone in practise, but this seems quite arbitrary. Actually concatenate_states handle list of state with arbitrary system sizes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions