Tag Info

Hot answers tagged


While it is true that you can not save a full state of the kernel, in some cases it may be enough for your purposes to save all symbols' definitions in some context(s), such as Global` (or whatever other contexts are of interest to you). This can be done via DumpSave, like DumpSave["state.mx", "Global`"] The .mx file generated by DumpSave will be ...


Maybe this ? ClearAll["Global`*"]


What was saved was the content of sol, which happens to contain the solution to your equation (you explicitly set it to that), and therefore is certainly sufficient for your plot. Saving Kernel state however would involve saving things like the random seed, so the following would give the same output twice (using a hypothetical function SaveKernelState and ...


There is an easy way to keep your data in the notebook itself and NOT to save them in external file - using Compress. As @Leonid says here and I already mentioned this before in this answer for similar case with Interpolation function. Start from some output you need: sol = NDSolve[{D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == 0, u[t, 0] == Sin[t], ...


In the days when computers were slower, and the kernel took a long time to start up (in wall time), a little package was made to help with cleaning up without having to restart the kernel. This package is still included with Mathematica, and is found in AddOns\ExtraPackages\Utilities\CleanSlate.m (within the Mathematica installation directory). It is more ...


I use a shortcut key Ctrl+Q for Quit[], allowing rapid clearing of all sessions variables. Here is how you can add this to Mathematica: You will be editing KeyEventTranslations.tr. This is an important system file so be careful. Start by copying the file you are going to edit from the $InstallationDirectory to $UserBaseDirectory in the same tree. This ...


The option to save a variable, a value, in a notebook, that I find simple and deserves a chance is to store them in the notebook's tagging rules. You can compress it if you want, or you can autoload it through an initialization cell or through the NotebookDynamicExpression too. The core is this: r = RandomReal[{-1, 1}, 1000000]; ...


I have the following commands in my init.m file, which can be found in $UserBaseDirectory/Kernel/init.m. eraseAll := ClearAll[Evaluate[$Context<>"*"]]; eraseAll::usage="eraseAll clears all values, definitions, attributes, messages and defaults associated with symbols in the current context" removeAll := Remove[Evaluate[$Context<>"*"]]; ...


There's a related question with interesting answers, where I suggested storing in the notebook's tagging rules. Just use something like this as a variable CurrentValue[EvaluationNotebook[], {TaggingRules, "myvars", "x"}] and it will be stored in the notebook, so it survives kernel crashes. If it's something big however, I would probably use DumpSave before ...


As an alternative to DumpSave, what I've done in the past was to Compress the relevant results and store them within the same notebook. You can optionally set things up so that your data/results would self-uncompress themselves upon being called the first time. For one example of such use, see this answer. In any case, the advantage of this approach is ...


You need to set CellLabelAutoDelete->False You can do this programmatically: SetOptions[EvaluationNotebook[],CellLabelAutoDelete->False] or set it in your stylesheet.


A very fine solution is given by this answer by WReach on Stackoverflow/Mathematica. He provides an approach with simple file-backed storage during operations. An alternative using SQL is given as well.


Some fancy ways have already been posted, but I'd like to mention the simple ones. Per Notebook Use an Initialization Cell (Cell > Cell Properties > Initialization Cell) for code that should be evaluated any time you first evaluate code in the Notebook in each session. Globally Use the Kernel\init.m file (FileNameJoin[{$UserBaseDirectory, "Kernel", ...


I just found that doing Quit[] does what I want, too. It may not be the nicest way, but it is easy to remember. Another Mathematica kernel seems to be automatically started when the next command is run.


You could wrap (the relevant part of) your code in DynamicModule. The documentation says "Symbols specified in a DynamicModule will by default have their values maintained even across Mathematica sessions."


I classify your question as "Serious" thus, here is my answer. In many cases I have found myself in situations where a "canonical solution" does not seem to exist for a given problem found while creating Mathematica solutions. In those cases I tend to create a reasonable enough solution. When I read your question I remembered that a couple of years ago I ...


I have added to this question the possibility of saving the current context, storing it inside the notebook, so that it can be loaded after. It is still very rough, but I think that it can work for same cases, and give an idea for a more adapted tool.

Only top voted, non community-wiki answers of a minimum length are eligible