In [1]:
import cutiepy
cutiepy.interactive.INTERACTIVE = False
cutiepy.operators.SPARSITY_N_CUTOFF = 6

import qutip
qutip_rhs_reuse = True

import numpy as np
import scipy
%matplotlib inline
import matplotlib.pyplot as plt

n_small_cutoffs = list(range(  7,  14     ))
n_med_cutoffs   = list(range( 10, 100,  10))
n_big_cutoffs   = list(range(100, 600, 100))
ns = [n_small_cutoffs, n_med_cutoffs, n_big_cutoffs]
periods = [100, 10, 1]

def cutiepy_sym_state(n):
    return cutiepy.Ket.anon([n], np.ones((n,1), dtype=complex)/n**0.5)

def qutip_sym_state(n):
    return qutip.Qobj(np.ones((n,1), dtype=complex)/n**0.5)

from timeit import repeat

setup = '''
import cutiepy
cutiepy.interactive.INTERACTIVE = False
cutiepy.operators.SPARSITY_N_CUTOFF = 6

import qutip
qutip_rhs_reuse = True

import numpy as np
import scipy

def cutiepy_sym_state(n):
    return cutiepy.Ket.anon([n], np.ones((n,1), dtype=complex)/n**0.5)
def qutip_sym_state(n):
    return qutip.Qobj(np.ones((n,1), dtype=complex)/n**0.5)
'''

def parametric_timeit(ex_, setup_, params):
    res = []
    for _ns, _p in zip(ns, params):
        _res = []
        for _n in _ns:
            print('\r p=%d, n=%d'%(_p,_n), end='', flush=True)
            _r = repeat(ex_, setup+setup_.format(param=_p, N_cutoff=_n),repeat=5,number=1)
            _res.append(_r)
        res.append(_res)
    print('\r Done!')
    return res

def plot_times(datas, labels):
    datas = [[np.array([sorted(_runs) for _runs in _vsn]) for _vsn in data]
             for data in datas]
    plt.figure(figsize=(14,3))
    for data in datas:
        plt.subplot(1,3,1)
        plt.plot(n_small_cutoffs, data[0][:,0], 'o')
        plt.subplot(1,3,2)
        plt.plot(n_med_cutoffs, data[1][:,0], 'o')
        plt.subplot(1,3,3)
        plt.plot(n_big_cutoffs, data[2][:,0], 'o')
    plt.subplot(1,3,1)
    plt.ylabel('seconds')
    plt.xlabel('problem dimension')
    plt.title('%d periods'%periods[0])
    plt.subplot(1,3,2)
    plt.title('%d periods'%periods[1])
    plt.subplot(1,3,3)
    plt.legend(labels, loc=2)
    plt.title('%d period'%periods[2])

Time independent


In [2]:
setup_q = '''
ts = np.linspace(0,{param}*np.pi,{param}*10)
init = qutip_sym_state({N_cutoff})
H = qutip.num({N_cutoff})
opt = qutip.Options(rhs_reuse=qutip_rhs_reuse, nsteps=1000*{N_cutoff})
'''
ex_q = '''
res = qutip.sesolve(H,init,ts,[], options=opt)
'''

HARM_OSC_SYM_STATE_qutip = parametric_timeit(ex_q, setup_q, periods)


 Done!

In [3]:
setup_c = '''
ts = np.linspace(0,{param}*np.pi,{param}*10)
init = cutiepy_sym_state({N_cutoff})
H = cutiepy.num({N_cutoff})
mxsteps = 1000*{N_cutoff}
'''
ex_c = '''
res = cutiepy.sesolve(H,init,ts, mxsteps=mxsteps)
'''

HARM_OSC_SYM_STATE_cutiepy = parametric_timeit(ex_c, setup_c, periods)


 Done!

In [4]:
plot_times([HARM_OSC_SYM_STATE_cutiepy, HARM_OSC_SYM_STATE_qutip], ['cutiepy', 'qutip'])


Time dependent


In [42]:
setup_q = '''
ts = np.linspace(0,{param}*np.pi/10,{param}*10)
init = qutip_sym_state({N_cutoff})
H0 = qutip.zero_oper({N_cutoff})
H = qutip.num({N_cutoff})
tdep = 't/({param}*np.pi)'
opt = qutip.Options(rhs_reuse=qutip_rhs_reuse, nsteps=1000*{N_cutoff})
'''
ex_q = '''
res = qutip.mesolve([H0,[H,tdep]],init,ts,[],[], options=opt)
'''

HARM_OSC_RAMP_SYM_STATE_qutip = parametric_timeit(ex_q, setup_q, periods)


 Done!

In [2]:
setup_c = '''
ts = np.linspace(0,{param}*np.pi/10,{param}*10)
init = cutiepy_sym_state({N_cutoff})
H = cutiepy.num({N_cutoff})*cutiepy.t/({param}*np.pi)
mxsteps = 1000*{N_cutoff}
'''
ex_c = '''
res = cutiepy.mesolve(H,[],init,ts, mxsteps=mxsteps)
'''

