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
329 stars 127 forks source link

Error in md.constrain.Rigid.create_bodies #1476

Closed tcmoore3 closed 1 year ago

tcmoore3 commented 1 year ago

Description

When initializing from a snapshot (either a hoomd.Snapshot or a gsd.hoomd.Snapshot) where the particle.body values are not -1, a memory error occurs.

Script

import hoomd

# create snapshot
s = hoomd.Snapshot()
N = 1000
s.particles.N = N
s.particles.position[:] = [[0.0, 0, 0]] * N
s.particles.body[:] = [x for x in range(N)]
s.particles.types = ['a', 'b']
s.particles.typeid[:] = [0] * N
s.configuration.box = [2, 2, 2, 0, 0, 0]

# create simulation object and add integrator
device = hoomd.device.auto_select()
sim = hoomd.Simulation(device=device)
sim.create_state_from_snapshot(s)
integrator = hoomd.md.Integrator(dt=0.001)
sim.operations.integrator = integrator

# rigid bodies
rigid = hoomd.md.constrain.Rigid()
rigid.body['a'] = {
    'constituent_types': ['b', 'b'],
    'positions': [[0, 0, -0.5], [0, 0, 0.5]],
    'orientations': [(1, 0, 0, 0)] * 2,
    'charges': [0.0] * 2,
    'diameters': [1.0] * 2,
}
rigid.create_bodies(sim.state)
print('created rigid bodies')

Input files

No response

Output

malloc(): invalid size (unsorted)
[cheme-hodges:554365] *** Process received signal ***
[cheme-hodges:554365] Signal: Aborted (6)
[cheme-hodges:554365] Signal code:  (-6)
[cheme-hodges:554365] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f644d952520]
[cheme-hodges:554365] [ 1] /lib/x86_64-linux-gnu/libc.so.6(pthread_kill+0x12c)[0x7f644d9a6a7c]
[cheme-hodges:554365] [ 2] /lib/x86_64-linux-gnu/libc.so.6(raise+0x16)[0x7f644d952476]
[cheme-hodges:554365] [ 3] /lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x7f644d9387f3]
[cheme-hodges:554365] [ 4] /lib/x86_64-linux-gnu/libc.so.6(+0x896f6)[0x7f644d9996f6]
[cheme-hodges:554365] [ 5] /lib/x86_64-linux-gnu/libc.so.6(+0xa0d7c)[0x7f644d9b0d7c]
[cheme-hodges:554365] [ 6] /lib/x86_64-linux-gnu/libc.so.6(+0xa415c)[0x7f644d9b415c]
[cheme-hodges:554365] [ 7] /lib/x86_64-linux-gnu/libc.so.6(+0xa4dcf)[0x7f644d9b4dcf]
[cheme-hodges:554365] [ 8] /lib/x86_64-linux-gnu/libc.so.6(posix_memalign+0xa6)[0x7f644d9b7206]
[cheme-hodges:554365] [ 9] /home/mtimc/software/hoomd-builds/v3.7.0/hoomd/_hoomd.cpython-39-x86_64-linux-gnu.so(+0x1f82f1)[0x7f644c4082f1]
[cheme-hodges:554365] [10] /home/mtimc/software/hoomd-builds/v3.7.0/hoomd/_hoomd.cpython-39-x86_64-linux-gnu.so(+0x1f8add)[0x7f644c408add]
[cheme-hodges:554365] [11] /home/mtimc/software/hoomd-builds/v3.7.0/hoomd/_hoomd.cpython-39-x86_64-linux-gnu.so(+0x1f8c45)[0x7f644c408c45]
[cheme-hodges:554365] [12] /home/mtimc/software/hoomd-builds/v3.7.0/hoomd/_hoomd.cpython-39-x86_64-linux-gnu.so(_ZN5hoomd12ParticleData22initializeFromSnapshotIdEEvRKNS_20SnapshotParticleDataIT_EEb+0x1cc3)[0x7f644c57ffa3]
[cheme-hodges:554365] [13] /home/mtimc/software/hoomd-builds/v3.7.0/hoomd/md/_md.cpython-39-x86_64-linux-gnu.so(_ZN5hoomd2md14ForceComposite17createRigidBodiesEv+0x59f)[0x7f63758a973f]
[cheme-hodges:554365] [14] /home/mtimc/software/hoomd-builds/v3.7.0/hoomd/md/_md.cpython-39-x86_64-linux-gnu.so(+0x16daa6)[0x7f63758b1aa6]
[cheme-hodges:554365] [15] /home/mtimc/software/hoomd-builds/v3.7.0/hoomd/md/_md.cpython-39-x86_64-linux-gnu.so(+0xaba72)[0x7f63757efa72]
[cheme-hodges:554365] [16] python(+0x14e0fc)[0x5615fe1930fc]
[cheme-hodges:554365] [17] python(_PyObject_MakeTpCall+0x347)[0x5615fe179a57]
[cheme-hodges:554365] [18] python(+0x14bcf2)[0x5615fe190cf2]
[cheme-hodges:554365] [19] python(_PyEval_EvalFrameDefault+0x4cbc)[0x5615fe17546c]
[cheme-hodges:554365] [20] python(+0x12a7d7)[0x5615fe16f7d7]
[cheme-hodges:554365] [21] python(+0x14ba5f)[0x5615fe190a5f]
[cheme-hodges:554365] [22] python(_PyEval_EvalFrameDefault+0x4cbc)[0x5615fe17546c]
[cheme-hodges:554365] [23] python(+0x12a7d7)[0x5615fe16f7d7]
[cheme-hodges:554365] [24] python(_PyEval_EvalCodeWithName+0x47)[0x5615fe16f497]
[cheme-hodges:554365] [25] python(PyEval_EvalCodeEx+0x39)[0x5615fe16f449]
[cheme-hodges:554365] [26] python(PyEval_EvalCode+0x1b)[0x5615fe229ddb]
[cheme-hodges:554365] [27] python(+0x213409)[0x5615fe258409]
[cheme-hodges:554365] [28] python(+0x20f5a4)[0x5615fe2545a4]
[cheme-hodges:554365] [29] python(+0x951a8)[0x5615fe0da1a8]
[cheme-hodges:554365] *** End of error message ***

Expected output

created rigid bodies

Platform

CPU, GPU, Linux, macOS

Installation method

Compiled from source

HOOMD-blue version

Tested with 3.3, 3.7, and 3.8

Python version

3.9.15

tcmoore3 commented 1 year ago

@joaander walked me through a debugging session, and we found a failed assertion in the create_bodies code. We never figured out what was causing the memory error, but after making some changes to the create_bodies code we got it running without errors.