2
$\begingroup$

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?

$\endgroup$
7
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Apr 21, 2013 at 0:44
  • $\begingroup$ @Spawn1701D So I could simply write Save["SaveFile.mx",G], where G is my graph? $\endgroup$ Commented Apr 21, 2013 at 0:48
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Apr 21, 2013 at 0:54
  • $\begingroup$ 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 $\endgroup$ Commented Apr 21, 2013 at 0:57
  • $\begingroup$ @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. $\endgroup$ Commented Apr 21, 2013 at 1:21

1 Answer 1

2
$\begingroup$

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"]. 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.