Skip to content

Commit

Permalink
Merge pull request #1164 from pyiron/cloudpickel
Browse files Browse the repository at this point in the history
Switch from dill to cloudpickle
  • Loading branch information
jan-janssen authored Dec 19, 2023
2 parents 39abf69 + d07b0f7 commit e359d95
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .ci_support/environment-old.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
channels:
- conda-forge
dependencies:
- dill =0.3.1.1
- cloudpickle =2.0.0
- gitpython =3.1.23
- h5io =0.1.2
- h5py =3.6.0
Expand Down
2 changes: 1 addition & 1 deletion .ci_support/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
dependencies:
- coverage
- codacy-coverage
- dill =0.3.7
- cloudpickle =3.0.0
- gitpython =3.1.40
- h5io =0.1.9
- h5py =3.10.0
Expand Down
13 changes: 10 additions & 3 deletions pyiron_base/jobs/datamining.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import codecs
from datetime import datetime
import dill as pickle
import cloudpickle
import json
import numpy as np
import os
Expand Down Expand Up @@ -34,11 +34,18 @@


def _to_pickle(hdf, key, value):
hdf[key] = codecs.encode(pickle.dumps(value), "base64").decode()
hdf[key] = codecs.encode(
cloudpickle.dumps(obj=value, protocol=5, buffer_callback=None), "base64"
).decode()


def _from_pickle(hdf, key):
return pickle.loads(codecs.decode(hdf[key].encode(), "base64"))
try:
return cloudpickle.loads(codecs.decode(hdf[key].encode(), "base64"))
except ModuleNotFoundError:
import dill

return dill.loads(codecs.decode(hdf[key].encode(), "base64"))


def get_job_id(job):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
]
dependencies = [
"dill==0.3.7",
"cloudpickle==3.0.0",
"gitpython==3.1.40",
"h5io==0.1.9",
"h5py==3.10.0",
Expand Down
33 changes: 33 additions & 0 deletions tests/backwards/test_dill_cloudpickle_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest
from pyiron_base.jobs.datamining import _from_pickle

dill_str_1 = 'gASV9AIAAAAAAAB9lCiMCmdldF9qb2JfaWSUiIwJZ2V0X2luY2FylImMCWdldF9zaWdtYZSJjBln\nZXRfdG90YWxfbnVtYmVyX29mX2F0b21zlImMDGdldF9lbGVtZW50c5SJjBVnZXRfY29udmVyZ2Vu\nY2VfY2hlY2uUiYwVZ2V0X251bWJlcl9vZl9zcGVjaWVzlImMGWdldF9udW1iZXJfb2ZfaW9uaWNf\nc3RlcHOUiYwKZ2V0X2lzbWVhcpSJjAlnZXRfZW5jdXSUiYwKZ2V0X25fa3B0c5SJjA5nZXRfbl9l\ncXVfa3B0c5SJjCRnZXRfbnVtYmVyX29mX2ZpbmFsX2VsZWN0cm9uaWNfc3RlcHOUiYwUZ2V0X21h\nam9yaXR5X3NwZWNpZXOUiYwMZ2V0X2pvYl9uYW1llImMDmdldF9lbmVyZ3lfdG90lImMDmdldF9l\nbmVyZ3lfcG90lImMD2dldF9lbmVyZ3lfZnJlZZSJjA5nZXRfZW5lcmd5X2ludJSJjBdnZXRfZW5l\ncmd5X3RvdF9wZXJfYXRvbZSJjBdnZXRfZW5lcmd5X3BvdF9wZXJfYXRvbZSJjBhnZXRfZW5lcmd5\nX2ZyZWVfcGVyX2F0b22UiYwXZ2V0X2VuZXJneV9pbnRfcGVyX2F0b22UiYwQZ2V0X2VfY29udl9s\nZXZlbJSJjAxnZXRfZl9zdGF0ZXOUiYwKZ2V0X2VfYmFuZJSJjB5nZXRfbWFqb3JpdHlfY3J5c3Rh\nbF9zdHJ1Y3R1cmWUiYwaZ2V0X2VxdWlsaWJyaXVtX3BhcmFtZXRlcnOUiYwNZ2V0X3N0cnVjdHVy\nZZSJjApnZXRfZm9yY2VzlImMFmdldF9tYWduZXRpY19zdHJ1Y3R1cmWUiYwRZ2V0X2F2ZXJhZ2Vf\n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ZXKU\nSwJDAgwBlCkpdJRSlGNfX2J1aWx0aW5fXwpfX21haW5fXwpoN05OdJRSlH2UfZRoH32Uc4aUYoeU\nUjCMDGJ1bGtfbW9kdWx1c5RoBChoE2NweWlyb25fYmFzZS5qb2JzLmRhdGFtaW5pbmcKX19kaWN0\nX18KaA1OaBVOhZRSlGgVToWUUpSGlHSUUpR9lH2UKGgffZRoIWgidYaUYmguaEZoL2hCh5RSMGgu\naERoL2gEKGgGKEMCAAGUSwFLAEsASwFLAktDQwh8AGQBGQBTAJROjB9vdXRwdXQvZXF1aWxpYnJp\ndW1fYnVsa19tb2R1bHVzlIaUKWgKhZRoNowGZ2V0X2JtlEsGQwIIAZQpKXSUUpRjX19idWlsdGlu\nX18KX19tYWluX18KaFROTnSUUpR9lH2UaB99lHOGlGKHlFIwjAlwb3RlbnRpYWyUaAQoaBNjcHlp\ncm9uX2Jhc2Uuam9icy5kYXRhbWluaW5nCl9fZGljdF9fCmgNTmgVToWUUpRoFU6FlFKUhpR0lFKU\nfZR9lChoH32UaCFoInWGlGJoLmhjaC9oX4eUUjBoLmhhaC9oBChoBihDBAABFAGUSwFLAEsASwJL\nBEtDQxx8AGoAoAF8AGQBGQBkAhkAoQF9AXwBZAMZAFMAlChOjAlvdXRwdXQvaWSUSwCMFGlucHV0\nL3BvdGVudGlhbC9OYW1llHSUjAdwcm9qZWN0lIwHaW5zcGVjdJSGlGgKjAVjaGlsZJSGlGg2jAdn\nZXRfcG90lEsKQwQUAQgBlCkpdJRSlGNfX2J1aWx0aW5fXwpfX21haW5fXwpodk5OdJRSlH2UfZRo\nH32Uc4aUYoeUUjB1Lg==\n'


try:
import dill

skip_dill_test = False
except ImportError:
skip_dill_test = True


class TestDillCloudpickleComptaibility(unittest.TestCase):
def test_1(self):
output = _from_pickle(hdf={"test": dill_str_1}, key="test")
self.assertEqual(len(output.keys()), 36)
self.assertTrue(output['get_job_id'])
for k in output.keys():
if k != 'get_job_id':
self.assertFalse(output[k])

@unittest.skipIf(
skip_dill_test, "dill is not installed, so the dill tests are skipped."
)
def test_2(self):
output = _from_pickle(hdf={"test": dill_str_2}, key="test")
self.assertEqual(len(output.keys()), 3)
self.assertEqual(list(output.keys()), ['a_eq', 'bulk_modulus', 'potential'])
for k in output.keys():
self.assertTrue(callable(output[k]))

0 comments on commit e359d95

Please sign in to comment.