Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

problems with attach on Mac

I am having problems with attaching a file to a notebook. At first Sage cannot find cython, when I removed the python calls sage cannot find parallel. See the code fragments and error below.

The code works as written when contained in the notebook. Am I doing something worng or is this a bug?

Thank you for your help.

Mike

The code is:

... cython(""" import numpy as np import scipy as sp from scipy import linalg cimport numpy as np cdef extern from "math.h": float cosf(float theta) float sinf(float theta) def shape_calc_cy(Omega_array_stuff): Omega_array_pt = Omega_array_stuff[0] rf_shape = Omega_array_stuff[1] t_step = Omega_array_stuff[2] phi_p = Omega_array_stuff[3]

def pulse(Omega_0, omega_nut, t_p, phi_p):
    Brot = np.matrix([[0,-Omega_0,omega_nut*sinf(phi_p)],[Omega_0,0,-omega_nut*cosf(phi_p)],[-omega_nut*sinf(phi_p),omega_nut*cosf(phi_p),0]],dtype = np.complex128)
    return sp.linalg.expm(np.dot(Brot,t_p))
MPs = np.array([0,0,1],dtype = np.complexfloating)
for s in range(len(rf_shape)):
    tmp = MPs
    MPs = np.dot(pulse(Omega_array_pt, rf_shape[s], t_step, phi_p[s]),tmp)
return MPs

""") ...

The error is:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_5.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfb3JpX2N5dGhvbi5zYWdlIikgIyBBdHRhY2ggbXkgQmxvY2ggcm91dGluZXMKYXR0YWNoZWRfZmlsZXMoKQ=="),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

File "/private/var/folders/j8/d2zfx1m16zv25klkgh71rjv40000gn/T/tmpcqrA7g/___code___.py", line 3, in <module> attach ("/Users/michael/MHF_Bloch_n_Plot_ori_cython.sage") # Attach my Bloch routines File "sage/misc/lazy_import.pyx", line 389, in sage.misc.lazy_import.LazyImport.__call__ (/Users/michael/sage-7.5/src/build/cythonized/sage/misc/lazy_import.c:4007) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/attach.py", line 349, in attach load(filename, globals(), attach=True) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/load.py", line 242, in load exec(code, globals) File "/Users/michael/.sage/temp/Michaels-MBP.freystuff.com/83858/MHF_Bloch_n_Plot_ori_cython.sagemdLt2C.py", line 193, in <module> cython(""" NameError: name 'cython' is not define

The parallel code:

import multiprocessing @parallel('fork', ncpus = (multiprocessing.cpu_count())) def shape_calc(Omega_array_stuff): return shape_calc_cy(Omega_array_stuff)

The parallel error is:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_7.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfbm9fY3l0aG9uLnNhZ2UiKSAjIEF0dGFjaCBteSBCbG9jaCByb3V0aW5lcwphdHRhY2hlZF9maWxlcygp"),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

File "/private/var/folders/j8/d2zfx1m16zv25klkgh71rjv40000gn/T/tmpuKkIzm/___code___.py", line 3, in <module> attach ("/Users/michael/MHF_Bloch_n_Plot_no_cython.sage") # Attach my Bloch routines File "sage/misc/lazy_import.pyx", line 389, in sage.misc.lazy_import.LazyImport.__call__ (/Users/michael/sage-7.5/src/build/cythonized/sage/misc/lazy_import.c:4007) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/attach.py", line 349, in attach load(filename, globals(), attach=True) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/load.py", line 242, in load exec(code, globals) File "/Users/michael/.sage/temp/Michaels-MBP.freystuff.com/83858/MHF_Bloch_n_Plot_no_cython.sagesTGITt.py", line 216, in <module> @parallel('fork', ncpus = (multiprocessing.cpu_count())) NameError: name 'parallel' is not defined

problems with attach on Mac

I am having problems with attaching a file to a notebook. At first Sage cannot find cython, when I removed the python cython calls sage cannot find parallel. See the code fragments and error below.

The code works as written when contained in the notebook. Am I doing something worng wrong or is this a bug?

Thank you for your help.

Mike

The code is:

