|
| 1 | +from typing import Tuple, List |
| 2 | + |
| 3 | +from deepmd.env import tf |
| 4 | +from deepmd.utils.graph import get_embedding_net_variables |
| 5 | +from .descriptor import Descriptor |
| 6 | + |
| 7 | + |
| 8 | +class DescrptSe (Descriptor): |
| 9 | + """A base class for smooth version of descriptors. |
| 10 | + |
| 11 | + Notes |
| 12 | + ----- |
| 13 | + All of these descriptors have an environmental matrix and an |
| 14 | + embedding network (:meth:`deepmd.utils.network.embedding_net`), so |
| 15 | + they can share some similiar methods without defining them twice. |
| 16 | +
|
| 17 | + Attributes |
| 18 | + ---------- |
| 19 | + embedding_net_variables : dict |
| 20 | + initial embedding network variables |
| 21 | + descrpt_reshape : tf.Tensor |
| 22 | + the reshaped descriptor |
| 23 | + descrpt_deriv : tf.Tensor |
| 24 | + the descriptor derivative |
| 25 | + rij : tf.Tensor |
| 26 | + distances between two atoms |
| 27 | + nlist : tf.Tensor |
| 28 | + the neighbor list |
| 29 | + |
| 30 | + """ |
| 31 | + def _identity_tensors(self, suffix : str = "") -> None: |
| 32 | + """Identify tensors which are expected to be stored and restored. |
| 33 | + |
| 34 | + Notes |
| 35 | + ----- |
| 36 | + These tensors will be indentitied: |
| 37 | + self.descrpt_reshape : o_rmat |
| 38 | + self.descrpt_deriv : o_rmat_deriv |
| 39 | + self.rij : o_rij |
| 40 | + self.nlist : o_nlist |
| 41 | + Thus, this method should be called during building the descriptor and |
| 42 | + after these tensors are initialized. |
| 43 | +
|
| 44 | + Parameters |
| 45 | + ---------- |
| 46 | + suffix : str |
| 47 | + The suffix of the scope |
| 48 | + """ |
| 49 | + self.descrpt_reshape = tf.identity(self.descrpt_reshape, name = 'o_rmat' + suffix) |
| 50 | + self.descrpt_deriv = tf.identity(self.descrpt_deriv, name = 'o_rmat_deriv' + suffix) |
| 51 | + self.rij = tf.identity(self.rij, name = 'o_rij' + suffix) |
| 52 | + self.nlist = tf.identity(self.nlist, name = 'o_nlist' + suffix) |
| 53 | + |
| 54 | + def get_tensor_names(self, suffix : str = "") -> Tuple[str]: |
| 55 | + """Get names of tensors. |
| 56 | + |
| 57 | + Parameters |
| 58 | + ---------- |
| 59 | + suffix : str |
| 60 | + The suffix of the scope |
| 61 | +
|
| 62 | + Returns |
| 63 | + ------- |
| 64 | + Tuple[str] |
| 65 | + Names of tensors |
| 66 | + """ |
| 67 | + return (f'o_rmat{suffix}:0', f'o_rmat_deriv{suffix}:0', f'o_rij{suffix}:0', f'o_nlist{suffix}:0') |
| 68 | + |
| 69 | + def pass_tensors_from_frz_model(self, |
| 70 | + descrpt_reshape : tf.Tensor, |
| 71 | + descrpt_deriv : tf.Tensor, |
| 72 | + rij : tf.Tensor, |
| 73 | + nlist : tf.Tensor |
| 74 | + ): |
| 75 | + """ |
| 76 | + Pass the descrpt_reshape tensor as well as descrpt_deriv tensor from the frz graph_def |
| 77 | +
|
| 78 | + Parameters |
| 79 | + ---------- |
| 80 | + descrpt_reshape |
| 81 | + The passed descrpt_reshape tensor |
| 82 | + descrpt_deriv |
| 83 | + The passed descrpt_deriv tensor |
| 84 | + rij |
| 85 | + The passed rij tensor |
| 86 | + nlist |
| 87 | + The passed nlist tensor |
| 88 | + """ |
| 89 | + self.rij = rij |
| 90 | + self.nlist = nlist |
| 91 | + self.descrpt_deriv = descrpt_deriv |
| 92 | + self.descrpt_reshape = descrpt_reshape |
| 93 | + |
| 94 | + def init_variables(self, |
| 95 | + model_file : str, |
| 96 | + suffix : str = "", |
| 97 | + ) -> None: |
| 98 | + """ |
| 99 | + Init the embedding net variables with the given dict |
| 100 | +
|
| 101 | + Parameters |
| 102 | + ---------- |
| 103 | + model_file : str |
| 104 | + The input frozen model file |
| 105 | + suffix : str, optional |
| 106 | + The suffix of the scope |
| 107 | + """ |
| 108 | + self.embedding_net_variables = get_embedding_net_variables(model_file, suffix = suffix) |
0 commit comments