Exemple #1
0
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 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
Exemple #5
0
def calc_q_mean(S_list, i, j):
    '''
    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.
    '''
    global dims
    global conf_counter
    global herm_counter
    
    q_mean_list=[]
    for w in range(nfreq):
        s = S_list[i,j][3*w:3*w+3]
        q_mean = np.trace(scat.calc_Q(s,dk)[0]) /(2*dims[w])
        q_mean_list.append(q_mean)            
    return q_mean_list
Exemple #6
0
if (len(dims)%3 == 0):
    Nk = len(dims)/3
else:
    sys.exit("ABORT: # of S matrices not divisible by 3")

if (refmodes > int(min(dims)/2)):
    print ("WARNING: # of modes under consideration (%i)"
           "> # minimum number of modes (%i)") % (refmodes,int(min(dims)/2))


t , t_q = trans.calc_t(S, dims, refmodes)
#trans.write_teigvals(t_q, refmodes)
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)

refpos = int(0.5*(Nk-1)) # k[refpos] = kmean for odd Nk

qref = q[refpos]
tref = t_q[3*refpos+1]
tinv = np.linalg.inv(tref)


class TRC:
   '''
   '''
   modes = 0
   refmodes = 0
   refpos = 0
    sys.exit("ABORT: # of S matrices not divisible by 3")

if (refmodes > int(min(dims) / 2)):
    print "WARNING: # of modes under consideration (%i) > # minimum number of modes (%i)" % (
        refmodes, int(min(dims) / 2))

t = []
t_q = []
for i in range(3 * Nk):
    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")
Exemple #8
0
def calc_q_mean(S_list, i, j):
    return [np.trace( scat.calc_Q(s,dk)[0] ) for s in np.reshape(S_list[i,j], (nfreq,3))]
        if (abs(q_mean.imag) > 10**(-0)):
            q_mean = 0.0
            conf_counter[i, w] -= 1
            herm_counter += 1
            #print i,w,conf_counter[i,w]
        q_mean_list.append(q_mean)
    return q_mean_list


if (do_pickle):
    q_mean = np.array([[calc_q_mean(S, i, j) for j in range(nconf)]
                       for i in range(nr)])

    qt_bar = np.array([[[
        np.trace(scat.calc_Q(t[i, 3 * w:3 * w + 3, j], dk)[0]) / dims[w]
        for j in range(nconf)
    ] for w in range(nfreq)] for i in range(nr)])
    qr_bar = np.array([[[
        np.trace(scat.calc_Q(r[i, 3 * w:3 * w + 3, j], dk)[0]) / dims[w]
        for j in range(nconf)
    ] for w in range(nfreq)] for i in range(nr)])
    qtp_bar = np.array([[[
        np.trace(scat.calc_Q(tp[i, 3 * w:3 * w + 3, j], dk)[0]) / dims[w]
        for j in range(nconf)
    ] for w in range(nfreq)] for i in range(nr)])
    qrp_bar = np.array([[[
        np.trace(scat.calc_Q(rp[i, 3 * w:3 * w + 3, j], dk)[0]) / dims[w]
        for j in range(nconf)
    ] for w in range(nfreq)] for i in range(nr)])
#!/usr/bin/env python

import numpy as np
import scipy as sp
import scipy.optimize as spopt
import matplotlib.pyplot as plt
import sys
from math import pi as Pi

from Utils import utils as ut
from Scattering import scattering2D as scat

filen = str(sys.argv[1]) # namestring of calculation
n     = int(sys.argv[2]) # number of calculation
dims  = int(sys.argv[3]) # number of open modes in left lead

data_direc = "../../VSC2/AverageDwellTime-20130618/" + filen + "/scatterdata/"

energs = scat.read_S(data_direc, filen+".%i.0"%n)[2]
kvals = np.sqrt(2*energs)
dk = (kvals[-1] - kvals[-2]) / 1.0

filen_i = filen+".%i.%i" % (n,0)
print "reading file: "+filen_i
S = scat.read_S(data_direc, filen_i)[0]
q_mean = np.trace(scat.calc_Q(S,dk)[0]) /(2*dims)

print q_mean.real
Exemple #11
0
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')