HARM_OSC_RAMP_SYM_STATE_cutiepy = parametric_timeit(ex_c, setup_c, periods)


 p=100, n=7
Error compiling Cython file:
------------------------------------------------------------
...
            E[i,j] = 0.0031830988618379067*A*D[i,j]
    # G = C.F
    ii = C.shape[0]
    jj = C.shape[1]
    kk = F.shape[1]
    zgemm('N', 'N', &kk, &ii, &jj, &zONE, &F[0,0], &kk, &C[0,0], &jj, &zZERO, &G[0,0], &kk)
                                              ^
------------------------------------------------------------

cutiepy_tmp_d_mjvb1g.pyx:63:47: Too many indices specified for type double complex[:]

Error compiling Cython file:
------------------------------------------------------------
...
            E[i,j] = 0.0031830988618379067*A*D[i,j]
    # G = C.F
    ii = C.shape[0]
    jj = C.shape[1]
    kk = F.shape[1]
    zgemm('N', 'N', &kk, &ii, &jj, &zONE, &F[0,0], &kk, &C[0,0], &jj, &zZERO, &G[0,0], &kk)
                                                                                  ^
------------------------------------------------------------

cutiepy_tmp_d_mjvb1g.pyx:63:83: Too many indices specified for type double complex[:]

Error compiling Cython file:
------------------------------------------------------------
...
    # H = -0.0031830988618379067*A*G
    ii = G.shape[0]
    jj = G.shape[1]
    for i in range(ii):
        for j in range(jj):
            H[i,j] = -0.0031830988618379067*A*G[i,j]
                                                  ^
------------------------------------------------------------

cutiepy_tmp_d_mjvb1g.pyx:69:51: Too many indices specified for type double complex[:]

Error compiling Cython file:
------------------------------------------------------------
...
    # H = -0.0031830988618379067*A*G
    ii = G.shape[0]
    jj = G.shape[1]
    for i in range(ii):
        for j in range(jj):
            H[i,j] = -0.0031830988618379067*A*G[i,j]
                ^
------------------------------------------------------------

cutiepy_tmp_d_mjvb1g.pyx:69:17: Too many indices specified for type double complex[:]

Error compiling Cython file:
------------------------------------------------------------
...
    # I = E+H
    ii = E.shape[0]
    jj = E.shape[1]
    for i in range(ii):
        for j in range(jj):
            I[i,j] = E[i,j]+H[i,j]
                                ^
------------------------------------------------------------

cutiepy_tmp_d_mjvb1g.pyx:75:33: Too many indices specified for type double complex[:]

Error compiling Cython file:
------------------------------------------------------------
...
    # I = E+H
    ii = E.shape[0]
    jj = E.shape[1]
    for i in range(ii):
        for j in range(jj):
            I[i,j] = E[i,j]+H[i,j]
                ^
------------------------------------------------------------

cutiepy_tmp_d_mjvb1g.pyx:75:17: Too many indices specified for type double complex[:]

Error compiling Cython file:
------------------------------------------------------------
...
    # J = -1j*I
    ii = I.shape[0]
    jj = I.shape[1]
    for i in range(ii):
        for j in range(jj):
            J[i,j] = -1j*I[i,j]
                             ^
------------------------------------------------------------

cutiepy_tmp_d_mjvb1g.pyx:81:30: Too many indices specified for type double complex[:]

Error compiling Cython file:
------------------------------------------------------------
...
    # J = -1j*I
    ii = I.shape[0]
    jj = I.shape[1]
    for i in range(ii):
        for j in range(jj):
            J[i,j] = -1j*I[i,j]
                ^
------------------------------------------------------------

cutiepy_tmp_d_mjvb1g.pyx:81:17: Too many indices specified for type double complex[:]

Error compiling Cython file:
------------------------------------------------------------
...
    void cvsi_destroy(cvsi_instance *instance)

cdef inline void RHS(double t, double *y, double *ydot):
    generated_function(t,
                       <double complex [:7, :7]> <double complex *> y,
                       <double complex [:7, :7]> <double complex *> ydot)
                      ^
------------------------------------------------------------

cutiepy_tmp_d_mjvb1g.pyx:114:23: Memoryview 'double complex[:, ::1]' not conformable to memoryview 'double complex[:]'.
---------------------------------------------------------------------------
DistutilsExecError                        Traceback (most recent call last)
/usr/lib/python3.4/distutils/unixccompiler.py in _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts)
    115             self.spawn(compiler_so + cc_args + [src, '-o', obj] +
--> 116                        extra_postargs)
    117         except DistutilsExecError as msg:

/usr/lib/python3.4/distutils/ccompiler.py in spawn(self, cmd)
    908     def spawn(self, cmd):
--> 909         spawn(cmd, dry_run=self.dry_run)
    910 

/usr/lib/python3.4/distutils/spawn.py in spawn(cmd, search_path, verbose, dry_run)
     35     if os.name == 'posix':
---> 36         _spawn_posix(cmd, search_path, dry_run=dry_run)
     37     elif os.name == 'nt':

/usr/lib/python3.4/distutils/spawn.py in _spawn_posix(cmd, search_path, verbose, dry_run)
    161                           "command %r failed with exit status %d"
