Mathematica Interrupting Mathematica in mid calculation

AI Thread Summary
The discussion focuses on extracting useful information from a long-running Mathematica calculation that has exceeded its expected duration. Users can access a subsession via a specific key combination to inspect the evaluation stack using the Stack[] function, which allows them to view ongoing calculations without disrupting the process. However, the output from Stack[] can be extensive and may not provide the desired insights.To improve future calculations, suggestions include using LinkWrite to update the notebook's status line with progress messages, which can help monitor the calculation's status. Additionally, implementing file appending during calculations is recommended, allowing partial results to be saved incrementally. This method ensures that even if the process is interrupted, the data can still be retrieved and analyzed later. Advanced techniques, such as setting time limits for individual calculations, are also mentioned for managing long-running tasks effectively.
muppet
Messages
602
Reaction score
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
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
Views
2K
Replies
1
Views
2K
Replies
6
Views
4K
Replies
4
Views
3K
Replies
1
Views
9K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
2
Views
3K
Back
Top