-
Hi hoomd community, I noticed that when using create_state_from_snapshot() the resulting state is saved in single precision. Below is a snippet, where I get the charge from a snapshot I create and np.sum(ch1) gives 1e-15. The same charge after create-from_snapshot (np.sum(ch2) gives 2e-5. Just confirming that this is the expected behaviour. I checked and the same loss of precision happens with the mass. The only issue is that when the charges add up to 2e-5 hoomd issues a warning in that the charge is not zero. Any comments are welcome. .. code-block:: python |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
I am not able to reproduce the behavior you describe when I run your script, I get
Provided that you compiled HOOMD-blue with Line 95 in ec0b84c hoomd-blue/hoomd/SnapshotSystemData.cc Lines 169 to 171 in ec0b84c and get_snapshot returns a double precision snapshot:hoomd-blue/hoomd/SystemDefinition.cc Line 299 in ec0b84c Line 308 in ec0b84c You can confirm this by checking the numpy array type of the snapshot:
You can also confirm that double precision values survive a round trip through create_state_from_snapshot/set_snapshot/get_snapshot.
Note that GSD frames store values in single precision: https://gsd.readthedocs.io/en/v3.4.2/schema-hoomd.html |
Beta Was this translation helpful? Give feedback.
-
Hi Josh, Thanks for the detailed answer. I was expecting this would be a much trivial issue, so I thought with a snippet it would be enough. Here is a more detailed answer. I have generated a snapshot with another program (hoodlt), so what I have done is to pickle the object, snap.p The script test_sp.py does the following:
The script is quite verbose so as to make it self-explanatory. It is puzzling to me how it happens that the original snapshot ends up in single precision. Is it possible that the original Frame object (as read from the pickle file) has some flag that triggers hoomd or gsd to save it in single precision? I really have no clue what is it that can be happening. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot Josh, I am sure you are right, but I am a little confused by your answer. When I print the output in my machine, it shows that the pickled snap snap_p.particles.charge is of type float64 What do you mean by "Therefore, your individual float32 inputs from snap_p", as far as I see, there are no float32 inputs. It is snap that somehow becomes float32. I added a couple of lines to the script explicitly showing this: |
Beta Was this translation helpful? Give feedback.
Thanks a lot Josh. My confusion was because snap_p.particles.charge came as float64 when it should be single precision. Now I understand.
Thanks a lot again and have a happy Thanksgiving.