pythonpython-3.xqutip

Why my code in not working for loops and if conditions?


I am trying to run this code in qutip. But its not showing any result. However there is not showing any error. All codes are correct and not showing any error. But don't know why the program is not execute. If anybody can resolve this problem is most welcome.

  from __future__ import division
  from qutip import *
  import pylab
  import math
  import matplotlib.pyplot as plt
  import numpy as np
  import csv
  #import plotly.plotly as py
  #from plotly.graph_objs import *
  #py.sign_in("cayayald", "zlae2s4d1i")
  #linewidth
  #gamma = 1 => fully independent
  #G = 1 => fully collective
  gamma = .25
  G = 1.0 - gamma
  #delta is detuning
  delta = -1
  deltastep = 0.1
  dlist = []
  #n is number of atoms
  n = 16
  #V is energy shiftdue to dipole-dipole
  V = 10
  #omega is rabi freq
  omega = 1.5
  omegastep = 0
  #lowering, raising, and state collapsing operators
  sigmamlist = []
  sigmaplist = []
  c_op_list =  []
  for j in range (n):
   if j==0:
   sigmajm=sigmam()
   else:
   sigmajm=qeye(2)
   for i in range (1,n):
   if j == i:
   sigmaj1= tensor(sigmam(),sigmajm)
   else:
   sigmajm = tensor(qeye(2),sigmajm)
   sigmamlist.append(sigmajm)


  coplist.append(math.sqrt(gamma)*sigmajm) #n-many indep collapse ops
  sigmajp = sigmajm.dag()
  sigmaplist.append(sigmajp)
  coplist.append(math.sqrt(G)*sum(sigmamlist)) #one collective collapse op
  #we want expectation values of operators in exoplist
  exoplist = []
  #numerator of cross correlation
  exoplist.append(sigmaplist[0]*sigmamlist[0]*sigmaplist[1]*sigmamlist[1])
  #denomenator of cross correlation
  exoplist.append(sigmaplist[0]*sigmamlist[0])
  exoplist.append(sigmaplist[1]*sigmamlist[1])

After this These codes below are not running and taking time. don't know why?

   #initial state vector
  psi0 = basis(2,0)
  for i in range(1,n):
  psi0 = tensor(psi0,basis(2,0))
  #build Hamiltonian
  g2 = []
  list = np.linspace(0,200,2000)
  ntraj = 1
  while delta <= 7:
  glist = []
  hlist = []
  vlist = []
  for i in range(n):
        hlist.append(-delta*(sigmaplist[i]*sigmamlist[i])+ (omega / 2)*(sigmaplist[i] + 
        sigmamlist[i]))
  for i in range(n):
  for j in range(i):
        vlist.append((V / (n - 1))*((sigmaplist[j]*sigmamlist[j])
   *(sigmaplist[i]*sigmamlist[i])))
   H = sum(hlist) + sum(vlist)
   #monte carlo trajectory
   montecar = mcsolve(H, psi0, tlist, coplist, exoplist, ntraj)
   for i in range(len(montecar.expect[0])):
   numerator = montecar.expect[0][i]
  denomenator = montecar.expect[1][i]
  denom2 = montecar.expect[2][i]
  glist.append(numerator/(denomenator*denom2))
  g2.append(sum(glist)/len(glist))
  dlist.append(delta)
  delta = delta + deltastep
  x = np.arange(10)
  fig = plt.figure()
  ax = plt.subplot(111)
  ax.plot(dlist, g2)
  # Shink current axis by 20%
  box = ax.get_position()
  ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
  plt.grid(True)
  plt.show()   

Solution

  • You have to use indentation, smt. like this:

    for j in range (n):
        if j==0:
            sigmajm=sigmam()
        else:
            sigmajm=qeye(2)
    
    for i in range (1,n):
        if j == i:
            sigmaj1= tensor(sigmam(),sigmajm)
        else:
            sigmajm = tensor(qeye(2),sigmajm)
            sigmamlist.append(sigmajm)
    

    Update: https://www.tutorialspoint.com/python/python_basic_syntax.htm