Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devel' into compress-any-neuron
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz committed Oct 18, 2023
2 parents d9a68c0 + 64a5aa8 commit 3fc74d3
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 33 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,41 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

build_pypi_index:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist/packages
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.11'
- run: pip install dumb-pypi
- run: |
ls dist/packages > package_list.txt
dumb-pypi --output-dir dist --packages-url ../../packages --package-list package_list.txt --title "DeePMD-kit Developed Packages"
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
with:
path: dist
deploy_pypi_index:
needs: build_pypi_index
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/devel' && github.repository_owner == 'deepmodeling'
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2

pass:
name: Pass testing build wheels
needs: [build_wheels, build_sdist]
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ repos:
- id: blacken-docs
# C++
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.6
rev: v17.0.2
hooks:
- id: clang-format
exclude: ^source/3rdparty|source/lib/src/gpu/cudart/.+\.inc
Expand Down
8 changes: 4 additions & 4 deletions deepmd/train/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,12 @@ def _build_network(self, data, suffix=""):
self.place_holders[kk] = tf.placeholder(
GLOBAL_TF_FLOAT_PRECISION, [None], "t_" + kk
)
self._get_place_horders(data_requirement)
self._get_place_holders(data_requirement)
else:
if not self.multi_task_mode:
self._get_place_horders(data.get_data_dict())
self._get_place_holders(data.get_data_dict())
else:
self._get_place_horders(data[next(iter(data.keys()))].get_data_dict())
self._get_place_holders(data[next(iter(data.keys()))].get_data_dict())

