Indentation problem

13 views
Skip to first unread message

Imran Mirza

unread,
Apr 18, 2017, 11:14:05 PM4/18/17
to QuTiP: Quantum Toolbox in Python
Hi all,

I am trying to run a QuTip code which I am using from a reference Thesis. Unfortunately while putting the code in the thesis the author has not taken care of correct Indentation. Therefore I am getting indentation errors when I run this code in QuTip. Since I have just started to use QuTip (and Python) therefore can someone correct the indentation in the following code? I'll highly appreciate the help.
Thanks!

********************************************************************************************
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 = []
coplist = []
for j in range (n):
if j==0:
sigmajm = sigmam()
else:
sigmajm = qeye(2)
for i in range (1,n):
if j==i:
sigmajm = 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])
#initial state vector
psi0 = basis(2,0)
for i in range(1,n):
psi0 = tensor(psi0,basis(2,0))
#build Hamiltonian
g2 = []
tlist = 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, label='g_c=' +str(G)+ '')
# 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)
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
ax.tick_params(axis='x', labelsize=15)
ax.tick_params(axis='y', labelsize=15)
# Put a legend to the right of the current axis
ax.legend(loc=10, prop={'size':12}, bbox_to_anchor=(0.1, 0.5))
#ax.set_yscale('log')
plt.title('g2 with n=' +str(n)+'')
plt.xlabel('Detuning', size='x-large')
plt.ylabel('Intensity', size='x-large')
plt.show()

********************************************************************************************

Alex Pitchford

unread,
Apr 19, 2017, 5:52:21 AM4/19/17
to qu...@googlegroups.com
Hi Imran,

In Python everything inside a for loop must be indented. Also inside if else statements. Assuming that you also need to understand what this code is suppose to do, then I think you should be able to work it out. 

From a quick scan I would say about half of it needs to be indented at least once. The standard single indent is 4 spaces. If you use some IDE like Spyder, then tab will automatically be converted to 4 spaces.

Have a go and see how you get on. If it's still not producing the results you expect, then post your attempt, and I will happily try and make suggestions.

Alex



--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Imran Mirza

unread,
Apr 19, 2017, 10:52:16 AM4/19/17
to qu...@googlegroups.com
Hi Alex,

Thanks so much for your reply. I'll give a try to fix indentation issues and will let you know if the problem persisted.

Thanks again and Best,
Imran

--
You received this message because you are subscribed to a topic in the Google Groups "QuTiP: Quantum Toolbox in Python" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/qutip/p7LvI6twIj0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to qutip+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages