I applied the change suggested by Nils Bruin (above) to Sage 9.1 installed from source on Kubuntu 20.04, and it works for me. On Friday, 21 August 2020 at 11:37:36 UTC+10 Paul Leopardi wrote:
> See also https://trac.sagemath.org/ticket/30402 which relates. > > > On Tuesday, 4 August 2020 at 05:45:46 UTC+10 Nils Bruin wrote: > >> Looking at the offending code (in matrix_integer_dense.pyx, line 535: >> >> def _unpickle(self, data, int version): >> if version == 0: >> if isinstance(data, bytes): >> self._unpickle_version0(data) >> elif isinstance(data, list): >> self._unpickle_matrix_2x2_version0(data) >> else: >> >> raise RuntimeError("invalid pickle data") >> else: >> >> raise RuntimeError("unknown matrix version (=%s)"%version) >> >> it's the classing Py2/Py3 unpickle incompatibility: there's a shift >> between str/bytes/unicode between the 3 that rather fundamentally breaks >> pickling of them. It can be fixed fairly easily. We're probably unpickling >> what used to be a python 2 (str==bytes) object as a python 3 latin1-encoded >> string, because most py2 str/bytes objects are supposed to be strings (and >> latin1 has the nice property that it preserves bit patterns). So in the >> code above, we just need to check >> >> I think we want change this to something like: >> >> 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): >> >> >> Making this change is really worthwhile: these are small problems that >> are hard to find without a "pickle jar" without good coverage. Each of them >> is probably fairly easy to fix. These problems come up particularly when >> data is encoded as "bytes". That happens for optimized picklers. There >> aren't that many of them, so the number of these changes required is >> probably limited, and each of them can have a huge positive knock-on effect >> as you can see here. >> >> (If I have important, expensive computational data I want to save for >> posterity, I would not go for Pickle anyway: you want something that's >> platform-independent. Sage will die at some point in the future too, and >> Pickle is not a format that is *that* easy to maintain: It's not archive >> quality in the librarian sense). >> > -- 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/7cca4333-66be-4a92-8e27-8decca9d9792n%40googlegroups.com.