diff --git a/dpgen/auto_test/Lammps.py b/dpgen/auto_test/Lammps.py index b39211710..adc34eb93 100644 --- a/dpgen/auto_test/Lammps.py +++ b/dpgen/auto_test/Lammps.py @@ -289,7 +289,7 @@ def compute(self, if len(line) and str(ii) == line[0]: try: [float(kk) for kk in line] - except: + except Exception: continue stress.append([]) virial.append([]) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index b14034c1d..1e3cba355 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -571,7 +571,7 @@ def make_scale(jdata): try: pos_src = os.path.join(os.path.join(init_path, ii), 'CONTCAR') assert(os.path.isfile(pos_src)) - except: + except Exception: raise RuntimeError("not file %s, vasp relaxation should be run before scale poscar") scale_path = os.path.join(work_path, ii) scale_path = os.path.join(scale_path, "scale-%.3f" % jj) @@ -604,7 +604,7 @@ def make_scale_ABACUS(jdata): try: pos_src = os.path.join(os.path.join(init_path, ii), 'OUT.ABACUS/STRU_ION_D') assert(os.path.isfile(pos_src)) - except: + except Exception: raise RuntimeError("not file %s, vasp relaxation should be run before scale poscar") scale_path = os.path.join(work_path, ii) scale_path = os.path.join(scale_path, "scale-%.3f" % jj) @@ -1238,7 +1238,7 @@ def gen_init_bulk(args) : jdata=loadfn(args.PARAM) if args.MACHINE is not None: mdata=loadfn(args.MACHINE) - except: + except Exception: with open (args.PARAM, 'r') as fp : jdata = json.load (fp) if args.MACHINE is not None: diff --git a/dpgen/data/reaction.py b/dpgen/data/reaction.py index 5e1f4f120..b9574d525 100644 --- a/dpgen/data/reaction.py +++ b/dpgen/data/reaction.py @@ -191,7 +191,7 @@ def gen_init_reaction(args): jdata = loadfn(args.PARAM) if args.MACHINE is not None: mdata = loadfn(args.MACHINE) - except: + except Exception: with open(args.PARAM, 'r') as fp: jdata = json.load(fp) if args.MACHINE is not None: diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index 13420e118..bc31b6705 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -447,7 +447,7 @@ def make_scale(jdata): try: pos_src = os.path.join(os.path.join(init_path, ii), 'CONTCAR') assert(os.path.isfile(pos_src)) - except: + except Exception: raise RuntimeError("not file %s, vasp relaxation should be run before scale poscar") scale_path = os.path.join(work_path, ii) scale_path = os.path.join(scale_path, "scale-%.3f" % jj) @@ -583,7 +583,7 @@ def gen_init_surf(args): jdata=loadfn(args.PARAM) if args.MACHINE is not None: mdata=loadfn(args.MACHINE) - except: + except Exception: with open (args.PARAM, 'r') as fp : jdata = json.load (fp) if args.MACHINE is not None: diff --git a/dpgen/data/tools/cessp2force_lin.py b/dpgen/data/tools/cessp2force_lin.py index 1cead0ba8..ceaa3b775 100755 --- a/dpgen/data/tools/cessp2force_lin.py +++ b/dpgen/data/tools/cessp2force_lin.py @@ -290,7 +290,7 @@ def Parser(): try: name = str(item.split('=')[0]) number = int(item.split('=')[1]) - except: + except Exception: sys.stderr.write("\nERROR: Could not read the -c string\n") sys.exit() if number >= max_types: diff --git a/dpgen/database/run.py b/dpgen/database/run.py index 7a524a459..f66e4c56f 100644 --- a/dpgen/database/run.py +++ b/dpgen/database/run.py @@ -83,7 +83,7 @@ def _parsing_vasp(paths,config_info_dict, id_prefix,iters=True): iter_record.sort() dlog.info("iter_record") dlog.info(iter_record) - except: + except Exception: pass for path in paths: try: diff --git a/dpgen/database/vasp.py b/dpgen/database/vasp.py index 72b26075f..add777e6d 100644 --- a/dpgen/database/vasp.py +++ b/dpgen/database/vasp.py @@ -27,7 +27,7 @@ def __init__(self,symbols=None,functional="PBE",pp_file=None,pp_lists=None): else: try: self.potcars=Potcar(symbols=symbols, functional=functional) - except: + except Exception: warnings.warn ("""Inproperly configure of POTCAR !""") self.potcars=None @@ -80,7 +80,7 @@ def from_file(cls,filename): try: potcars=Potcar.from_file(filename) return cls(pp_lists=potcars) - except: + except Exception: with open(filename,'r') as f: content=f.readlines() functional=content[0].strip().split(':')[-1].strip() @@ -179,7 +179,7 @@ def from_directory(input_dir, optional_files=None): ("POSCAR", Poscar), ("POTCAR", DPPotcar)]: fullzpath = zpath(os.path.join(input_dir, fname)) sub_d[fname.lower()] = ftype.from_file(fullzpath) - except: + except Exception: for fname, ftype in [("INCAR", Incar), ("POSCAR", Poscar), ("POTCAR", DPPotcar)]: fullzpath = zpath(os.path.join(input_dir, fname)) diff --git a/dpgen/dispatcher/ALI.py b/dpgen/dispatcher/ALI.py index ef4f850b2..2a01ab378 100644 --- a/dpgen/dispatcher/ALI.py +++ b/dpgen/dispatcher/ALI.py @@ -352,7 +352,7 @@ def delete_template(self): response = self.client.do_action_with_exception(request) flag = 1 break - except: + except Exception: count += 1 # count = 10 and still failed, continue @@ -382,7 +382,7 @@ def get_image_id(self, img_name): return img["ImageId"] flag = 1 break - except: + except Exception: count += 1 time.sleep(10) if not flag: @@ -441,7 +441,7 @@ def change_apg_capasity(self, capasity): response = self.client.do_action_with_exception(request) flag = 1 break - except: + except Exception: count += 1 time.sleep(10) if not flag: @@ -510,5 +510,5 @@ def get_ip(self, instance_list): else: ip_list.append(response["Instances"]["Instance"][0]["VpcAttributes"]["PrivateIpAddress"]['IpAddress'][0]) return ip_list - except: return [] + except Exception: return [] diff --git a/dpgen/dispatcher/Dispatcher.py b/dpgen/dispatcher/Dispatcher.py index 239654b26..579a71cd3 100644 --- a/dpgen/dispatcher/Dispatcher.py +++ b/dpgen/dispatcher/Dispatcher.py @@ -333,7 +333,7 @@ def make_dispatcher(mdata, mdata_resource=None, work_path=None, run_tasks=None, context_type = 'local' try: batch_type = mdata['batch'] - except: + except Exception: dlog.info('cannot find key "batch" in machine file, try to use deprecated key "machine_type"') batch_type = mdata['machine_type'] lazy_local = (mdata.get('lazy-local', False)) or (mdata.get('lazy_local', False)) diff --git a/dpgen/dispatcher/DispatcherList.py b/dpgen/dispatcher/DispatcherList.py index ba72b7bd2..085ae5d9a 100644 --- a/dpgen/dispatcher/DispatcherList.py +++ b/dpgen/dispatcher/DispatcherList.py @@ -178,7 +178,7 @@ def make_dispatcher(self, ii): self.dispatcher_list[ii]["dispatcher_status"] = "unsubmitted" flag = 1 break - except: + except Exception: count += 1 time.sleep(60) if not flag: @@ -201,7 +201,7 @@ def check_dispatcher_status(self, ii, allow_failue=False): finished = self.dispatcher_list[ii]["dispatcher"].all_finished(self.dispatcher_list[ii]["entity"].job_handler, allow_failue, clean) if finished: self.dispatcher_list[ii]["dispatcher_status"] = "finished" - except: + except Exception: pass elif status == 1: # self.dispatcher_list[ii]["dispatcher_status"] = "terminated" diff --git a/dpgen/dispatcher/LSF.py b/dpgen/dispatcher/LSF.py index c31b5178c..dfde7c5e3 100644 --- a/dpgen/dispatcher/LSF.py +++ b/dpgen/dispatcher/LSF.py @@ -11,7 +11,7 @@ class LSF(Batch) : def check_status(self): try: job_id = self._get_job_id() - except: + except Exception: return JobStatus.terminated if job_id == "" : raise RuntimeError("job %s has not been submitted" % self.context.remote_root) diff --git a/dpgen/dispatcher/SSHContext.py b/dpgen/dispatcher/SSHContext.py index 35a7e5997..aca7d8368 100644 --- a/dpgen/dispatcher/SSHContext.py +++ b/dpgen/dispatcher/SSHContext.py @@ -125,7 +125,7 @@ def __init__ (self, self.ssh_session.ensure_alive() try: self.sftp.mkdir(self.remote_root) - except: + except Exception: pass @property diff --git a/dpgen/dispatcher/Shell.py b/dpgen/dispatcher/Shell.py index 731ad52f5..35a82018d 100644 --- a/dpgen/dispatcher/Shell.py +++ b/dpgen/dispatcher/Shell.py @@ -93,9 +93,9 @@ def sub_script_cmd(self, fp_max_errors = 3 try: fp_max_errors = res['fp_max_errors'] - except: + except Exception: pass - except: + except Exception: cvasp=False _cmd = cmd.split('1>')[0].strip() diff --git a/dpgen/dispatcher/Slurm.py b/dpgen/dispatcher/Slurm.py index a1f8ba933..e1d3550e2 100644 --- a/dpgen/dispatcher/Slurm.py +++ b/dpgen/dispatcher/Slurm.py @@ -130,9 +130,9 @@ def sub_script_cmd(self, fp_max_errors = 3 try: fp_max_errors = res['fp_max_errors'] - except: + except Exception: pass - except: + except Exception: cvasp=False _cmd = cmd.split('1>')[0].strip() diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 67cca9e82..cf929f16c 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -576,7 +576,7 @@ def run_train (iter_index, try: train_group_size = mdata['train_group_size'] - except: + except Exception: train_group_size = 1 api_version = mdata.get('api_version', '0.9') @@ -2530,11 +2530,11 @@ def post_fp_vasp (iter_index, for oo in sys_outcars : try: _sys = dpdata.LabeledSystem(oo, type_map = jdata['type_map']) - except: + except Exception: dlog.info('Try to parse from vasprun.xml') try: _sys = dpdata.LabeledSystem(oo.replace('OUTCAR','vasprun.xml'), type_map = jdata['type_map']) - except: + except Exception: _sys = dpdata.LabeledSystem() dlog.info('Failed fp path: %s'%oo.replace('OUTCAR','')) if len(_sys) == 1: @@ -2914,7 +2914,7 @@ def run_iter (param_file, machine_file) : warnings.simplefilter('ignore', ruamel.yaml.error.MantissaNoDotYAML1_1Warning) jdata=loadfn(param_file) mdata=loadfn(machine_file) - except: + except Exception: with open (param_file, 'r') as fp : jdata = json.load (fp) with open (machine_file, 'r') as fp: diff --git a/dpgen/remote/RemoteJob.py b/dpgen/remote/RemoteJob.py index 057eb3d3e..4cdc76e9c 100644 --- a/dpgen/remote/RemoteJob.py +++ b/dpgen/remote/RemoteJob.py @@ -63,7 +63,7 @@ def download(self, elif os.path.isdir(os.path.join(self.remote_root,job_dir,ii)): try: os.rmdir(os.path.join(self.local_root,job_dir,ii)) - except: + except Exception: print('dir is not empty '+str(os.path.join(self.local_root,job_dir,ii))) else: shutil.copytree(os.path.join(self.remote_root,job_dir,ii),os.path.join(self.local_root,job_dir,ii)) @@ -176,7 +176,7 @@ def __init__ (self, sftp = self.ssh.open_sftp() sftp.mkdir(self.remote_root) sftp.close() - except: + except Exception: pass # open('job_uuid', 'w').write(self.job_uuid) @@ -410,7 +410,7 @@ def _submit(): else: dlog.debug('task is finished') - except: + except Exception: dlog.debug('no job_id file') dlog.debug('task restart point !!!') _submit() @@ -529,9 +529,9 @@ def _make_script(self, cvasp=res['cvasp'] try: fp_max_errors = res['fp_max_errors'] - except: + except Exception: fp_max_errors = 3 - except: + except Exception: cvasp=False for ii,jj in zip(job_dirs, args) : @@ -765,7 +765,7 @@ def submit(self, dlog.debug('task is running') else: dlog.debug('task is finished') - #except: + #except Exception: #dlog.debug('no job_id file') #dlog.debug('task restart point !!!') #self._submit(job_dirs, cmd, args, resources) @@ -805,7 +805,7 @@ def check_limit(self, task_max): def check_status(self) : try: job_id = self._get_job_id() - except: + except Exception: return JobStatus.terminated if job_id == "" : raise RuntimeError("job %s is has not been submitted" % self.remote_root) diff --git a/dpgen/remote/decide_machine.py b/dpgen/remote/decide_machine.py index 2688d3ca3..31691f322 100644 --- a/dpgen/remote/decide_machine.py +++ b/dpgen/remote/decide_machine.py @@ -68,7 +68,7 @@ def convert_mdata(mdata, task_types=["train", "model_devi", "fp"]): # if 'command' in profile: # mdata['train_command'] = profile["command"] # continue_flag = True -# except: +# except Exception: # pass # if ("hostname" not in mdata["train"][0]["machine"]) or (len(mdata["train"]) == 1): # mdata["train_machine"] = mdata["train"][0]["machine"] @@ -180,7 +180,7 @@ def convert_mdata(mdata, task_types=["train", "model_devi", "fp"]): # mdata['model_devi_command'] = profile['command'] # mdata['model_devi_group_size'] = profile['group_size'] # continue_flag = True -# except: +# except Exception: # pass # if ("hostname" not in mdata["model_devi"][0]["machine"]) or (len(mdata["model_devi"]) == 1): # mdata["model_devi_machine"] = mdata["model_devi"][0]["machine"] @@ -263,7 +263,7 @@ def convert_mdata(mdata, task_types=["train", "model_devi", "fp"]): # mdata['fp_group_size'] = profile['group_size'] # # continue_flag = True -# except: +# except Exception: # pass # if ("hostname" not in mdata["fp"][0]["machine"]) or (len(mdata["fp"]) == 1): # mdata["fp_machine"] = mdata["fp"][0]["machine"] diff --git a/dpgen/remote/group_jobs.py b/dpgen/remote/group_jobs.py index b816ac0bb..588bcfbed 100644 --- a/dpgen/remote/group_jobs.py +++ b/dpgen/remote/group_jobs.py @@ -341,7 +341,7 @@ def group_slurm_jobs(ssh_sess, if not job_fin[idx] : try: status = rjob.check_status() - except: + except Exception: ssh_sess = SSHSession(ssh_sess.remote_profile) for _idx,_rjob in enumerate(job_list): job_list[_idx] = SlurmJob(ssh_sess, work_path, _rjob.job_uuid) @@ -426,5 +426,5 @@ def delete(self): f_path_map=self.f_path_map try: os.remove(f_path_map) - except: + except Exception: pass diff --git a/dpgen/simplify/simplify.py b/dpgen/simplify/simplify.py index 8deb5a918..982db3114 100644 --- a/dpgen/simplify/simplify.py +++ b/dpgen/simplify/simplify.py @@ -263,7 +263,7 @@ def run_model_devi(iter_index, jdata, mdata): # submit try: model_devi_group_size = mdata['model_devi_group_size'] - except: + except Exception: model_devi_group_size = 1 forward_files = [rest_data_name] @@ -599,7 +599,7 @@ def run_iter(param_file, machine_file): 'ignore', ruamel.yaml.error.MantissaNoDotYAML1_1Warning) jdata = loadfn(param_file) mdata = loadfn(machine_file) - except: + except Exception: with open(param_file, 'r') as fp: jdata = json.load(fp) with open(machine_file, 'r') as fp: diff --git a/dpgen/tools/relabel.py b/dpgen/tools/relabel.py index 4b9cc3499..75117ce05 100755 --- a/dpgen/tools/relabel.py +++ b/dpgen/tools/relabel.py @@ -127,7 +127,7 @@ def create_init_tasks(target_folder, param_file, output, fp_json, verbose = True try: fp_params = fp_jdata['user_fp_params'] user_input = True - except: + except Exception: fp_params = fp_jdata['fp_params'] user_input = False make_pwscf('.', fp_params, mass_map, fp_pp_files, fp_pp_files, user_input) @@ -240,7 +240,7 @@ def create_tasks(target_folder, param_file, output, fp_json, verbose = True, num try: fp_params = fp_jdata['user_fp_params'] user_input = True - except: + except Exception: fp_params = fp_jdata['fp_params'] user_input = False make_pwscf('.', fp_params, mass_map, fp_pp_files, fp_pp_files, user_input) diff --git a/dpgen/tools/stat_iter.py b/dpgen/tools/stat_iter.py index 519486727..531868c51 100644 --- a/dpgen/tools/stat_iter.py +++ b/dpgen/tools/stat_iter.py @@ -42,10 +42,10 @@ def stat_iter(target_folder, pk_id, task_dirname, OUTCAR_filename=path_doc.rsplit('/', 2) # pylint: disable=unused-variable try: _sys = dpdata.LabeledSystem(path_doc, type_map = jdata['type_map'] ) - except: + except Exception: try: _sys = dpdata.LabeledSystem(path_doc.replace('OUTCAR','vasprun.xml'), type_map = jdata['type_map']) - except: + except Exception: _sys = dpdata.LabeledSystem() if len(_sys) == 1: pass diff --git a/tests/auto_test/test_mpdb.py b/tests/auto_test/test_mpdb.py index 1c3eca745..7299d28da 100644 --- a/tests/auto_test/test_mpdb.py +++ b/tests/auto_test/test_mpdb.py @@ -14,7 +14,7 @@ try: os.environ['MAPI_KEY'] exist_key=True -except: +except Exception: exist_key=False diff --git a/tests/database/test_db_vasp.py b/tests/database/test_db_vasp.py index 577d2f7da..9e5251880 100644 --- a/tests/database/test_db_vasp.py +++ b/tests/database/test_db_vasp.py @@ -61,7 +61,7 @@ def testDPPotcar(self): Potcar(['Al']) #ps TITEL = PAW_PBE Al 04Jan2001 refd.update({'hashs':['9aafba2c552fad8414179cae2e888e67']}) - except: + except Exception: pass for f in self.init_path+self.iter_path: @@ -121,7 +121,7 @@ def testParsingVasp(self): #try: # Potcar(['Al']) # ref=os.path.join(self.cwd,'data/all_data_pp.json') - #except: + #except Exception: # ref=os.path.join(self.cwd,'data/all_data.json') #Potcar(['Al']) ref=os.path.join(self.cwd,'data/all_data_pp.json') diff --git a/tests/dispatcher/shell/test_shell_ssh.py b/tests/dispatcher/shell/test_shell_ssh.py index d80bb5688..7b9f0773b 100644 --- a/tests/dispatcher/shell/test_shell_ssh.py +++ b/tests/dispatcher/shell/test_shell_ssh.py @@ -24,7 +24,7 @@ def setUp(self) : 'port': port, 'username' : getpass.getuser(), 'work_path' : os.path.join(os.getcwd(), 'rmt')}) - except: + except Exception: ssh_session = SSHSession({'hostname' : 'localhost', 'port': 5566, 'username' : getpass.getuser(), diff --git a/tests/dispatcher/test_ssh_context.py b/tests/dispatcher/test_ssh_context.py index 550fcaa12..a24e2d653 100644 --- a/tests/dispatcher/test_ssh_context.py +++ b/tests/dispatcher/test_ssh_context.py @@ -26,14 +26,14 @@ def setUp(self) : 'port': 22, 'username' : getpass.getuser(), 'work_path' : os.path.join(os.getcwd(), 'rmt')}) - except: + except Exception: # for tianhe-2 try: self.ssh_session = SSHSession({'hostname' : 'localhost', 'port': 5566, 'username' : getpass.getuser(), 'work_path' : os.path.join(os.getcwd(), 'rmt')}) - except: + except Exception: self.skipTest("Network error") self.job = SSHContext('loc', self.ssh_session) self.job1 = SSHContext('loc', self.ssh_session, job_uuid = self.job.job_uuid)