Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get["file.mx"] doesn't work

524 views
Skip to first unread message

Martin Vavpotič

unread,
May 16, 2011, 7:28:20 AM5/16/11
to
My computer broke. I installed Mathematica on a laptop and I wanted to
load the calculations I already made. I used the Get command and I got
this:

File Lensing_08_118_06_1e-3.mx cannot be loaded, it is corrupted or is
written on a different machine

Does this mean my backed up files are no good on a different computer?
Do I need to make those files all over again?

Oliver Ruebenkoenig

unread,
May 17, 2011, 7:47:13 AM5/17/11
to

Martin,

those are binary files and thus platform dependent. I.e you can not load a
mx file generated on Windows on a Linux or Mac platform.

Oliver

Albert Retey

unread,
May 17, 2011, 7:48:28 AM5/17/11
to

mx, as the documentation says, is a machine and version dependent
format, it depends e.g. on OS and also differs for e.g. 32 vs. 64 bit
machines. It also does differ between various versions of mathematica. I
think your best bet is to find a machine with the same OS and Processor
type as your old machine running the same Mathematica version as your
old computer and convert to something machine independent, e.g. wdx.
Maybe in the future you also want to use machine independent formats,
although they are a little less efficient. Of course it could also be
that your files got corrupted, your old computer might have written
nonsense to disk before completley breaking down...

hth,

albert


Sjoerd C. de Vries

unread,
May 17, 2011, 7:49:10 AM5/17/11
to
If you saved the file using DumpSave the result may be machine specific (MaxOS vs Win vs Linux; 32 bit vs 64 bit). Other kinds of saving results (a normal save in a .nb notebook or using Save are machine independent if I'm not mistaken).

Cheers -- Sjoerd

Mathematica questions quickly answered at StackOverflow
http://stackoverflow.com/questions/tagged/mathematica


David Bailey

unread,
May 18, 2011, 7:15:48 AM5/18/11
to
There is an interesting alternative to using MX files, which seems to be
portable:

str=OpenWrite[file,BinaryFormat->True];
BinaryWrite[str,Compress[expr],"TerminatedString"];
Close[str];

This is not quite as fast as using an mx file, but it is still very fast.

David Bailey
http://www.dbaileyconsultancy.co.uk


Scot T. Martin

unread,
May 18, 2011, 7:14:33 AM5/18/11
to
To add to what Albert writes, somewhat surprisingly to me the .mx format also depends on the storage medium. That is, when using the same machine (i.e., control therefore on OS and 32/64-bit), I have made .mx files and stored that to my local hard drive. I then copy those files over to a network drive, which I believe is Linux but appears to me just as a mapped network drive within Windows. The .mx files then no longer work. I have to re-run and generate the .mx files directly to the network drive.

________________________________________
From: Albert Retey [aw...@gmx-topmail.de]
Sent: Tuesday, May 17, 2011 07:48
Subject: Re: Get["file.mx"] doesn't work

DrMajorBob

unread,
May 19, 2011, 7:42:13 AM5/19/11
to
Wow. Take away message? NEVER save to .mx format. EVER.

Too many things can go wrong.

Bobby

On Wed, 18 May 2011 06:14:29 -0500, Scot T. Martin
<sma...@seas.harvard.edu> wrote:

> To add to what Albert writes, somewhat surprisingly to me the .mx format
> also depends on the storage medium. That is, when using the same machine
> (i.e., control therefore on OS and 32/64-bit), I have made .mx files and
> stored that to my local hard drive. I then copy those files over to a
> network drive, which I believe is Linux but appears to me just as a
> mapped network drive within Windows. The .mx files then no longer work.
> I have to re-run and generate the .mx files directly to the network
> drive.
>
>
>
> ________________________________________
> From: Albert Retey [aw...@gmx-topmail.de]
> Sent: Tuesday, May 17, 2011 07:48

> To: math...@smc.vnet.net


> Subject: Re: Get["file.mx"] doesn't work
>
> Am 16.05.2011 13:28, schrieb Martin Vavpoti==C4==8D:
>> My computer broke. I installed Mathematica on a laptop and I wanted to
>> load the calculations I already made. I used the Get command and I got
>> this:
>>
>> File Lensing_08_118_06_1e-3.mx cannot be loaded, it is corrupted or is
>> written on a different machine
>>
>> Does this mean my backed up files are no good on a different computer?
>> Do I need to make those files all over again?
>
> mx, as the documentation says, is a machine and version dependent
> format, it depends e.g. on OS and also differs for e.g. 32 vs. 64 bit
> machines. It also does differ between various versions of mathematica. I
> think your best bet is to find a machine with the same OS and Processor
> type as your old machine running the same Mathematica version as your
> old computer and convert to something machine independent, e.g. wdx.
> Maybe in the future you also want to use machine independent formats,
> although they are a little less efficient. Of course it could also be
> that your files got corrupted, your old computer might have written
> nonsense to disk before completley breaking down...
>
> hth,
>
> albert
>
>


--
DrMaj...@yahoo.com

Albert Retey

unread,
May 19, 2011, 7:44:41 AM5/19/11
to
Hi,

> There is an interesting alternative to using MX files, which seems to
> be portable:
>
> str=OpenWrite[file,BinaryFormat->True];
> BinaryWrite[str,Compress[expr],"TerminatedString"]; Close[str];
>

Another alternative seems to be WDX (Wolfram Data eXchange) which I am
using without problems on a variety of machines and which also seems to
be portable, can be used exactly like MX files, is binary, is documented
and thus I would consider officially supported. And it is used by the
data paclet functionality, so I guess it is reasonably performant and
well tested on all systems (an assumption which my experience does
support up to now).

On the other hand that format seems to not be promoted by Wolfram very
much. Has anyone any information what the "official" state of that
format is, and whether WRI thinks it is save and recommended to be used
by ordinary users or not?

Honestly I could well imagine that WDX basically does something very
close to what David suggested :-). If anyone has time to do some
performance comparison between the two, I would be interested to hear
the results...

cheers,

albert

Ulf-Dietrich Braumann

unread,
May 20, 2011, 6:38:53 AM5/20/11
to
Hi,

if no expressions need to be stored, just datasets, you also might
consider exporting to NASACDF (common data format specified by NASA). It
of course is portable, is binary, and one can specify some lossless
compression methods. Recently I have used it for storing some scalar 32bit
real valued autoradiographic images (approx. 9000x7000 pixels, approx.
150MB on disk):

Export["psl.cdf", {psl}, {"Datasets", {"Photo Stimulated Luminescence"}},
{"DataFormat" -> "Real32", "DataEncoding" -> "GZIP"}];

(NB: TIFF export/import in Mathematica still cannot deal with real-valued
images, whereas my images' value range was somewhat exotic: 0,...,2.5).

One can check what named data sets are included simply typing:
Import["psl.cdf"]
and gets:
{"Photo Stimulated Luminescence"}

Loading is done like this:
psl=Import["psl.cdf", {"Datasets", {"Photo Stimulated Luminescence"}}];

To store more data sets in one file, simply extend the list of variables
and data set names...

At the moment unfortunately I cannot do performance comparisons (WDX,
BinaryWrite, MX, NASACDF, ...).

Regards - Ulf-Dietrich

Peter Pein

unread,
May 20, 2011, 7:02:55 AM5/20/11
to

soory to say, Albert, but Ex- and Import is not an easy to handle
alternative to DumpSave:

In[1]:= f[x_]:=x+1
In[2]:= SetDirectory["C:\\Users\\Peter"];
In[3]:= DumpSave["f.mx",f];
In[4]:= Remove[f];
In[5]:= <<"f.mx"
In[6]:= f[a]
Out[6]= 1+a

this should work with an alternative. But:

In[7]:= Export["f.wdx",f];
In[8]:= Remove@f
In[9]:= Import["f.wdx"]
Out[9]= f
In[10]:= f[b]
Out[10]= f[b]

and of course the following leads to a real mess:

In[11]:= f:=Import["f.wdx"]
In[12]:= f[c]
During evaluation of In[12]:= $RecursionLimit::reclim: Recursion depth
of 256 exceeded. >>
During evaluation of In[12]:= $RecursionLimit::reclim: Recursion depth
of 256 exceeded. >>
During evaluation of In[12]:= $RecursionLimit::reclim: Recursion depth
of 256 exceeded. >>
During evaluation of In[12]:= General::stop: Further output of
$RecursionLimit::reclim will be suppressed during this calculation. >>
Out[12]= $Aborted

One would have to find a way to save all (d)ownvalues, upvalues (and
possibly "inbetweenvalues" ;-) ) and to restore them. Not too trivial,
is it?

Cheers,
Peter


Albert Retey

unread,
May 21, 2011, 6:47:00 AM5/21/11
to
Hi,

What you say is of course all true, I meant that wdx is capable of doing
what an Import[filename,data,"MX"] can do, which means it can handle
arbitrary mathematica expressions, it does not require data to be of a
certain type, as most other binary export formats do. I should emphasize
that Davids suggestion to write a Compressed binary representation of an
expression does fulfill this requirement just as well, which is thanks
to the power of Compress to handle expressions of any kind. I was lead
to the assumption that that was what the OP wanted since he was talking
about MX format, not DumpSave. Sorry if that was not clear from my
previous post.

> One would have to find a way to save all (d)ownvalues, upvalues (and
> possibly "inbetweenvalues" ;-) ) and to restore them. Not too trivial,
> is it?

What you can do is to use Save, which works like DumpSave in that
respect, it looks up all definitions that the expression you want to
save potentially depend on. The drawback is of course that it is not a
binary format, so it will much more space and time consuming to save and
reload the definitions, but it will be portable.

Obviously there is no holy grail in that respect, namely a DumpSave to a
portable format.

On the other hand my impression is that it should be relatively simple
to create something that works as DumpSave but stores to WDX instead of
MX for WRI, maybe someone listens and realizes that there might be a
need for it. Or maybe the functionality is there but we have not found
how to use it. If you'd want to program this yourself, you would have to
rewrite some nontrivial code that already exists (not a motivating
situation :-)) or get ahold of these internal functionalities in one way
or the other. That is not something I would try without very urgent need...

I think that this does not come up more frequently is that most serious
users of Mathematica have learned how to depart definitions (=code) from
data, where former can best be stored to .m files (and be version
controlled!) and the latter could e.g. be saved in .wdx files in a
portable way or more often saved to more specific other file formats. Of
course I know that the nature of Mathematica makes no clear distinctions
between the two, but I rarely have seen real world examples where these
concepts could not easily be distinguished. If in doubt I guess you can
get away with: if it's large ("megabytes"), its data, if not it's ok to
be treated "like" code and can go to a .m (text)file...

cheers,

albert

0 new messages