self.place_holders["type"] = tf.placeholder(tf.int32, [None], name="t_type")
self.place_holders["natoms_vec"] = tf.placeholder(
Expand Down Expand Up @@ -1035,7 +1035,7 @@ def save_compressed(self):
if self.is_compress:
self.saver.save(self.sess, os.path.join(os.getcwd(), self.save_ckpt))

def _get_place_horders(self, data_dict):
def _get_place_holders(self, data_dict):
for kk in data_dict.keys():
if kk == "type":
continue
Expand Down
2 changes: 1 addition & 1 deletion doc/install/easy-install-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ docker pull ghcr.io/deepmodeling/deepmd-kit:devel
Below is an one-line shell command to download the [artifact](https://nightly.link/deepmodeling/deepmd-kit/workflows/build_wheel/devel/artifact.zip) containing wheels and install it with `pip`:

```sh
bash -c 'wget -O /tmp/z.$$ https://nightly.link/deepmodeling/deepmd-kit/workflows/build_wheel/devel/artifact.zip && unzip /tmp/z.$$ -d /tmp/dist.$$ && pip install -U --pre deepmd-kit[gpu,cu11,lmp] --find-links /tmp/dist.$$ && rm -r /tmp/z.$$ /tmp/dist.$$'
pip install -U --pre deepmd-kit[gpu,cu11,lmp] --extra-index-url https://deepmodeling.github.io/deepmd-kit/simple
```

`cu11` and `lmp` are optional, which is the same as the stable version.
Expand Down
8 changes: 7 additions & 1 deletion doc/third-party/lammps-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pair_style deepmd models ... keyword value ...
- models = frozen model(s) to compute the interaction.
If multiple models are provided, then only the first model serves to provide energy and force prediction for each timestep of molecular dynamics,
and the model deviation will be computed among all models every `out_freq` timesteps.
- keyword = *out_file* or *out_freq* or *fparam* or *fparam_from_compute* or *atomic* or *relative* or *relative_v* or *aparam* or *ttm*
- keyword = *out_file* or *out_freq* or *fparam* or *fparam_from_compute* or *aparam_from_compute* or *atomic* or *relative* or *relative_v* or *aparam* or *ttm*
<pre>
<i>out_file</i> value = filename
filename = The file name for the model deviation output. Default is model_devi.out
Expand All @@ -48,6 +48,8 @@ and the model deviation will be computed among all models every `out_freq` times
parameters = one or more frame parameters required for model evaluation.
<i>fparam_from_compute</i> value = id
id = compute id used to update the frame parameter.
<i>aparam_from_compute</i> value = id
id = compute id used to update the atom parameter.
<i>atomic</i> = no value is required.
If this keyword is set, the force model deviation of each atom will be output.
<i>relative</i> value = level
Expand All @@ -69,6 +71,9 @@ pair_coeff * * O H
pair_style deepmd cp.pb fparam_from_compute TEMP
compute TEMP all temp
pair_style deepmd ener.pb aparam_from_compute 1
compute 1 all ke/atom
```

### Description
Expand All @@ -89,6 +94,7 @@ $$E_{v_i}=\frac{\left|D_{v_i}\right|}{\left|v_i\right|+l}$$

If the keyword `fparam` is set, the given frame parameter(s) will be fed to the model.
If the keyword `fparam_from_compute` is set, the global parameter(s) from compute command (e.g., temperature from [compute temp command](https://docs.lammps.org/compute_temp.html)) will be fed to the model as the frame parameter(s).
If the keyword `aparam_from_compute` is set, the atomic parameter(s) from compute command (e.g., per-atom translational kinetic energy from [compute ke/atom command](https://docs.lammps.org/compute_ke_atom.html)) will be fed to the model as the atom parameter(s).
If the keyword `aparam` is set, the given atomic parameter(s) will be fed to the model, where each atom is assumed to have the same atomic parameter(s).
If the keyword `ttm` is set, electronic temperatures from [fix ttm command](https://docs.lammps.org/fix_ttm.html) will be fed to the model as the atomic parameters.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ TYPED_TEST(TestInferDeepPotModeDeviFparamAparam, cpu_lmp_list_std) {
for (int kk = 0; kk < nmodel; ++kk) {
avg_f[dd] += fmd[kk][ii * 3 + dd];
}
avg_f[dd] /= (nmodel)*1.0;
avg_f[dd] /= (nmodel) * 1.0;
}
VALUETYPE std = 0.;
for (int kk = 0; kk < nmodel; ++kk) {
Expand Down
2 changes: 1 addition & 1 deletion source/api_c/tests/test_deeppot_model_devi_hpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ TYPED_TEST(TestInferDeepPotModeDevi, cpu_lmp_list_std) {
for (int kk = 0; kk < nmodel; ++kk) {
avg_f[dd] += fmd[kk][ii * 3 + dd];
}
avg_f[dd] /= (nmodel)*1.0;
avg_f[dd] /= (nmodel) * 1.0;
}
VALUETYPE std = 0.;
for (int kk = 0; kk < nmodel; ++kk) {
Expand Down
2 changes: 1 addition & 1 deletion source/api_cc/tests/test_deeppot_model_devi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ TYPED_TEST(TestInferDeepPotModeDevi, cpu_lmp_list_std) {
for (int kk = 0; kk < nmodel; ++kk) {
avg_f[dd] += fmd[kk][ii * 3 + dd];
}
avg_f[dd] /= (nmodel)*1.0;
avg_f[dd] /= (nmodel) * 1.0;
}
VALUETYPE std = 0.;
for (int kk = 0; kk < nmodel; ++kk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ TYPED_TEST(TestInferDeepPotModeDeviFparamAparam, cpu_lmp_list_std) {
for (int kk = 0; kk < nmodel; ++kk) {
avg_f[dd] += fmd[kk][ii * 3 + dd];
}
avg_f[dd] /= (nmodel)*1.0;
avg_f[dd] /= (nmodel) * 1.0;
}
VALUETYPE std = 0.;
for (int kk = 0; kk < nmodel; ++kk) {
Expand Down
92 changes: 72 additions & 20 deletions source/lmp/pair_deepmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,59 @@ static void make_uniform_aparam(vector<double> &daparam,
}

void PairDeepMD::make_fparam_from_compute(vector<double> &fparam) {
assert(do_compute);
assert(do_compute_fparam);

int icompute = modify->find_compute(compute_id);
int icompute = modify->find_compute(compute_fparam_id);
Compute *compute = modify->compute[icompute];

assert(compute);
fparam.resize(dim_fparam);

if (dim_fparam == 1) {
compute->compute_scalar();
if (!(compute->invoked_flag & Compute::INVOKED_SCALAR)) {
compute->compute_scalar();
compute->invoked_flag |= Compute::INVOKED_SCALAR;
}
fparam[0] = compute->scalar;
} else if (dim_fparam > 1) {
compute->compute_vector();
if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) {
compute->compute_vector();
compute->invoked_flag |= Compute::INVOKED_VECTOR;
}
double *cvector = compute->vector;
for (int jj = 0; jj < dim_fparam; ++jj) {
fparam[jj] = cvector[jj];
}
}
}

void PairDeepMD::make_aparam_from_compute(vector<double> &aparam) {
assert(do_compute_aparam);

int icompute = modify->find_compute(compute_aparam_id);
Compute *compute = modify->compute[icompute];

assert(compute);
int nlocal = atom->nlocal;
aparam.resize(dim_aparam * nlocal);

if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
compute->compute_peratom();
compute->invoked_flag |= Compute::INVOKED_PERATOM;
}
if (dim_aparam == 1) {
double *cvector = compute->vector_atom;
aparam.assign(cvector, cvector + nlocal);
} else if (dim_aparam > 1) {
double **carray = compute->array_atom;
for (int ii = 0; ii < nlocal; ++ii) {
for (int jj = 0; jj < dim_aparam; ++jj) {
aparam[ii * dim_aparam + jj] = carray[ii][jj];
}
}
}
}

#ifdef USE_TTM
void PairDeepMD::make_ttm_fparam(vector<double> &fparam) {
assert(do_ttm);
Expand Down Expand Up @@ -379,7 +412,8 @@ PairDeepMD::PairDeepMD(LAMMPS *lmp)
eps_v = 0.;
scale = NULL;
do_ttm = false;
do_compute = false;
do_compute_fparam = false;
do_compute_aparam = false;
single_model = false;
multi_models_mod_devi = false;
multi_models_no_mod_devi = false;
Expand Down Expand Up @@ -492,8 +526,10 @@ void PairDeepMD::compute(int eflag, int vflag) {
}
}

// uniform aparam
if (aparam.size() > 0) {
if (do_compute_aparam) {
make_aparam_from_compute(daparam);
} else if (aparam.size() > 0) {
// uniform aparam
make_uniform_aparam(daparam, aparam, nlocal);
} else if (do_ttm) {
#ifdef USE_TTM
Expand All @@ -505,7 +541,7 @@ void PairDeepMD::compute(int eflag, int vflag) {
#endif
}

if (do_compute) {
if (do_compute_fparam) {
make_fparam_from_compute(fparam);
}

Expand Down Expand Up @@ -884,6 +920,7 @@ static bool is_key(const string &input) {
keys.push_back("fparam");
keys.push_back("aparam");
keys.push_back("fparam_from_compute");
keys.push_back("aparam_from_compute");
keys.push_back("ttm");
keys.push_back("atomic");
keys.push_back("relative");
Expand Down Expand Up @@ -1019,15 +1056,24 @@ void PairDeepMD::settings(int narg, char **arg) {
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)");
"fparam_from_compute compute_fparam_id(str)");
}
}
do_compute = true;
compute_id = arg[iarg + 1];
do_compute_fparam = true;
compute_fparam_id = arg[iarg + 1];
iarg += 1 + 1;
}

else if (string(arg[iarg]) == string("atomic")) {
} else if (string(arg[iarg]) == string("aparam_from_compute")) {
for (int ii = 0; ii < 1; ++ii) {
if (iarg + 1 + ii >= narg || is_key(arg[iarg + 1 + ii])) {
error->all(FLERR,
"invalid aparam_from_compute key: should be "
"aparam_from_compute compute_aparam_id(str)");
}
}
do_compute_aparam = true;
compute_aparam_id = arg[iarg + 1];
iarg += 1 + 1;
} else if (string(arg[iarg]) == string("atomic")) {
out_each = 1;
iarg += 1;
} else if (string(arg[iarg]) == string("relative")) {
Expand Down Expand Up @@ -1056,10 +1102,12 @@ void PairDeepMD::settings(int narg, char **arg) {
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");
if ((int)do_ttm + (int)do_compute_aparam + (int)(aparam.size() > 0) > 1) {
error->all(FLERR,
"aparam, aparam_from_compute, and ttm should NOT be set "
"simultaneously");
}
if (do_compute && fparam.size() > 0) {
if (do_compute_fparam && fparam.size() > 0) {
error->all(
FLERR,
"fparam and fparam_from_compute should NOT be set simultaneously");
Expand Down Expand Up @@ -1104,9 +1152,13 @@ void PairDeepMD::settings(int narg, char **arg) {
}
cout << endl;
}
if (do_compute) {
cout << pre << "using compute id: ";
cout << compute_id << " " << endl;
if (do_compute_fparam) {
cout << pre << "using compute id (fparam): ";
cout << compute_fparam_id << " " << endl;
}
if (do_compute_aparam) {
cout << pre << "using compute id (aparam): ";
cout << compute_aparam_id << " " << endl;
}
if (aparam.size() > 0) {
cout << pre << "using aparam(s): ";
Expand Down
7 changes: 5 additions & 2 deletions source/lmp/pair_deepmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ class PairDeepMD : public Pair {
double eps_v;

void make_fparam_from_compute(std::vector<double> &fparam);
bool do_compute;
std::string compute_id;
bool do_compute_fparam;
std::string compute_fparam_id;
void make_aparam_from_compute(std::vector<double> &aparam);
bool do_compute_aparam;
std::string compute_aparam_id;

void make_ttm_fparam(std::vector<double> &fparam);

Expand Down

0 comments on commit 3fc74d3

Please sign in to comment.