SCM-NV / PLAMS

Python Library for Automating Molecular Simulations
https://www.scm.com/doc/plams
Other
65 stars 24 forks source link

job.run does not pickle #123

Closed damdaepark closed 4 months ago

damdaepark commented 1 year ago

Hi SCM,

I found that two PLAMS, one installed by pip install plams (through PyPI) and the other one installed by pip install git+https://github.com/SCM-NV/PLAMS.git@master (through source code from Github), behave quite differently.

The latter one does not appropriately save the finished job (pickling .dill file) after job.run(), and this should be addressed.

damdaepark commented 1 year ago

I just found a temporary workaround that changing the code from

def pickle(self, filename=None):
        """Pickle this instance and save to a file indicated by *filename*. If ``None``, save to ``[jobname].dill`` in the job folder."""
        filename = filename or opj(self.path, self.name+'.dill')
        with open(filename, 'wb') as f:
            try:
                pickle.dump(self, f, config.job.pickle_protocol)
            except:
                log('Pickling of {} failed'.format(self.name), 1)

to

def pickle(self, filename=None):
        """Pickle this instance and save to a file indicated by *filename*. If ``None``, save to ``[jobname].dill`` in the job folder."""
        filename = filename or opj(self.path, self.name+'.dill')
        with open(filename, 'wb') as f:
            try:
                # pickle.dump(self, f, config.job.pickle_protocol)
                pickle.dump(self, f, -1)  #! override
            except:
                log('Pickling of {} failed'.format(self.name), 1)

that is inside /plams/core/basejob.py

dormrod commented 4 months ago

Hi, thanks for raising this issue.

The value of config.job.pickle_protocol is set to -1 here on initialisation, so the behaviour of the two snippets above should be the same.

I have confirmed that in the latest version on master, the job is pickled correctly (creating the .dill file) and can be successfully reloaded.

Therefore I am closing this issue as resolved.