From de1753615aa4fb4b3e5b21137e2ddb0479446cd0 Mon Sep 17 00:00:00 2001 From: RandomDefaultUser Date: Thu, 21 Nov 2024 16:12:05 +0000 Subject: [PATCH] deploy: 01320fae49ada8a1c0c2852b0f0b1cfba224a7d9 --- _modules/mala/common/parameters.html | 102 ++++++++++++++++---- _modules/mala/network/hyper_opt_oat.html | 6 -- _modules/mala/network/hyper_opt_optuna.html | 6 -- _modules/mala/targets/density.html | 8 +- _sources/advanced_usage/predictions.rst.txt | 6 +- advanced_usage/predictions.html | 6 +- api/mala.common.html | 4 +- api/mala.common.parameters.html | 63 +++++------- api/mala.html | 4 +- api/modules.html | 4 +- genindex.html | 6 +- objects.inv | Bin 6367 -> 6356 bytes searchindex.js | 2 +- 13 files changed, 123 insertions(+), 94 deletions(-) diff --git a/_modules/mala/common/parameters.html b/_modules/mala/common/parameters.html index b593f36ae..c43d01ffa 100644 --- a/_modules/mala/common/parameters.html +++ b/_modules/mala/common/parameters.html @@ -125,6 +125,7 @@

Source code for mala.common.parameters

             "openpmd_configuration": {},
             "openpmd_granularity": 1,
             "lammps": True,
+            "atomic_density_formula": False,
         }
         pass
 
@@ -176,6 +177,11 @@ 

Source code for mala.common.parameters

     def _update_lammps(self, new_lammps):
         self._configuration["lammps"] = new_lammps
 
+    def _update_atomic_density_formula(self, new_atomic_density_formula):
+        self._configuration["atomic_density_formula"] = (
+            new_atomic_density_formula
+        )
+
     @staticmethod
     def _member_to_json(member):
         if isinstance(member, (int, float, type(None), str)):
@@ -422,11 +428,6 @@ 

Source code for mala.common.parameters

 
     atomic_density_sigma : float
         Sigma used for the calculation of the Gaussian descriptors.
-
-    use_atomic_density_energy_formula : bool
-        If True, Gaussian descriptors will be calculated for the
-        calculation of the Ewald sum as part of the total energy module.
-        Default is False.
     """
 
     def __init__(self):
@@ -456,7 +457,6 @@ 

Source code for mala.common.parameters

         # atomic density may be used at the same time, if e.g. bispectrum
         # descriptors are used for a full inference, which then uses the atomic
         # density for the calculation of the Ewald sum.
-        self.use_atomic_density_energy_formula = False
         self.atomic_density_sigma = None
         self.atomic_density_cutoff = None
 
@@ -662,11 +662,6 @@ 

Source code for mala.common.parameters

 
     Attributes
     ----------
-    descriptors_contain_xyz : bool
-        Legacy option. If True, it is assumed that the first three entries of
-        the descriptor vector are the xyz coordinates and they are cut from the
-        descriptor vector. If False, no such cutting is peformed.
-
     snapshot_directories_list : list
         A list of all added snapshots.
 
@@ -1307,9 +1302,6 @@ 

Source code for mala.common.parameters

     hyperparameters : ParametersHyperparameterOptimization
         Parameters used for hyperparameter optimization.
 
-    debug : ParametersDebug
-        Container for all debugging parameters.
-
     manual_seed: int
         If not none, this value is used as manual seed for the neural networks.
         Can be used to make experiments comparable. Default: None.
@@ -1341,6 +1333,7 @@ 

Source code for mala.common.parameters

         # different.
         self.openpmd_granularity = 1
         self.use_lammps = True
+        self.use_atomic_density_formula = False
 
     @property
     def openpmd_granularity(self):
@@ -1392,7 +1385,7 @@ 

Source code for mala.common.parameters

 
     @property
     def use_gpu(self):
-        """Control whether or not a GPU is used (provided there is one)."""
+        """Control whether a GPU is used (provided there is one)."""
         return self._use_gpu
 
     @use_gpu.setter
@@ -1407,6 +1400,12 @@ 

Source code for mala.common.parameters

                     "GPU requested, but no GPU found. MALA will "
                     "operate with CPU only."
                 )
+        if self._use_gpu and self.use_lammps:
+            printout(
+                "Enabling atomic density formula because LAMMPS and GPU "
+                "are used."
+            )
+            self.use_atomic_density_formula = True
 
         # Invalidate, will be updated in setter.
         self.device = None
@@ -1419,7 +1418,7 @@ 

Source code for mala.common.parameters

 
     @property
     def use_ddp(self):
-        """Control whether or not dd is used for parallel training."""
+        """Control whether ddp is used for parallel training."""
         return self._use_ddp
 
     @use_ddp.setter
@@ -1470,7 +1469,7 @@ 

Source code for mala.common.parameters

 
     @property
     def use_mpi(self):
-        """Control whether or not MPI is used for paralle inference."""
+        """Control whether MPI is used for paralle inference."""
         return self._use_mpi
 
     @use_mpi.setter
@@ -1514,12 +1513,18 @@ 

Source code for mala.common.parameters

 
     @property
     def use_lammps(self):
-        """Control whether or not to use LAMMPS for descriptor calculation."""
+        """Control whether to use LAMMPS for descriptor calculation."""
         return self._use_lammps
 
     @use_lammps.setter
     def use_lammps(self, value):
         self._use_lammps = value
+        if self.use_gpu and value:
+            printout(
+                "Enabling atomic density formula because LAMMPS and GPU "
+                "are used."
+            )
+            self.use_atomic_density_formula = True
         self.network._update_lammps(self.use_lammps)
         self.descriptors._update_lammps(self.use_lammps)
         self.targets._update_lammps(self.use_lammps)
@@ -1527,6 +1532,48 @@ 

Source code for mala.common.parameters

         self.running._update_lammps(self.use_lammps)
         self.hyperparameters._update_lammps(self.use_lammps)
 
+    @property
+    def use_atomic_density_formula(self):
+        """Control whether to use the atomic density formula.
+
+        This formula uses as a Gaussian representation of the atomic density
+        to calculate the structure factor and with it, the Ewald energy
+        and parts of the exchange-correlation energy. By using it, one can
+        go from N^2 to NlogN scaling, and offloads most of the computational
+        overhead of energy calculation from QE to LAMMPS. This is beneficial
+        since LAMMPS can benefit from GPU acceleration (QE GPU acceleration
+        is not used in the portion of the QE code MALA employs). If set
+        to True, this means MALA will perform another LAMMPS calculation
+        during inference. The hyperparameters for this atomic density
+        calculation are set via the parameters.descriptors object.
+        Default is False, except for when both use_gpu and use_lammps
+        are True, in which case this value will be set to True as well.
+        """
+        return self._use_atomic_density_formula
+
+    @use_atomic_density_formula.setter
+    def use_atomic_density_formula(self, value):
+        self._use_atomic_density_formula = value
+
+        self.network._update_atomic_density_formula(
+            self.use_atomic_density_formula
+        )
+        self.descriptors._update_atomic_density_formula(
+            self.use_atomic_density_formula
+        )
+        self.targets._update_atomic_density_formula(
+            self.use_atomic_density_formula
+        )
+        self.data._update_atomic_density_formula(
+            self.use_atomic_density_formula
+        )
+        self.running._update_atomic_density_formula(
+            self.use_atomic_density_formula
+        )
+        self.hyperparameters._update_atomic_density_formula(
+            self.use_atomic_density_formula
+        )
+
 
[docs] def show(self): @@ -1736,6 +1783,18 @@

Source code for mala.common.parameters

                     ].from_json(json_dict[key])
                     setattr(loaded_parameters, key, sub_parameters)
 
+                    # Backwards compatability:
+                    if key == "descriptors":
+                        if (
+                            "use_atomic_density_energy_formula"
+                            in json_dict[key]
+                        ):
+                            loaded_parameters.use_atomic_density_formula = (
+                                json_dict[key][
+                                    "use_atomic_density_energy_formula"
+                                ]
+                            )
+
             # We iterate a second time, to set global values, so that they
             # are properly forwarded.
             for key in json_dict:
@@ -1749,6 +1808,13 @@ 

Source code for mala.common.parameters

                         setattr(loaded_parameters, key, json_dict[key])
             if no_snapshots is True:
                 loaded_parameters.data.snapshot_directories_list = []
+            # Backwards compatability: since the transfer of old property
+            # to new property happens _before_ all children descriptor classes
+            # are instantiated, it is not properly propagated. Thus, we
+            # simply have to set it to its own value again.
+            loaded_parameters.use_atomic_density_formula = (
+                loaded_parameters.use_atomic_density_formula
+            )
         else:
             raise Exception("Unsupported parameter save format.")
 
diff --git a/_modules/mala/network/hyper_opt_oat.html b/_modules/mala/network/hyper_opt_oat.html
index 31b7cc491..cc2a6e455 100644
--- a/_modules/mala/network/hyper_opt_oat.html
+++ b/_modules/mala/network/hyper_opt_oat.html
@@ -518,12 +518,6 @@ 

Source code for mala.network.hyper_opt_oat

 
             self._save_params_and_scaler()
 
-            # Next, we save all the other objects.
-            # Here some horovod stuff would have to go.
-            # But so far, the optuna implementation is not horovod-ready...
-            # if self.params.use_horovod:
-            #     if hvd.rank() != 0:
-            #         return
             # The study only has to be saved if the no RDB storage is used.
             if self.params.hyperparameters.rdb_storage is None:
                 hyperopt_name = (
diff --git a/_modules/mala/network/hyper_opt_optuna.html b/_modules/mala/network/hyper_opt_optuna.html
index 503aef9fb..db7c73bf8 100644
--- a/_modules/mala/network/hyper_opt_optuna.html
+++ b/_modules/mala/network/hyper_opt_optuna.html
@@ -487,12 +487,6 @@ 

Source code for mala.network.hyper_opt_optuna

self._save_params_and_scaler() - # Next, we save all the other objects. - # Here some horovod stuff would have to go. - # But so far, the optuna implementation is not horovod-ready... - # if self.params.use_horovod: - # if hvd.rank() != 0: - # return # The study only has to be saved if the no RDB storage is used. if self.params.hyperparameters.rdb_storage is None: hyperopt_name = ( diff --git a/_modules/mala/targets/density.html b/_modules/mala/targets/density.html index 4ee0e513d..e906cd44b 100644 --- a/_modules/mala/targets/density.html +++ b/_modules/mala/targets/density.html @@ -1266,7 +1266,7 @@

Source code for mala.targets.density

         # instantiate the process with the file.
         positions_for_qe = self.get_scaled_positions_for_qe(atoms_Angstrom)
 
-        if self._parameters_full.descriptors.use_atomic_density_energy_formula:
+        if self.parameters._configuration["atomic_density_formula"]:
             # Calculate the Gaussian descriptors for the calculation of the
             # structure factors.
             barrier()
@@ -1335,8 +1335,8 @@ 

Source code for mala.targets.density

         te.set_positions(
             np.transpose(positions_for_qe),
             number_of_atoms,
-            self._parameters_full.descriptors.use_atomic_density_energy_formula,
-            self._parameters_full.descriptors.use_atomic_density_energy_formula,
+            self.parameters._configuration["atomic_density_formula"],
+            self.parameters._configuration["atomic_density_formula"],
         )
         barrier()
         printout(
@@ -1347,7 +1347,7 @@ 

Source code for mala.targets.density

         )
         barrier()
 
-        if self._parameters_full.descriptors.use_atomic_density_energy_formula:
+        if self.parameters._configuration["atomic_density_formula"]:
             t0 = time.perf_counter()
             gaussian_descriptors = np.reshape(
                 gaussian_descriptors,
diff --git a/_sources/advanced_usage/predictions.rst.txt b/_sources/advanced_usage/predictions.rst.txt
index a16ece7bd..3246526c8 100644
--- a/_sources/advanced_usage/predictions.rst.txt
+++ b/_sources/advanced_usage/predictions.rst.txt
@@ -81,11 +81,13 @@ Gaussian representation of atomic positions. In this algorithm, most of the
 computational overhead of the total energy calculation is offloaded to the
 computation of this Gaussian representation. This calculation is realized via
 LAMMPS and can therefore be GPU accelerated (parallelized) in the same fashion
-as the bispectrum descriptor calculation. Simply activate this option via
+as the bispectrum descriptor calculation. If a GPU is activated (and LAMMPS
+is available), this option will be used by default. It can also manually be
+activated via
 
     .. code-block:: python
 
-        parameters.descriptors.use_atomic_density_energy_formula = True
+        parameters.use_atomic_density_formula = True
 
 The Gaussian representation algorithm is describe in
 the publication `Predicting electronic structures at any length scale with machine learning `_.
diff --git a/advanced_usage/predictions.html b/advanced_usage/predictions.html
index 7c5237880..fc7e411ce 100644
--- a/advanced_usage/predictions.html
+++ b/advanced_usage/predictions.html
@@ -168,9 +168,11 @@
 computational overhead of the total energy calculation is offloaded to the
 computation of this Gaussian representation. This calculation is realized via
 LAMMPS and can therefore be GPU accelerated (parallelized) in the same fashion
-as the bispectrum descriptor calculation. Simply activate this option via

+as the bispectrum descriptor calculation. If a GPU is activated (and LAMMPS +is available), this option will be used by default. It can also manually be +activated via

-
parameters.descriptors.use_atomic_density_energy_formula = True
+
parameters.use_atomic_density_formula = True
 
diff --git a/api/mala.common.html b/api/mala.common.html index 685c79be2..1ba1a8179 100644 --- a/api/mala.common.html +++ b/api/mala.common.html @@ -146,7 +146,6 @@

common<
  • Parameters.data
  • Parameters.running
  • Parameters.hyperparameters
  • -
  • Parameters.debug
  • Parameters.manual_seed
  • Parameters.load_from_file()
  • Parameters.load_from_json()
  • @@ -159,6 +158,7 @@

    common<
  • Parameters.device
  • Parameters.openpmd_configuration
  • Parameters.openpmd_granularity
  • +
  • Parameters.use_atomic_density_formula
  • Parameters.use_ddp
  • Parameters.use_gpu
  • Parameters.use_lammps
  • @@ -173,7 +173,6 @@

    common<
  • ParametersData
  • ParametersData