... cython(""" import numpy as np import scipy as sp from scipy import linalg cimport numpy as np cdef extern from "math.h": float cosf(float theta) float sinf(float theta) def shape_calc_cy(Omega_array_stuff): Omega_array_pt = Omega_array_stuff[0] rf_shape = Omega_array_stuff[1] t_step = Omega_array_stuff[2] phi_p = Omega_array_stuff[3]

def pulse(Omega_0, omega_nut, t_p, phi_p):
    Brot = np.matrix([[0,-Omega_0,omega_nut*sinf(phi_p)],[Omega_0,0,-omega_nut*cosf(phi_p)],[-omega_nut*sinf(phi_p),omega_nut*cosf(phi_p),0]],dtype = np.complex128)
    return sp.linalg.expm(np.dot(Brot,t_p))
MPs = np.array([0,0,1],dtype = np.complexfloating)
for s in range(len(rf_shape)):
    tmp = MPs
    MPs = np.dot(pulse(Omega_array_pt, rf_shape[s], t_step, phi_p[s]),tmp)
return MPs

""") ...

The error is:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_5.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfb3JpX2N5dGhvbi5zYWdlIikgIyBBdHRhY2ggbXkgQmxvY2ggcm91dGluZXMKYXR0YWNoZWRfZmlsZXMoKQ=="),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

File "/private/var/folders/j8/d2zfx1m16zv25klkgh71rjv40000gn/T/tmpcqrA7g/___code___.py", line 3, in <module> attach ("/Users/michael/MHF_Bloch_n_Plot_ori_cython.sage") # Attach my Bloch routines File "sage/misc/lazy_import.pyx", line 389, in sage.misc.lazy_import.LazyImport.__call__ (/Users/michael/sage-7.5/src/build/cythonized/sage/misc/lazy_import.c:4007) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/attach.py", line 349, in attach load(filename, globals(), attach=True) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/load.py", line 242, in load exec(code, globals) File "/Users/michael/.sage/temp/Michaels-MBP.freystuff.com/83858/MHF_Bloch_n_Plot_ori_cython.sagemdLt2C.py", line 193, in <module> cython(""" NameError: name 'cython' is not define

The parallel code:

import multiprocessing @parallel('fork', ncpus = (multiprocessing.cpu_count())) def shape_calc(Omega_array_stuff): return shape_calc_cy(Omega_array_stuff)

The parallel error is:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_7.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfbm9fY3l0aG9uLnNhZ2UiKSAjIEF0dGFjaCBteSBCbG9jaCByb3V0aW5lcwphdHRhY2hlZF9maWxlcygp"),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

File "/private/var/folders/j8/d2zfx1m16zv25klkgh71rjv40000gn/T/tmpuKkIzm/___code___.py", line 3, in <module> attach ("/Users/michael/MHF_Bloch_n_Plot_no_cython.sage") # Attach my Bloch routines File "sage/misc/lazy_import.pyx", line 389, in sage.misc.lazy_import.LazyImport.__call__ (/Users/michael/sage-7.5/src/build/cythonized/sage/misc/lazy_import.c:4007) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/attach.py", line 349, in attach load(filename, globals(), attach=True) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/load.py", line 242, in load exec(code, globals) File "/Users/michael/.sage/temp/Michaels-MBP.freystuff.com/83858/MHF_Bloch_n_Plot_no_cython.sagesTGITt.py", line 216, in <module> @parallel('fork', ncpus = (multiprocessing.cpu_count())) NameError: name 'parallel' is not defined

problems with attach on Mac

I am having problems with attaching a file to a notebook. At first Sage cannot find cython, when I removed the cython calls sage cannot find parallel. See the code fragments and error below.

The code works as written when contained in the notebook. Am I doing something wrong or is this a bug?

Thank you for your help.

Mike

The code is:

