def calculate(): C = constants.const() filename = 'Xcalc_log_cos.txt' """ Load info from collected simulation info file """ f = h5py.File(C['combineread_output'], 'r') var_set = f.get('var_set') theta = np.sort(np.unique(var_set[:, 0])) msg = "theta vec: %s" % str(theta * (180 / np.pi)) fn.WP(msg, filename) f.close f = h5py.File(C['basiscos_output'], 'a') """Evalute the cosine basis functions for theta""" for q in xrange(C['N_q']): vec = np.cos(q * np.pi * theta / C['L_th']) set_id = 'q_%s' % str(q).zfill(5) f.create_dataset(set_id, data=vec) fn.WP(set_id, filename) f.close()
def calculate(): C = constants.const() filename = 'Xcalc_log_cos.txt' """ Load info from collected simulation info file """ f = h5py.File(C['combineread_output'], 'r') var_set = f.get('var_set') theta = np.sort(np.unique(var_set[:, 0])) et_norm = np.sort(np.unique(var_set[:, 4])) f.close f = h5py.File(C['basis_eval_cos'], 'a') """Evalute the cosine basis functions for theta""" for q in xrange(C['N_q']): vec = np.cos(q * np.pi * theta / C['L_th']) set_id = 'q_%s' % str(q).zfill(5) f.create_dataset(set_id, data=vec) fn.WP(set_id, filename) """Evalute the cosine basis functions for en""" for r in xrange(C['N_r']): vec = np.cos(r * np.pi * (et_norm - C['a']) / C['L_en']) set_id = 'r_%s' % str(r).zfill(5) f.create_dataset(set_id, data=vec) fn.WP(set_id, filename) f.close()
def combine(): C = constants.const() filename = 'log_Xcalc_combine.txt' f_master = h5py.File(C['combineXcalc_output'], 'w') """load the cosine basis evaluations""" f_cos = h5py.File(C['Xcalccos_output'], 'r') for name in f_cos.keys(): fn.WP(name, filename) tmp = f_cos.get(name)[...] f_master.create_dataset(name, data=tmp) del tmp f_cos.close() """load the GSH basis evaluations""" for jobnum in xrange(C['XcalcGSH_njobs']): f_gsh = h5py.File(C['XcalcGSH_output'] % str(jobnum).zfill(5), 'r') for name in f_gsh.keys(): fn.WP(name, filename) tmp = f_gsh.get(name)[...] f_master.create_dataset(name, data=tmp) del tmp f_gsh.close() f_master.close()
def calculate(): C = constants_old.const() filename = 'Xcalc_log_cos.txt' """ Load info from collected simulation info file """ f = h5py.File(C['combineread_output'], 'r') var_set = f.get('var_set') theta = var_set[:, 0] f.close f = h5py.File(C['Xcalccos_output'], 'a') """Evalute the cosine basis functions for theta""" st = time.time() for q in xrange(C['N_q']): vec = np.cos(q*np.pi*theta/C['L_th']) set_id = 'q_%s' % str(q).zfill(5) f.create_dataset(set_id, data=vec) fn.WP(set_id, filename) msg = "Cosine basis evaluation for theta complete: %ss" \ % np.round(time.time()-st, 3) fn.WP(msg, filename) f.close()
def job_check(n_jobs, walltime, scriptname, logfile): flag_sum = 0 st = time.time() while flag_sum < n_jobs: time.sleep(5) flag_sum = 0 for ii in xrange(n_jobs): flag_file = "flag%s" % str(ii).zfill(5) if os.path.isfile(flag_file): flag_sum += 1 else: break if (time.time()-st)/3600. > walltime: raise RuntimeError("walltime exceeded for %s" % scriptname) for ii in xrange(n_jobs): os.remove("flag%s" % str(ii).zfill(5)) fn.WP('all jobs completed', logfile)
def combine(): C = constants_old.const() filename = 'log_combine_coef.txt' """ Combine the results of the coefficient determination""" # coeff is the combined vector of coefficients as calculated by the # orthogonal regression coef = np.zeros((C['cmax'], 10), dtype='complex128') c = 0 for tnum in xrange(C['integrate_njobs']): fn.WP(str(tnum), filename) # load partially filled coefficient arrays from each file f = h5py.File(C['integrate_output'] % str(tnum).zfill(5), 'r') coef_prt = f.get('coef_prt')[...] f.close() clen = coef_prt.shape[0] coef[c:c+clen, :] = coef_prt c += clen # save the coefficients file f = h5py.File(C['combinecoef_coef'], 'w') f.create_dataset('coef', data=coef) f.close() rrr = np.hstack([np.arange(coef.shape[0])[:, None], coef[:, 0].real[:, None]]) print np.round(rrr, 1)
filename = 'log_combine_coeff.txt' """ Initialize important variables """ # pick range of indxmat to calculate n_jobs = 5 # number of jobs submitted to PACE N_p = 215 # number of GSH bases to evaluate cmax = N_p # total number of permutations of basis functions print cmax """ Combine the results of the parallelized integration """ # coeff is the combined vector of coefficients as calculated by the # integration coeff = np.zeros(cmax, dtype='complex128') c = 0 for tnum in xrange(n_jobs): fn.WP(str(tnum), filename) # load partially filled XtX arrays from each file f = h5py.File('coeff_prt_%s.hdf5' % tnum, 'r') coeff_prt = f.get('coeff_prt') for ii in xrange(coeff_prt.shape[0]): coeff[c] = coeff_prt[ii] c += 1 f = h5py.File('coeff_total.hdf5', 'w') f.create_dataset('coeff', data=coeff) f.close()
all_basis_p[:, p] = np.squeeze(gsh.gsh_eval(X, [p])) all_basis_q = np.zeros([N_pts, N_q], dtype='complex128') for q in xrange(N_q): all_basis_q[:, q] = np.cos(q * np.pi * theta / L_th) all_basis_r = np.zeros([N_pts, N_r], dtype='complex128') for r in xrange(N_r): all_basis_r[:, r] = np.cos(r * np.pi * (et_norm - a) / L_en) """Select the desired set of coefficients""" cmax = N_p * N_q * N_r # total number of permutations of basis functions fn.WP(str(cmax), filename) cmat = np.unravel_index(np.arange(cmax), [N_p, N_q, N_r]) cmat = np.array(cmat).T cuttoff = thr * np.abs(coeff).max() indxvec = np.arange(cmax)[np.abs(coeff) > cuttoff] N_coef = indxvec.size pct_coef = 100. * N_coef / cmax fn.WP("number of coefficients retained: %s" % N_coef, filename) fn.WP("percentage of coefficients retained %s%%" % np.round(pct_coef, 4), filename) """Perform the prediction""" Y_ = np.zeros(theta.size, dtype='complex128')
def gen(): C = constants.const() filename = 'log_gen_test_data.txt' inc2rad = C['inc'] * np.pi / 180. """get the test euler angle set""" thetavec = (np.arange(C['n_th']) + 0.5) * inc2rad phi1vec = (np.arange(C['n_p1']) + 0.5) * inc2rad phivec = (np.arange(C['n_P']) + 0.5) * inc2rad phi2vec = (np.arange(C['n_p2']) + 0.5) * inc2rad phi1, phi, phi2 = np.meshgrid(phi1vec, phivec, phi2vec) phi1 = phi1.reshape(phi1.size) phi = phi.reshape(phi.size) phi2 = phi2.reshape(phi2.size) angles = np.zeros([C['n_tot'], 4], dtype='float64') for ii in xrange(C['n_th']): ii_stt = ii * C['n_eul'] ii_end = ii_stt + C['n_eul'] angles[ii_stt:ii_end, 0] = thetavec[ii] angles[ii_stt:ii_end, 1] = phi1 angles[ii_stt:ii_end, 2] = phi angles[ii_stt:ii_end, 3] = phi2 """Generate test Y""" bvec = np.random.randint(low=0, high=C['cmax'], size=(5)) bvec[0] = 0 bvec = np.unique(bvec) bval = np.random.randint(low=1, high=10, size=bvec.size) msg = "bvec: %s" % str(bvec) fn.WP(msg, filename) msg = "bval: %s" % str(bval) fn.WP(msg, filename) cmat = np.unravel_index(np.arange(C['cmax']), C['N_tuple']) cmat = np.array(cmat).T Y = np.zeros((C['n_tot']), dtype='complex128') for ii in xrange(bvec.size): p, q = cmat[bvec[ii], :] tmpgsh = gsh.gsh_eval(angles[:, 1:4], [p]) tmpcos = np.cos(q * np.pi * angles[:, 0] / C['L_th']) Y += bval[ii] * np.squeeze(tmpgsh) * tmpcos alldata = np.zeros((C['n_tot'], 14), dtype='complex128') alldata[:, :4] = angles alldata[:, 4] = Y f1 = h5py.File(C['combineread_output'], 'w') f1.create_dataset("var_set", data=alldata) f1.close()
N_L = 15 # number of GSH basis functions N_p = 8 # number of complex exponential basis functions N_q = 8 # number of Legendre basis functions cmax = N_L*N_p*N_q # total number of permutations of basis functions print cmax # XtX is the matrix (X^T * X) in the normal equation for multiple # linear regression XtX = np.zeros((cmax, cmax), dtype='complex128') # pick range of indxmat to calculate n_jobs = 50 # number of jobs submitted to PACE for tnum in xrange(n_jobs): fn.WP(str(tnum), filename) # load partially filled XtX arrays from each file f = h5py.File('XtX%s.hdf5' % tnum, 'r') dotvec = f.get('dotvec') for c in xrange(dotvec.shape[0]): ii, jj = np.real(dotvec[c, 0:2]) if XtX[ii, jj] != 0 and XtX[jj, ii] != 0: fn.WP("overlap in parallel calculations!!!", filename) if ii == jj: XtX[ii, ii] = dotvec[c, 2] else: XtX[ii, jj] = dotvec[c, 2]
# cid.combine() # fn.WP('input files combined', logfile) """run scripts to calculate X for GSH""" af.job_submit(njobs=C['XcalcGSH_njobs'], mem=C['XcalcGSH_mem'], walltime=C['XcalcGSH_walltime'], path=C['path'], scriptname=C['XcalcGSH_scriptname']) """run scripts to calculate X for the cosine bases""" xcos.calculate() fn.WP('X calculated for the cosine bases', logfile) """check to see that the jobs for XcalcGSH have completed""" af.job_check(n_jobs=C['XcalcGSH_njobs'], walltime=C['XcalcGSH_walltime'], scriptname=C['XcalcGSH_scriptname'], logfile=logfile) """combine the X calculations""" cxc.combine() fn.WP('X combined for all bases', logfile) """run scripts to perform the integration for coefficients"""
theta = var_set[:, 0] X = np.zeros((N_pts, 3), dtype='float64') X[:, 0] = var_set[:, 1] # phi1 X[:, 1] = var_set[:, 2] # phi X[:, 2] = var_set[:, 3] # phi2 et_norm = var_set[:, 4] Y = var_set[:, 5] f.close() """Select the desired set of coefficients""" cmax = N_p * N_q * N_r # total number of permutations of basis functions fn.WP(str(cmax), filename) cmat = np.unravel_index(np.arange(cmax), [N_p, N_q, N_r]) cmat = np.array(cmat).T cuttoff = thr * np.abs(coeff).max() indxvec = np.arange(cmax)[np.abs(coeff) > cuttoff] N_coef = indxvec.size pct_coef = 100. * N_coef / cmax fn.WP("number of coefficients retained: %s" % N_coef, filename) fn.WP("percentage of coefficients retained %s%%" % np.round(pct_coef, 4), filename) """Evaluate the parts of the basis function individually""" st = time.time()
af.job_submit(njobs=C['read_njobs'], mem=C['read_mem'], walltime=C['read_walltime'], path=C['path'], scriptname=C['read_scriptname']) """check that the read jobs have completed""" af.job_check(n_jobs=C['read_njobs'], walltime=C['read_walltime'], scriptname=C['read_scriptname'], logfile=logfile) """combine the files to read""" cid.combine() fn.WP('input files combined', logfile) """run scripts to calculate X for GSH""" af.job_submit(njobs=C['XcalcGSH_njobs'], mem=C['XcalcGSH_mem'], walltime=C['XcalcGSH_walltime'], path=C['path'], scriptname=C['XcalcGSH_scriptname']) """run scripts to calculate X for the cosine bases""" xcos.calculate() fn.WP('X calculated for the cosine bases', logfile) """check to see that the jobs for XcalcGSH have completed""" af.job_check(n_jobs=C['XcalcGSH_njobs'], walltime=C['XcalcGSH_walltime'],
import numpy as np import db_functions as fn import constants import h5py C = constants.const() filename = 'log_Xcalc_combine.txt' f_master = h5py.File("X_parts.hdf5", 'w') """load the cosine basis evaluations""" f_cos = h5py.File("X_parts_cos.hdf5", 'r') for name in f_cos.keys(): fn.WP(name, filename) tmp = f_cos.get(name)[...] f_master.create_dataset(name, data=tmp) del tmp f_cos.close() """load the GSH basis evaluations""" for jobnum in xrange(C['n_jobs_Xcalc']): f_gsh = h5py.File("X_parts_GSH_%s.hdf5" % jobnum, 'r') for name in f_gsh.keys(): fn.WP(name, filename) tmp = f_gsh.get(name)[...] f_master.create_dataset(name, data=tmp) del tmp
import itertools as it import db_functions as fn import h5py import time import sys tnum = np.int64(sys.argv[1]) filename = 'log_XtX_%s.txt' % str(tnum) N_L = 15 # number of GSH basis functions N_p = 8 # number of complex exponential basis functions N_q = 8 # number of Legendre basis functions cmax = N_L*N_p*N_q # total number of permutations of basis functions fn.WP(str(cmax), filename) # iivec is vector of indices for all permutations of basis function indices Ivec = np.arange(cmax) # cmat is the matrix containing all permutations of basis function indices cmat = np.unravel_index(np.arange(cmax), [N_L, N_p, N_q]) cmat = np.array(cmat).T # indxmat is the matrix containing all unique combinations of elements of iivec tmp = it.combinations_with_replacement(Ivec, 2) Imat = np.array(list(tmp)) ImatL = Imat.shape[0] fn.WP(str(ImatL), filename) # pick range of indxmat to calculate
cmax = N_L * N_p * N_q cvec = np.unravel_index(np.arange(cmax), [N_L, N_p, N_q]) cvec = np.array(cvec).T st = time.time() f = h5py.File('var_extract_total.hdf5', 'r') var_set = f.get('var_set') Y = var_set[:, 5] f.close XtY = np.zeros(cmax, dtype='complex128') for ii in xrange(cmax): fn.WP(str(ii), filename) L, p, q = cvec[ii, :] set_id_ii = 'set_%s_%s_%s' % (L, p, q) f = h5py.File('pre_fourier_p%s_q%s.hdf5' % (p, q), 'r') ep_set_ii = f.get(set_id_ii)[...] f.close() XtY[ii] = np.dot(ep_set_ii.conj(), Y) f = h5py.File('XtYtotal.hdf5', 'w') f.create_dataset('XtY', data=XtY) f.close() fn.WP("XtY prepared: %ss" % (np.round(time.time() - st, 3)), filename)
X = np.zeros((theta.size, 3), dtype='float64') X[:, 0] = var_set[:, 1] # phi1 X[:, 1] = var_set[:, 2] # phi X[:, 2] = var_set[:, 3] # phi2 Y = var_set[:, 4] f.close() L_th = np.pi / 3. N_p = 215 # number of GSH bases to evaluate N_q = 9 # number of cosine bases to evaluate cmax = N_p * N_q # total number of permutations of basis functions fn.WP(str(theta.size), filename) fn.WP(str(cmax), filename) cmat = np.unravel_index(np.arange(cmax), [N_p, N_q]) cmat = np.array(cmat).T st = time.time() f = h5py.File('X_parts.hdf5', 'r') vec = np.zeros(theta.size, dtype='complex128') # for ii in xrange(10): for ii in xrange(cmax): if np.mod(ii, 100) == 0:
f.close() cmax = N_p * N_q * N_r # total number of permutations of basis functions print cmax """ Combine the results of the coefficient determination and calculate the value of the test function """ # coeff is the combined vector of coefficients as calculated by the # orthogonal regression coeff = np.zeros(cmax, dtype='complex128') Y_ = np.zeros(Y.shape, dtype='complex128') c = 0 for tnum in xrange(n_jobs): fn.WP(str(tnum), filename) # load partially filled coefficient arrays from each file f = h5py.File('coeff_prt_%s.hdf5' % tnum, 'r') coeff_prt = f.get('coeff_prt')[...] test_prt = f.get('test_prt')[...] f.close() Y_ += test_prt # add pre-calculated portions to function prediction # insert pre-calculated coefficients to final list for ii in xrange(coeff_prt.shape[0]): coeff[c] = coeff_prt[ii] c += 1
et_norm = var_set[:, 4] f.close f = h5py.File('X_parts.hdf5', 'a') """ first evalute the GSH basis functions """ st = time.time() for p in xrange(N_p): vec = gsh.gsh_eval(X, [p]) set_id = 'p_%s' % p f.create_dataset(set_id, data=vec) fn.WP(set_id, filename) msg = "GSH basis evaluation complete: %ss" % np.round(time.time() - st, 3) fn.WP(msg, filename) """ second evalute the cosine basis functions for theta""" st = time.time() for q in xrange(N_q): vec = np.cos(q * np.pi * theta / L_th) set_id = 'q_%s' % q f.create_dataset(set_id, data=vec) fn.WP(set_id, filename)
n_th = 60/inc_th # number of theta samples for FZ n_p1 = 360/inc_eul # number of phi1 samples for FZ n_P = 90/inc_eul # number of Phi samples for FZ n_p2 = 60/inc_eul # number of phi2 samples for FZ n_en = 14 # number of et samples for FZ L_th = np.pi/3. L_en = b-a n_eul = n_p1*n_P*n_p2 """ Calculate basis function indices """ cmax = N_p*N_q*N_r # total number of permutations of basis functions fn.WP(str(cmax), filename) # cmat is the matrix containing all permutations of basis function indices cmat = np.unravel_index(np.arange(cmax), [N_p, N_q, N_r]) cmat = np.array(cmat).T """ Deal with the parallelization of this operation specifically pick range of indxmat to calculate """ n_ii = np.int64(np.ceil(np.float(cmax)/n_jobs)) # number dot products per job fn.WP(str(n_ii), filename) ii_stt = tnum*n_ii # start index if (tnum+1)*n_ii > cmax: ii_end = cmax else: ii_end = (tnum+1)*n_ii # end index
# """check to see that the jobs for XcalcGSH have completed""" # af.job_check(n_jobs=C['basisgsh_njobs'], # walltime=C['basisgsh_walltime'], # scriptname=C['basisgsh_scriptname'], # logfile=logfile) # fn.WP('gsh bases evaluated', logfile) # """combine the basis evaluations""" # bc.combine() # fn.WP('all bases combined', logfile) """run scripts to perform the integration for coefficients""" af.job_submit(njobs=C['integrate_njobs'], mem=C['integrate_mem'], walltime=C['integrate_walltime'], path=C['path'], scriptname=C['integrate_scriptname']) """check to see that the jobs for integrate_parallel have completed""" af.job_check(n_jobs=C['integrate_njobs'], walltime=C['integrate_walltime'], scriptname=C['integrate_scriptname'], logfile=logfile) """combine the coefficients""" cc.combine() fn.WP('coefficients combined', logfile)
def evalf(theta, euler, var_id, thr, LL_p): """variable assignments var_id 0: sigma'11 var_id 1: sigma'22 var_id 2: sigma'33 var_id 3: sigma'12 var_id 4: sigma'12 var_id 5: sigma'23 var_id 6: total shear rate var_id 7: w12 var_id 8: w13 var_id 9: w23 """ filename = "log_eval.txt" C = constants.const() f = h5py.File('coef.hdf5', 'r') coef = f.get('coef')[:, var_id] f.close() basis_info = gsh.gsh_basis_info() N_p_tmp = np.sum( basis_info[:, 0] <= LL_p) # number of GSH bases to evaluate N_pts = theta.size """Select the desired set of coefficients""" msg = "cmax: %s" % C['cmax'] fn.WP(msg, filename) cmat = np.unravel_index(np.arange(C['cmax']), C['N_tuple']) cmat = np.array(cmat).T cuttoff = thr * np.abs(coef).max() print "cutoff: %s" % cuttoff cuttoffvec = (np.abs(coef) > cuttoff) * \ (np.arange(C['cmax']) < N_p_tmp*C['N_q']) print "cuttoffvec.shape: %s" % str(cuttoffvec.shape) indxvec = np.arange(C['cmax'])[cuttoffvec] N_coef = indxvec.size pct_coef = 100. * N_coef / (N_p_tmp * C['N_q']) fn.WP("number of coefficients retained: %s" % N_coef, filename) fn.WP("percentage of coefficients retained %s%%" % np.round(pct_coef, 4), filename) """Evaluate the parts of the basis function individually""" st = time.time() p_U = np.unique(cmat[indxvec, 0]) q_U = np.unique(cmat[indxvec, 1]) all_basis_p = np.zeros([N_pts, C['N_p']], dtype='complex128') for p in p_U: all_basis_p[:, p] = np.squeeze(gsh.gsh_eval(euler, [p])) fn.WP("number of p basis functions used: %s" % p_U.size, filename) all_basis_q = np.zeros([N_pts, C['N_q']], dtype='complex128') for q in q_U: all_basis_q[:, q] = np.cos(q * np.pi * theta / C['L_th']) fn.WP("number of q basis functions used: %s" % q_U.size, filename) """Perform the prediction""" Y_ = np.zeros(theta.size, dtype='complex128') for ii in indxvec: p, q = cmat[ii, :] basis_p = all_basis_p[:, p] basis_q = all_basis_q[:, q] ep_set = basis_p * basis_q Y_ += coef[ii] * ep_set if np.mod(ii, 1000) == 0: msg = "evaluation complete for coefficient" +\ " %s out of %s" % (ii, N_coef) fn.WP(msg, filename) Ttime = np.round(time.time() - st, 3) msg = "total interpolation time: %ss" % Ttime fn.WP(msg, filename) msg = "interpolation time per point: %s" % (Ttime / theta.size) fn.WP(msg, filename) return Y_
import db_functions as fn import gsh_cub_tri_L0_16 as gsh import h5py import time import sys import constants tnum = np.int64(sys.argv[1]) C = constants.const() filename = 'log_integrate_parallel_%s.txt' % str(tnum).zfill(5) """calculate basis function indices""" # cmax: total number of permutations of basis functions fn.WP(str(C['cmax']), filename) # cmat is the matrix containing all permutations of basis function indices cmat = np.unravel_index(np.arange(C['cmax']), C['N_tuple']) cmat = np.array(cmat).T """deal with the parallelization of this operation specifically pick range of indxmat to calculate""" # n_ii: number integrations per job n_ii = np.int64(np.ceil(np.float(C['cmax'])/C['integrate_njobs'])) fn.WP(str(n_ii), filename) ii_stt = tnum*n_ii # start index ii_end = ii_stt + n_ii # end index if ii_end > C['cmax']:
all_basis_p[:, p] = np.squeeze(gsh.gsh_eval(X, [p])) all_basis_q = np.zeros([N_pts, N_q], dtype='complex128') for q in xrange(N_q): all_basis_q[:, q] = np.cos(q * np.pi * theta / L_th) all_basis_r = np.zeros([N_pts, N_r], dtype='complex128') for r in xrange(N_r): all_basis_r[:, r] = np.cos(r * np.pi * (et_norm - a) / L_en) """Select the desired set of coefficients""" cmax = N_p * N_q * N_r # total number of permutations of basis functions fn.WP(str(cmax), filename) cmat = np.unravel_index(np.arange(cmax), [N_p, N_q, N_r]) cmat = np.array(cmat).T cuttoff = thr * np.abs(coeff).max indxvec = np.arange(cmax)[np.abs(coeff) > cuttoff] """Perform the prediction""" Y_ = np.zeros(theta.size, dtype='complex128') modval = np.round(cmax, 1 - len(str(cmax))) / 100 fn.WP("modval: %s" % modval, filename) # for ii in xrange(10): for ii in xrange(cmax):
import sys import constants tnum = np.int64(sys.argv[1]) C = constants.const() filename = 'log_basis_eval_gsh_%s.txt' % str(tnum).zfill(5) """ Load info from collected simulation info file """ f = h5py.File(C['combineread_output'], 'r') var_set = f.get('var_set') g = np.zeros((C['n_eul'], 3), dtype='float64') g[...] = var_set[:C['n_eul'], 1:4] msg = "unique phi1: %s" % str(np.unique(g[:, 0]) * (180 / np.pi)) fn.WP(msg, filename) msg = "unique Phi: %s" % str(np.unique(g[:, 1]) * (180 / np.pi)) fn.WP(msg, filename) msg = "unique phi2: %s" % str(np.unique(g[:, 2]) * (180 / np.pi)) fn.WP(msg, filename) f.close """ Deal with the parallelization of this operation specifically pick range of indxmat to calculate """ # n_ii: number of basis evaluations per job n_ii = np.int64(np.ceil(np.float(C['N_p']) / C['basisgsh_njobs'])) fn.WP(str(n_ii), filename) ii_stt = tnum * n_ii # start index ii_end = ii_stt + n_ii # end index
f.close f = h5py.File('X_parts.hdf5', 'a') """ first evalute the GSH basis functions """ st = time.time() for p in xrange(N_p): vec = gsh.gsh(X, [p]) set_id = 'p_%s' % p f.create_dataset(set_id, data=vec) msg = "GSH basis evaluation complete: %ss" % np.round(time.time() - st, 3) fn.WP(msg, filename) """ second evalute the cosine basis functions """ st = time.time() for q in xrange(N_q): vec = np.cos(2. * np.pi * q * theta / L_th) set_id = 'q_%s' % q f.create_dataset(set_id, data=vec) msg = "Cosine basis evaluation complete: %ss" % np.round(time.time() - st, 3) fn.WP(msg, filename) """ third evalute the legendre basis functions """
def combine(): C = constants.const() filename = 'log_combine_coef.txt' st = time.time() # start timing f = h5py.File(C['combineread_output'], 'r') var_set = f.get('var_set') theta = var_set[:, 0] X = np.zeros((theta.size, 3), dtype='float64') X[:, 0] = var_set[:, 1] # phi1 X[:, 1] = var_set[:, 2] # phi X[:, 2] = var_set[:, 3] # phi2 et_norm = var_set[:, 4] Y = var_set[:, 5] f.close() """ Combine the results of the coefficient determination and calculate the value of the test function """ # coeff is the combined vector of coefficients as calculated by the # orthogonal regression coef = np.zeros(C['cmax'], dtype='complex128') Y_ = np.zeros(Y.shape, dtype='complex128') c = 0 for tnum in xrange(C['integrate_njobs']): fn.WP(str(tnum), filename) # load partially filled coefficient arrays from each file f = h5py.File('coef_prt_%s.hdf5' % str(tnum).zfill(5), 'r') coef_prt = f.get('coef_prt')[...] test_prt = f.get('test_prt')[...] f.close() Y_ += test_prt # add pre-calculated portions to function prediction # insert pre-calculated coefficients to final list for ii in xrange(coef_prt.shape[0]): coef[c] = coef_prt[ii] c += 1 # save the coefficients file f = h5py.File(C['combinecoef_coef'], 'w') f.create_dataset('coef', data=coef) f.close() Ttime = np.round(time.time() - st, 3) msg = "total interpolation time: %ss" % Ttime fn.WP(msg, filename) msg = str(Y_.shape) fn.WP(msg, filename) error = np.abs(np.real(Y_) - Y) msg = "min function value: %s" % Y.min() fn.WP(msg, filename) msg = "mean function values: %s" % Y.mean() fn.WP(msg, filename) msg = "max function value: %s" % Y.max() fn.WP(msg, filename) msg = "mean prediction value: %s" % np.real(Y_).mean() fn.WP(msg, filename) msg = "mean error: %s" % error.mean() fn.WP(msg, filename) msg = "std of error: %s" % error.std() fn.WP(msg, filename) msg = "max error: %s" % error.max() fn.WP(msg, filename) f = h5py.File(C['combinecoef_results'], 'w') results = np.zeros((Y.size, 8), dtype='complex128') results[:, 0] = theta results[:, 1:4] = X results[:, 4] = et_norm results[:, 5] = Y results[:, 6] = Y_ results[:, 7] = error f.create_dataset('results', data=results) f.close()