0
$\begingroup$

Since I have some quite memory expensive calculations to do, I exported my results as lists in the .mx format. Now our office has upgraded to Mathematica 11.1.1. While before 11.1.1 it was also possible to open the file within mathematica without importing. It is now only possible to read the .mx files by using mathematica's Import[] function. And, even worse, it is not possible anymore to import the ".mx" files with a earlier versions of mathematica. On our system we have installed versions 8, 9 and 11. Mathematica 8 and 9 cannot import ".mx" files that have been generated with the Export function of Mathematica 11.

I have Version 9 on my laptop installed and there I did most of the developing, but since our main computer is much faster I was counting on being able to run all the calculations there. Now however, it seems that I would need a entirely different code by exporting into something like ".text" format, which requires then {} around the Import command such that it can be used as an input for Mathematica's interpolation function.

Is there a command for Mathematica 11 such that it generates ".mx" that are readable by versions 8 or 9 ?

Edit: This comment was very helpful Save open Mathematica Notebook from command line or second Notebook to avoid data loss

In order to make it work for me I had to modify it with [[1,1]] in the importing command

zimport[filename_] := Uncompress@Import[filename, "String"][[1, 1]]

zexport[filename_, data_] := Export[filename, Compress[data], "String"]

This seems stable in all directions between windows, linux and v11 and 9.

Compression is not neccessarily needed for functionality, but is of course very nice if a large amount of files, or big ones, are copied in between different systems.

$\endgroup$
3
  • $\begingroup$ I don't think so but you can use suggestions from 7583. I'd mark it a duplicate, do you agree? $\endgroup$
    – Kuba
    Commented Aug 28, 2017 at 9:05
  • $\begingroup$ Somehow, yes. It seems related. I also noticed just now that if I use Import["filename","mx"] instead of Import[StringJoin["filename",".mx"]] it seems to work. $\endgroup$ Commented Aug 28, 2017 at 9:08
  • 1
    $\begingroup$ Also see this comment. $\endgroup$
    – Szabolcs
    Commented Aug 28, 2017 at 9:11

1 Answer 1

1
$\begingroup$

No, as of version 11.1, there isn't a way to read later-version MX files in older-version Mathematica. MX trades off compatibility to gain performance.

From the MX documentation:

MX files cannot be exchanged between different operating systems or versions of the Wolfram System.

This statement is actually outdated and only valid up to version 9. Up to that version, MX files were not compatible between either different versions of Mathematica or different operating systems or hardware architectures.

Since version 10.0, compatibility is improved. Later versions of Mathematica can generally read MX files created by earlier versions. Version 11 can read version-10 MX files, but version 10 cannot read version-11 MX files.

Furthermore, since version 10, MX files are compatible across different operating systems provided that they have the same $SystemWordLength. This means that an MX files created by a 64-bit version of Mathematica for OS X can be read with a 64-bit version on Windows. But it cannot be read with a 32-bit version on any operating system.


Itai Seggev has stated that starting with 11.2, cross-version MX compatibility will be improved:

On the plus side, one thing we did in the forth coming 11.2 is improve cross-version compatibility of MX files. So, unless a new feature forces an incompatible change in the format, 11.2 will be able to read MX files from later versions. (Obviously, new features won't work in an older kernel).

$\endgroup$
9
  • $\begingroup$ So using the .text workaround might be the easiest and most reliable solution for me right now. Since it is only lists, there shouldn't be any compatibility problems if I save the data as text, right? $\endgroup$ Commented Aug 28, 2017 at 9:21
  • $\begingroup$ I also want to be able to read them in a separate file. Since the final lists depend on many integrations and other definitions, it makes debugging much more easy if I don't have to open them in the same file. Yes, I can always import them in a new notebook, but then I have different kernels, and different directories initialized and such. Doubleclicks with the mouse are so much more convenient. $\endgroup$ Commented Aug 28, 2017 at 9:25
  • $\begingroup$ I don't know what you mean by "the .text workaround". $\endgroup$
    – Szabolcs
    Commented Aug 28, 2017 at 9:26
  • $\begingroup$ I thought I described it in my question. Sorry. I am panicking, since I have a deadline on Aug 31st. Since it is only lists I can export them as simple text file and then use Interpolation[{Import[]}] with the {} around the import command. That way I get the same result as by using mx. But text files will be compatible across plattforms, computer architectures and versions as well. And they are editable. $\endgroup$ Commented Aug 28, 2017 at 9:39
  • 2
    $\begingroup$ Take a look at the Table and CSV Import/Export formats. It's best to specify the format explicitly. Yes, these formats are useful for data exchange and archiving but very limited in what data they can hold. So far I found the output of Compress to be just as reliable, and it can hold any Mathematica expression. $\endgroup$
    – Szabolcs
    Commented Aug 28, 2017 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.