I have lots of precomputed data computed by sage8.9 and before that I rely on. The reason I save that data is that it took a lot of computation time to obtain it. The data is saved as .sobj-files.
Suddenly I get "invalid pickle data"-errors when trying to load some of that data with the new version of sage. I am therefore unable to do computations on top of the precomputed data.
I strongly suspect that this issue is due to basing sage9.x on Python3.
How do I convert the data so that I can use it in the new version of sage?
I'm using sage-9.1-OSX_10.15.4-x86_64.app now on a late 2013 MacBookPro running MacOSCatalina 10.15.6. A toy example of a sobj-file that now produces the error is attached. The error messages are reproduced below.
Help is greatly appreciated.
Now, said error messages:
--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-1-90aa9dc4a056> in <module>() ----> 1 DiGraph = load('A3VuDiGraph') /Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7/site-packages/sage/misc/persist.pyx in sage.misc.persist.load (build/cythonized/sage/misc/persist.c:2900)() 156 157 ## Load file by absolute filename --> 158 with open(filename, 'rb') as fobj: 159 X = loads(fobj.read(), compress=compress, **kwargs) 160 try: /Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7/site-packages/sage/misc/persist.pyx in sage.misc.persist.load (build/cythonized/sage/misc/persist.c:2850)() 157 ## Load file by absolute filename 158 with open(filename, 'rb') as fobj: --> 159 X = loads(fobj.read(), compress=compress, **kwargs) 160 try: 161 X._default_filename = os.path.abspath(filename) /Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7/site-packages/sage/misc/persist.pyx in sage.misc.persist.loads (build/cythonized/sage/misc/persist.c:7424)() 1042 1043 unpickler = SageUnpickler(io.BytesIO(s), **kwargs) -> 1044 return unpickler.load() 1045 1046 /Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7/site-packages/sage/matrix/matrix0.pyx in sage.matrix.matrix0.unpickle (build/cythonized/sage/matrix/matrix0.c:39715)() 5874 A._cache = cache 5875 if version >= 0: -> 5876 A._unpickle(data, version) 5877 else: 5878 A._unpickle_generic(data, version) /Applications/SageMath-9.1.app/Contents/Resources/sage/local/lib/python3.7/site-packages/sage/matrix/matrix_integer_dense.pyx in sage.matrix.matrix_integer_dense.Matrix_integer_dense._unpickle (build/cythonized/sage/matrix/matrix_integer_dense.c:8217)() 540 self._unpickle_matrix_2x2_version0(data) 541 else: --> 542 raise RuntimeError("invalid pickle data") 543 else: 544 raise RuntimeError("unknown matrix version (=%s)"%version) RuntimeError: invalid pickle data
I have lots of precomputed data computed by sage8.9 and before that I rely on. The reason I save that data is that it took a lot of computation time to obtain it. The data is saved as .sobj-files.
Suddenly I get "invalid pickle data"-errors when trying to load some of that data with the new version of sage. I am therefore unable to do computations on top of the precomputed data.
I strongly suspect that this issue is due to basing sage9.x on Python3.
How do I convert the data so that I can use it in the new version of sage?
have to figure out a way to save the information in a version-independent way asap and meanwhile keep using sage8.9. It doesn't sound easy to do.
sage: m = matrix(ZZ, [[1, 2], [3, 4]])
sage: mpy = {tuple(k):int(v) for k, v in m.dict().items()}
sage: mpy
{(0, 0): 1, (0, 1): 2, (1, 0): 3, (1, 1): 4}
sage: save(mpy, 'mpy.sobj')
sage: mpy_back = load('mpy.sobj')
sage: m == matrix(mpy_back)
True
sage -pip install ruamel.yaml
sage: from ruamel.yaml import YAML
sage: yaml = YAML()
sage: fp = open('mpy.yaml', "w")
sage: yaml.dump(mpy, fp)
sage: fp.close()
sage: fp = open('mpy.yaml', "r")
sage: mpy_back_yaml = yaml.load(fp)
sage: mpy_back_yaml
ordereddict([((0, 0), 1), ((0, 1), 2), ((1, 0), 3), ((1, 1), 4)])
sage: m == matrix(mpy_back_yaml)
True
cat mpy.yaml
? - 0
- 0
: 1
? - 0
- 1
: 2
? - 1
- 0
: 3
? - 1
- 1
: 4
--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/eb2330dd-015f-4320-a1c6-eeb2fbba486do%40googlegroups.com.
if version == 0:
+ if isinstance(data, str): #old Py2 pickle: old "bytes" object reaches us as a latin1-encoded string
+ data = data.encode('latin1')
if isinstance(data, bytes):