espressomd / espresso

The ESPResSo package
https://espressomd.org
GNU General Public License v3.0
229 stars 185 forks source link

Checkpoint error when bonded interaction is not initialized #1019

Closed KaiSzuttor closed 7 years ago

KaiSzuttor commented 7 years ago

If you want to load a pickled espressomd.System.part object which includes bonded interactions, an error occurs: 'list' object has no attribute '_bond_id'

hmenke commented 7 years ago

This is not reproducible with the following adapted minimal-polymer.py. The first run generates a checkpoint, the second one loads it (and should crash but doesn’t).

from __future__ import print_function
import espressomd
from espressomd import thermostat
from espressomd import interactions
from espressomd import polymer
from espressomd import checkpointing

checkpoint = checkpointing.Checkpointing(checkpoint_id="checkpoint")

system = espressomd.System()
checkpoint.register("system")
checkpoint.register("system.analysis")

system.time_step = 0.01
system.cell_system.skin = 0.4
system.box_l = [100, 100, 100]
system.thermostat.set_langevin(kT=1.0, gamma=1.0)
system.cell_system.set_n_square(use_verlet_lists=False)
checkpoint.register("system.thermostat")

system.non_bonded_inter[0, 0].lennard_jones.set_params(
    epsilon=1, sigma=1,
    cutoff=2**(1. / 6), shift="auto")

checkpoint.register("system.non_bonded_inter")

fene = interactions.FeneBond(k=10, d_r_max=2)
system.bonded_inter.add(fene)
checkpoint.register("system.bonded_inter")

polymer.create_polymer(N_P = 1, bond_length = 1.0, MPC=50, bond=fene)
checkpoint.register("system.part")

if not checkpoint.has_checkpoints():
    print("Saving checkpoint")
    checkpoint.save()
else:
    print("Restoring checkpoint")
    checkpoint.load()

for inter in system.bonded_inter:
    print(inter.params)
KaiSzuttor commented 7 years ago

I did not say anything about using the checkpoint module of espresso but rather pickling directly the particle object.

hmenke commented 7 years ago

I don’t see how this is possible. If I try to pickle the system.part object I get an error.

from __future__ import print_function
import espressomd
from espressomd import interactions
from espressomd import polymer
import pickle

system = espressomd.System()

system.time_step = 0.01
system.cell_system.skin = 0.1
system.box_l = [100, 100, 100]

fene = interactions.FeneBond(k=10, d_r_max=2)
system.bonded_inter.add(fene)

polymer.create_polymer(N_P = 1, bond_length = 1.0, MPC=50, bond=fene)

with open("dump.pickle", "w") as f:
    pickle.dump(system.part, f)

Error message:

Traceback (most recent call last):
  File "minimal-polymer.py", line 19, in <module>
    pickle.dump(system.part, f)
  File "/usr/lib64/python2.7/pickle.py", line 1376, in dump
    Pickler(file, protocol).dump(obj)
  File "/usr/lib64/python2.7/pickle.py", line 224, in dump
    self.save(obj)
  File "/usr/lib64/python2.7/pickle.py", line 306, in save
    rv = reduce(self.proto)
  File "/usr/lib64/python2.7/copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle ParticleList objects
KaiSzuttor commented 7 years ago

I used "import dill as pickle". This package is able to pickle the ParticleList object. Sorry for confusion.

hmenke commented 7 years ago

I see. However, since ParticleList is unpickleable I’m closing this as invalid.