else:
    sys.exit("ABORT: # of S matrices not divisible by 3")

if (refmodes > int(min(dims)/2)):
    print "WARNING: # of modes under consideration (%i) > # minimum number of modes (%i)" % (refmodes,int(min(dims)/2))


t = []
t_q = []
for i in range(3*Nk):
    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")
Exemple #13
0
      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)





#!/usr/bin/env python

import numpy as np
import scipy as sp
import scipy.optimize as spopt
import matplotlib.pyplot as plt
import sys
from math import pi as Pi

from Utils import utils as ut
from Scattering import scattering2D as scat

filen = str(sys.argv[1])  # namestring of calculation
n = int(sys.argv[2])  # number of calculation
dims = int(sys.argv[3])  # number of open modes in left lead

data_direc = "../../VSC2/AverageDwellTime-20130618/" + filen + "/scatterdata/"

energs = scat.read_S(data_direc, filen + ".%i.0" % n)[2]
kvals = np.sqrt(2 * energs)
dk = (kvals[-1] - kvals[-2]) / 1.0

filen_i = filen + ".%i.%i" % (n, 0)
print "reading file: " + filen_i
S = scat.read_S(data_direc, filen_i)[0]
q_mean = np.trace(scat.calc_Q(S, dk)[0]) / (2 * dims)

print q_mean.real
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

q_peaks = np.zeros((ptc,nin), dtype='complex')
for i, pos in enumerate(pos_range):
   peak_range = range(pos,pos+ptc)
   q_block = q_y[np.meshgrid(peak_range,peak_range)]

   block_eigv = ut.sort_eig(q_block)[1].T
   q_peaks = np.dot(block_eigv, y_eigm[peak_range])
Exemple #16
0
# take only transmitted states for q
t_ref = t_noise[refpos]
tdt_eigval, tdt_eigvec = ut.sort_eig(t_ref.T.conj().dot(t_ref))
trans_mask = np.abs(tdt_eigval) > 1.0e-3
trans_vec = tdt_eigvec[:, trans_mask]

print
print tdt_eigval
print

q_arg = np.einsum('ij,wjk,kl->wil',
                  trans_vec.conj().T, t_noise_full[3 * refpos:3 * refpos + 3],
                  trans_vec)

q = scat.calc_Q(q_arg, dw, inv=True)[0]
q = trans_vec.dot(q).dot(trans_vec.conj().T)
qeigstates = ut.sort_eig(q)[1].T

phat = qeigstates[qeigst]

phat_rand = (np.random.random(size=(refmodes)) -
             0.5) - I * (np.random.random(size=(refmodes)) - 0.5)
phat_rand = phat_rand / np.linalg.norm(phat_rand)

if (qeigst < 0): phat = phat_rand
if (readst):
    phat = np.load("movie." + filen + "." + "opt_rand" + ".dat.npy")[2]

if (not nloop and nloop != 0): nloop = 100000
phat = normalize(phat)

# take only transmitted states for q
t_ref = t_noise[refpos]
tdt_eigval, tdt_eigvec = ut.sort_eig(t_ref.T.conj().dot(t_ref))
trans_mask = np.abs(tdt_eigval) > 1.0e-3
trans_vec = tdt_eigvec[:,trans_mask]

print
print tdt_eigval
print

q_arg = np.einsum('ij,wjk,kl->wil',
                  trans_vec.conj().T, t_noise_full[3*refpos:3*refpos+3], trans_vec)

q = scat.calc_Q(q_arg, dw, inv=True)[0]
q = trans_vec.dot(q).dot(trans_vec.conj().T)
qeigstates = ut.sort_eig(q)[1].T


phat = qeigstates[qeigst]

phat_rand = (np.random.random(size=(refmodes)) - 0.5) - I * (np.random.random(size=(refmodes)) - 0.5)
phat_rand = phat_rand / np.linalg.norm(phat_rand)

if(qeigst<0): phat = phat_rand
if(readst): phat = np.load("movie."+filen+"."+"opt_rand"+".dat.npy")[2]

if (not nloop and nloop!=0): nloop = 100000
phat = normalize(phat)
phat_new = phat