def neuralnetpredict(pm, bs, nc, numd, seed, zz=0): '''For the given box, mesh, numd, seed and redshift, do the neural network prediction from the network saved in cfg file and return predict, nnpred, nnmass ''' dpath = '/global/project/projectdirs/astro250/chmodi/cosmo4d/' import yaml import nettools as ntools with open(dpath + 'train/models.yaml', 'r') as ymlfile: cfg = yaml.load(ymlfile) ptpath = dpath + 'train/' + cfg['%s-%s' % (int(bs), int(nc))][0][numd]['ppath'] mtpath = ptpath + cfg['%s-%s' % (int(bs), int(nc))][0][numd]['mpath'] # mtpath = ptpath + cfg['%s-%s'%(bs,nc)][0][numd]['mpathnf'] ptup, pftname, plocal, pdict = ntools.setuppos2(ptpath) mtup, mftname, mlocal, mdict = ntools.setupmass(mtpath) R1, R2 = pdict['R1'], pdict['R2'] num = int(numd * bs**3) meshdict, hdict = ntools.readfiles( pm, dpath + '/data/z%02d/L%04d_N%04d_S%04d_05step/' % (zz, bs, nc, seed), R1=R1, R2=R2, mexp=None) ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal) mftt = ntools.createdata(pm, meshdict, mftname, mlocal) nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc) nnmass = ntools.applynet(mftt, mtup).reshape(nc, nc, nc) predict = nnpred * nnmass ## return pm.create(mode='real', value=predict), nnpred, nnmass
else: mtup, mftname, mlocal, mdict = ntools.setupmass(mtpath) R1, R2 = pdict['R1'], pdict['R2'] #####Files #model predicts, datas = [], [] datasgs = [[], []] sgs = [0.1, 0.20] for seed in [100, 500, 900, 800]: meshdict, dummy = ntools.readfiles( pm, scratch + '/data/L%04d_N%04d_S%04d_05step/' % (bs, nc, seed), R1=R1, R2=R2, abund=abund, doexp=doexp, mexp=mexp, cc=cc, stellar=stellar) ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal) mftt = ntools.createdata(pm, meshdict, mftname, mlocal) nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc) if regression: nnmass = ntools.applymassreg(mftt, mtup).reshape(nc, nc, nc) else: nnmass = ntools.applynet(mftt, mtup).reshape(nc, nc, nc) if doexp: nnmass = mf.fmexp(ntools.relu(nnmass), mexp, cc) predict = pm.create(mode='real') predict[...] = nnpred * nnmass
mbinsm = 10**mbinsm msave = [1e15] + list(mbinsm) ptpath = train + cfg['%s-%s' % (bs, nc)][0][numd]['ppath'] mtpath = ptpath + cfg['%s-%s' % (bs, nc)][0][numd]['mpath'] #ptpath = train + 'L0400_N0128_05step-n10/width_5/Wts_50_1/r3rf1/hlim-20_clim-20_nreg-40_batch-100/' #mtpath = ptpath + '/eluWts-20_1/blim-13_nreg-33_batch-1000/' ptup, pftname, plocal, pdict = ntools.setuppos2(ptpath) mtup, mftname, mlocal, mdict = ntools.setupmass(mtpath) R1, R2 = pdict['R1'], pdict['R2'] #model meshdict, dummy = ntools.readfiles( pm, scratch + '/data/L%04d_N%04d_S%04d_05step/' % (bs, nc, seed), R1=R1, R2=R2, abund=abund) ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal) mftt = ntools.createdata(pm, meshdict, mftname, mlocal) nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc) nnmass = ntools.applynet(mftt, mtup).reshape(nc, nc, nc) predict = pm.create(mode='real') predict[...] = nnpred * nnmass predictR = ft.smooth(predict, 3, 'fingauss') #data #hdictf = ntools.gridhalos(pm, scratch +'/data/L%04d_N%04d_S%04d_40step/'%(bs, 4*nc, seed), rank=num, R1=R1, R2=R2, pmesh=True) #datapt = pm.create(mode='real', zeros=True) #datapt[...] = hdictf[0]['halomesh']
else: mtup, mftname, mlocal, mdict = ntools.setupmass(mtpath) R1 = pdict['R1'] try: R2 = pdict['R2'] except: sfac = pdict['sfac'] R2 = R1 * sfac #model print('Reading Files') meshdict, dummy = ntools.readfiles( pm, proj + '/data/z%02d/L%04d_N%04d_S%04d_05step/' % (zz * 10, bs, nc, seed), R1=R1, R2=R2, abund=abund, doexp=doexp, mexp=mexp, cc=cc, stellar=stellar) ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal) mftt = ntools.createdata(pm, meshdict, mftname, mlocal) nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc) nnmass = ntools.applynet(mftt, mtup).reshape(nc, nc, nc) predict = pm.create(mode='real') predict[...] = nnpred * nnmass predictr = ntools.relu(predict[...]) #predictR = ft.smooth(predict, Rsm, 'fingauss') #data
print(key, ' = ', ddict[key]) ########### #for seed in ddict['seeds']: # pass seed = 100 proj = '/project/projectdirs/astro250/chmodi/cosmo4d/' dpath = proj + 'data/z%02d/L%04d_N%04d_S%04d_%02dstep/' % (zz * 10, bs, nc, seed, 5) dpathf = proj + 'data/z%02d/L%04d_N%04d_S%04d_%02dstep/' % ( zz * 10, bs, fine * nc, seed, 40) meshdict, halos = readfiles(pm, dpath, R1, R2, abund=False, quad=False, z=zz, shear=False) halosf = gridhalos(pm, dpath=dpathf, rank=None, abund=False, sigma=False, seed=seed, pmesh=True, z=zz) print('Keys in meshdict ', meshdict.keys()) print('Keys in halos ', halos.keys()) print('Length of list halosf ', len(halosf))