ADicksonLab / wepy

Weighted Ensemble simulation framework in Python
https://adicksonlab.github.io/wepy/index.html
MIT License
51 stars 20 forks source link

Gracefully handle missing velocities in initial states #103

Closed salotz closed 11 months ago

salotz commented 11 months ago

Currently if the velocities are missing from an initial state the HDF5Reporter will raise an error in the case that the velocities are somehow autogenerated by the bound context. These autogenerated velocities are not necessarily unitted and so the probe for the velocities units will fail. Relevant stack trace portion:

    sim_manager.run_simulation(num_cycles, steps)
  File "/work/app/src/wepy/sim_manager.py", line 733, in run_simulation
    self.init(num_workers=num_workers)
  File "/work/app/src/wepy/sim_manager.py", line 588, in init
    continue_run=continue_run,
  File "/work/app/src/wepy/reporter/hdf5.py", line 384, in init
    for k, v in walker.state.dict().items()
  File "/work/app/src/wepy/runners/openmm.py", line 1140, in dict
    for key, value in self.omm_state_dict().items():
  File "/work/app/src/wepy/runners/openmm.py", line 1116, in omm_state_dict
    "velocities": self.velocities_values(),
  File "/work/app/src/wepy/runners/openmm.py", line 706, in velocities_values
    return self.velocities.value_in_unit(self.velocities_unit)
AttributeError: 'numpy.ndarray' object has no attribute 'value_in_unit'
(venv) root@hdx-binding-test-deploy-79647f74cb-cj8r2:/work# 
salotz commented 11 months ago

The underlying issue is that we are using the OpenMMState.sim_state.getForces(asNumpy=True). If asNumpy=False then it raises an error, but if True then it returns a numpy array of the right shape filled with 0s that has no units.

This should probably be an upstream bug but I want to check on the latest OpenMM, I'm testing this 7.7.0.