...
cython("""
import numpy as np
import scipy as sp
from scipy import linalg
cimport numpy as np
cdef extern from "math.h":
    float cosf(float theta)
    float sinf(float theta)
def shape_calc_cy(Omega_array_stuff):
    Omega_array_pt = Omega_array_stuff[0]
    rf_shape = Omega_array_stuff[1]
    t_step = Omega_array_stuff[2]
    phi_p = Omega_array_stuff[3]

Omega_array_stuff[3]

    def pulse(Omega_0, omega_nut, t_p, phi_p):
     Brot = np.matrix([[0,-Omega_0,omega_nut*sinf(phi_p)],[Omega_0,0,-omega_nut*cosf(phi_p)],[-omega_nut*sinf(phi_p),omega_nut*cosf(phi_p),0]],dtype = np.complex128)
     return sp.linalg.expm(np.dot(Brot,t_p))
 MPs = np.array([0,0,1],dtype = np.complexfloating)
 for s in range(len(rf_shape)):
     tmp = MPs
     MPs = np.dot(pulse(Omega_array_pt, rf_shape[s], t_step, phi_p[s]),tmp)
 return MPs
""")
...

""") ...

The error is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_5.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -- -*- coding: utf-8 --\n" -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfb3JpX2N5dGhvbi5zYWdlIikgIyBBdHRhY2ggbXkgQmxvY2ggcm91dGluZXMKYXR0YWNoZWRfZmlsZXMoKQ=="),globals())+"\n"); _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfb3JpX2N5dGhvbi5zYWdlIikgIyBBdHRhY2ggbXkgQmxvY2ggcm91dGluZXMKYXR0YWNoZWRfZmlsZXMoKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

<module> File "/private/var/folders/j8/d2zfx1m16zv25klkgh71rjv40000gn/T/tmpcqrA7g/___code___.py", line 3, in <module> attach ("/Users/michael/MHF_Bloch_n_Plot_ori_cython.sage") # Attach my Bloch routines File "sage/misc/lazy_import.pyx", line 389, in sage.misc.lazy_import.LazyImport.__call__ (/Users/michael/sage-7.5/src/build/cythonized/sage/misc/lazy_import.c:4007) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/attach.py", line 349, in attach load(filename, globals(), attach=True) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/load.py", line 242, in load exec(code, globals) File "/Users/michael/.sage/temp/Michaels-MBP.freystuff.com/83858/MHF_Bloch_n_Plot_ori_cython.sagemdLt2C.py", line 193, in <module> cython(""" NameError: name 'cython' is not define

define

The parallel code:

import multiprocessing
@parallel('fork', ncpus = (multiprocessing.cpu_count()))
def shape_calc(Omega_array_stuff):
    return shape_calc_cy(Omega_array_stuff)

shape_calc_cy(Omega_array_stuff)

The parallel error is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_7.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -- -*- coding: utf-8 --\n" -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfbm9fY3l0aG9uLnNhZ2UiKSAjIEF0dGFjaCBteSBCbG9jaCByb3V0aW5lcwphdHRhY2hlZF9maWxlcygp"),globals())+"\n"); _support_.preparse_worksheet_cell(base64.b64decode("dz13YWxsdGltZSgpCmF0dGFjaCAoIi9Vc2Vycy9taWNoYWVsL01IRl9CbG9jaF9uX1Bsb3Rfbm9fY3l0aG9uLnNhZ2UiKSAjIEF0dGFjaCBteSBCbG9jaCByb3V0aW5lcwphdHRhY2hlZF9maWxlcygp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

<module> File "/private/var/folders/j8/d2zfx1m16zv25klkgh71rjv40000gn/T/tmpuKkIzm/___code___.py", line 3, in <module> attach ("/Users/michael/MHF_Bloch_n_Plot_no_cython.sage") # Attach my Bloch routines File "sage/misc/lazy_import.pyx", line 389, in sage.misc.lazy_import.LazyImport.__call__ (/Users/michael/sage-7.5/src/build/cythonized/sage/misc/lazy_import.c:4007) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/attach.py", line 349, in attach load(filename, globals(), attach=True) File "/Users/michael/sage-7.5/local/lib/python2.7/site-packages/sage/repl/load.py", line 242, in load exec(code, globals) File "/Users/michael/.sage/temp/Michaels-MBP.freystuff.com/83858/MHF_Bloch_n_Plot_no_cython.sagesTGITt.py", line 216, in <module> @parallel('fork', ncpus = (multiprocessing.cpu_count())) NameError: name 'parallel' is not defined

defined