From 0a3e2086e262b166eefa3b6762be4b4928c509f8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 3 Feb 2024 03:07:52 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- deepmd/pt/model/model/dp_atomic_model.py | 2 +- source/api_cc/src/DeepPotPT.cc | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/deepmd/pt/model/model/dp_atomic_model.py b/deepmd/pt/model/model/dp_atomic_model.py index 7190723eb0..f9c47105cf 100644 --- a/deepmd/pt/model/model/dp_atomic_model.py +++ b/deepmd/pt/model/model/dp_atomic_model.py @@ -100,7 +100,7 @@ def get_rcut(self) -> float: def get_sel(self) -> List[int]: """Get the neighbor selection.""" return self.sel - + def get_nnei(self) -> List[int]: """Get the the number of selected atoms in the cut-off radius.""" return self.nnei diff --git a/source/api_cc/src/DeepPotPT.cc b/source/api_cc/src/DeepPotPT.cc index 959ebe4695..3cb8e32046 100644 --- a/source/api_cc/src/DeepPotPT.cc +++ b/source/api_cc/src/DeepPotPT.cc @@ -71,10 +71,11 @@ void DeepPotPT::compute(ENERGYVTYPE& ener, const std::vector& box, const InputNlist& lmp_list, const int& ago) { - if(cpu_enabled) + if (cpu_enabled) { torch::Device device(torch::kCPU); - else + } else { torch::Device device(torch::kCUDA, gpu_id); + } std::vector coord_wrapped = coord; int natoms = atype.size(); auto options = torch::TensorOptions().dtype(torch::kFloat64); @@ -93,9 +94,10 @@ void DeepPotPT::compute(ENERGYVTYPE& ener, at::Tensor firstneigh = torch::from_blob( nlist_data.jlist, {lmp_list.inum, max_num_neighbors}, int32_options); at::Tensor nlist = firstneigh.to(torch::kInt64).to(device); - firstneigh_tensor = - module.run_method("format_nlist", coord_wrapped_Tensor,atype_Tensor,nlist) - .toTensor(); + firstneigh_tensor = module + .run_method("format_nlist", coord_wrapped_Tensor, + atype_Tensor, nlist) + .toTensor(); } else { at::Tensor firstneigh = torch::from_blob( nlist_data.jlist, {1, lmp_list.inum, max_num_neighbors}, @@ -106,7 +108,10 @@ void DeepPotPT::compute(ENERGYVTYPE& ener, bool do_atom_virial_tensor = true; torch::Tensor mapping_tensor = torch::Tensor(nullptr); c10::Dict outputs = - module.run_method("forward_lower",coord_wrapped_Tensor,atype_Tensor,firstneigh_tensor,mapping_tensor, do_atom_virial_tensor).toGenericDict(); + module + .run_method("forward_lower", coord_wrapped_Tensor, atype_Tensor, + firstneigh_tensor, mapping_tensor, do_atom_virial_tensor) + .toGenericDict(); c10::IValue energy_ = outputs.at("energy"); c10::IValue force_ = outputs.at("extended_force"); c10::IValue virial_ = outputs.at("reduced_virial"); @@ -190,10 +195,11 @@ void DeepPotPT::compute(ENERGYVTYPE& ener, const std::vector& coord, const std::vector& atype, const std::vector& box) { - if(cpu_enabled) + if (cpu_enabled) { torch::Device device(torch::kCPU); - else + } else { torch::Device device(torch::kCUDA, gpu_id); + } std::vector coord_wrapped = coord; int natoms = atype.size(); auto options = torch::TensorOptions().dtype(torch::kFloat64);