def test_pw2qmcpack_incorporate_result(): from generic import NexusError,obj from simulation import Simulation from test_pwscf_simulation import pseudo_inputs,get_pwscf_sim tpath = testing.setup_unit_test_output_directory('pwscf_simulation','test_check_result',**pseudo_inputs) other = Simulation() scf = get_pwscf_sim('scf') sim = get_pw2qmcpack_sim(path='scf') try: sim.incorporate_result('unknown',None,other) raise TestFailed except NexusError: None except FailedTest: failed() except Exception as e: failed(str(e)) #end try sim.incorporate_result('orbitals',None,scf) clear_all_sims() restore_nexus()
def test_convert4qmc_get_result(): from generic import NexusError,obj sim = get_convert4qmc_sim() try: sim.get_result('unknown',None) raise FailedTest except NexusError: None except FailedTest: failed() except Exception as e: failed(str(e)) #end try result = sim.get_result('orbitals',None) result_ref = obj( location = './runs/sample.wfj.xml', ) assert(object_eq(result,result_ref)) result = sim.get_result('particles',None) result_ref = obj( location = './runs/sample.structure.xml', ) assert(object_eq(result,result_ref)) clear_all_sims()
def test_pyscf_to_afqmc_get_result(): from generic import NexusError,obj sim = get_pyscf_to_afqmc_sim() sim.input.output = 'afqmc.h5' try: sim.get_result('unknown',None) raise FailedTest except NexusError: None except FailedTest: failed() except Exception as e: failed(str(e)) #end try result_ref = obj( h5_file = './runs/afqmc.h5', ) result = sim.get_result('wavefunction',None) assert(object_eq(result,result_ref)) result = sim.get_result('hamiltonian',None) assert(object_eq(result,result_ref)) clear_all_sims()
def test_pw2qmcpack_check_sim_status(): import os from generic import NexusError, obj from nexus_base import nexus_core tpath = testing.setup_unit_test_output_directory( 'qmcpack_converter_simulations', 'test_pw2qmcpack_check_sim_status', divert=True) nexus_core.runs = '' sim = get_pw2qmcpack_sim() assert (sim.locdir.rstrip('/') == tpath.rstrip('/')) assert (not sim.finished) assert (not sim.failed) try: sim.check_sim_status() raise FailedTest except IOError: None except Exception as e: failed(str(e)) #end try sim.create_directories() outfile = os.path.join(sim.locdir, sim.outfile) outfile_text = 'JOB DONE' out = open(outfile, 'w') out.write(outfile_text) out.close() assert (outfile_text in open(outfile, 'r').read()) prefix = sim.input.inputpp.prefix outdir = sim.input.inputpp.outdir outdir_path = os.path.join(tpath, outdir) if not os.path.exists(outdir_path): os.makedirs(outdir_path) #end if filenames = [ prefix + '.pwscf.h5', prefix + '.ptcl.xml', prefix + '.wfs.xml' ] for filename in filenames: filepath = os.path.join(tpath, outdir, filename) f = open(filepath, 'w') f.write('') f.close() assert (os.path.exists(filepath)) #end for sim.job.finished = True sim.check_sim_status() assert (sim.finished) assert (not sim.failed) clear_all_sims() restore_nexus()
def test_pyscf_to_afqmc_incorporate_result(): import os from generic import NexusError,obj from simulation import Simulation from test_pyscf_simulation import get_pyscf_sim other = Simulation() scf = get_pyscf_sim() sim = get_pyscf_to_afqmc_sim() try: sim.incorporate_result('unknown',None,other) raise TestFailed except NexusError: None except FailedTest: failed() except Exception as e: failed(str(e)) #end try result = obj( chkfile = os.path.join(scf.locdir,'scf.chk'), ) assert(sim.input.input==None) sim.incorporate_result('wavefunction',result,scf) assert(sim.input.input=='scf.chk') clear_all_sims()
def test_pw2qmcpack_check_result(): sim = get_pw2qmcpack_sim() assert(not sim.check_result('unknown',None)) assert(sim.check_result('orbitals',None)) clear_all_sims()
def test_pw2qmcpack_get_result(): from generic import NexusError,obj sim = get_pw2qmcpack_sim() try: sim.get_result('unknown',None) raise FailedTest except NexusError: None except FailedTest: failed() except Exception as e: failed(str(e)) #end try result = sim.get_result('orbitals',None) result_ref = obj( h5file = './runs/pwscf_output/pwscf.pwscf.h5', ptcl_xml = './runs/pwscf_output/pwscf.ptcl.xml', wfs_xml = './runs/pwscf_output/pwscf.wfs.xml', ) assert(object_eq(result,result_ref)) clear_all_sims()
def test_check_sim_status(): import os tpath = testing.setup_unit_test_output_directory('vasp_simulation', 'test_check_sim_status', **pseudo_inputs) sim = setup_vasp_sim(tpath) assert (sim.locdir.strip('/') == tpath.strip('/')) assert (not sim.finished) assert (not sim.input.performing_neb()) sim.check_sim_status() assert (not sim.finished) outcar_file = os.path.join(tpath, 'OUTCAR') outcar_text = 'General timing and accounting' outcar = open(outcar_file, 'w') outcar.write(outcar_text) outcar.close() assert (os.path.exists(outcar_file)) assert (outcar_text in open(outcar_file, 'r').read()) sim.check_sim_status() assert (sim.finished) assert (not sim.failed) clear_all_sims() restore_nexus()
def test_get_output_files(): import os tpath = testing.setup_unit_test_output_directory('vasp_simulation', 'test_get_output_files', **pseudo_inputs) sim = setup_vasp_sim(tpath) vfiles = 'INCAR KPOINTS POSCAR CONTCAR OUTCAR'.split() for vfile in vfiles: f = open(os.path.join(tpath, vfile), 'w') f.write('') f.close() #end for files = sim.get_output_files() assert (value_eq(files, vfiles)) for vfile in vfiles: assert (os.path.exists( os.path.join(tpath, sim.identifier + '.' + vfile))) #end for clear_all_sims() restore_nexus()
def test_convert4qmc_check_result(): sim = get_convert4qmc_sim() assert(not sim.check_result('unknown',None)) assert(sim.check_result('orbitals',None)) assert(sim.check_result('particles',None)) clear_all_sims()
def test_minimal_init(): from machines import job from vasp import Vasp, generate_vasp sim = generate_vasp(job=job(machine='ws1', cores=1), ) assert (isinstance(sim, Vasp)) clear_all_sims()
def test_pyscf_to_afqmc_minimal_init(): from machines import job from qmcpack_converters import PyscfToAfqmc, generate_pyscf_to_afqmc sim = generate_pyscf_to_afqmc(job=job(machine='ws1', cores=1), ) assert (isinstance(sim, PyscfToAfqmc)) clear_all_sims()
def test_pw2qmcpack_minimal_init(): from machines import job from qmcpack_converters import Pw2qmcpack, generate_pw2qmcpack sim = generate_pw2qmcpack(job=job(machine='ws1', cores=1), ) assert (isinstance(sim, Pw2qmcpack)) clear_all_sims()
def test_minimal_init(): from machines import job for cls,gen in get_class_generators(): sim = gen(job=job(machine='ws1',cores=1)) assert(isinstance(sim,cls)) #end for clear_all_sims()
def test_minimal_init(): from machines import job from pyscf_sim import Pyscf, generate_pyscf sim = generate_pyscf(job=job(machine='ws1', cores=1), ) assert (isinstance(sim, Pyscf)) clear_all_sims()
def test_incorporate_result(): import os import shutil from numpy import array from generic import obj tpath = testing.setup_unit_test_output_directory( 'vasp_simulation', 'test_incorporate_result', **pseudo_inputs) sim = setup_vasp_sim(tpath, identifier='diamond', files=True) pcfile = os.path.join(tpath, 'diamond_POSCAR') ccfile = os.path.join(tpath, sim.identifier + '.CONTCAR') assert (sim.locdir.strip('/') == tpath.strip('/')) shutil.copy2(pcfile, ccfile) assert (os.path.exists(ccfile)) result = sim.get_result('structure', None) sim2 = setup_vasp_sim(tpath) pid = id(sim2.input.poscar) sim2.incorporate_result('structure', result, None) assert (id(sim2.input.poscar) != pid) poscar_ref = obj( axes=array([[3.57, 3.57, 0.], [0., 3.57, 3.57], [3.57, 0., 3.57]], dtype=float), coord='cartesian', description=None, dynamic=None, elem=['C'], elem_count=[16], pos=array([[0., 0., 0.], [0.8925, 0.8925, 0.8925], [1.785, 1.785, 0.], [2.6775, 2.6775, 0.8925], [0., 1.785, 1.785], [0.8925, 2.6775, 2.6775], [1.785, 3.57, 1.785], [2.6775, 4.4625, 2.6775], [1.785, 0., 1.785], [2.6775, 0.8925, 2.6775], [3.57, 1.785, 1.785], [4.4625, 2.6775, 2.6775], [1.785, 1.785, 3.57], [2.6775, 2.6775, 4.4625], [3.57, 3.57, 3.57], [4.4625, 4.4625, 4.4625]], dtype=float), scale=1.0, vel=None, vel_coord=None, ) assert (object_eq(sim2.input.poscar.to_obj(), poscar_ref)) clear_all_sims() restore_nexus()
def test_check_result(): from machines import job for cls,gen in get_class_generators(): sim = gen(job=job(machine='ws1',cores=1)) assert(isinstance(sim,cls)) assert(not sim.check_result('anything',None)) #end for clear_all_sims()
def test_minimal_init(): from machines import job from rmg import Rmg,generate_rmg sim = generate_rmg( job = job(machine='ws1',cores=1), ) assert(isinstance(sim,Rmg)) clear_all_sims()
def test_minimal_init(): from machines import job from pwscf import Pwscf,generate_pwscf sim = generate_pwscf( job = job(machine='ws1',cores=1), system = get_system(), ) assert(isinstance(sim,Pwscf)) clear_all_sims()
def test_check_sim_status(): from machines import job for cls,gen in get_class_generators(): sim = gen(job=job(machine='ws1',cores=1)) assert(isinstance(sim,cls)) sim.check_sim_status() assert(sim.finished) assert(not sim.failed) #end for clear_all_sims()
def test_check_result(): tpath = testing.setup_unit_test_output_directory('pwscf_simulation','test_check_result',**pseudo_inputs) sim = get_pwscf_sim('scf') assert(not sim.check_result('unknown',None)) assert(sim.check_result('charge_density',None)) assert(sim.check_result('restart',None)) assert(sim.check_result('orbitals',None)) assert(not sim.check_result('structure',None)) clear_all_sims() restore_nexus()
def test_pyscf_to_afqmc_check_result(): sim = get_pyscf_to_afqmc_sim() assert(not sim.check_result('unknown',None)) assert(not sim.check_result('wavefunction',None)) assert(not sim.check_result('hamiltonian',None)) sim.input.output = 'afqmc.h5' assert(sim.check_result('wavefunction',None)) assert(sim.check_result('hamiltonian',None)) clear_all_sims()
def test_check_result(): tpath = testing.setup_unit_test_output_directory('vasp_simulation', 'test_check_result', **pseudo_inputs) sim = setup_vasp_sim(tpath) assert (not sim.check_result('unknown', None)) assert (sim.check_result('structure', None)) clear_all_sims() restore_nexus()
def test_pyscf_to_afqmc_check_sim_status(): import os from generic import NexusError, obj from nexus_base import nexus_core tpath = testing.setup_unit_test_output_directory( 'qmcpack_converter_simulations', 'test_pyscf_to_afqmc_check_sim_status', divert=True) nexus_core.runs = '' sim = get_pyscf_to_afqmc_sim() assert (sim.locdir.rstrip('/') == tpath.rstrip('/')) assert (not sim.finished) assert (not sim.failed) try: sim.check_sim_status() raise FailedTest except IOError: None except Exception as e: failed(str(e)) #end try sim.input.output = 'afqmc.h5' sim.create_directories() outfile = os.path.join(sim.locdir, sim.outfile) outfile_text = '# Finished.' out = open(outfile, 'w') out.write(outfile_text) out.close() assert (outfile_text in open(outfile, 'r').read()) output_file = os.path.join(sim.locdir, sim.input.output) f = open(output_file, 'w') f.write('') f.close() assert (os.path.exists(output_file)) sim.job.finished = True sim.check_sim_status() assert (sim.finished) assert (not sim.failed) clear_all_sims() restore_nexus()
def test_get_result(): from generic import NexusError tpath = testing.setup_unit_test_output_directory('pwscf_simulation','test_get_result',**pseudo_inputs) sim = get_pwscf_sim('scf') try: sim.get_result('unknown',None) raise FailedTest except NexusError: None except FailedTest: failed() except Exception as e: failed(str(e)) #end try result = sim.get_result('charge_density',None) result2 = sim.get_result('restart',None) assert(object_eq(result,result2)) result_ref = dict( locdir = 'scf', outdir = 'scf/pwscf_output', location = 'scf/pwscf_output/pwscf.save/charge-density.dat', spin_location = 'scf/pwscf_output/pwscf.save/spin-polarization.dat', ) assert(set(result.keys())==set(result_ref.keys())) for k,path in result.items(): path = path.replace(tpath,'').lstrip('/') assert(path==result_ref[k]) #end for result = sim.get_result('orbitals',None) result_ref = dict( location = 'scf/pwscf_output/pwscf.wfc1', ) assert(set(result.keys())==set(result_ref.keys())) for k,path in result.items(): path = path.replace(tpath,'').lstrip('/') assert(path==result_ref[k]) #end for clear_all_sims() restore_nexus()
def test_incorporate_result(): from generic import obj tpath = testing.setup_unit_test_output_directory('pwscf_simulation','test_incorporate_result',**pseudo_inputs) sim = get_pwscf_sim('scf') sim_start = sim.to_obj().copy() assert(object_eq(sim.to_obj(),sim_start)) # charge density result = obj( locdir = sim.locdir, ) sim.incorporate_result('charge_density',result,None) assert(object_eq(sim.to_obj(),sim_start)) # restart sim.incorporate_result('restart',result,None) c = sim.input.control assert(c.restart_mode=='restart') del c.restart_mode assert(object_eq(sim.to_obj(),sim_start)) # structure altered_structure = sim.system.structure.copy() altered_structure.pos += 0.1 result = obj( structure = altered_structure, ) sim.incorporate_result('structure',result,None) sim_ref = sim_start.copy() pos_ref = sim_ref.system.structure.delete('pos')+0.1 sim_ref.input.atomic_positions.delete('positions') pos = sim.system.structure.delete('pos') apos = sim.input.atomic_positions.delete('positions') assert(value_eq(pos,pos_ref)) assert(value_eq(apos,pos_ref)) assert(object_eq(sim.to_obj(),sim_ref)) clear_all_sims() restore_nexus()
def test_check_sim_status(): import os tpath = testing.setup_unit_test_output_directory('pwscf_simulation','test_check_sim_status',**pseudo_inputs) sim = get_pwscf_sim('scf') assert(sim.locdir.rstrip('/')==os.path.join(tpath,'scf').rstrip('/')) if not os.path.exists(sim.locdir): os.makedirs(sim.locdir) #end if assert(not sim.finished) try: sim.check_sim_status() except IOError: None except Exception as e: failed(str(e)) #end try assert(not sim.finished) out_path = os.path.join(tpath,'scf',sim.outfile) out_text = '' outfile = open(out_path,'w') outfile.write(out_text) outfile.close() assert(os.path.exists(out_path)) sim.check_sim_status() assert(not sim.finished) out_text = 'JOB DONE' outfile = open(out_path,'w') outfile.write(out_text) outfile.close() assert(out_text in open(out_path,'r').read()) sim.check_sim_status() assert(sim.finished) assert(not sim.failed) clear_all_sims() restore_nexus()
def test_check_sim_status(): import os from nexus_base import nexus_core tpath = testing.setup_unit_test_output_directory('qmcpack_simulation', 'test_check_sim_status', divert=True) nexus_core.runs = '' sim = get_qmcpack_sim(identifier='qmc') assert (sim.locdir.rstrip('/') == tpath.rstrip('/')) assert (not sim.finished) assert (not sim.failed) try: sim.check_sim_status() except IOError: None #end try assert (not sim.finished) assert (not sim.failed) outfile = os.path.join(tpath, sim.outfile) out_text = 'Total Execution' out = open(outfile, 'w') out.write(out_text) out.close() assert (os.path.exists(outfile)) assert (out_text in open(outfile, 'r').read()) errfile = os.path.join(tpath, sim.errfile) err = open(errfile, 'w') err.write('') err.close() assert (os.path.exists(errfile)) sim.check_sim_status() assert (sim.finished) assert (not sim.failed) clear_all_sims() restore_nexus()
def test_get_result(): import os from generic import NexusError, obj from nexus_base import nexus_core tpath = testing.setup_unit_test_output_directory('pyscf_simulation', 'test_get_result', divert=True) nexus_core.runs = '' template_file = 'scf_template.py' template_text = 'template $chkfile' template_filepath = os.path.join(tpath, template_file) f = open(template_filepath, 'w') f.write(template_text) f.close() sim = get_pyscf_sim( prefix='scf', checkpoint='scf.chk', template=template_filepath, ) try: sim.get_result('unknown', None) raise FailedTest except NexusError: None except FailedTest: failed() except Exception as e: failed(str(e)) #end try result = sim.get_result('orbitals', None) assert (result.h5_file.replace(tpath, '').lstrip('/') == 'scf.h5') result = sim.get_result('wavefunction', None) assert (result.chkfile.replace(tpath, '').lstrip('/') == 'scf.chk') clear_all_sims() restore_nexus()
def test_check_sim_status(): sim = get_pyscf_sim() assert (not sim.failed) assert (not sim.finished) sim.check_sim_status() assert (not sim.failed) assert (not sim.finished) sim.job.finished = True sim.check_sim_status() assert (not sim.failed) assert (sim.finished) clear_all_sims()