def makeMinPickle(gon,vertex,modeType, maxItter): test = PlanarLayout(gon = gon, vertex = vertex, side =1, radius_method = 'lin', modeType = modeType) test.populate(maxItter = maxItter) pickleDict = {} pickleDict['gon'] = test.gon pickleDict['vertex'] = test.vertex pickleDict['itter'] = test.itter pickleDict['modeType'] = test.modeType pickleDict['Es'] = test.Es pickleDict['Eorder'] = test.Eorder pickleName = str(test.gon) + 'gon_' + str(test.vertex) + 'vertex_' + str(test.itter) + '_' + str(test.modeType) + '_DOSminimal' pickleDict['name'] = pickleName pickle.dump(pickleDict, open(pickleName + '.pkl', 'wb'))
def makeMinPickle(gon, vertex, modeType, maxItter): ''' Old function used for making minimal pickles of the energies for effective graphs. ''' test = PlanarLayout(gon=gon, vertex=vertex, side=1, radius_method='lin', modeType=modeType) test.populate(maxItter=maxItter) pickleDict = {} pickleDict['gon'] = test.gon pickleDict['vertex'] = test.vertex pickleDict['itter'] = test.itter pickleDict['modeType'] = test.modeType pickleDict['Es'] = test.Es pickleDict['Eorder'] = test.Eorder pickleName = str(test.gon) + 'gon_' + str(test.vertex) + 'vertex_' + str( test.itter) + '_' + str(test.modeType) + '_DOSminimal' pickleDict['name'] = pickleName pickle.dump(pickleDict, open(pickleName + '.pkl', 'wb'))
#minimal = False if showHardWall: if minimal: # testDict = pickle.load( open('8gon_3vertex_4_FW_DOSminimal.pkl', "rb")) # testDict = pickle.load( open('8gon_3vertex_5_FW_DOSminimal.pkl', "rb")) # testDict = pickle.load( open('7gon_3vertex_6_FW_DOSminimal.pkl', "rb")) testDict = pickle.load( open('7gon_3vertex_6_HW_DOSminimal.pkl', "rb")) else: # test = PlanarLayout(file_path = '7gon_3vertex_ 3.pkl') # test = PlanarLayout(file_path = '7gon_3vertex_ 4.pkl') # test = PlanarLayout(file_path = '7gon_3vertex_ 5.pkl') #test = PlanarLayout(file_path = '7gon_3vertex_ 6.pkl') test = PlanarLayout(file_path = '8gon_3vertex_ 3.pkl') # test = PlanarLayout(file_path = '8gon_3vertex_ 4.pkl') ###### #trying DOS comparison versus sytem size instead ###### #set up frequency sweep freq_range = 4.01 freq_res = 0.04 # freq_res = 0.06 #freq_res = 0.12 freqs = scipy.arange(-freq_range/2, freq_range, freq_res) + freq_res/2. freq_bins = scipy.arange(-freq_range/2, freq_range+freq_res, freq_res)
def makeMinLayoutPickle_hyperbolic( gon, vertex, maxItter, modeType='FW', verbose=True, saveFolder=r'/Users/kollar2/Documents/HouckLab/HyperbolicPlanning/layoutDOSs', sparse=True, flags=5): ''' Old function used for making minimal pickles of the energies for effective graphs. ''' test = PlanarLayout(gon=gon, vertex=vertex, side=1, radius_method='lin', modeType=modeType) test.populate(maxItter=maxItter, resonatorsOnly=True) if sparse: Hmat = generate_layout_Hamiltonian(test, verbose=verbose, sparse=True, flags=flags) # Es,Psis = scipy.sparse.linalg.eigsh(Hmat, k = test.coords.shape[0]-1 + flags) #will get all but one eigenvalue Es = scipy.sparse.linalg.eigsh( Hmat, k=test.coords.shape[0] - 1 + flags, return_eigenvectors=False) #will get all but one eigenvalue Eorder = numpy.argsort(Es) if Es[Eorder[flags - 1]] < 7.4: #all the flag values are present, so an actual eigenvalue is missing print 'actual eigenvalue missing' Es = Es[flags:] else: print 'all real eigenvalues found' Es = Es[flags - 1:] else: Hmat = generate_layout_Hamiltonian(test, verbose=verbose, sparse=False) Es, Psis = scipy.linalg.eigh(Hmat) Eorder = numpy.argsort(Es) if verbose: print 'max eigenvalue = ' + str(numpy.max(Es)) pickleDict = {} pickleDict['gon'] = test.gon pickleDict['vertex'] = test.vertex pickleDict['itter'] = test.itter pickleDict['modeType'] = test.modeType pickleDict['Es'] = Es pickleDict['Eorder'] = Eorder if sparse: pickleDict['sparse'] = True else: pickleDict['sparse'] = False # pickleName = str(test.gon) + 'gon_' + str(test.vertex) + 'vertex_' + str(test.itter) + '_' + str(test.modeType) + '_layoutDOSminimal' pickleName1 = str(test.gon) + 'gon_' + str(test.vertex) + 'vertex_' + str( test.itter) + '_' + str(test.modeType) if sparse: pickleName = pickleName1 + '_splayoutDOSminimal' else: pickleName = pickleName1 + '_layoutDOSminimal' pickleDict['name'] = pickleName # pickle.dump(pickleDict, open(pickleName + '.pkl', 'wb')) filePath = os.path.join(saveFolder, pickleName + '.pkl') pickle.dump(pickleDict, open(filePath, 'wb')) return Es # pickleName = str(test.gon) + 'gon_' + str(test.vertex) + 'vertex_' + str(test.itter) + '_' + str(test.modeType) + '_layoutDOSminimal' pickleName1 = str(test.gon) + 'gon_' + str(test.vertex) + 'vertex_' + str( test.itter) + '_' + str(test.modeType) if sparse: pickleName = pickleName1 + '_splayoutDOSminimal' else: pickleName = pickleName1 + '_layoutDOSminimal' pickleDict['name'] = pickleName # pickle.dump(pickleDict, open(pickleName + '.pkl', 'wb')) filePath = os.path.join(saveFolder, pickleName + '.pkl') pickle.dump(pickleDict, open(filePath, 'wb')) return Es
def compile_lambda_extrema(maxItt, gon = 7, tree = False, degree = 3, roundDepth = 6, save = True, saveFolder = '', secondEnergy = False): lambdaMax_vals = numpy.zeros(maxItt) lambdaMin_vals = numpy.zeros(maxItt) if secondEnergy: lambda2Max_vals = numpy.zeros(maxItt) lambda2Min_vals = numpy.zeros(maxItt) sizes = numpy.zeros(maxItt) if tree: stepSize = 2 itts = scipy.arange(1,maxItt+1, 1)*stepSize #go up ins steps of 3 generations at a time maxItt = maxItt*stepSize for ind in range(0, len(itts)): itt = itts[ind] base = TreeResonators(degree = degree, iterations = itt) baseName = '3tree' print itt nameStr = baseName + '_' + str(itt) test = GeneralLayout(resonators = base.get_all_resonators(), resonatorsOnly = True, modeType = 'FW', name = nameStr, roundDepth = roundDepth) Hsparse = generate_layout_Hamiltonian(test, roundDepth = roundDepth, t = 1, verbose = False, sparse = True, flags = 0) almostMaxs = scipy.sparse.linalg.eigsh(Hsparse, sigma = 3, return_eigenvectors = False) almostMins = scipy.sparse.linalg.eigsh(Hsparse, sigma = -3, return_eigenvectors = False) lambdaMax_vals[ind] = numpy.max(almostMaxs) lambdaMin_vals[ind] = numpy.min(almostMins) if secondEnergy: tempMaxs = almostMaxs tempMins = almostMins flagmax = numpy.where(tempMaxs == numpy.max(almostMaxs))[0][0] flagmin = numpy.where(tempMins == numpy.min(almostMins))[0][0] tempMaxs[flagmax] = -200 tempMins[flagmin] = 200 lambda2Max_vals[ind] = numpy.max(tempMaxs) lambda2Min_vals[ind] = numpy.min(tempMins) sizes[ind] = test.coords.shape[0] else: itts = scipy.arange(1,maxItt+1, 1) base = PlanarLayout(gon = gon, vertex = degree, side =1, radius_method = 'exp', modeType = 'FW') base.populate(maxItter = 1, resonatorsOnly = True) baseName = str(gon) + 'gon_' + str(degree) + 'vertex' for itt in itts: if itt > 1: base.itter_generate() base.generate_semiduals() print itt nameStr = baseName + '_' + str(itt) test = GeneralLayout(resonators = base.get_all_resonators(), resonatorsOnly = True, modeType = 'FW', name = nameStr, roundDepth = roundDepth) Hsparse = generate_layout_Hamiltonian(test, roundDepth = roundDepth, t = 1, verbose = False, sparse = True, flags = 0) almostMaxs = scipy.sparse.linalg.eigsh(Hsparse, sigma = 3, return_eigenvectors = False) almostMins = scipy.sparse.linalg.eigsh(Hsparse, sigma = -3, return_eigenvectors = False) lambdaMax_vals[itt-1] = numpy.max(almostMaxs) lambdaMin_vals[itt-1] = numpy.min(almostMins) if secondEnergy: tempMaxs = almostMaxs tempMins = almostMins flagmax = numpy.where(tempMaxs == numpy.max(almostMaxs))[0][0] flagmin = numpy.where(tempMins == numpy.min(almostMins))[0][0] tempMaxs[flagmax] = -200 tempMins[flagmin] = 200 lambda2Max_vals[itt-1] = numpy.max(tempMaxs) lambda2Min_vals[itt-1] = numpy.min(tempMins) sizes[itt-1] = test.coords.shape[0] pickleDict = {} pickleDict['itts'] = itts pickleDict['lambdaMax'] = lambdaMax_vals pickleDict['lambdaMin'] = lambdaMin_vals pickleDict['name'] = baseName pickleDict['systemSizes'] = sizes if secondEnergy: pickleDict['lambda2Max'] = lambda2Max_vals pickleDict['lambda2Min'] = lambda2Min_vals if save: if secondEnergy: saveName = baseName + '_layoutLambdaExtremaAndSecond_' + str(maxItt) + '.pkl' else: saveName = baseName + '_layoutLambdaExtrema_' + str(maxItt) + '.pkl' save_path = os.path.join(saveFolder, saveName) pickle.dump(pickleDict, open(save_path, 'wb')) print save_path fig1 = pylab.figure(1) pylab.clf() ax = pylab.subplot(1,2,1) pylab.plot(itts, lambdaMax_vals, 'b.-', label = 'sparse') if secondEnergy: pylab.plot(itts, lambda2Max_vals, color = 'dodgerblue', marker = '.', linestyle = '-', label = 'sparse, 2nd') # pylab.plot(itts_full[2:], lambdaMax_vals_full[2:], color = 'deepskyblue', linestyle = '-', marker = '.', label = 'full') ax.legend(loc = 'lower right') pylab.title('$\lambda_{max}$') pylab.xlabel('itterations') ax = pylab.subplot(1,2,2) pylab.plot(itts, lambdaMin_vals, 'r.-', label = 'sparse') if secondEnergy: pylab.plot(itts, lambda2Min_vals, color = 'firebrick', marker = '.', linestyle = '-', label = 'sparse, 2nd') # pylab.plot(itts_full[2:], lambdaMin_vals_full[2:], color = 'deepskyblue', linestyle = '-', marker = '.', label = 'full') ax.legend(loc = 'upper right') pylab.title('$\lambda_{min}$') pylab.xlabel('itterations') pylab.suptitle(baseName) fig1.set_size_inches([9.7,5.1]) pylab.show() if save: fig_saveName = baseName + '_layoutLambdaExtremaFig_' + str(maxItt) + '.png' fig_save_path = os.path.join(saveFolder, fig_saveName) fig1.savefig(fig_save_path,transparent= False, dpi = 200) return lambdaMax_vals, lambdaMin_vals, itts
def compile_lambda_target_sigma(maxItt, gon = 7, target = 1.51, numVals = 20, roundDepth = 6, save = True, saveFolder = ''): lambda_vals = numpy.zeros((maxItt, numVals)) sizes = numpy.zeros(maxItt) itts = scipy.arange(1,maxItt+1, 1) base = PlanarLayout(gon = gon, vertex = 3, side =1, radius_method = 'exp', modeType = 'FW') base.populate(maxItter = 1, resonatorsOnly = True) baseName = str(gon) + 'gon_3vertex' for itt in itts: if itt > 1: base.itter_generate() base.generate_semiduals() print itt nameStr = baseName + '_' + str(itt) test = GeneralLayout(resonators = base.get_all_resonators(), resonatorsOnly = True, modeType = 'FW', name = nameStr, roundDepth = roundDepth) Hsparse = generate_layout_Hamiltonian(test, roundDepth = roundDepth, t = 1, verbose = False, sparse = True, flags = 0) almostMaxs = scipy.sparse.linalg.eigsh(Hsparse, sigma = target, return_eigenvectors = False, k = numVals) lambda_vals[itt-1,: ] = almostMaxs sizes[itt-1] = test.coords.shape[0] pickleDict = {} pickleDict['itts'] = itts pickleDict['lambdas'] = lambda_vals pickleDict['target'] = target pickleDict['name'] = baseName pickleDict['systemSizes'] = sizes saveName_0 = baseName + '_' + str(maxItt) + '_layoutLambdaTarget_' + str(target) + '_' +str(numVals) if save: saveName = saveName_0 + '.pkl' save_path = os.path.join(saveFolder, saveName) pickle.dump(pickleDict, open(save_path, 'wb')) fig1 = pylab.figure(1) pylab.clf() ax = pylab.subplot(1,1,1) for ind in range(0, numVals): pylab.plot(itts, lambda_vals[:, ind], 'b.-', label = 'sparse') # ax.legend(loc = 'lower right') pylab.title('$\lambda$_' + str(target)) pylab.xlabel('itterations') # ax = pylab.subplot(1,2,2) # pylab.plot(itts, lambdaMin_vals, 'r.-', label = 'sparse') ## pylab.plot(itts_full[2:], lambdaMin_vals_full[2:], color = 'deepskyblue', linestyle = '-', marker = '.', label = 'full') # ax.legend(loc = 'upper right') # pylab.title('$\lambda_{min}$') # pylab.xlabel('itterations') pylab.suptitle(saveName_0) fig1.set_size_inches([5.1,5.1]) pylab.show() if save: # fig_saveName = baseName + '_layoutLambdaExtremaFig_' + str(maxItt) + '.png' fig_saveName = saveName_0 +'.png' fig_save_path = os.path.join(saveFolder, fig_saveName) fig1.savefig(fig_save_path,transparent= False, dpi = 200) return lambda_vals, itts
def compile_lambda_extrema_gonSequence(maxItt, firstGon = 7, lastGon = 10, degree = 3, roundDepth = 6, save = True, saveFolder = ''): lambdaMax_vals = numpy.zeros(lastGon - firstGon + 1) lambdaMin_vals = numpy.zeros(lastGon - firstGon + 1) sizes = numpy.zeros(lastGon - firstGon + 1) gons = scipy.arange(firstGon,lastGon+1, 1) # baseName = str(gon) + 'gon_' + str(degree) + 'vertex' for ind in range(0, len(gons)): gon = gons[ind] base = PlanarLayout(gon = gon, vertex = degree, side =1, radius_method = 'exp', modeType = 'FW') base.populate(maxItter = maxItt, resonatorsOnly = True) nameStr = str(gon) + 'gon_' + str(degree) + 'vertex' + '_' + str(maxItt) test = GeneralLayout(resonators = base.get_all_resonators(), resonatorsOnly = True, modeType = 'FW', name = nameStr, roundDepth = roundDepth) Hsparse = generate_layout_Hamiltonian(test, roundDepth = roundDepth, t = 1, verbose = False, sparse = True, flags = 0) almostMaxs = scipy.sparse.linalg.eigsh(Hsparse, sigma = degree, return_eigenvectors = False) almostMins = scipy.sparse.linalg.eigsh(Hsparse, sigma = -degree, return_eigenvectors = False) lambdaMax_vals[ind] = numpy.max(almostMaxs) lambdaMin_vals[ind] = numpy.min(almostMins) sizes[ind] = test.coords.shape[0] baseName = str(firstGon) + '_' + str(lastGon) + 'gon_' + str(degree) + 'vertex' pickleDict = {} pickleDict['gons'] = gons pickleDict['lambdaMax'] = lambdaMax_vals pickleDict['lambdaMin'] = lambdaMin_vals pickleDict['name'] = baseName pickleDict['systemSizes'] = sizes if save: saveName = baseName + '_layoutLambdaExtrema_' + str(maxItt) + '.pkl' save_path = os.path.join(saveFolder, saveName) pickle.dump(pickleDict, open(save_path, 'wb')) fig1 = pylab.figure(1) pylab.clf() ax = pylab.subplot(1,2,1) pylab.plot(gons, lambdaMax_vals, 'b.-', label = 'sparse') ax.legend(loc = 'upper right') pylab.title('$\lambda_{max}$') pylab.xlabel('k') ax = pylab.subplot(1,2,2) pylab.plot(gons, lambdaMin_vals, 'r.-', label = 'sparse') ax.legend(loc = 'upper right') pylab.title('$\lambda_{min}$') pylab.xlabel('k') pylab.suptitle(baseName) fig1.set_size_inches([9.7,5.1]) pylab.show() if save: fig_saveName = baseName + '_layoutLambdaExtremaFig_' + str(maxItt) + '.png' fig_save_path = os.path.join(saveFolder, fig_saveName) fig1.savefig(fig_save_path,transparent= False, dpi = 200) return lambdaMax_vals, lambdaMin_vals, gons