In [1]:
from cutiepy import *
import numpy as np
N = 4
cutiepy.operators.SPARSITY_N_CUTOFF = max(cutiepy.operators.SPARSITY_N_CUTOFF, N+1)

op1 = randomH(N)
op2 = randomH(N)
op3 = randomH(N)
op4 = randomH(N)
id = identity(N)
a = destroy(N)
ad = create(N)

y_anon = Ket.anon(N)
def compile_and_test(op):
    print('Generating code...', flush=True)
    cf = generate_cython(evalf(op*y_anon),         
                         func=NDArrayFunction(),            
                         argument_order = [t,y_anon])
    print('Compiling code...', flush=True)
    ccf = cf.compiled()
    print('Executing...', flush=True)
    return ccf.pythoncall(1, 1j*np.random.random([N,1]))

In [2]:
opA = op1+t**2*op2
compile_and_test( opA )


Generating code...
Compiling code...
Executing...
Out[2]:
array([[ 0.39220584+1.50986594j],
       [ 0.44567630+1.12454048j],
       [-0.25913388+1.65840452j],
       [-0.22000740+1.79391584j]])

In [3]:
opB = op3+sin(2*t+1)*op4
compile_and_test( opA*opB )


Generating code...
Compiling code...
Executing...
Out[3]:
array([[ 0.87901682+6.53269267j],
       [ 0.61676963+4.74113624j],
       [-1.03019657+5.51961716j],
       [-1.04746180+6.49085124j]])

In [4]:
opC = opA*opB**3
compile_and_test( opC )


Generating code...
Compiling code...
Executing...
Out[4]:
array([[ 10.68751240+53.18384143j],
       [  5.65960234+38.63249045j],
       [ -7.85495684+43.35971249j],
       [ -7.08511521+51.14608402j]])

In [5]:
opD = Commutator(opA, opC)
compile_and_test( opD )


Generating code...
Compiling code...
Executing...
Out[5]:
array([[ 8.66382188 +4.63132334j],
       [ 8.57670763 +8.03356004j],
       [-1.51521564 +8.51919037j],
       [ 1.49904262+12.87144706j]])

In [6]:
opE = cutiepy.symbolic._CG_AppliedLindbladSuperoperator(evalf(opD), evalf(opB))
compile_and_test( opE )


Generating code...
Compiling code...
Executing...
Out[6]:
array([[ 1331.55685158 +129.39942676j],
       [ 1919.56873767-1017.09648145j],
       [ -989.00460167 -620.27003444j],
       [-1062.40809049+2472.29812356j]])

In [7]:
opF = 2*opE
compile_and_test( opF )


Generating code...
Compiling code...
Executing...
Out[7]:
array([[ 2510.53655097 +279.64113049j],
       [ 3745.57415777-2317.49873757j],
       [-2135.18048374-1685.48702959j],
       [-2988.40268042+5211.05186236j]])