Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 26, 2024
1 parent 53d9643 commit 6f7a0fe
Show file tree
Hide file tree
Showing 25 changed files with 119 additions and 112 deletions.
2 changes: 1 addition & 1 deletion deepmd/pt/infer/deep_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import numpy as np
import torch
from deepmd.infer.deep_pot import DeepPot as DeepPotBase

from deepmd.infer.deep_pot import DeepPot as DeepPotBase
from deepmd.pt.model.model import (
get_model,
)
Expand Down
6 changes: 3 additions & 3 deletions deepmd/pt/infer/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

import numpy as np
import torch
from deepmd.common import (
expand_sys_str,
)
from torch.utils.data import (
DataLoader,
RandomSampler,
)

from deepmd.common import (
expand_sys_str,
)
from deepmd.pt.loss import (
DenoiseLoss,
EnergyStdLoss,
Expand Down
1 change: 0 additions & 1 deletion deepmd/pt/model/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from torch.jit import Final

from deepmd.model_format import EnvMat as DPEnvMat

from deepmd.pt.model.network.mlp import (
EmbeddingNet,
NetworkCollection,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/model/atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
)

import torch

from deepmd.model_format import (
FittingOutputDef,
)

from deepmd.pt.model.task import (
Fitting,
)
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/model/dp_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
)

import torch

from deepmd.model_format import (
FittingOutputDef,
)

from deepmd.pt.model.descriptor.descriptor import (
Descriptor,
)
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/model/make_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
)

import torch

from deepmd.model_format import (
ModelOutputDef,
)

from deepmd.pt.model.model.transform_output import (
communicate_extended_output,
fit_output_to_model_output,
Expand Down
1 change: 1 addition & 0 deletions deepmd/pt/model/model/transform_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)

import torch

from deepmd.model_format import (
FittingOutputDef,
ModelOutputDef,
Expand Down
1 change: 0 additions & 1 deletion deepmd/pt/model/network/mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
make_fitting_network,
make_multilayer_network,
)

from deepmd.pt.utils.env import (
DEFAULT_PRECISION,
PRECISION_DICT,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/task/denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
)

import torch

from deepmd.model_format import (
FittingOutputDef,
OutputVariableDef,
fitting_check_output,
)

from deepmd.pt.model.network.network import (
MaskLMHead,
NonLinearHead,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/task/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
)

import torch

from deepmd.model_format import (
FittingOutputDef,
OutputVariableDef,
fitting_check_output,
)

from deepmd.pt.model.network.network import (
ResidualDeep,
)
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/task/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import numpy as np
import torch

from deepmd.model_format import (
FittingOutputDef,
)

