def check_nrg(value): """ Check for PDF energy against known value :param value: :return: """ # setup atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans = atoms2.get_potential_energy() assert ans >= thresh del atoms1, atoms2, proc1, alg1, p, thresh, scat, target_data, calc, ans
def check_del_atom(value): atoms, exp = value[0:2] proc, alg = value[-1] scat = ElasticScatter(exp_dict=exp, verbose=True) scat.set_processor(proc, alg) assert scat._check_wrap_atoms_state(atoms) == False # Test a set of different sized ensembles ans1 = scat.get_fq(atoms) assert scat._check_wrap_atoms_state(atoms) == True # Check that Scatter gave back something assert ans1 is not None assert np.any(ans1) atoms2 = dc(atoms) del atoms2[np.random.choice(len(atoms2))] assert scat._check_wrap_atoms_state(atoms2) == False ans2 = scat.get_fq(atoms2) assert scat._check_wrap_atoms_state(atoms2) == True # Check that Scatter gave back something assert ans2 is not None assert np.any(ans2) assert not np.allclose(ans1, ans2) # make certain we did not give back the same pointer assert ans1 is not ans2 # Check that all the values are not zero del atoms, exp, proc, alg, scat, ans1 return
def check_scatter_fq(value): """ Smoke test for FQ Parameters ---------- value: list or tuple The values to use in the tests """ atoms, exp = value[0:2] proc, alg = value[-1] scat = ElasticScatter(exp_dict=exp, verbose=True) scat.set_processor(proc, alg) # Test a set of different sized ensembles ans = scat.get_fq(atoms) # Check that Scatter gave back something assert ans is not None # Check that all the values are not zero assert np.any(ans) del atoms, exp, proc, alg, scat, ans return
def check_scatter_sq(value): """ Check two processor, algorithm pairs against each other for SQ calculation :param value: :return: """ # set everything up atoms, exp = value[:2] scat = ElasticScatter(exp_dict=exp, verbose=True) proc1, alg1 = value[-1][0] proc2, alg2 = value[-1][1] # run algorithm 1 scat.set_processor(proc1, alg1) ans1 = scat.get_sq(atoms) # run algorithm 2 scat.set_processor(proc2, alg2) ans2 = scat.get_sq(atoms) # test stats_check(ans1, ans2, rtol, atol) assert_allclose(ans1, ans2, rtol=rtol, atol=atol) # make certain we did not give back the same pointer assert ans1 is not ans2
def check_scatter_consistancy(value): atoms, exp = value[0:2] proc, alg = value[-1] scat = ElasticScatter(exp_dict=exp, verbose=True) scat.set_processor(proc, alg) ans = scat.get_pdf(atoms) ans1 = scat.get_fq(atoms) print(len(ans1)) print(scat.get_scatter_vector().shape) ans2 = scat.get_sq(atoms) print(len(ans2)) ans3 = scat.get_iq(atoms)
def check_nrg(value): """ Check two processor, algorithm pairs against each other for PDF energy Parameters ---------- value: list or tuple The values to use in the tests """ rtol = 4e-6 atol = 9e-6 # setup atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3][0] proc2, alg2 = value[3][1] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans1 = atoms2.get_potential_energy() scat.set_processor(proc2, alg2) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans2 = atoms2.get_potential_energy() stats_check(ans2, ans1, rtol, atol)
def check_forces(value): """ Check two processor, algorithm pairs against each other for PDF forces :param value: :return: """ # setup rtol = 1e-4 atol = 6e-5 atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3][0] proc2, alg2 = value[3][1] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans1 = atoms2.get_forces() scat.set_processor(proc2, alg2) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) ans2 = atoms2.get_forces() stats_check(ans2, ans1, rtol=rtol, atol=atol)
def check_forces(value): """ Check for PDF forces against known value :param value: :return: """ # setup atoms1, atoms2 = value[0] exp_dict = value[1] p, thresh = value[2] proc1, alg1 = value[3] scat = ElasticScatter(verbose=True) scat.update_experiment(exp_dict) scat.set_processor(proc1, alg1) if value[4] == 'FQ': exp_func = scat.get_fq exp_grad = scat.get_grad_fq elif value[4] == 'PDF': exp_func = scat.get_pdf exp_grad = scat.get_grad_pdf else: exp_func = None exp_grad = None target_data = exp_func(atoms1) calc = Calc1D(target_data=target_data, exp_function=exp_func, exp_grad_function=exp_grad, potential=p) atoms2.set_calculator(calc) # print atoms2.get_potential_energy() forces = atoms2.get_forces() print(forces) com = atoms2.get_center_of_mass() for i in range(len(atoms2)): dist = atoms2[i].position - com stats_check(np.cross(dist, forces[i]), np.zeros(3), atol=1e-7) del dist del atoms1, atoms2, proc1, alg1, p, thresh, scat, target_data, calc, \ forces, com
def check_scatter_grad_pdf(value): """ Smoke test for grad PDF :param value: :return: """ atoms, exp = value[0:2] proc, alg = value[-1] scat = ElasticScatter(exp_dict=exp, verbose=True) scat.set_processor(proc, alg) # Test a set of different sized ensembles ans = scat.get_grad_pdf(atoms) # Check that Scatter gave back something assert ans is not None # Check that all the values are not zero assert np.any(ans) del atoms, exp, proc, alg, scat, ans return
atoms = Atoms('Au4', [[0,0,0], [3,0,0], [0,3,0], [3,3,0]]) pdf = scat.get_pdf(atoms) type_list = [] time_list = [] benchmarks = [ ('CPU', 'flat'), ('Multi-GPU', 'flat') ] colors=['b', 'r'] sizes = range(10, 80, 5) print sizes for proc, alg in benchmarks: print proc, alg number_of_atoms = [] scat.set_processor(proc, alg) type_list.append((proc, alg)) nrg_l = [] f_l = [] try: for i in sizes: atoms = build_sphere_np('/mnt/work-data/dev/pyIID/benchmarks/1100138.cif', float(i) / 2) atoms.rattle() print len(atoms), i/10. number_of_atoms.append(len(atoms)) calc = PDFCalc(obs_data=pdf, scatter=scat, conv=1, potential='rw') atoms.set_calculator(calc) s = time.time() nrg = atoms.get_potential_energy() # scat.get_fq(atoms)