def test_faked_error_recovery(self): """ Run a calculation that *should* throw a symmetry error, and try to recover from the error. If CASTEP is not present, monkey patch such that ComputeTask copies the output files it would have expected. """ seed = REAL_PATH + "data/symmetry_failure/Sb.res" cell_dict, s = cell2dict(REAL_PATH + "/data/symmetry_failure/KSb.cell", verbosity=VERBOSITY, db=False) assert s param_dict, s = param2dict( REAL_PATH + "/data/symmetry_failure/KSb.param", verbosity=VERBOSITY, db=False, ) assert s ncores = 1 executable = REAL_PATH + "data/symmetry_failure/monkey_patch_move.sh" node = None relaxer = ComputeTask( ncores=ncores, nnodes=None, node=node, res=seed, param_dict=param_dict, cell_dict=cell_dict, verbosity=VERBOSITY, executable=executable, exec_test=False, polltime=1, start=False, ) with self.assertRaises(CalculationError): relaxer.begin() bad_castep_exists = isdir("bad_castep") completed_exists = isdir("completed") self.assertTrue(bad_castep_exists) self.assertFalse(completed_exists) self.assertTrue(relaxer.final_result is None) self.assertEqual(relaxer._num_retries, 3) self.assertTrue("symmetry_generate" not in relaxer.calc_doc) self.assertTrue("snap_to_symmetry" not in relaxer.calc_doc) self.assertTrue("symmetry_tol" not in relaxer.calc_doc)
def test_failed_relaxation(self): """ Set a relaxation up to fail. """ seed = "_LiAs_testcase.res" shutil.copy( REAL_PATH + "data/structures/LiAs_testcase_bad.res", "_LiAs_testcase.res" ) cell_dict, s = cell2dict( REAL_PATH + "/data/LiAs_tests/LiAs.cell", verbosity=VERBOSITY, db=False ) assert s param_dict, s = param2dict( REAL_PATH + "/data/LiAs_tests/LiAs.param", verbosity=VERBOSITY, db=False ) assert s param_dict["geom_max_iter"] = 3 executable = "castep" node = None shutil.copy(REAL_PATH + "data/pspots/Li_00PBE.usp", ".") shutil.copy(REAL_PATH + "data/pspots/As_00PBE.usp", ".") relaxer = ComputeTask( ncores=NCORES, nnodes=None, node=node, res=seed, param_dict=param_dict, cell_dict=cell_dict, verbosity=VERBOSITY, killcheck=True, memcheck=False, reopt=True, executable=executable, rough=0, fine_iter=3, start=False, ) with self.assertRaises(CalculationError): relaxer.begin() bad_exists = isfile("bad_castep/_LiAs_testcase.res") num = reset_job_folder() self.assertTrue(bad_exists, "couldn't find output file!") self.assertEqual(num, 0)
def test_old_file(self): """ Run a calculation with an executable that only does "sleep", in the presence of a file that was written previouisly, and check that run3 will stop the calculation early as no file is written. """ seed = REAL_PATH + "data/symmetry_failure/Sb.res" with open("Sb.castep", "w") as f: f.write("I am a CASTEP file, for sure.") cell_dict, s = cell2dict(REAL_PATH + "/data/symmetry_failure/KSb.cell", verbosity=VERBOSITY, db=False) assert s param_dict, s = param2dict( REAL_PATH + "/data/symmetry_failure/KSb.param", verbosity=VERBOSITY, db=False, ) assert s executable = REAL_PATH + "data/missing_file_test/monkey_patch_sleep.sh" node = None relaxer = ComputeTask( ncores=NCORES, nnodes=None, node=node, res=seed, param_dict=param_dict, cell_dict=cell_dict, verbosity=VERBOSITY, executable=executable, exec_test=False, polltime=1, start=False, ) with self.assertRaises(CalculationError): relaxer.begin() self.assertTrue(relaxer.final_result is None)