>
> 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.
>

Let me try to help: As I understood your test case consists of matrices 
over the integers, right? If you convert it into a pure Python dictionary 
over Python integers  before you save it to an sobj-file then you will have 
a much more stable format. From such a dictionary you can recover your 
matrix easily by Sage construction functionality:

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



If you still feel unsafe with that you shoud choose a readable format, for 
example json as suggested before. I prefer yaml since it can be easily used 
for dictionaries. But unfortunately it is not included in Sage per default. 
So you have to install it first:


sage -pip install ruamel.yaml




Now doing the same as above with 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




The file looks like this:


cat mpy.yaml
? - 0
  - 0
: 1
? - 0
  - 1
: 2
? - 1
  - 0
: 3
? - 1
  - 1
: 4



In the first ticket I've linked to this thread I've uploaded a ipynb-file 
<https://trac.sagemath.org/attachment/ticket/28302/demo_yaml.ipynb> to 
demonstrate more advanced applications of YAML with Sage.


On Wednesday, July 29, 2020 at 9:17:19 AM UTC+2, Udo Baumgartner wrote:
>
> Many thanks for your replies. I understand the problem now much better and 
> obviously 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.
>
> Those pointers to tickets #28302 und #28444 were particularly helpful. 
>
> Aside: It is disappointing that no secure method to store computed values 
> is available yet. One of my computations took half a year to complete and 
> on top of that loading some of the data used in those computations is also 
> not possible with sage9.1.
>
> seb....@gmail.com schrieb am Dienstag, 28. Juli 2020 um 12:11:28 UTC+2:
>
>> Related tickets to this issue are #28302 
>> <https://trac.sagemath.org/ticket/28302> and #28444! 
>> <https://trac.sagemath.org/ticket/28444>
>>
>> Best,
>> Sebastian
>>
>>
>> On Saturday, July 25, 2020 at 12:03:07 AM UTC+2, Udo Baumgartner wrote:
>>>
>>> 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
>>>
>>>
>>>

-- 
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+unsubscr...@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.

Reply via email to