From a7e8374ea79e9003ad3e19c8f20f96debb16e464 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 18 May 2023 14:33:42 -0400 Subject: [PATCH] lmp: forward errors to error->one instead of error->all Fix #2516. Signed-off-by: Jinzhe Zeng --- source/lmp/compute_deeptensor_atom.cpp | 9 ++++++--- source/lmp/fix_dplr.cpp | 22 +++++++++++++++++----- source/lmp/pair_deepmd.cpp | 12 ++++++------ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/source/lmp/compute_deeptensor_atom.cpp b/source/lmp/compute_deeptensor_atom.cpp index 72c51cdf3a..89eb6fb38e 100644 --- a/source/lmp/compute_deeptensor_atom.cpp +++ b/source/lmp/compute_deeptensor_atom.cpp @@ -32,8 +32,11 @@ ComputeDeeptensorAtom::ComputeDeeptensorAtom(LAMMPS *lmp, int narg, char **arg) // initialize deeptensor int gpu_rank = dp.get_node_rank(); - std::string model_file_content = dp.get_file_content(model_file); - dt.init(model_file, gpu_rank); + try { + dt.init(model_file, gpu_rank); + } catch (deepmd_compat::deepmd_exception &e) { + error->one(FLERR, e.what()); + } sel_types = dt.sel_types(); std::sort(sel_types.begin(), sel_types.end()); @@ -128,7 +131,7 @@ void ComputeDeeptensorAtom::compute_peratom() { dt.compute(gtensor, force, virial, atensor, avirial, dcoord, dtype, dbox, nghost, lmp_list); } catch (deepmd_compat::deepmd_exception &e) { - error->all(FLERR, e.what()); + error->one(FLERR, e.what()); } // store the result in tensor diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index b786cb1794..8f049f033f 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -102,8 +102,12 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) // dpt.init(model); // dtm.init("frozen_model.pb"); - dpt.init(model, 0, "dipole_charge"); - dtm.init(model, 0, "dipole_charge"); + try { + dpt.init(model, 0, "dipole_charge"); + dtm.init(model, 0, "dipole_charge"); + } catch (deepmd_compat::deepmd_exception &e) { + error->one(FLERR, e.what()); + } sel_type = dpt.sel_types(); sort(sel_type.begin(), sel_type.end()); @@ -271,7 +275,11 @@ void FixDPLR::pre_force(int vflag) { // declear output vector tensor; // compute - dpt.compute(tensor, dcoord, dtype, dbox, nghost, lmp_list); + try { + dpt.compute(tensor, dcoord, dtype, dbox, nghost, lmp_list); + } catch (deepmd_compat::deepmd_exception &e) { + error->one(FLERR, e.what()); + } // cout << "tensor of size " << tensor.size() << endl; // cout << "nghost " << nghost << endl; // cout << "nall " << dtype.size() << endl; @@ -434,8 +442,12 @@ void FixDPLR::post_force(int vflag) { // output vects vector dfcorr, dvcorr; // compute - dtm.compute(dfcorr, dvcorr, dcoord, dtype, dbox, valid_pairs, dfele, nghost, - lmp_list); + try { + dtm.compute(dfcorr, dvcorr, dcoord, dtype, dbox, valid_pairs, dfele, nghost, + lmp_list); + } catch (deepmd_compat::deepmd_exception &e) { + error->one(FLERR, e.what()); + } assert(dfcorr.size() == dcoord.size()); assert(dfcorr.size() == nall * 3); // backward communication of fcorr diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index d70e2a0c75..ccf95c0984 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -501,7 +501,7 @@ void PairDeepMD::compute(int eflag, int vflag) { deep_pot.compute(dener, dforce, dvirial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); } catch (deepmd_compat::deepmd_exception &e) { - error->all(FLERR, e.what()); + error->one(FLERR, e.what()); } } else { dforce.resize((extend_inum + extend_nghost) * 3); @@ -510,7 +510,7 @@ void PairDeepMD::compute(int eflag, int vflag) { extend_dtype, dbox, extend_nghost, extend_lmp_list, ago, fparam, daparam); } catch (deepmd_compat::deepmd_exception &e) { - error->all(FLERR, e.what()); + error->one(FLERR, e.what()); } } } @@ -524,7 +524,7 @@ void PairDeepMD::compute(int eflag, int vflag) { dtype, dbox, nghost, lmp_list, ago, fparam, daparam); } catch (deepmd_compat::deepmd_exception &e) { - error->all(FLERR, e.what()); + error->one(FLERR, e.what()); } } else { dforce.resize((extend_inum + extend_nghost) * 3); @@ -533,7 +533,7 @@ void PairDeepMD::compute(int eflag, int vflag) { extend_dtype, dbox, extend_nghost, extend_lmp_list, ago, fparam, daparam); } catch (deepmd_compat::deepmd_exception &e) { - error->all(FLERR, e.what()); + error->one(FLERR, e.what()); } } if (eflag_atom) { @@ -574,7 +574,7 @@ void PairDeepMD::compute(int eflag, int vflag) { all_energy, all_force, all_virial, all_atom_energy, all_atom_virial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); } catch (deepmd_compat::deepmd_exception &e) { - error->all(FLERR, e.what()); + error->one(FLERR, e.what()); } // deep_pot_model_devi.compute_avg (dener, all_energy); // deep_pot_model_devi.compute_avg (dforce, all_force); @@ -720,7 +720,7 @@ void PairDeepMD::compute(int eflag, int vflag) { try { deep_pot.compute(dener, dforce, dvirial, dcoord, dtype, dbox); } catch (deepmd_compat::deepmd_exception &e) { - error->all(FLERR, e.what()); + error->one(FLERR, e.what()); } } else { error->all(FLERR, "Serial version does not support model devi");