glotzerlab / hoomd-blue

Molecular dynamics and Monte Carlo soft matter simulation on GPUs.
http://glotzerlab.engin.umich.edu/hoomd-blue
BSD 3-Clause "New" or "Revised" License
336 stars 133 forks source link

`RuntimeError: Buffer is full.` when resetting MD walls. #1879

Open joaander opened 2 months ago

joaander commented 2 months ago

Description

The script below should run to completion but does not.

Script

import hoomd

sim = hoomd.util.make_example_simulation(particle_types=['W'])

integrator = hoomd.md.Integrator(dt=0.005)
integrator.methods.append(hoomd.md.methods.Langevin(filter=hoomd.filter.All(), kT=1.5))
sim.state.set_box(hoomd.Box.cube(L=80))

left_wall = hoomd.wall.Plane(origin=(-35, 0, 0), normal=(1, 0, 0))
right_wall = hoomd.wall.Plane(origin=(35, 0, 0), normal=(-1, 0, 0))
lj_wall = hoomd.md.external.wall.ForceShiftedLJ(walls=[left_wall, right_wall])
lj_wall.params[['W']] = {"epsilon": 1.0, "sigma": 1.0, "r_cut": 2.0 ** (1 / 6)}
integrator.forces.append(lj_wall)

sim.operations.integrator = integrator
# Step 1: Subclass hoomd.custom.Action.
class WallParameterModifier(hoomd.custom.Action):
    def __init__(self, lj_wall):
        super().__init__()
        self.lj_wall = lj_wall

    def act(self, timestep):
        print(timestep)
        wall_position = -35 + timestep * 0.0005 
        left = hoomd.wall.Plane(origin=(wall_position, 0, 0), normal=(1, 0, 0))
        self.lj_wall.walls = [left, right_wall]

# Step 2: Create a hoomd.update.CustomUpdater
wall_parameter_modifier = WallParameterModifier(lj_wall)
wall_parameter_updater = hoomd.update.CustomUpdater(
    trigger=hoomd.trigger.Periodic(1), action=wall_parameter_modifier)

# Step 3: Add the updater to the operations
sim.operations.updaters.append(wall_parameter_updater)

sim.run(60_000)
print(lj_wall.walls[0])

Input files

No response

Output

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Traceback (most recent call last):
  File "/Users/joaander/test/hoomd-wall-change/test.py", line 36, in <module>
    sim.run(60_000)
  File "/Users/joaander/build/hoomd/hoomd/simulation.py", line 562, in run
    self._cpp_sys.run(steps_int, write_at_start)
  File "/Users/joaander/test/hoomd-wall-change/test.py", line 26, in act
    self.lj_wall.walls = [left, right_wall]
    ^^^^^^^^^^^^^^^^^^
  File "/Users/joaander/build/hoomd/hoomd/operation.py", line 92, in __setattr__
    self._setattr_hook(attr, value)
  File "/Users/joaander/build/hoomd/hoomd/operation.py", line 96, in _setattr_hook
    super().__setattr__(attr, value)
  File "/Users/joaander/build/hoomd/hoomd/md/external/wall.py", line 221, in walls
    self._walls._sync({
  File "/Users/joaander/build/hoomd/hoomd/wall.py", line 475, in _sync
    self._backend_lists[wall_type]._sync(None, wall_list)
  File "/Users/joaander/build/hoomd/hoomd/data/syncedlist.py", line 246, in _sync
    raise err
  File "/Users/joaander/build/hoomd/hoomd/data/syncedlist.py", line 243, in _sync
    self._synced_list.append(self._to_synced_list_conversion(item))
  File "/Users/joaander/build/hoomd/hoomd/data/array_view.py", line 18, in wrapped_method
    return getattr(self._get_array_view(), method.__name__)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Buffer is full.

Expected output

... ... 59997 59998 59999 Plane(origin=_HOOMDTuple(-5.000499999999999, 0.0, 0.0), normal=_HOOMDTuple(1.0, 0.0, 0.0),

Platform

CPU, GPU, Linux, macOS

Installation method

Compiled from source

HOOMD-blue version

trunk-patch

Python version

3.12.5

joaander commented 2 months ago

Originally posted as a discussion in #1874.