Bug? Cython & complex number multiplication

80 views
Skip to first unread message

zmi...@gmail.com

unread,
Aug 5, 2015, 5:44:59 PM8/5/15
to QuTiP: Quantum Toolbox in Python
I am seeing a problem in using complex numbers in the cython code. Here is a simple code that generates the error:

from qutip import *;

sm = destroy(2);
H = [0*identity(2), [sm, '1j*Omega']]
args = {'Omega':2*pi*1}
res = mesolve(H, basis(2,1), np.linspace(0,10,100), [], [sm.dag()*sm], args = args)


If I have '1j+Omega' things works ok, but with the multiplication sign they do not, also with a division sign. 
Alternatively I removed the 1j from string and put it in the args, however this also failed. 

Can you please help? This is important for doing time dependent problems involving things like  exp(1j*Omega*t)

I believe I am up to date on the packets:
QuTiP Version:      3.1.0
Numpy Version:      1.9.2
Scipy Version:      0.15.1
Cython Version:     0.21
Matplotlib Version: 1.4.2
Fortran mcsolver:   False
scikits.umfpack:    False
Python Version:     2.7.9
Platform Info:      Darwin (x86_64)
Installation path:  /Users/zlatko/anaconda/lib/python2.7/site-packages/qutip



Here is the full error:
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-342-c606dc238672> in <module>()
      3 H = [0*identity(2), [sm, '1j*Omega+1j']]
      4 args = {'Omega':2*pi*1}
----> 5 res = mesolve(H, basis(2,1), np.linspace(0,10,100), [], [sm.dag()*sm], args = args)
      6 plt.plot(res.expect[0])

/Users/zlatko/anaconda/lib/python2.7/site-packages/qutip/mesolve.pyc in mesolve(H, rho0, tlist, c_ops, e_ops, args, options, progress_bar)
    315         elif n_str > 0:
    316             res = _sesolve_list_str_td(H, rho0, tlist,
--> 317                                        e_ops, args, options, progress_bar)
    318         elif isinstance(H, (types.FunctionType,
    319                             types.BuiltinFunctionType, partial)):

/Users/zlatko/anaconda/lib/python2.7/site-packages/qutip/sesolve.pyc in _sesolve_list_str_td(H_list, psi0, tlist, e_ops, args, opt, progress_bar)
    388         code = compile('from ' + config.tdname + ' import cy_td_ode_rhs',
    389                        '<string>', 'exec')
--> 390         exec(code, globals())
    391         config.tdfunc = cy_td_ode_rhs
    392 

/Users/zlatko/anaconda/lib/python2.7/site-packages/qutip/sesolve.pyc in <module>()

/Users/zlatko/anaconda/lib/python2.7/site-packages/pyximport/pyximport.pyc in load_module(self, fullname)
    429                                  self.pyxbuild_dir,
    430                                  build_inplace=self.inplace,
--> 431                                  language_level=self.language_level)
    432         return module
    433 

/Users/zlatko/anaconda/lib/python2.7/site-packages/pyximport/pyximport.pyc in load_module(name, pyxfilename, pyxbuild_dir, is_package, build_inplace, language_level, so_path)
    207                 module_name = name
    208             so_path = build_module(module_name, pyxfilename, pyxbuild_dir,
--> 209                                    inplace=build_inplace, language_level=language_level)
    210         mod = imp.load_dynamic(name, so_path)
    211         if is_package and not hasattr(mod, '__path__'):

/Users/zlatko/anaconda/lib/python2.7/site-packages/pyximport/pyximport.pyc in build_module(name, pyxfilename, pyxbuild_dir, inplace, language_level)
    184                                   setup_args=sargs,
    185                                   inplace=inplace,
--> 186                                   reload_support=pyxargs.reload_support)
    187     assert os.path.exists(so_path), "Cannot find: %s" % so_path
    188 

/Users/zlatko/anaconda/lib/python2.7/site-packages/pyximport/pyxbuild.pyc in pyx_to_dll(filename, ext, force_rebuild, build_in_temp, pyxbuild_dir, setup_args, reload_support, inplace)
     96     try:
     97         obj_build_ext = dist.get_command_obj("build_ext")
---> 98         dist.run_commands()
     99         so_path = obj_build_ext.get_outputs()[0]
    100         if obj_build_ext.inplace:

/Users/zlatko/anaconda/lib/python2.7/distutils/dist.pyc in run_commands(self)
    951         """
    952         for cmd in self.commands:
--> 953             self.run_command(cmd)
    954 
    955     # -- Methods that operate on its Commands --------------------------

/Users/zlatko/anaconda/lib/python2.7/distutils/dist.pyc in run_command(self, command)
    970         cmd_obj = self.get_command_obj(command)
    971         cmd_obj.ensure_finalized()
--> 972         cmd_obj.run()
    973         self.have_run[command] = 1
    974 

/Users/zlatko/anaconda/lib/python2.7/site-packages/Cython/Distutils/build_ext.pyc in run(self)
    161             optimization.disable_optimization()
    162 
--> 163         _build_ext.build_ext.run(self)
    164 
    165     def build_extensions(self):

/Users/zlatko/anaconda/lib/python2.7/distutils/command/build_ext.pyc in run(self)
    335 
    336         # Now actually compile and link everything.
--> 337         self.build_extensions()
    338 
    339     def check_extensions_list(self, extensions):

/Users/zlatko/anaconda/lib/python2.7/site-packages/Cython/Distutils/build_ext.pyc in build_extensions(self)
    169         for ext in self.extensions:
    170             ext.sources = self.cython_sources(ext.sources, ext)
--> 171             self.build_extension(ext)
    172 
    173     def cython_sources(self, sources, extension):

/Users/zlatko/anaconda/lib/python2.7/distutils/command/build_ext.pyc in build_extension(self, ext)
    494                                          debug=self.debug,
    495                                          extra_postargs=extra_args,
--> 496                                          depends=ext.depends)
    497 
    498         # XXX -- this is a Vile HACK!

/Users/zlatko/anaconda/lib/python2.7/distutils/ccompiler.pyc in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends)
    572             except KeyError:
    573                 continue
--> 574             self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
    575 
    576         # Return *all* object filenames, not just the ones we just built.

/Users/zlatko/anaconda/lib/python2.7/distutils/unixccompiler.pyc in _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts)
    120                        extra_postargs)
    121         except DistutilsExecError, msg:
--> 122             raise CompileError, msg
    123 
    124     def create_static_lib(self, objects, output_libname,

ImportError: Building module rhs4603204 failed: ["CompileError: command 'gcc' failed with exit status 1\n"]


Paul Nation

unread,
Aug 5, 2015, 8:04:41 PM8/5/15
to qu...@googlegroups.com
Download the latest development version on Github.  It should work for you.

Paul

fbe...@gmail.com

unread,
Nov 17, 2015, 5:18:45 PM11/17/15
to QuTiP: Quantum Toolbox in Python, zmi...@gmail.com
I am experiencing the same problem right now. Is it necessary to download the development version to fix this ? I think it is very important that QuTiP be able to solve Hamiltonians with functions of the forme exp(i w t), since any driven system will have this kind of contribution. It is not always possible to eliminate these contributions by going into a rotating frame.

Paul Nation

unread,
Nov 17, 2015, 6:31:49 PM11/17/15
to QuTiP Group

Yep, get the developer version.

Paul

--
You received this message because you are subscribed to the Google Groups "QuTiP: Quantum Toolbox in Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qutip+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages