def sample_cutoff(test): print "** Sampling for Real Space" samples_dir = Config.get_test_samples_dir(Config.test) Config.create_dir(samples_dir) lmp_config = PPPMUtilities.LammpsPPPMConfig() lmp_config.npart = test.npart lmp_config.timesteps = test.timesteps lmp_config.ewald = real_space_sampling_params["ewald"] # cutoff set in the loop lmp_config.order = real_space_sampling_params["order"] lmp_config.grid = real_space_sampling_params["grid"] lmp_config.mixing = test.mixing lmp_config.diff = test.diff_mode # cutoffs = get_sampled_cutoffs(test.npart, test.domain, test.box) timings = [None for _ in cutoffs] ewald = rsp["ewald"] P = rsp["order"] grid = rsp["grid"] for i, c in enumerate( get_sampled_cutoffs(test.npart, test.domain, test.box)): try: t = extract_timings_from_log( os.path.join(samples_dir, "Output-%s-%s-%.2f-%.2f-%d-%dx%dx%d" % \ (test.diff_mode, test.mixing, ewald, c, P, grid[0], grid[1], grid[2])) )[1] timings[i] = t except Exception, e: pass
def fit_neigh(test): samples_dir = Config.get_test_samples_dir(Config.test) cutoffs, timings = [], [] ewald = rsp["ewald"] P = rsp["order"] grid = rsp["grid"] for c in get_sampled_cutoffs(test.npart, test.domain, test.box): try: t = extract_timings_from_log( os.path.join(samples_dir, "Output-%s-%s-%.2f-%.2f-%d-%dx%dx%d" % \ (test.diff_mode, test.mixing, ewald, c, P, grid[0], grid[1], grid[2])) )[3] cutoffs.append(c) timings.append(t) except Exception, e: pass
def fit_samples(npart, domain, box, mixing, np, nn, ts, diff): cwd = os.getcwd() os.chdir(Config.get_test_samples_dir(Config.test)) fits = [] fit_cutoff(Config.test) fits.append(get_real_space_prediction) fit_neigh(Config.test) fits.append(get_neigh_prediction) # kspace samples ewald = ksp["ewald"] cutoffs = get_sampled_cutoffs(npart, domain, box) _c.extend((cutoffs[0], cutoffs[-1])) Ps = get_sampled_Ps(npart, domain, box) grids = get_sampled_grid_sizes(npart, domain, box) for i, cutoff in enumerate([cutoffs[0], cutoffs[-1]]): _kspace_piecewise[i].extend( [None for _ in range(Ps[0] - Config.order_values[0])]) for P in Ps: timings = [] gs = [] for grid in grids: try: t = extract_timings_from_log( "Output-%s-%s-%.2f-%.2f-%d-%dx%dx%d" % (diff, mixing, ewald, cutoff, P, grid[0], grid[1], grid[2]))[2] gs.append(grid) timings.append(t) except Exception, e: pass try: x, y = filter_data([mult(g_) for g_ in gs], timings) bounds, fit_vars = topdown.top_down(numpy.array(x), numpy.array(y), kspace_fitting_f) _kspace_piecewise[i].append((bounds, fit_vars)) except ValueError, e: print e print >> sys.stderr, "Cannot fit. Infs or Nans found." (p, g) = (float('NaN'), float('NaN')) raise Exception
def sample(lmp_config, target, value): if target in ("cutoff", "neigh"): lmp_config.cutoff = value if target == "cutoff": log_pos = 1 else: log_pos = 3 print "Sampling cutoff:", value elif target == "kspace": # gonna need to deal with grid and mult(grid) lmp_config.grid = value log_pos = 2 print "Sampling grid:", value #return # Set paths and write lammps config file lmp_config.set_file_paths(Config.get_test_samples_dir(Config.test)) lmp_config.write_config_file(lmp_config.infile) # done = False attempt = 1 while not done and attempt <= 10: try: os.remove(lmp_config.outfile) except OSError: pass try: #subprocess32.check_call("mpirun -np %d $HOME/MD-libs/lammps-22Jan14/src/lmp_openmpi -l /dev/null < %s > %s" % (Config.test.nprocesses, lmp_config.infile, lmp_config.outfile), shell=True, timeout=1500) subprocess32.check_call( "$MPIEXEC -np %d $HOME/MD-libs/lammps-22Jan14/src/lmp_openmpi -l /dev/null < %s > %s" % (Config.test.nprocesses, lmp_config.infile, lmp_config.outfile), shell=True, timeout=1500) t = extract_timings_from_log(lmp_config.outfile)[log_pos] if not math.isnan(t): done = True except subprocess32.TimeoutExpired: pass attempt += 1 if done: return t else: raise Exception
def sample_kspace(test): print "** Sampling for KSpace" samples_dir = Config.get_test_samples_dir(Config.test) Config.create_dir(samples_dir) lmp_config = PPPMUtilities.LammpsPPPMConfig() lmp_config.npart = test.npart lmp_config.timesteps = test.timesteps lmp_config.ewald = kspace_sampling_params["ewald"] lmp_config.mixing = test.mixing lmp_config.diff = test.diff_mode # grids = get_sampled_grid_sizes(test.npart, test.domain, test.box) grids_cont = [mult(g) for g in grids] Ps = get_sampled_Ps(test.npart, test.domain, test.box) # cutoffs = get_sampled_cutoffs(test.npart, test.domain, test.box) c_min = cutoffs[0] c_max = cutoffs[-1] ewald = kspace_sampling_params["ewald"] for c in [c_min, c_max]: lmp_config.cutoff = c for P in Ps: lmp_config.order = P timings = [None for _ in grids] for i, g in enumerate(grids): try: t = extract_timings_from_log( os.path.join(samples_dir, "Output-%s-%s-%.2f-%.2f-%d-%dx%dx%d" % \ (test.diff_mode, test.mixing, ewald, c, P, g[0], g[1], g[2])) )[2] if not math.isnan(t): timings[i] = t except Exception, e: print c, P, g, e pass dynamic_sampling(lmp_config, "kspace", grids_cont, grids, timings, kspace_fitting_f)
def get_interface_timings(npart, domain, box, mixing, np, nn, ts, diff, accuracy): diff = diff mixing = mixing grids = get_grid_sizes(npart, domain, box) timings = [] for (cutoff_idx, P_idx, grid_idx, ewald_error) in get_interface_points(npart, domain, box): # extract parameters cutoff = Config.cutoff_values[cutoff_idx] P = Config.order_values[P_idx] grid = grids[grid_idx] ewald = ewald_error[0][0] # load data output_dir = Config.get_test_timings_dir(Config.test) fp = os.path.join( output_dir, "Output-%s-%s-%.2f-%.2f-%d-%dx%dx%d" % (diff, mixing, ewald, cutoff, P, grid[0], grid[1], grid[2])) #t = extract_timings_from_log_full( fp ) # tuple (total, real, kspace) t = extract_timings_from_log(fp) # tuple (total, real, kspace) # store timings.append((t, (cutoff_idx, P_idx, grid_idx, ewald_error))) #print timings[-1] return timings