from deepmd.pt.model.task.task import (
TaskBaseMethod,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/pt/utils/auto_batch_size.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import torch

from deepmd.utils.batch_size import AutoBatchSize as AutoBatchSizeBase


Expand Down
8 changes: 4 additions & 4 deletions deepmd/pt/utils/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
import torch
import torch.distributed as dist
import torch.multiprocessing
from deepmd.utils.data_system import (
prob_sys_size_ext,
process_sys_probs,
)
from torch.utils.data import (
DataLoader,
Dataset,
Expand All @@ -39,6 +35,10 @@
from deepmd.pt.utils.dataset import (
DeepmdDataSetForLoader,
)
from deepmd.utils.data_system import (
prob_sys_size_ext,
process_sys_probs,
)

torch.multiprocessing.set_sharing_strategy("file_system")

Expand Down
51 changes: 32 additions & 19 deletions source/pt/lmp/pair_deepmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,24 @@ static bool is_key(const string &input) {
return false;
}

static void ana_st(double &max, double &min, double &sum,
const vector<double> &vec, const int &nloc) {
if (nloc == 0)
static void ana_st(double &max,
double &min,
double &sum,
const vector<double> &vec,
const int &nloc) {
if (nloc == 0) {
return;
}
max = vec[0];
min = vec[0];
sum = vec[0];
for (unsigned ii = 1; ii < nloc; ++ii) {
if (vec[ii] > max)
if (vec[ii] > max) {
max = vec[ii];
if (vec[ii] < min)
}
if (vec[ii] < min) {
min = vec[ii];
}
sum += vec[ii];
}
}
Expand Down Expand Up @@ -129,13 +135,15 @@ void PairDeepMD::settings(int narg, char **arg) {
"Illegal pair_style command\nwrong number of parameters\n");
}
if (string(arg[iarg]) == string("out_freq")) {
if (iarg + 1 >= narg)
if (iarg + 1 >= narg) {
error->all(FLERR, "Illegal out_freq, not provided");
}
out_freq = atoi(arg[iarg + 1]);
iarg += 2;
} else if (string(arg[iarg]) == string("out_file")) {
if (iarg + 1 >= narg)
if (iarg + 1 >= narg) {
error->all(FLERR, "Illegal out_file, not provided");
}
out_file = string(arg[iarg + 1]);
iarg += 2;
} else if (string(arg[iarg]) == string("fparam")) {
Expand Down Expand Up @@ -184,8 +192,9 @@ void PairDeepMD::settings(int narg, char **arg) {
else if (string(arg[iarg]) == string("fparam_from_compute")) {
for (int ii = 0; ii < 1; ++ii) {
if (iarg + 1 + ii >= narg || is_key(arg[iarg + 1 + ii])) {
error->all(FLERR, "invalid fparam_from_compute key: should be "
"fparam_from_compute compute_id(str)");
error->all(FLERR,
"invalid fparam_from_compute key: should be "
"fparam_from_compute compute_id(str)");
}
}
do_compute = true;
Expand Down Expand Up @@ -219,8 +228,9 @@ void PairDeepMD::settings(int narg, char **arg) {
}
}

if (out_freq < 0)
if (out_freq < 0) {
error->all(FLERR, "Illegal out_freq, should be >= 0");
}
if (do_ttm && aparam.size() > 0) {
error->all(FLERR, "aparam and ttm should NOT be set simultaneously");
}
Expand Down Expand Up @@ -282,12 +292,12 @@ void PairDeepMD::compute(int eflag, int vflag) {
}

// get box
dbox[0] = domain->h[0]; // xx
dbox[4] = domain->h[1]; // yy
dbox[8] = domain->h[2]; // zz
dbox[7] = domain->h[3]; // zy
dbox[6] = domain->h[4]; // zx
dbox[3] = domain->h[5]; // yx
dbox[0] = domain->h[0]; // xx
dbox[4] = domain->h[1]; // yy
dbox[8] = domain->h[2]; // zz
dbox[7] = domain->h[3]; // zy
dbox[6] = domain->h[4]; // zx
dbox[3] = domain->h[5]; // yx

// int ago = numb_models > 1 ? 0 : neighbor->ago;
int ago = neighbor->ago;
Expand Down Expand Up @@ -392,8 +402,9 @@ void PairDeepMD::compute(int eflag, int vflag) {
}
MPI_Gather(&nlocal, 1, MPI_INT, counts, 1, MPI_INT, 0, world);
displacements[0] = 0;
for (int ii = 0; ii < nprocs - 1; ii++)
for (int ii = 0; ii < nprocs - 1; ii++) {
displacements[ii + 1] = displacements[ii] + counts[ii];
}
MPI_Gatherv(tagsend, nlocal, MPI_LMP_TAGINT, tagrecv, counts,
displacements, MPI_LMP_TAGINT, 0, world);
MPI_Gatherv(stdfsend, nlocal, MPI_DOUBLE, stdfrecv, counts,
Expand Down Expand Up @@ -440,8 +451,9 @@ void PairDeepMD::compute(int eflag, int vflag) {
void PairDeepMD::coeff(int narg, char **arg) {
// if (narg < 4 || narg > 5) error->all(FLERR, "Incorrect args for pair
// coefficients");
if (!allocated)
if (!allocated) {
allocate();
}

int ilo, ihi, jlo, jhi;
utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error);
Expand All @@ -458,8 +470,9 @@ void PairDeepMD::coeff(int narg, char **arg) {
}
}

if (count == 0)
if (count == 0) {
error->all(FLERR, "Incorrect args for pair coefficients");
}
}

/* ---------------------------------------------------------------------- */
Expand Down
12 changes: 6 additions & 6 deletions source/pt/lmp/pair_deepmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace deepmd_compat = deepmd;
namespace LAMMPS_NS {

class PairDeepMD : public Pair {
public:
public:
PairDeepMD(class LAMMPS *);
~PairDeepMD() override;
void compute(int, int) override;
Expand Down Expand Up @@ -55,18 +55,18 @@ class PairDeepMD : public Pair {
// std::vector<std::string> get_file_content(
// const std::vector<std::string> &models);

protected:
protected:
virtual void allocate();
double **scale;

private:
private:
deepmd_compat::DeepPot deep_pot;
deepmd_compat::DeepPotModelDevi deep_pot_model_devi;
unsigned numb_models;
double cutoff;
int numb_types;
int numb_types_spin;
std::vector<std::vector<double>> all_force;
std::vector<std::vector<double> > all_force;
std::ofstream fp;
int out_freq;
std::string out_file;
Expand All @@ -84,7 +84,7 @@ class PairDeepMD : public Pair {
int extend_inum;
std::vector<int> extend_ilist;
std::vector<int> extend_numneigh;
std::vector<std::vector<int>> extend_neigh;
std::vector<std::vector<int> > extend_neigh;
std::vector<int *> extend_firstneigh;
std::vector<double> extend_dcoord;
std::vector<int> extend_dtype;
Expand Down Expand Up @@ -112,7 +112,7 @@ class PairDeepMD : public Pair {
std::vector<int> type_idx_map;
};

} // namespace LAMMPS_NS
} // namespace LAMMPS_NS

#endif
#endif
13 changes: 6 additions & 7 deletions source/tests/pt/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@

import json

from deepmd.tf.common import (
expand_sys_str,
)
from deepmd.tf.env import (
op_module,
)

from deepmd.pt.model.descriptor import (
prod_env_mat_se_a,
)
Expand All @@ -32,6 +25,12 @@
GLOBAL_PT_FLOAT_PRECISION,
TEST_CONFIG,
)
from deepmd.tf.common import (
expand_sys_str,
)
from deepmd.tf.env import (
op_module,
)

CUR_DIR = os.path.dirname(__file__)

Expand Down
9 changes: 4 additions & 5 deletions source/tests/pt/test_embedding_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

tf.disable_eager_execution()

from deepmd.tf.common import (
expand_sys_str,
)
from deepmd.tf.descriptor import DescrptSeA as DescrptSeA_tf

from deepmd.pt.model.descriptor import (
DescrptSeA,
)
Expand All @@ -29,6 +24,10 @@
GLOBAL_NP_FLOAT_PRECISION,
TEST_CONFIG,
)
from deepmd.tf.common import (
expand_sys_str,
)
from deepmd.tf.descriptor import DescrptSeA as DescrptSeA_tf

CUR_DIR = os.path.dirname(__file__)

Expand Down
7 changes: 3 additions & 4 deletions source/tests/pt/test_fitting_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@

tf.disable_eager_execution()

from deepmd.tf.fit.ener import (
EnerFitting,
)

from deepmd.pt.model.task import (
EnergyFittingNet,
)
from deepmd.pt.utils.env import (
GLOBAL_NP_FLOAT_PRECISION,
)
from deepmd.tf.fit.ener import (
EnerFitting,
)


class FakeDescriptor:
Expand Down
Loading

0 comments on commit 6f7a0fe

Please sign in to comment.