def plot_nmVsL(L_list, IC_list, typical_nm, fignum=2, saveQ=False): fig = plt.figure(fignum, figsize=(7,8.5)) #obs_list_flat = list(set([obs for obs_list in obs_list_list # for obs in obs_list])) obs_list_flat = ['ND', 'CC', 'Y'] letters = {0:'a', 1:'b', 2:'c', 3:'d'} M = len(IC_list) N = len(obs_list_flat) for m, IC in enumerate(IC_list): if IC[0] == 'R': IC = 'R' for n, obs in enumerate(obs_list_flat): i = 1+m*(M-1) + n ax = fig.add_subplot(M,N,i) x = typical_nm[IC]['L'] xs = np.linspace(min(x), max(x), 100) y = typical_nm[IC][obs] ys = nm_exact(IC, obs, xs) #error = max(np.abs(y - nm_exact(IC, obs, x[:]))) if m != M-1: pass #plt.setp([ax.get_xticklabels()], visible=False) ax.set_ylim(0, max(y)*5/4) if np.std(y)<1e-10: ax.set_ylim(np.mean(y)-0.1, np.mean(y)+0.1) if IC == 'W': ax.set_ylim(top=0.4) if IC == 'c2_B0-1_3': if obs == 'Y': ax.set_ylim(top=0.6) #plot_loglog_fit(x, y, ax) #plot_semilogy(x, y, ax) ax.plot(x,y, 'ok', alpha=0.6, markersize=4) plt.setp([ax.get_xticklabels()], visible=True) ax.xaxis.major.locator.set_params(nbins=6) ax.yaxis.major.locator.set_params(nbins=3) ax.plot(xs, ys, '-k', alpha=0.7) #ax.set_title('$\mathrm{error}_\mathrm{max} = 0$' , fontsize=12) #if error != 0: # ax.set_title('$\mathrm{error}_\mathrm{max} = ' + # pt.as_sci(error,1)+'$', fontsize=12) if n == 0: ax.text(-0.5, 1.1, '('+letters[m]+') '+pretty_names_dict(IC), transform=ax.transAxes, fontsize=13) ax.set_ylabel(pretty_names_dict(obs)) if m == M-1: ax.set_xlabel(r'$L$') ax.margins(0.1) fig.subplots_adjust(hspace=0.4, wspace=0.7, left=0.13, right=.98, top=.94, bottom=.05) if saveQ: bnp = io.base_name('typical_nm', 'plots') fnamep = 'nmVsL.pdf' io.multipage(bnp + fnamep, clip=False) else: plt.show()
def make_typical_nm(L_list, IC_list, importQ=False, nsamp=300): bnd = io.base_name('typical_nm', 'data') fnamed = 'typical_net_meas_rand.hdf5' if importQ: typical_nm = h5py.File(bnd+fnamed) return typical_nm else: L_list_cp = L_list.copy() typical_nm = dict() print('IC', 'L', 'ND', 'CC', 'Y') for IC in IC_list: typical_nm[IC] = dict() ND_list, CC_list, Y_list = [], [], [] for i, L in enumerate(L_list): if IC == 'R': ND, CC, Y = 0, 0 ,0 mjk = np.zeros((L,L)) for s in range(nsamp): IC_tmp = IC +str(s) state = get_state(L, IC_tmp) mjk = mutual_info_calc(state) ND += nm.density(mjk)/nsamp CC += nm.clustering(mjk)/nsamp Y += nm.disparity(mjk)/nsamp elif IC == 'N': ND, CC, Y = 0, 0 ,0 for s in range(nsamp): mjk = random_network(L) ND += nm.density(mjk)/nsamp CC += nm.clustering(mjk)/nsamp Y += nm.disparity(mjk)/nsamp else: state = get_state(L, IC) if state is not None: mjk = mutual_info_calc(state) ND = nm.density(mjk) CC = nm.clustering(mjk) Y = nm.disparity(mjk) if state is not None: Y_list.append(Y) CC_list.append(CC) ND_list.append(ND) print(IC, L, ND, CC, Y) typical_nm[IC]['ND'] = np.array(ND_list) typical_nm[IC]['CC'] = np.array(CC_list) typical_nm[IC]['Y'] = np.array(Y_list) typical_nm[IC]['L'] = np.array(L_list_cp) typ_copy = typical_nm.copy() io.write_hdf5(bnd + fnamed, typical_nm, force_rewrite=True) return typ_copy
def plot_scatters(L_list, IC_list, typical_nm, fignum=1, saveQ=True): fig = plt.figure(fignum, figsize=(6.5, 2.1)) letters = ['(a)', '(b)', '(c)'] for IC in IC_list: c, c_full = make_c_list(IC, L_list, typical_nm) for i, obs_list in enumerate(obs_list_list): ax = scatter_plot(fig, typical_nm, obs_list, IC, c, c_full, i, cmap=cmap, letter=letters[i]) plot_config(fig, ax, L_list, IC_list) if saveQ: bnp = io.base_name('typical_nm', 'plots') fnamep = 'typical_net_meas.pdf' io.multipage(bnp + fnamep, clip=False) else: plt.show()
def rule_plot(params_list_list, show_S=[1, 6, 9, 14], show_L=[15]): fignum = 0 c_list = ['c', 'orange', 'crimson', 'limegreen'] c_list = cycle(c_list) m_list = ['s', 'o', '^', 'd'] m_list = cycle(m_list) fig = plt.figure(fignum, figsize=(3, 3)) ax = fig.add_subplot(1, 1, 1) for m, params_list in enumerate(params_list_list): avg_list = [] for n, params in enumerate(params_list): if data_repo is not None: sname = io.sim_name(params) data_path = data_repo + sname + '_v0.hdf5' else: sname = io.sim_name(params) data_path = io.default_file_name(params, 'data', '.hdf5') data_set = h5py.File(data_path) L = params['L'] S = params['S'] T = params['T'] sb = data_set['sbond'][::] print(sb[0:3, int(L / 2)]) sb[::, int(L / 2)] = np.zeros(params['T'] + 1) sb /= [min(c + 1, L - c - 1) for c in range(L - 1)] center_sb = sb[::, int(L / 2)] avg_sb = np.mean(sb, axis=1) avg_avg_sb = np.mean(avg_sb[500::]) avg_center_sb = np.mean(center_sb[500::]) avg_list.append([L, S, avg_avg_sb]) #S_plot(ax, c_list, center_sb, r'$L={}$'.format(L), r'$S={}$'.format(S)) L_avg_plot(ax, c_list, m_list, avg_list, r'$S={}$'.format(S)) bn = io.base_name(output_dir, 'plots/sbond/') #fn = 'S1_sbond_center_growth'+'.pdf' fn = 'S1-6-9-14_th0_sbond_center_tavg_Lscale' + '.pdf' io.multipage(bn + fn)
def make_speeds(fixed_params_dict, var_params_dict, **kwargs): params_list_list = io.make_params_list_list(fixed_params_dict, var_params_dict) fignum = 3 for c, params_list in zip(['b', 'g', 'r'], params_list_list): speeds_0, dspeeds_0, diffs_0, ddiffs_0 = [], [], [], [] speeds_1, dspeeds_1, diffs_1, ddiffs_1 = [], [], [], [] ths = [] transport = {'tmax_1': None} for params in params_list: transport, fignum = add_speed(params, transport, fignum, speeds_0, dspeeds_0, diffs_0, ddiffs_0, speeds_1, dspeeds_1, diffs_1, ddiffs_1, ths, **kwargs) plot_speed_diffs(params, transport, fignum, speeds_0, dspeeds_0, diffs_0, ddiffs_0, speeds_1, dspeeds_1, diffs_1, ddiffs_1, ths, c) io.multipage( io.base_name(fixed_params_dict['output_dir'][0], 'plots') + 'L' + str(params['L']) + '_S6_speeds_' + kwargs['dirr'] + '_90_gaussian.pdf')
def init_params_1d(): output_dir = 'fock_IC' data_repo = '/mnt/ext0/qca_output/' + output_dir + '/data/' #data_repo = None #uID = '_somethin_' uID = '_ICc3_f1_' IC_label = 'fock' modes = ['alt'] Ss = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14] degs = [90] Vs = ['HP_' + str(deg) for deg in degs] Ls = [17] Ts = [1000] ICs = ['c3_f1'] #ICs = ['G', 'W', 'c2_B0-1_0', 'c2_B0-1_1', 'c2_B0-1_2', 'c2_B0-1_3' ] #ICs = ['c3_f1', 'c3_f0-1', 'c3_f0-2', 'c3_f0-1-2'] #ICs = ['r5-10', 'r5-20', 'r5-30'] obs_list = ['ND', 'CC', 'Y', 'z'] # outer params fixed_params_dict = { 'output_dir': [output_dir], 'L': Ls, 'T': Ts, 'BC': ['1_00'], } #inner params var_params_dict = {'V': Vs, 'IC': ICs, 'S': Ss, 'mode': modes} params_list_list = io.make_params_list_list(fixed_params_dict, var_params_dict) bn = io.base_name(fixed_params_dict['output_dir'][0], 'plots/fourier') def plots_out_pathf(L): return bn + IC_label + '_'+'-'.join(modes) + '_L'+str(L)+ uID +\ 'DCYZ.pdf' return params_list_list, obs_list, data_repo, plots_out_pathf
obs[np.isnan(obs)] = 0 obs_mean = np.nanmean(obs) obs_means[m, j, n] = obs_mean colors[m, j, n] = val if typ == 'PCA': plot_PCA(obs_means, fignum) clip = False if typ == 'scatter': ncplus = False if color_by == 'S': ncplus = True plot_scatter(fig, ax, m, obs_means, colors, val_min, val_max, cbar_label, obs_list, cmap, ncplus, cb_tick_labels) ax.set_title(letter) clip = True if typ == 'hist3D': plot_3D_hist(fignum, m, colors, val_min, val_max, obs_means, cbar_label, obs_list, letter) clip = False bn = io.base_name(fixed_params_dict['output_dir'][0], 'plots/scatters') fname = IC_label + '_' + '-'.join(modes) + '_L' + '-'.join(map( str, Ls)) + uID + typ + '.pdf' print(fname) io.multipage(bn + fname, clip=clip)
def mem(L): return 2**(L + 4) nb_list = [] L_list = [] for L in range(Lmin, Lmax): state = ss.make_state(L, 'f0') nb = state.nbytes del state nb_list.append(nb) L_list.append(L) fig = plt.figure(1, (7, 2.5)) ax = fig.add_subplot(111) ax.plot(Ls, mem(Ls), '--c', label='theoretical', lw=2) ax.plot(L_list, nb_list, 'ks', label='measured', ms=5) ax.set_ylabel(r'$N_{\mathrm{bytes}}$') ax.set_xlabel(r'system size [$L$]') ax.set_yscale('log', basey=2) ax.set_yticks([2**n for n in range(6, 29, 4)]) #ax.get_yaxis().set_major_formatter(mpl.ticker.ScalarFormatter()) ax.legend(loc='lower right') ax.grid('on') ax.set_ylim([2**(Lmin + 3), 2**(Lmax + 4)]) ax.set_xlim([Lmin - 0.5, Lmax - 0.5]) #plt.show() plots_fname = io.base_name('timing', 'plots') + 'state_memory_use.pdf' io.multipage(plots_fname)
delta = max(1, int(len(x_tick_labels)/n_xticks)) ax.set_xticks(range(0, len(x_tick_labels), delta )) ax.set_xticklabels(x_tick_labels[::delta]) n_yticks = 3 delta = max(1, int(len(y_tick_labels)/n_yticks)) ax.set_yticks(range(0, len(y_tick_labels), delta )) ax.set_yticklabels(y_tick_labels[::delta]) ax.spines['bottom'].set_position(('data',0.1)) ax.spines['left'].set_bounds(0.1, 60) ax.spines['right'].set_bounds(0.1, 60) im_ext = im.get_extent() box = ax.get_position() # cax = plt.axes([box.x1+0.01, box.y0, 0.02, box.height - 0.03]) cax = plt.axes([box.x1-0.03, box.y0, 0.02, box.height - 0.01]) cb = plt.colorbar(im, cax = cax, ticks = [0.0,0.5, 1.0]) # cb.ax.tick_params(labelsize=9) # cb.set_label(r'$s_j$', rotation=0, labelpad = -24, y=1.12) cb.set_label(r'$s^{\mathrm{bond}}$', rotation=0, labelpad = -24, y=1.1, fontsize=14) # cb.set_label(r'$P_1(j,t)$', rotation=0, labelpad = -22, y=1.10) #cax = plt.axes([box.x1-0.05, box.y0+0.2, 0.02, box.height + 0.02]) #cb = plt.colorbar(im, cax = cax) fig.subplots_adjust(wspace=-0.5, hspace=0.2) bn = io.base_name(output_dir,'plots') #plt.savefig(bn+params['mode']+'_sbond_comp.pdf', # dpi=300, clip=True) io.multipage(bn+params['mode']+'_sbond_comp.pdf') #plt.show()
def plot(params, corrj=None): print('Plotting results...') results = h5py.File(params['fname'], 'r+') # get spin projections along x, y, and z x_grid, y_grid, z_grid = [ measures.get_diag_vecs(results[ab][::]) for ab in ('xx', 'yy', 'zz') ] proj_grids_stats = results['stats'] # get g2 correlators at constant row j if corrj is None: corrj = results['gstats']['corrj'][0] x_g2grid, y_g2grid, z_g2grid = [ measures.get_row_vecs(results[ab][::], j=corrj) for ab in ['gxx', 'gyy', 'gzz'] ] g2grids_stats = results['gstats'] # get mi measure results and place in ordered dict for plotting meas_keys = ['ND', 'CC', 'Y'] meas_list = [results[meas_key][::] for meas_key in meas_keys] Fmeas_list = [{ 'amps': results['F' + meas_key][::], 'RN': results['RN' + meas_key][::] } for meas_key in meas_keys] meas_dict = OrderedDict( (key, data) for key, data in zip(meas_keys, meas_list)) Fmeas_dict = OrderedDict( (key, Fdata) for key, Fdata in zip(meas_keys, Fmeas_list)) # get local and entropies stj = results['s'][::] # get mutual information adjacency matrices mtjk = results['m'][::] # plot spin projections proj_titles = [ r'$\langle \sigma^x_j \rangle$', r'$\langle \sigma^y_j \rangle$', r'$\langle \sigma^z_j \rangle$' ] prob_titles = [ r'$\frac{\sum_j j P_j(x-)}{\sum_j P_j(x-)}$', r'$\frac{\sum_j j P_j(y-)}{\sum_j P_j(y-)}$', r'$\frac{\sum_j j P_j(z-)}{\sum_j P_j(z-)}$' ] plot_grids([x_grid, y_grid, z_grid], fignum=0, titles=proj_titles, suptitle='Spin Projections', xlabels=['site', 'site', 'site'], wspace=.05) plot_grid_time_avg_stats(proj_grids_stats, fignum=1, titles=proj_titles) # this makes three figures #plot_grid_center_stats(proj_grids_stats, fignum=2, titles=prob_titles) # plot two-point correlator w.r.t site corrj g2_titles = [ '$g_2(\sigma^x_{%i},\sigma^x_k;t)$' % corrj, '$g_2(\sigma^y_{%i},\sigma^y_k;t)$' % corrj, '$g_2(\sigma^z_{%i},\sigma^z_k;t)$' % corrj ] plot_grids([x_g2grid, y_g2grid, z_g2grid], fignum=5, titles=g2_titles, suptitle='Two Point Correlator', xlabels=['site', 'site', 'site'], wspace=0.05) plot_grid_time_avg_stats(g2grids_stats, fignum=6, titles=g2_titles) #plot_grid_space_center_stats(g2grids_stats, fignum=7, titles=g2_titles) # plot local and bond entropies entropies = [stj] if 'sbond' in results: stc = results['sbond'][::] entropies.append(stc) if len(entropies) == 2: wspace = 0.088 elif len(entropies) == 1: wspace = -0.23 plot_grids(entropies, titles=[r'$S(j,t)$', r'$S_c(j,t)$'], xlabels=['site', 'cut'], suptitle='von Neumann entropies', wspace=wspace, fignum=10) # plot probabilities of spin down and space/time averages plot_grid_with_avgs(z_grid, fignum=11, suptitle='average probability of measuring 1') # plot mi measures plot_measures(meas_dict, fignum=12) # plot measure Fourier transforms plot_measure_fts(Fmeas_dict, fignum=13) # plot distribution of mutual information over time #plot_edge_strength_contour(mtjk, # bins=60, rng=(0,.1), emax=150, fignum=14) # create the full path to where plots will be saved fname = params['fname'] io.base_name(params['output_dir'], 'plots') path_list = fname.split('/') sub_dir_ind = path_list.index('data') path_list[sub_dir_ind] = 'plots' path_ext_list = '/'.join(path_list).split('.') path_ext_list[-1] = '.pdf' out_fname = ''.join(path_ext_list) # save all figures to one pdf io.multipage(out_fname) results.close() plt.close('all') return out_fname
plot_time_series(ys, plt.subplot(gs[0])) plot_ft(freqs, amps, plt.subplot(gs[1]), RN=rn, dt=dt) plt.subplot(gs[1]).scatter(max_freq, max_amp) print('freq found: ', max_freq, ' given freq: ', f) plt.show() if __name__ == '__main__': import time_evolve params = { 'output_dir': 'L27', 'L': 17, 'T': 100, 'mode': 'alt', 'S': 6, 'V': 'HP_0', 'IC': 'f0-16', 'BC': '1_00' } import numpy import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable #fft_check() params['fname'] = io.base_name(params['output_dir'], 'data') +\ io.sim_name(params)+'_v0.hdf5' print(params['fname']) plot(params, corrj=13)