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
335 stars 131 forks source link

Passing a large integer as simulation seed from Python fails with opaque error message #1364

Closed Luthaf closed 2 years ago

Luthaf commented 2 years ago

Description

I'm following the HOOMD tutorial at FOMMS, and got an opaque error message while playing around the code. I've been told the root cause is that the C++ code expects a 16-bit integer, and 0xdeadbeef does not fit in this size.

Script

# Include a minimal script that reproduces the problem
sim = hoomd.Simulation(device=cpu, seed=0xdeadbeef)

snapshot = gsd.hoomd.Snapshot()
box, positions = freud.data.UnitCell.fcc().generate_system(num_replicas=3,
                                                           scale=1.5)
snapshot.particles.N = len(positions)
snapshot.particles.position = positions
snapshot.particles.types = ['octahedron']
snapshot.configuration.box = [box.Lx, box.Ly, box.Lz, 0, 0, 0]

sim.create_state_from_snapshot(snapshot)

Output

TypeError                                 Traceback (most recent call last)
     ...

File /opt/miniforge3/envs/hoomd-workshop/lib/python3.10/site-packages/hoomd/simulation.py:259, in Simulation.create_state_from_snapshot(self, snapshot, domain_decomposition)
    256 if self.timestep is not None:
    257     step = self.timestep
--> 259 self._init_system(step)

File /opt/miniforge3/envs/hoomd-workshop/lib/python3.10/site-packages/hoomd/simulation.py:124, in Simulation._init_system(self, step)
    121 self._cpp_sys = _hoomd.System(self.state._cpp_sys_def, step)
    123 if self._seed is not None:
--> 124     self._state._cpp_sys_def.setSeed(self._seed)
    126 self._init_communicator()

TypeError: setSeed(): incompatible function arguments. The following argument types are supported:
    1. (self: hoomd._hoomd.SystemDefinition, arg0: int) -> None

Invoked with: <hoomd._hoomd.SystemDefinition object at 0x12204cff0>, 3735928559

Expected output

It would be better to get a clear error message, ideally linked to the hoomd.Simulation(device=cpu, seed=0xdeadbeef) call instead of the sim.create_state_from_snapshot(snapshot) call.

Configuration

Platform:

Installation method:

Versions:

joaander commented 2 years ago

Thanks for the report. Someone on the mailing list just ran into the same issue as well: https://groups.google.com/g/hoomd-users/c/jHLsivvZz9E

I have a fix on a local branch, will make a pull request when I have time.