0
$\begingroup$

Is there a way to force the kernel to quit if some code runs for x seconds? Currently, I have:

TimeConstrained[
 FindMinimumCostFlow[ mat0, Join[supplyamount, demandamount]]; 
 TimeRemaining[], 1]

As above, I am using FindMinimumCostFlow and want it to abort if it runs for more than 1 second. However, this line has been running for over 30 minutes and still refuses to stop.

Does anyone have any suggestions? I also tried

TimeConstrained[
 FindMinimumCostFlow[ mat0, Join[supplyamount, demandamount]]; 
 TimeRemaining[], 1, Quit[]]

Which also doesn't work.

For some context, FindMinimuCostFlow seems to hang for seemingly random sets of parameters (with no discernible pattern). The only way to quit the evaluation is to quit the kernel (it does not respond to "Abort Evaluation"). I am trying to automate the process of quitting the kernel if the evaluation runs overtime and resetting the parameters.

$\endgroup$
3
  • $\begingroup$ Can you share a minimum example of inputs that cause the hang? $\endgroup$
    – MarcoB
    Nov 1, 2022 at 15:40
  • $\begingroup$ Sadly, I can't minimize the code easily– I am trying to compute the Earth Mover's Distance between two Gaussian functions: one being displaced from the other by 0.6 units. I am using a discretized grid of 40x40. I know that this is not too many boxes because a grid of 50x50 works fine. I would probably need to post the entire notebook. Is there a way to do that on here? $\endgroup$
    – burntclaw
    Nov 1, 2022 at 15:44
  • $\begingroup$ You can't post the notebook, but you can definitely add more code to your original question. $\endgroup$
    – MarcoB
    Nov 1, 2022 at 21:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.