Closed KaiSzuttor closed 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)
I did not say anything about using the checkpoint module of espresso but rather pickling directly the particle object.
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
I used "import dill as pickle". This package is able to pickle the ParticleList object. Sorry for confusion.
I see. However, since ParticleList
is unpickleable I’m closing this as invalid.
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'