Message Boards Message Boards

GROUPS:

Abort time evaluation in package and report the current result

Posted 1 year ago
1018 Views
|
1 Reply
|
0 Total Likes
|

This is the same question I asked in StackExchange, I am really trying to find a solution :) https://mathematica.stackexchange.com/questions/171247/abort-time-evaluation-in-package-and-report-the-current-result

I am doing a time-dependent calculation and I would like to have the option to stop the calculation but obtain the current (last) result. Generally, I do some groundwork as what can be done before asking a question but this time I don't even know where to start. I wrote the "toy" version of my problem.

Here is the user interface that I would like to insert the "ABORT" button. and the "time-dependent" package.

Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
"AbortCal.wl"}]];

Panel[Framed[
 DynamicModule[{tfinal = 100}, 
 Column[{Style["Compute", "Subsection"] ,
 Row[{Style["Final Time ", 12, Blue], 
   InputField[Dynamic[tfinal]]}, Spacer[5]],
 Button[Style["Compute", Green, Bold], 
  Res = AbortCal`MainAbortCal[tfinal]; Plt = Res[[1]]; 
  a = Res[[2]];, Method -> "Queued"],
 Row[{Button["Stop", Interrupt[]; Print[Dynamic[a]]]}],

 Row[{Style["Plot  ", 12, Red], 
   InputField[Dynamic[Plt], FieldSize -> {50, 15}, 
    Enabled -> False, BaseStyle -> {12}]}, Spacer[15]]
     }],

 Initialization :> (
 Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
 "AbortCal.wl"}]];)], Background -> Lighter[Gray, .6]]]

And the package is

BeginPackage["AbortCal`"];
SetOptions[$FrontEnd, "ClearEvaluationQueueOnKernelQuit" -> False]

MainAbortCal::usage=" ";
Begin["`Private`"];
$MaxExtraPrecision=\[Infinity];

MainAbortCal[tfinal_]:=Module[{a},

a=ConstantArray[1, {50, 50}];

Do[a=a+1; Pause[2];,{i,tfinal}];
plta=ListPlot3D[a,ImageSize->Full];

Return[{plta,a}]];
End[];
SetAttributes[{MainAbortCal},{ReadProtected,Protected,Locked}];
SetOptions[$FrontEnd, "ClearEvaluationQueueOnKernelQuit" -> False]
EndPackage[];

Ideally I would like to get the plot but I would be happy even if I get the current "a" matrix.

Posted 11 months ago
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract