-
Notifications
You must be signed in to change notification settings - Fork 70
Closed
Description
state_to_device in ts.state is supposed to create a new SimState with all tensors moved to the specified device and with the specified data type.
But in order to do it, vars(state) is used which actually is a pointer to the internal variables of state. Change the indexes of the dictionary you modify the input. And of course attrs["positions"] = attrs["positions"].to(dtype=dtype), actually changes the device of the input.
So
- It has a side effect of modifying implicitly it's input.
- As the variables are not cloned, the "new" state has all its variables linked to the input state.
This function is used in 3 places in torchsim.
- SimState.to (so side effect is ok)
- in concatenate_state, for which actually .to should be used, but it does change the behavior in the end
- initialize_state: for which is not really clear if one wants to modify the input.
What I suggest is either:
- Create a really new state. needs copy vars(state) and clone tensors.
- Just return state, and not create a new state, referencing the input entirely. Then changing the description
Metadata
Metadata
Assignees
Labels
No labels