gsd filewrite during sim.run not working

184 views
Skip to first unread message

ifh...@gmail.com

unread,
Jun 14, 2023, 7:45:22 AM6/14/23
to hoomd-users
Hello everyone,
In Version 4.0.0 the writing behavior of hoomd.write.GSD has changed. Before it would simply write every 10000 steps with trigger=hoomd.trigger.Periodic(10000) now however it just creates the gsd file but the write is happening only after the script has finished.
I tried to add gsd_writer.flush() in the script as mentioned in the documentation but this seems to do nothing in my case.

What am I missing?

I tried to add the flush command to the example script for the MD tutorial but it only saves the gsd after it has completely finished.

import hoomd
import gsd.hoomd

frame = gsd.hoomd.Frame()

# Place a polymer in the box.
frame.particles.N = 5
frame.particles.position = [[-2, 0, 0], [-1, 0, 0], [0, 0, 0], [1, 0, 0],
                            [2, 0, 0]]
frame.particles.types = ['A']
frame.particles.typeid = [0] * 5
frame.configuration.box = [20, 20, 20, 0, 0, 0]

# Connect particles with bonds.
frame.bonds.N = 4
frame.bonds.types = ['A-A']
frame.bonds.typeid = [0] * 4
frame.bonds.group = [[0, 1], [1, 2], [2, 3], [3, 4]]

with gsd.hoomd.open(name='molecular.gsd', mode='xb') as f:
    f.append(frame)

# Apply the harmonic potential on the bonds.
harmonic = hoomd.md.bond.Harmonic()
harmonic.params['A-A'] = dict(k=100, r0=1.0)

# Perform the MD simulation.
sim = hoomd.Simulation(device=hoomd.device.GPU(), seed=1)
sim.create_state_from_gsd(filename='molecular.gsd')
langevin = hoomd.md.methods.Langevin(filter=hoomd.filter.All(), kT=1.0)
integrator = hoomd.md.Integrator(dt=0.005,
                                 methods=[langevin],
                                 forces=[harmonic])
gsd_writer = hoomd.write.GSD(filename='molecular_trajectory.gsd',
                             trigger=hoomd.trigger.Periodic(1000),
                             mode='xb')
sim.operations.integrator = integrator

sim.operations.writers.append(gsd_writer)

sim.run(10e3)
gsd_writer.flush()
sim.run(10e5)

Joshua Anderson

unread,
Jun 14, 2023, 9:13:43 AM6/14/23
to hoomd...@googlegroups.com
ifhtts,

Yes, GSD buffers writes more aggressively in 4.x than 3.x. This, combined with other GSD improvements, increases performance on some network file systems by orders of magnitude for 4.x when compared to 3.x.

As you mention, you must now call flush at defined points where you would like the file to be consistent with all frames written thus far. Your call to flush() does flush the pending frames to the file. You can confirm by opening the file and checking the number of frames immediately after calling flush().

gsd_trajectory = gsd.hoomd.open('molecular_trajectory.gsd')
print(len(gsd_trajectory))

I tested this in your example, and it prints 10 as expected. When I comment out the call to flush, it prints 0 as expected in this case. Any value less than or equal to 10 is valid without an explicit flush - the actual value will vary depending on the system size, the number and size of the quantities written to the file, and the buffer size. The default buffer size is 64 MiB.
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

--
You received this message because you are subscribed to the Google Groups "hoomd-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hoomd-users/c7fabc82-ec2d-4a5c-b93d-02cd72000286n%40googlegroups.com.

ifh...@gmail.com

unread,
Jun 15, 2023, 5:23:01 AM6/15/23
to hoomd-users
Thanks you are absolutely right. I tested again and now it worked. However I have one more question.
Can the flush be triggered with a periodic trigger? 

Joshua Anderson

unread,
Jun 15, 2023, 6:59:37 AM6/15/23
to hoomd...@googlegroups.com
ifhtts,

GSD does not implement a Trigger for flush(). You could implement a custom writer that calls flush and add give it the trigger.

------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan
Reply all
Reply to author
Forward
0 new messages