ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 10 Jun 2020 06:36:45 +0200Can a loop be made to skip an iteration if the run time exceeds a certain amount?https://ask.sagemath.org/question/51883/can-a-loop-be-made-to-skip-an-iteration-if-the-run-time-exceeds-a-certain-amount/I apologize if this is a little abstract, but is it possible to create some sort of "for" or "while" loop that will pass to the next iterate if the computation for that specific iterate takes too long?
For example, it could be something along the lines of, for some function/procedure
F(n)
we have
for n in range(100):
print(F(n))
but if for some n in the range, the computation of F(n) takes more than say, 1 minute CPU time, I want it to either just skip to computing F(n+1) and/or print "-1" in place of F(n).
So let's say F(0), F(1), and F(2) all take less than half a second to compute they print just fine, so then n gets set to n=3, and F(3) starts running, but let's say it runs for over a minute, I want it to be that the loop outputs "-1" (or something) and then moves on to computing F(4).
UPDATE: I'd also like to be able, if possible, to print out run times. So that the output would be something like
(F(1), time(1))
(F(2), time(2))
(F(3), times(3))
...
etc., where time(n) is the amount of time it took to compute F(n).sum8tionWed, 10 Jun 2020 06:36:45 +0200https://ask.sagemath.org/question/51883/Is there any way to have a cell tell you how long it took to run in the Jupyter notebook?https://ask.sagemath.org/question/47269/is-there-any-way-to-have-a-cell-tell-you-how-long-it-took-to-run-in-the-jupyter-notebook/ The question is basically all in the title. I'm working on a project in the Jupyter and notebook, and I have some cells that have longer run times. Sometimes I let these run, and come back to check on them later, however it would be nice to know exactly what duration those cells ran for.sum8tionFri, 26 Jul 2019 23:31:17 +0200https://ask.sagemath.org/question/47269/Execution time vs. Computation time in MILPhttps://ask.sagemath.org/question/30495/execution-time-vs-computation-time-in-milp/ Hi,
I am using GLPK in Sage 6.9 to solve MILP problem. I am also using the `Solver_parameter('timelimit')` to terminate the problem after the specficied time. According to [SageMath documentation](http://doc.sagemath.org/html/en/reference/numerical/sage/numerical/mip.html), `"timelimit" defines the maximum time spent on a computation. Measured in seconds.` However, I am a bit confused with this definition. This is because:
I am solving `the same problem` with `the same timelimit value` for `different input values (generated randomly using uniform distribution)` while I was printing `execution time` of each. I have noticed `different execution times` when I am giving `different inputs` (ranging from 1min, 5mins, to even 10mins).
Can some one please tell me how the `computation time` is calculated for timelimit? Why they are different even though I used the same problem with the same timelimit? Is it something related to the size of the input, as its only difference between them? Is there any relation between `computation` and `execution` times?
Cheers,
Aissan
Aissan DalvandiFri, 06 Nov 2015 03:24:44 +0100https://ask.sagemath.org/question/30495/