--> 162                           % (cmd, exit_status))
    163             elif os.WIFSTOPPED(status):

DistutilsExecError: command 'x86_64-linux-gnu-gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

CompileError                              Traceback (most recent call last)
<ipython-input-2-6e1808a02888> in <module>()
      9 '''
     10 
---> 11 HARM_OSC_RAMP_SYM_STATE_cutiepy = parametric_timeit(ex_c, setup_c, periods)

<ipython-input-1-d859219ab1aa> in parametric_timeit(ex_, setup_, params)
     48         for _n in _ns:
     49             print('\r p=%d, n=%d'%(_p,_n), end='', flush=True)
---> 50             _r = repeat(ex_, setup+setup_.format(param=_p, N_cutoff=_n),repeat=5,number=1)
     51             _res.append(_r)
     52         res.append(_res)

/usr/lib/python3.4/timeit.py in repeat(stmt, setup, timer, repeat, number)
    216            repeat=default_repeat, number=default_number):
    217     """Convenience function to create Timer object and call repeat method."""
--> 218     return Timer(stmt, setup, timer).repeat(repeat, number)
    219 
    220 def main(args=None, *, _wrap_timer=None):

/usr/lib/python3.4/timeit.py in repeat(self, repeat, number)
    204         r = []
    205         for i in range(repeat):
--> 206             t = self.timeit(number)
    207             r.append(t)
    208         return r

/usr/lib/python3.4/timeit.py in timeit(self, number)
    176         gc.disable()
    177         try:
--> 178             timing = self.inner(it, self.timer)
    179         finally:
    180             if gcold:

/usr/lib/python3.4/timeit.py in inner(_it, _timer)

/home/stefan/python_lab/cutiepy/cutiepy/solver.py in mesolve(H, c_ops, state0, tlist, mxsteps, rtol, atol)
     40                          argument_order = [t, y_anon])
     41     iprint('Compiling cython code...')
---> 42     ccf = cf.compiled()
     43     state0_dim = dims(state0)
     44     state0_dense_array = numerical(evalf(state0))

/home/stefan/python_lab/cutiepy/cutiepy/codegen.py in compiled(self)
    170                     module_path = pyx_to_dll(filename, ext=self._extension)
    171                 except Exception as e:
--> 172                     raise e
    173                 finally:
    174                     os.remove(os.path.join(folder, extname+'.c'))

/home/stefan/python_lab/cutiepy/cutiepy/codegen.py in compiled(self)
    168                             )
    169                 try:
--> 170                     module_path = pyx_to_dll(filename, ext=self._extension)
    171                 except Exception as e:
    172                     raise e

/home/stefan/python_lab/lib/python3.4/site-packages/pyximport/pyxbuild.py in pyx_to_dll(filename, ext, force_rebuild, build_in_temp, pyxbuild_dir, setup_args, reload_support, inplace)
     98     try:
     99         obj_build_ext = dist.get_command_obj("build_ext")
--> 100         dist.run_commands()
    101         so_path = obj_build_ext.get_outputs()[0]
    102         if obj_build_ext.inplace:

/usr/lib/python3.4/distutils/dist.py in run_commands(self)
    953         """
    954         for cmd in self.commands:
--> 955             self.run_command(cmd)
    956 
    957     # -- Methods that operate on its Commands --------------------------

/usr/lib/python3.4/distutils/dist.py in run_command(self, command)
    972         cmd_obj = self.get_command_obj(command)
    973         cmd_obj.ensure_finalized()
--> 974         cmd_obj.run()
    975         self.have_run[command] = 1
    976 

/home/stefan/python_lab/lib/python3.4/site-packages/Cython/Distutils/build_ext.py in run(self)
    161             optimization.disable_optimization()
    162 
--> 163         _build_ext.build_ext.run(self)
    164 
    165     def build_extensions(self):

/usr/lib/python3.4/distutils/command/build_ext.py in run(self)
    337 
    338         # Now actually compile and link everything.
--> 339         self.build_extensions()
    340 
    341     def check_extensions_list(self, extensions):

/home/stefan/python_lab/lib/python3.4/site-packages/Cython/Distutils/build_ext.py 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):

/usr/lib/python3.4/distutils/command/build_ext.py in build_extension(self, ext)
    501                                          debug=self.debug,
    502                                          extra_postargs=extra_args,
--> 503                                          depends=ext.depends)
    504 
    505         # XXX -- this is a Vile HACK!

/usr/lib/python3.4/distutils/ccompiler.py 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.

/usr/lib/python3.4/distutils/unixccompiler.py in _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts)
    116                        extra_postargs)
    117         except DistutilsExecError as msg:
--> 118             raise CompileError(msg)
    119 
    120     def create_static_lib(self, objects, output_libname,

CompileError: command 'x86_64-linux-gnu-gcc' failed with exit status 1

In [46]:
plot_times([HARM_OSC_RAMP_SYM_STATE_cutiepy, HARM_OSC_RAMP_SYM_STATE_qutip], ['cutiepy', 'qutip'])



In [ ]: