def calc_q_mean(S_list, i, j): ''' ''' global dims global Weyl global r_list, t_list q_mean_list = [] for w in range(nfreq): s = S_list[i, j][3 * w:3 * w + 3] Q = scat.calc_Q(s, dk)[0] qlist = ut.sort_eig(Q)[0] r = r_list[i, 3 * w:3 * w + 3, j, 0:dims[w], 0:dims[w]] t = t_list[i, 3 * w:3 * w + 3, j, 0:dims[w], 0:dims[w]] Q_eigstates = (ut.sort_eig(Q)[1].T) # qmax = np.sum( # np.absolute(np.dot(r[1], state_max))**2 * \ # ( np.angle(np.dot(r[2], state_max)) - np.angle(np.dot(r[0], state_max)) ) / (2*dk) +\ # np.absolute(np.dot(t[1], state_max))**2 * \ # ( np.angle(np.dot(t[2], state_max)) - np.angle(np.dot(t[0], state_max)) ) / (2*dk) # ) for n, state in enumerate(Q_eigstates): qman = np.sum( np.absolute(np.dot(s[1], state))**2 * \ ( np.angle(np.dot(s[2], state)) - np.angle(np.dot(s[0], state)) ) / (2*dk) ) #print np.shape(t[2]), np.shape(t[0]), np.shape(state), np.shape(state[0:dims[w]]), tran = (np.linalg.norm(np.dot(t[0], state[0:dims[w]]))**2, np.linalg.norm(np.dot(t[1], state[0:dims[w]]))**2, np.linalg.norm(np.dot(t[2], state[0:dims[w]]))**2) refl = (np.linalg.norm(np.dot(r[2], state[0:dims[w]]))**2, np.linalg.norm(np.dot(r[0], state[0:dims[w]]))**2) if (abs((qman - qlist[n]) / qlist[n]) > 0.01): print "TIME", i, j, w, n, qman, qlist[n] qlist[n] = abs(qman) if (abs((tran[1] - tran[0]) / tran[0]) > 0.001 or abs( (tran[2] - tran[1]) / tran[1]) > 0.001): print "TRANS", i, j, w, n, tran[1], tran[0], qman qmax = 0.0 * qlist[-1] #qmax = 100000.0*Weyl[0] sdiff = np.array([ s[0] * np.exp(imag_i * qmax * dk), s[1], s[2] * np.exp(-imag_i * qmax * dk) ]) Qdiff = scat.calc_Q(sdiff, dk)[0] #qlist[-1] = ut.sort_eig(Qdiff)[0][-1] + qmax #qlist = ut.sort_eig(Qdiff)[0] + qmax q_mean = np.sum(qlist) q_mean_list.append(q_mean) return q_mean_list
def calc_q_mean(S_list, i, j): ''' ''' global dims global Weyl global r_list, t_list q_mean_list=[] for w in range(nfreq): s = S_list[i,j][3*w:3*w+3] Q = scat.calc_Q(s,dk)[0] qlist = ut.sort_eig(Q)[0] r = r_list[i,3*w:3*w+3,j,0:dims[w],0:dims[w]] t = t_list[i,3*w:3*w+3,j,0:dims[w],0:dims[w]] Q_eigstates = (ut.sort_eig(Q)[1].T) # qmax = np.sum( # np.absolute(np.dot(r[1], state_max))**2 * \ # ( np.angle(np.dot(r[2], state_max)) - np.angle(np.dot(r[0], state_max)) ) / (2*dk) +\ # np.absolute(np.dot(t[1], state_max))**2 * \ # ( np.angle(np.dot(t[2], state_max)) - np.angle(np.dot(t[0], state_max)) ) / (2*dk) # ) for n, state in enumerate(Q_eigstates): qman = np.sum( np.absolute(np.dot(s[1], state))**2 * \ ( np.angle(np.dot(s[2], state)) - np.angle(np.dot(s[0], state)) ) / (2*dk) ) #print np.shape(t[2]), np.shape(t[0]), np.shape(state), np.shape(state[0:dims[w]]), tran = ( np.linalg.norm(np.dot(t[0], state[0:dims[w]]))**2, np.linalg.norm(np.dot(t[1], state[0:dims[w]]))**2, np.linalg.norm(np.dot(t[2], state[0:dims[w]]))**2 ) refl = ( np.linalg.norm(np.dot(r[2], state[0:dims[w]]))**2, np.linalg.norm(np.dot(r[0], state[0:dims[w]]))**2 ) if ( abs((qman-qlist[n])/qlist[n]) > 0.01 ): print "TIME", i, j, w, n, qman, qlist[n] qlist[n] = abs(qman) if ( abs((tran[1]-tran[0])/tran[0]) > 0.001 or abs((tran[2]-tran[1])/tran[1]) > 0.001): print "TRANS", i, j, w, n, tran[1], tran[0], qman qmax = 0.0*qlist[-1] #qmax = 100000.0*Weyl[0] sdiff = np.array([s[0] * np.exp(imag_i*qmax*dk), s[1], s[2] * np.exp(-imag_i*qmax*dk)]) Qdiff = scat.calc_Q(sdiff,dk)[0] #qlist[-1] = ut.sort_eig(Qdiff)[0][-1] + qmax #qlist = ut.sort_eig(Qdiff)[0] + qmax q_mean = np.sum(qlist) q_mean_list.append(q_mean) return q_mean_list
def calc_q_eigv(S_list, i, j, w): ''' Calculates traces of Q operators of S matrices stored in S_list. If imaginary part of the traces are too high, their value is set to 0 and the number of configurations at this radius and frequency is decremented by 1. ''' s = S_list[i,j][3*w:3*w+3] return ut.sort_eig(scat.calc_Q(s,dk)[0])[0].real
def write_teigvals(t_q, refpos): ''' Write t-eigenvalues at reference frequency to file. ''' teigval = ut.sort_eig(t_q[3 * (refpos) + 1])[0] np.savetxt( data_direc + "teigvals." + filen + ".dat", np.array([range(np.shape(teigval)[0]), teigval.real, teigval.imag]).transpose())
def calc_eigensystem(a, modes): ''' Calculcate eigenvalues, right eigenvectors and left eigenvectors of matrix a. Eigenvectors are store column-wise and inflated by appending zeros to size modes x modes. ''' aeigval, aeigvec = ut.sort_eig(a) aeigvec = aeigvec.transpose() aLeigvec = np.linalg.inv(aeigvec).transpose() aeigvec = scat.inflate_small_mat(aeigvec, modes) aLeigvec = scat.inflate_small_mat(aLeigvec, modes) return aeigval, aeigvec, aLeigvec
print "Composing block %i of %i" % (block+1,Nseg), Seg, comp = compose_block(Slist, dims, Nseg) Seglist.append(Seg) # get new segments by composing old segments to blocks print comp Slist = Seglist # define blocks as new segments Slist = np.array(Slist) S = Slist[0] print print "Transmission eigenvalues at center frequency:" print np.abs(ut.sort_eig(trans.calc_t(S, dims, 1)[0][Nw/2])[0]) print "Reflection eigenvalues at center frequency: " print np.abs(ut.sort_eig(trans.calc_r(S, dims, 1)[0][Nw/2])[0]) Q = scat.calc_Q((S[3*(Nw/3/2)+0],S[3*(Nw/3/2)+1],S[3*(Nw/3/2)+2]), dw, inv=False)[0] Q = scat.calc_Q((S[0],S[1],S[2]), dw, inv=False)[0] print "Time delay eigenvalues at center frequency:" print ut.sort_eig(Q)[0] print "Writing output" create_output(S, energs, filen)
t.append(S[i][m:, 0:m]) # full t-matrix t_q.append(S[i][m:m + n, 0:n]) # considered part of t-matrix q = np.array([ scat.calc_Q([t_q[3 * i + 0], t_q[3 * i + 1], t_q[3 * i + 2]], dk, inv=True)[0] for i in range(Nk) ]) refpos = int(0.5 * (Nk - 1)) # k[refpos] = kmean for odd Nk ### define operators at reference frequency ### qref = q[refpos] tref = t_q[3 * refpos + 1] tinv = np.linalg.inv(tref) ### calculate and sort eigenvalues and left and right eigenvectors of operators ### qeigval, qeigvec = ut.sort_eig(qref) teigval, teigvec = ut.sort_eig(tref) qeigvec = qeigvec.transpose() teigvec = teigvec.transpose() modesvec = np.identity(refmodes, dtype="complex") teigval = ut.sort_eig(t_q[3 * (refpos) + 1])[0] np.savetxt( data_direc + "teigvals." + filen + ".dat", np.array([range(np.shape(teigval)[0]), teigval.real, teigval.imag]).transpose()) # left eigenvectors are to be calculated before inflating, needed for measure \mu qLeigvec = np.linalg.inv(qeigvec).transpose() tLeigvec = np.linalg.inv(teigvec).transpose()
m = dims[i]/2 n = min(m, refmodes) t.append( S[i][m:,0:m] ) # full t-matrix t_q.append( S[i][m:m+n,0:n] ) # considered part of t-matrix q = np.array([scat.calc_Q([t_q[3*i+0],t_q[3*i+1],t_q[3*i+2]], dk, inv=True)[0] for i in range(Nk)]) refpos = int(0.5*(Nk-1)) # k[refpos] = kmean for odd Nk ### define operators at reference frequency ### qref = q[refpos] tref = t_q[3*refpos+1] tinv = np.linalg.inv(tref) ### calculate and sort eigenvalues and left and right eigenvectors of operators ### qeigval, qeigvec = ut.sort_eig(qref) teigval, teigvec = ut.sort_eig(tref) qeigvec = qeigvec.transpose() teigvec = teigvec.transpose() modesvec = np.identity(refmodes, dtype="complex") teigval = ut.sort_eig(t_q[3*(refpos)+1])[0] np.savetxt(data_direc+"teigvals."+filen+".dat", np.array([range(np.shape(teigval)[0]), teigval.real, teigval.imag]).transpose()) # left eigenvectors are to be calculated before inflating, needed for measure \mu qLeigvec = np.linalg.inv(qeigvec).transpose() tLeigvec = np.linalg.inv(teigvec).transpose() ### inflate eigenvectors to maximum size and number by appending zeros ### qeigvec = scat.inflate_small_mat(qeigvec, modes)
from Scattering import scattering2D as scat from Utils import utils as ut import sys if (len(sys.argv)!=2): sys.exit("ABORT: filen needed") filen = str(sys.argv[1]) # namestring of calculation S_dis, dims, energs = scat.read_S('./', filen+'.dis') S_clean, dims, energs = scat.read_S('./', filen+'.clean') dk = np.sqrt(2.0*energs[-1]) - np.sqrt(2.0*energs[-2]) t_dis = [] t_clean = [] for i in range(3): nin = dims[i]/2 t_dis.append( S_dis[i][nin:,0:nin] ) t_clean.append( S_clean[i][nin:,0:nin] ) Q = scat.calc_Q(S_clean,dk)[0] Q11 = Q[0:nin,0:nin] Q11EigVec = ut.sort_eig(Q11)[1] TransStates = np.dot( np.linalg.inv(t_dis[1]), np.dot( t_clean[1], Q11EigVec )) ut.write_states(Q11EigVec.T, nin, nin, energs[-2], filen+'.clean') ut.write_states(TransStates.T, nin, nin, energs[-2], filen+'.dis')
from Utils import utils as ut from Scattering import scattering2D as scat from Packets import transmission as trans Pi = np.pi I = 0. + 1.J nin = 50 nloop = 10000 #np.random.seed(1786) A = np.random.random(size=(nin,nin)) + I * np.random.random(size=(nin,nin)) A = 0.5 * (A + A.conj().T) A = ut.sort_eig(A)[1] A = np.dot( A.conj().T, np.dot( 100*np.diagflat(np.random.random(size=(nin))), A)) #A = A / np.linalg.norm(A) C = np.random.random(size=(nin,nin)) + I * np.random.random(size=(nin,nin)) C = 0.5 * (C + C.conj().T) C = ut.sort_eig(C)[1] C = np.dot( C.conj().T, np.dot( np.diagflat(np.random.random(size=(nin))), C)) #C = C / np.linalg.norm(C) D = np.random.random(size=(nin,nin)) + I * np.random.random(size=(nin,nin)) D = 0.5 * (D + D.conj().T) D = ut.sort_eig(D)[1] D = np.dot( D.conj().T, np.dot( np.diagflat(np.random.random(size=(nin))), D)) #D = D / np.linalg.norm(D) phi = np.random.random(size=(nin)) + I * np.random.random(size=(nin)) phi = phi / np.linalg.norm(phi)
from Utils import utils as ut from Scattering import scattering2D as scat from Packets import transmission as trans Pi = np.pi I = 0. + 1.J nin = 50 nloop = 10000 #np.random.seed(1786) A = np.random.random(size=(nin, nin)) + I * np.random.random(size=(nin, nin)) A = 0.5 * (A + A.conj().T) A = ut.sort_eig(A)[1] A = np.dot(A.conj().T, np.dot(100 * np.diagflat(np.random.random(size=(nin))), A)) #A = A / np.linalg.norm(A) C = np.random.random(size=(nin, nin)) + I * np.random.random(size=(nin, nin)) C = 0.5 * (C + C.conj().T) C = ut.sort_eig(C)[1] C = np.dot(C.conj().T, np.dot(np.diagflat(np.random.random(size=(nin))), C)) #C = C / np.linalg.norm(C) D = np.random.random(size=(nin, nin)) + I * np.random.random(size=(nin, nin)) D = 0.5 * (D + D.conj().T) D = ut.sort_eig(D)[1] D = np.dot(D.conj().T, np.dot(np.diagflat(np.random.random(size=(nin))), D)) #D = D / np.linalg.norm(D) phi = np.random.random(size=(nin)) + I * np.random.random(size=(nin))
for k in range(nconf): rp_mat = np.array(S[i,k,1+3*j][dims[j]:2*dims[j],dims[j]:2*dims[j]]) # if transmission so low that somewhere set to zero: zero_mask = rp_mat == 0. rp_mat[zero_mask] = 10**(-16) rp[i,j,k,0:dims[j],0:dims[j]] = rp_mat elif (fullout): rp = np.zeros((nr, 3*nfreq, nconf, nin_max, nin_max), dtype='complex') for i in range(nr): for j in range(3*nfreq): for k in range(nconf): rp_mat = np.array(S[i,k,j][dims[int(j/3)]:2*dims[int(j/3)],dims[int(j/3)]:2*dims[int(j/3)]]) # if transmission so low that somewhere set to zero: zero_mask = rp_mat == 0. rp_mat[zero_mask] = 10**(-16) rp[i,j,k,0:dims[int(j/3)],0:dims[int(j/3)]] = rp_mat return rp def calc_tdt_eigvals(t, (nr,nfreq,nconf,nin_max)): '''Calculate eigenvalues of t^dagger.t from t-matrices''' tdt_eigvals = np.zeros((nr, nfreq, nconf, nin_max), dtype='complex') for i in range(nr): for j in range(nfreq): for k in range(nconf): tdt_eigvals[i,j,k] = ut.sort_eig(np.dot(t[i,j,k].T.conj(), t[i,j,k]))[0] # sometimes transmission so low that somewhere tdt-eigval gets negative neg_mask = tdt_eigvals < 10**(-16) tdt_eigvals[neg_mask] = 10**(-16) return tdt_eigvals
calculate normalized n-th lead mode In Flo's code y-axis points downwards, y=0 is upper egde of lead; modes are chosen such that most upper point is real and positive. ''' chi_n = np.sin((n+1)*np.pi/lead_width * yrange) return np.sqrt(2./lead_width) * chi_n chi = np.array(map(calc_modes, np.arange(0,nin))) def calc_yoperator(chi): '''calculate operator y-d/2 in chi-representation''' return np.dot(chi.conj() * [list(yrange),]*nin, chi.T)*dy y_op = calc_yoperator(chi) y_eigm = ut.sort_eig(y_op)[1].T #y_peaks = np.dot(y_eigm, chi) y_peaks = np.dot(y_eigm, chi) ut.write_states(y_eigm, nin, 'ypeaks') q = scat.calc_Q(t_q, dk, inv=True)[0] q_y = np.dot(y_eigm.conj(), np.dot(q, y_eigm.T)) t_y = np.dot(y_eigm.conj(), np.dot(t_q[1], y_eigm.T)) pos_range = (0, int(0.33*nin-0.5*ptc), int(0.5*nin-0.5*ptc))#, int(0.67*nin-0.5*ptc), nin-ptc) # pos_range: place states to these positions
t = [] t_q = [] for i in np.arange(3*Nk): m = dims[i]/2 n = min(m, nin) t.append( S[i][m:,0:m] ) # full t-matrix t_q.append( S[i][m:m+n,0:n] ) # considered part of t-matrix q = [] for i in range(Nk): q.append(scat.calc_Q([t_q[3*i+0],t_q[3*i+1],t_q[3*i+2]], dk, inv=True)[0]) q = np.array(q) t_q = t_q[::3] pos = ((-1,0), (-quartpos-1,quartpos), (-centpos,centpos-1)) pos_string = ('full', 'quart', 'cent') for i, p, s in zip(range(3), pos, pos_string): KEigVal, KEigVec = ut.sort_eig( np.dot(np.linalg.inv(t_q[p[1]]), t_q[p[0]]) )[:2] KEigVec = KEigVec.T KEigVec_L = np.linalg.inv(KEigVec).T data = np.array([range(nin), (-1.0J*np.log(KEigVal)).real, (-1.0J*np.log(KEigVal)).imag]) np.savetxt('KEigVals.'+filen+'.'+s+'.txt', data.T, fmt=('%3i', '%12.8f', '%12.8f')) ut.write_states(KEigVec, nin, nin_Max, energs[centpos], filen, s) pickle.dump((KEigVec, KEigVec_L), open('KEigVecs.%i.p'%i, 'wb'))
wlist = np.sqrt(2.0 * np.array(energs, dtype="float")) w0 = 0.5 * (wlist[-2] + wlist[1]) dw = w0 * 10**(-8) refpos = int(0.5 * len(wlist) / 3) nyout = int(0.5*(modes_min+modes_max)) * pphwl yvals = np.linspace(0.0,1.0,nyout+2) ky = (np.arange(refmodes)+1)*np.pi kx = np.array([np.sqrt(w**2 - ky**2) for w in wlist[1::3]]) lead_funcs = np.sqrt(2.) * np.sin(np.einsum('m,y->ym', ky, yvals)) chi = np.einsum('wm,ym->wym', 1.0/np.sqrt(kx), lead_funcs) y_op = np.einsum('ym,y,yn->mn', lead_funcs.conj(), yvals, lead_funcs) y_eigvec = ut.sort_eig(y_op)[1] y_funcs = np.dot(lead_funcs, ut.sort_eig(y_op)[1]).T if (pixel): chi = np.einsum('ym,wm,mn->wyn', lead_funcs, 1.0/np.sqrt(kx), y_eigvec) dummy, t_q = trans.calc_t(S, dims, refmodes) if (pixel): t_q = np.einsum('ij,wik,kl->wjl', y_eigvec.conj(), t_q, y_eigvec) dt = (t_q[2::3] - t_q[0::3]) / (2*dk) t = t_q[1::3] # add random noise with given strength print "Adding noise" noisamp = noiserat * np.abs(t_q)
nin_Max = int(0.5 * (modes_max + modes_min)) # nin_Max = n_open_modes wlist = np.sqrt(2.0 * np.array(energs, dtype="float")) w0 = 0.5 * (wlist[-2] + wlist[1]) dw = w0 * 10**(-8) refpos = int(0.5 * len(wlist) / 3) nyout = int(0.5 * (modes_min + modes_max)) * pphwl yvals = np.linspace(0.0, 1.0, nyout + 2) ky = (np.arange(refmodes) + 1) * np.pi kx = np.array([np.sqrt(w**2 - ky**2) for w in wlist[1::3]]) lead_funcs = np.sqrt(2.) * np.sin(np.einsum('m,y->ym', ky, yvals)) chi = np.einsum('wm,ym->wym', 1.0 / np.sqrt(kx), lead_funcs) y_op = np.einsum('ym,y,yn->mn', lead_funcs.conj(), yvals, lead_funcs) y_eigvec = ut.sort_eig(y_op)[1] y_funcs = np.dot(lead_funcs, ut.sort_eig(y_op)[1]).T if (pixel): chi = np.einsum('ym,wm,mn->wyn', lead_funcs, 1.0 / np.sqrt(kx), y_eigvec) dummy, t_q = trans.calc_t(S, dims, refmodes) if (pixel): t_q = np.einsum('ij,wik,kl->wjl', y_eigvec.conj(), t_q, y_eigvec) dt = (t_q[2::3] - t_q[0::3]) / (2 * dk) t = t_q[1::3] # add random noise with given strength print "Adding noise" noisamp = noiserat * np.abs(t_q) noise_full = np.zeros(np.shape(t_q), dtype="complex") for i in range(Nav):
q = [] for i in range(Nk): q.append( scat.calc_Q([t_q[3*i+0],t_q[3*i+1],t_q[3*i+2]], dk, inv=True)[0] ) refpos = int(0.5*(Nk-1)) # k[refpos] = kmean for odd Nk ### define operators at reference frequency ### qref = q[refpos] tref = t_q[3*refpos+1] tinv = np.linalg.inv(tref) ### calculate and sort eigenvalues and left and right eigenvectors of operators ### qeigval = ut.sort_eig(qref)[0] teigval = ut.sort_eig(tref)[0] #teigval = np.linalg.eig(tref)[0] teigval = ut.sort_eig(t_q[3*(refpos)+0])[0] np.savetxt(direc+"teigvals."+filen+".dat", np.array([range(np.shape(teigval)[0]), teigval.real, teigval.imag]).transpose()) qeigvec = ut.sort_eig(qref)[1].transpose() teigvec = ut.sort_eig(tref)[1].transpose() #teigvec = np.linalg.eig(tref)[1].transpose() modesvec = np.identity(refmodes, dtype="complex") # left eigenvectors are to be calculated before inflating qLeigvec = np.linalg.inv(qeigvec).transpose() tLeigvec = np.linalg.inv(teigvec).transpose()
def write_teigvals(t_q, refpos): ''' Write t-eigenvalues at reference frequency to file. ''' teigval = ut.sort_eig(t_q[3*(refpos)+1])[0] np.savetxt(data_direc+"teigvals."+filen+".dat", np.array([range(np.shape(teigval)[0]), teigval.real, teigval.imag]).transpose())