Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I generated a very large graph, too large to simply display and manipulate with copy/paste operations. How can I somehow save the graph to a file to allow it to be rapidly reloaded after I quit out of the kernel and restart Mathematica?

share|improve this question
1  
Save or DumpSave might be of help. With DumpSave you will have the object saved in an mx file so the size will be smaller and will load faster. –  Spawn1701D Apr 21 '13 at 0:44
    
@Spawn1701D So I could simply write Save["SaveFile.mx",G], where G is my graph? –  ThermalDance Apr 21 '13 at 0:48
1  
and Get["SaveFile.mx"] or <<SaveFile.mx to load it. Make sure the file is located inside the path of Mathematica and keep in mind that the file can be loaded only to computers with the same kind of OS, so if you make the mx on windows it won't load in Mac OS. –  Spawn1701D Apr 21 '13 at 0:54
    
Instead of DumpSave, I recommend Export, which can also write MX files, but doesn't store variable names inside (only the data). Or just use Export["name.mz", Compress[graph], "String"]. See also here –  Szabolcs Apr 21 '13 at 0:57
    
@Szabolcs Interesting... I did not know that about Export/Import and .mx files. I typically use DumpSave and Get with a dedicated internal variable and a wrapper function in my packages i.e. something like save[file_, var_] := Block[{$var}, DumpSave[file, $var = var];] and load[file_] := Block[{$var} = Get@file]. Oh well... I'll probably keep them the way they are, since it works. –  rm -rf Apr 21 '13 at 1:21
show 2 more comments

1 Answer

From the comments of Spawn1710D and Szabolcs:

Save or DumpSave might be of help. With DumpSave you will have the object saved in an mx file so the size will be smaller and will load faster.

You use

Save["SaveFile.mx",G]

, where G is your graph to save and

Get["SaveFile.mx"] 

or

 <<SaveFile.mx

to load it. Make sure the file is located inside the path of Mathematica and keep in mind that the file can be loaded only to computers with the same kind of OS, so if you make the mx on windows it won't load in Mac OS.

Instead of DumpSave, Export can be used. It can also write MX files, but doesn't store variable names inside (only the data). Or just use

Export["name.mz", Compress[graph], "String"].
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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