Interrupting Mathematica in mid calculation

In summary, the conversation revolves around the speaker's need to extract useful information about a Mathematica calculation that has been running for five days. They mention entering a "subsession" and using the Stack function to see the evaluation stack, but express frustration with its limitations. The speaker also suggests using the SetNotebookStatusLine function and doing primitive file appends during the calculation as possible solutions. They also mention more advanced techniques for setting a time limit on the calculation.
  • #1
muppet
608
1
Hi all,

I've left Mathematica running on a set of calculations that I thought should take about 5 hours, and after 5 days I need to stop it. Is there any way I can actually extract useful information about what it's been doing? I know that I can enter a "subsession" via the panel that comes up when I enter alt +, but I'm not sure what I can actually do in this dialog.

In particular, I asked it to evaluate about 1900 integrals, depending on three parameters, and tabulate the results; is there any way I can see how far along it is, and write any of the results to a file?

Thanks.
 
Physics news on Phys.org
  • #2
In the subsession you can issue a Stack[] or Stack[somepattern] and see what is sitting in the evaluation stack. Doing that should not damage the calculation in progress, unless something goes wrong and the whole session crashes. Unfortunately, the result of Stack is often very large and doesn't seem to contain what I'm hoping for when I really really need it.

http://reference.wolfram.com/mathematica/ref/Stack.html

Roughly, in a subsession you are sitting there with all the current state, can display things that have values, can even do calculations, etc. I suggest not changing the value of any variables, but just gently peeking at things.

IF you had been carefully building up a list of results and storing that in a global variable then you can look at the value of that variable or use Stack[] to look at some calculations in progress and see the accumulated results, but if you were just constructing a large Table of results and expecting the final value of that to be what you wanted then I would give up hope.
 
  • #3
Gave up. Thanks for your reply.
 
  • #4
A couple of things you can incorporate next time:

LinkWrite[$ParentLink, SetNotebookStatusLine[
FrontEnd`EvaluationNotebook[], ToString[{n, yourmsg}]]];

where n is the n'th integral you are working on and yourmsg is optionally something helpful to keep you informed, you get the idea, will paste a little message in the lower left corner of your notebook display so you can try to tell if it is hung and where. Google
Mathematica SetNotebookStatusLine
to find examples of using this.

Do some primitive file appends during your calculation, open a file, write a "{" and then close the file. At the completion of each integral open the file, append a single expression followed by a comma to the file and then close the file. If you have to kill it then the file should not be damaged, you can manually replace the final "," with "}" outside of Mathematica and then the whole file will be a single expression that can be read back in for inspection.

You can also do more complicated things where you roughly put a time limit on a particular calculation and bail out if it takes too long. That will let you get all the reasonable results and you can try to decide what to do about the rest, but this is more advanced and you need to do some poking around to learn the technique.
 
  • #5
Thanks for your suggestions.
 

1. How can I stop Mathematica from running a calculation?

To interrupt Mathematica in the middle of a calculation, you can use the keyboard shortcut "Command + ." (for Mac) or "Control + ." (for Windows). This will immediately stop the current calculation and return you to the input prompt.

2. Will interrupting Mathematica cause me to lose my progress?

No, interrupting Mathematica will not cause you to lose any of your progress. You can resume your calculation by re-evaluating the cell or function where the interruption occurred.

3. Is there a way to automatically interrupt long-running calculations?

Yes, you can use the built-in function TimeConstrained to automatically interrupt a calculation after a specified amount of time. For example, TimeConstrained[expr, t] will interrupt the evaluation of expr after t seconds.

4. Can I set a custom keyboard shortcut for interrupting Mathematica?

Yes, you can customize your keyboard shortcuts in Mathematica by going to the "Preferences" menu, selecting "Keyboard Shortcuts", and then choosing "Add" to assign a new shortcut for the "Interrupt Evaluation" function.

5. Will interrupting Mathematica affect other calculations or programs running on my computer?

No, interrupting Mathematica will only affect the current calculation and will not interfere with other programs or calculations running on your computer.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
Replies
8
Views
1K
Back
Top