ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 22 Apr 2020 06:09:34 -0500@fork decorator with try/except on different platforms, not executing except clausehttp://ask.sagemath.org/question/50912/fork-decorator-with-tryexcept-on-different-platforms-not-executing-except-clause/ I am having problems using the **@fork** decorator with a try & except clause. On SageMathCell the piece of code runs fine, whereas on both Jupyter and CoCalc it doesn't throw the exception clause properly. On CoCalc it didn't recognise the **@fork** decorator at all at first, but `from sage.all import *` (idea from question: "@fork decorator not recognized in script") seemed to help.
**Piece of code:**
from sage.all import * #for CoCalc
a_0,a_1 = var('a_0,a_1');s = [a_0,a_1]
equations = [69*a_0 + 4556 == 69*a_0 + 63*a_1, 69*a_1 - 3350 == -67*a_0 + 57*a_1, 63*a_0 - 3876 == -1542, 63*a_1 + 2850 == 7406]
try:
@fork(timeout=0.1, verbose=True) #use e.g. 0.1 and 10
def DirectSolution():
sage_solution = solve(equations, s , solution_dict=True)
print('Solves in time ,','sage_solution:',sage_solution)
return sage_solution
sage_solution = DirectSolution()[0]
except KeyboardInterrupt:
sage_solution = []
print('Takes too long , ','sage_solution:',sage_solution)
print('Execute the rest of the code, ','sage_solution:',sage_solution)
Running the @fork decorator without try/except with 0.1 seconds I got the `KeyboardInterrupt` error, that's why I used it in the except clause. Shouldn't this exception usually be "raised when the user hits the interrupt key" ?
- As mentioned above, on SageMathCell
the code works as intended:
With 10 seconds it computes the
solution and prints out the text. For
0.1 seconds it sets
`sage_solution = []` and prints out
the text.
- However, both on Jupyter and CoCalc it doesn't use the exception properly for 0.1 seconds.
I get the following message:
`Killing subprocess 1346 with input ((), {}) which took too long`
`Execute the rest of the code, sage_solution: N`
Meaning it didn't execute the except clause:
`sage_solution = []`
`print('Takes too long , ','sage_solution:',sage_solution)`
I am not sure what to look for here, because it is working on one platform. A simple try/except example worked fine. Another idea was that the `KeyboardInterrupt` could be the problem, but removing it didn't change anything.
I am new to Sage/Python, so there probably is a simple solution but I am happy for any help given. Unfortunately my karma was insufficient to publish links.RikWed, 22 Apr 2020 06:09:34 -0500http://ask.sagemath.org/question/50912/Sage Cloud & Parallel processinghttp://ask.sagemath.org/question/10659/sage-cloud-parallel-processing/Hi experts!
I wanna use multiprocessing using 288 cores of SageCloud for my Monte Carlo algorithm.
Is that possible?
My algorithm is like this:
import numpy as np
experiments=1000
sticks= np.array(range(1,1000,1))
def function_1():
funciton_1...
def function_2():
funciton_2...
for n in sticks:
for u range(experiments):
algorithm is executed and a number 'jjjj' is geretaed and saved in array 'numbers jjjj'.
all values in array 'numbers jjjj' are averaged and saved in array 'numbers for each stick'
the array 'numpers for each stick' is saved as .cvs
In the possitive case: I dont know how to incorporate `@parallel` decorator in my script.
Please help!
Thanks a lotmresimulatorSat, 26 Oct 2013 03:55:46 -0500http://ask.sagemath.org/question/10659/@fork decorator not recognized in scripthttp://ask.sagemath.org/question/10628/fork-decorator-not-recognized-in-script/I'm trying to run a test script with the @fork decorator, but it isn't being recognized. The script looks like this:
#!/home/raltman/sage-5.10/sage
@fork
def f(a):
return a;
out=f("hi");
print out;
When I run this, I get the following error message:
> Traceback (most recent call last):
> File "/home/raltman/test.sage", line
> 3, in <module>
>
>@fork
>
>NameError: name 'fork' is not defined
The same code works when I run it in the sage console, and the script itself works without the @fork decorator. I'd really appreciate any help on this!R AltmanFri, 18 Oct 2013 23:42:38 -0500http://ask.sagemath.org/question/10628/Use @profile decorator in my scripthttp://ask.sagemath.org/question/10458/use-profile-decorator-in-my-script/Hi experts!!
I write a script like this:
from scipy.stats import uniform
import numpy as np
print ('lalala')
LALA=[1,2,3,4,5]
for j in LALA:
algorithm (numpya arrays and other for and while cycles are invololved)
I have a RAM issue and i want to use @profile decorator. I install this for https://pypi.python.org/pypi/memory_profiler doing:
$ easy_install -U memory_profiler # pip install -U memory_profiler
But when i write @profile in the start of the code and then I execute this, i get a ERROR.
How can I do for use the @profile (and others) decoretor?
Waiting for your answers.
Thanks a lot!mresimulatorMon, 19 Aug 2013 15:26:39 -0500http://ask.sagemath.org/question/10458/