Open stefdoerr opened 4 days ago
This sounds like a bug in PLUMED, not the OpenMM plugin? We have no control over what it does with the files it opens.
Ok! I thought maybe you had some idea on how to force it to close them by maybe adding some command which restarts the PLUMED executable, but if not it's fine, it doesn't really affect my use cases.
Toni mentioned the plumed_finalize
command to me which is called in the destructor of PlumedForceImpl https://github.com/openmm/openmm-plumed/blob/95bfd46d6499625de03ea2151aec42edeae5f662/openmmapi/src/PlumedForceImpl.cpp#L47
It makes sense that it needs to be called for everything to flush correctly.
I tried through python to delete the force object however it didn't work. I think the reason is that:
del force
is called https://github.com/openmm/openmm-plumed/blob/95bfd46d6499625de03ea2151aec42edeae5f662/python/plumedplugin.iIndeed this is the case. I made the following changes:
Then in python I called this to delete the PlumedForce after my simulation
forces = simulation.system.getForces()
for i, force in enumerate(forces):
if force.getName() == "PlumedForce":
simulation.system.removeForce(i)
del force
break
Now it flushed fine. But once the python garbage collector was called I got a segmentation fault. I assume that somewhere in the OpenMM code it stores the PlumedForceImpl
object and at the end the force objects are freed again and since I deleted that object early I got a segfault.
A ForceImpl is owned by a Context, not by a Force. You can create many Contexts for a single System. When a Context is deleted, it deletes all its ForceImpls.
This is not a super critical bug for me since I don't really need the PLUMED output files that much but I can see users which use PLUMED output files having issues with this.
PLUMED practically never flushes its file buffers on files until the whole process finishes (meaning your python session dies).
It's very consistent with XTC file outputs but it also happens with text files (like the ones we store the biases in) but there you can sometimes get it to work by using the
FLUSH STRIDE
argument although it's a bit hit or miss if the file will have all the lines in it.If you execute this you will get the following error:
After the error you can read the file fine if you open a new python interpreter (after the first one dies) although sometimes get 9 frames instead of 10 so I guess even closing the process doesn't flush correctly.
Here is a reproducible example: plumed_file_flushing_bug.zip