PLAMS icon indicating copy to clipboard operation
PLAMS copied to clipboard

job.run does not pickle

Open damdaepark opened this issue 2 years ago • 1 comments

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 avatar Dec 21 '22 12:12 damdaepark

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

damdaepark avatar Dec 21 '22 13:12 damdaepark

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.

dormrod avatar Jul 03 '24 12:07 dormrod