Interrupting Mathematica in mid calculation

  • Context: Mathematica 
  • Thread starter Thread starter muppet
  • Start date Start date
  • Tags Tags
    Calculation Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the challenges of interrupting a long-running Mathematica calculation and extracting useful information from it. Participants explore methods to monitor progress and save results during extensive computations, particularly involving the evaluation of multiple integrals.

Discussion Character

  • Technical explanation, Exploratory, Debate/contested

Main Points Raised

  • One participant inquires about extracting information from a Mathematica session that has been running for an extended period, specifically regarding the evaluation of 1900 integrals.
  • Another participant suggests using the Stack[] function in a subsession to view the evaluation stack, noting that it may not provide the desired information and could be large.
  • A later reply offers practical tips for future calculations, including using LinkWrite to display progress messages and appending results to a file incrementally to avoid data loss if the session is terminated.
  • There is mention of implementing a time limit for calculations to manage long-running processes more effectively, although this is described as a more advanced technique.
  • Areas of Agreement / Disagreement

    Participants share various strategies for managing long calculations, but there is no consensus on the effectiveness of these methods or their applicability to the specific situation described.

    Contextual Notes

    Limitations include the uncertainty of what information can be extracted from the evaluation stack and the potential for large outputs that may not be useful. The discussion also highlights the dependency on how results are stored during the computation.

muppet
Messages
602
Reaction score
0
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
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.
 
Gave up. Thanks for your reply.
 
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.
 
Thanks for your suggestions.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K