Skip to content
Snippets Groups Projects
Commit 43c5016e authored by Qian Gong's avatar Qian Gong
Browse files

add data re-org code

parent 2d6c0473
Branches ml_dca
No related tags found
No related merge requests found
import sys
sys.path.append('/ccs/home/gongq/andes/indir/lib/python3.7/site-packages/adios2/')
import adios2 as ad2
import numpy as np
n_meas = 10000 # 50000
n_rank = 10
n_walk = 1
num_Gw = n_meas*n_rank*n_walk
# read G_k_w from single_meas_G.bp
G_k_w = np.zeros((num_Gw, 2, 1024), dtype='complex128')
# spins, times
vertexConf = np.zeros((num_Gw, 2, 1024), dtype='float64')
log_w = np.zeros(num_Gw, dtype='float64')
k = np.zeros(num_Gw, dtype='int32')
k_max = 1
#Mfun = np.zeros((num_Gw, 2, 1024), dtype='complex128')
# filename = '/gpfs/alpine/world-shared/cph102/epd/single_meas_G_additional_dens1.bp'
#filename = '/gpfs/alpine/world-shared/cph102/epd/single_meas_G_2_500K_additional_dens1/single_meas_G_2_250K_additional_dens1.bp'
filename = '/gpfs/alpine/world-shared/cph102/epd/single_meas_G_100B_100k_5.bp'
with ad2.open(filename, 'r') as fh:
for i in range(1,n_meas+1):
p = i * (n_rank*n_walk)
for j in range(n_rank):
q = j*n_walk
for walks in range(n_walk):
# MFunction = fh.read('/STQW_Configurations/r_'+str(j)+'_meas_'+str(i)+'_w_'+str(walks)+'/MFunction')
Gw = fh.read('/STQW_Configurations/r_'+str(j)+'_meas_'+str(i)+'_w_'+str(walks)+'/G_k_w')
config = fh.read('/STQW_Configurations/r_'+str(j)+'_meas_'+str(i)+'_w_'+str(walks)+'/times')
spins = fh.read('/STQW_Configurations/r_'+str(j)+'_meas_'+str(i)+'_w_'+str(walks)+'/spins')
idx = p+q+walks-n_rank*n_walk
# Mfun[idx, 0, :] = MFunction[:, 0, 0, 0, 0, 0]
# Mfun[idx, 1, :] = MFunction[:, 0, 1, 0, 1, 0]
# print('/STQW_Configurations/r_'+str(j)+'_meas_'+str(i)+'_w_'+str(k)+'/times')
# print(Gw.shape, config.shape)
print(i,j, idx, Gw.shape)
k[idx] = config.shape[0]
k_max = max(k[idx], k_max)
vertexConf[idx, 0, :k[idx]] = config
vertexConf[idx, 1, :k[idx]] = spins
log_w[idx] = fh.read('/STQW_Configurations/r_'+str(j)+'_meas_'+str(i)+'_w_'+str(walks)+'/log-weight')
G_k_w[idx,0,:] = Gw[:,0,0,0,0,0]
G_k_w[idx,1,:] = Gw[:,0,1,0,1,0]
# print(idx, vertexConf[idx,:,:].max())
#Mfun.tofile('MFunction.txt')
#G_k_w.tofile('G_k_w.txt')
#log_w.tofile('log_weight.txt')
#k.tofile('vertext_k.txt')
#vertexConf.tofile('vertexConf.txt')
#print('max vertex: ', k.max())
with ad2.open('single_meas_G_100B_100k_5.bp', 'w') as fh:
fh.write("vertexConf", np.ascontiguousarray(vertexConf.flatten(), dtype=np.float64), vertexConf.shape, [0, 0, 0], vertexConf.shape)
fh.write("G_wn", np.ascontiguousarray(G_k_w.flatten(), dtype=np.complex128), G_k_w.shape, [0, 0, 0], G_k_w.shape)
# fh.write("M_wn", np.ascontiguousarray(Mfun.flatten(), dtype=np.complex128), Mfun.shape, [0, 0, 0], Mfun.shape)
fh.write("k" , np.ascontiguousarray(k.flatten() , dtype=np.int32), [num_Gw], [0], [num_Gw])
fh.write("log_w" , np.ascontiguousarray(log_w.flatten() , dtype=np.int32), [num_Gw], [0], [num_Gw])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment