From 2a879b7ffabefb21f937366c0b944a6edee895ec Mon Sep 17 00:00:00 2001 From: alexgo Date: Tue, 24 Aug 2021 12:40:05 +0200 Subject: [PATCH 01/18] add cpp information to rascal model json * cpp representation and kernel information is now included in rascal's model json file. * weights are now always flattened to one dimension for consistency in the models format. --- bindings/rascal/models/kernels.py | 14 +++++++++++++- bindings/rascal/models/krr.py | 9 +++++++-- .../representations/spherical_covariants.py | 16 +++++++++++++++- .../representations/spherical_expansion.py | 16 +++++++++++++++- .../representations/spherical_invariants.py | 16 +++++++++++++++- 5 files changed, 65 insertions(+), 6 deletions(-) diff --git a/bindings/rascal/models/kernels.py b/bindings/rascal/models/kernels.py index 96801794d..b2140b4d0 100644 --- a/bindings/rascal/models/kernels.py +++ b/bindings/rascal/models/kernels.py @@ -107,9 +107,21 @@ def _get_init_params(self): def _set_data(self, data): super()._set_data(data) + # allows to load deprecated models + if "cpp_kernel" in data.keys(): + self._kernel = self._kernel.from_dict(data["cpp_kernel"]) + else: + print( + "WARNING: a deprecated model was loaded. Key 'cpp_kernel' " + "was not found in model. Please dump and reload the model " + "to update it. The model parameters will not change, only " + "the format." + ) def _get_data(self): - return super()._get_data() + data = super()._get_data() + data.update(cpp_kernel=self._kernel.to_dict()) + return data def __call__(self, X, Y=None, grad=(False, False), compute_neg_stress=False): """ diff --git a/bindings/rascal/models/krr.py b/bindings/rascal/models/krr.py index 6ec674554..12a9de84e 100644 --- a/bindings/rascal/models/krr.py +++ b/bindings/rascal/models/krr.py @@ -209,8 +209,13 @@ def predict_stress(self, managers, KNM=None): return -neg_stress - def get_weights(self): - return self.weights + @property + def weights(self): + return self._weights + + @weights.setter + def weights(self, weights): + self._weights = weights.reshape(-1) def _get_init_params(self): init_params = dict( diff --git a/bindings/rascal/representations/spherical_covariants.py b/bindings/rascal/representations/spherical_covariants.py index 57edbab04..9c67cf82a 100644 --- a/bindings/rascal/representations/spherical_covariants.py +++ b/bindings/rascal/representations/spherical_covariants.py @@ -377,6 +377,20 @@ def _get_init_params(self): def _set_data(self, data): super()._set_data(data) + # allows to load deprecated models + if "cpp_representation" in data.keys(): + self._representation = self._representation.from_dict( + data["cpp_representation"] + ) + else: + print( + "WARNING: a deprecated model was loaded. Key " + "'cpp_representation' was not found in model. Please dump and " + "reload the model to update it. The model parameters will not " + "change, only the format." + ) def _get_data(self): - return super()._get_data() + data = super()._get_data() + data.update(cpp_representation=self._representation.to_dict()) + return data diff --git a/bindings/rascal/representations/spherical_expansion.py b/bindings/rascal/representations/spherical_expansion.py index 305ad3165..0b8b32095 100644 --- a/bindings/rascal/representations/spherical_expansion.py +++ b/bindings/rascal/representations/spherical_expansion.py @@ -328,6 +328,20 @@ def _get_init_params(self): def _set_data(self, data): super()._set_data(data) + # allows to load deprecated models + if "cpp_representation" in data.keys(): + self._representation = self._representation.from_dict( + data["cpp_representation"] + ) + else: + print( + "WARNING: a deprecated model was loaded. Key " + "'cpp_representation' was not found in model. Please dump and " + "reload the model to update it. The model parameters will not " + "change, only the format." + ) def _get_data(self): - return super()._get_data() + data = super()._get_data() + data.update(cpp_representation=self._representation.to_dict()) + return data diff --git a/bindings/rascal/representations/spherical_invariants.py b/bindings/rascal/representations/spherical_invariants.py index b0e785e76..767004d9a 100644 --- a/bindings/rascal/representations/spherical_invariants.py +++ b/bindings/rascal/representations/spherical_invariants.py @@ -476,6 +476,20 @@ def _get_init_params(self): def _set_data(self, data): super()._set_data(data) + # allows to load deprecated models + if "cpp_representation" in data.keys(): + self._representation = self._representation.from_dict( + data["cpp_representation"] + ) + else: + print( + "WARNING: a deprecated model was loaded. Key " + "'cpp_representation' was not found in model. Please dump and " + "reload the model to update it. The model parameters will not " + "change, only the format." + ) def _get_data(self): - return super()._get_data() + data = super()._get_data() + data.update(cpp_representation=self._representation.to_dict()) + return data From 32a522f3d52b96e0475309a7deb4db75d3f7752f Mon Sep 17 00:00:00 2001 From: alexgo Date: Tue, 24 Aug 2021 12:47:58 +0200 Subject: [PATCH 02/18] update rascal models json in tests --- .../tests_only/simple_gap_model.json | 104 +++++++++++++++++- 1 file changed, 100 insertions(+), 4 deletions(-) diff --git a/reference_data/tests_only/simple_gap_model.json b/reference_data/tests_only/simple_gap_model.json index 2dcb57db9..527cb5ae8 100644 --- a/reference_data/tests_only/simple_gap_model.json +++ b/reference_data/tests_only/simple_gap_model.json @@ -5119,7 +5119,52 @@ "init_params": { "representation": { "class_name": "SphericalInvariants", - "data": {}, + "data": { + "cpp_representation": { + "compute_gradients": true, + "cutoff_function": { + "cutoff": { + "unit": "AA", + "value": 7.5 + }, + "exponent": { + "unit": "AA", + "value": 4 + }, + "rate": { + "unit": "AA", + "value": 1 + }, + "scale": { + "unit": "AA", + "value": 4.5 + }, + "smooth_width": { + "unit": "AA", + "value": 0.5 + }, + "type": "RadialScaling" + }, + "expansion_by_species_method": "environment wise", + "gaussian_density": { + "gaussian_sigma": { + "unit": "AA", + "value": 0.5 + }, + "type": "Constant" + }, + "global_species": [], + "inversion_symmetry": true, + "max_angular": 2, + "max_radial": 4, + "normalize": true, + "radial_contribution": { + "optimization": {}, + "type": "GTO" + }, + "soap_type": "PowerSpectrum" + } + }, "init_params": { "compute_gradients": true, "cutoff_function_parameters": { @@ -5152,13 +5197,64 @@ "description": "Simple fit of methane dimer energies, just for testing. Generated by fit_gap.py on 2021-03-25 at 13:17:33 CET", "kernel": { "class_name": "Kernel", - "data": {}, + "data": { + "cpp_kernel": { + "name": "GAP", + "target_type": "Structure", + "zeta": 2 + } + }, "init_params": { "kernel_type": "Sparse", "name": "GAP", "representation": { "class_name": "SphericalInvariants", - "data": {}, + "data": { + "cpp_representation": { + "compute_gradients": true, + "cutoff_function": { + "cutoff": { + "unit": "AA", + "value": 7.5 + }, + "exponent": { + "unit": "AA", + "value": 4 + }, + "rate": { + "unit": "AA", + "value": 1 + }, + "scale": { + "unit": "AA", + "value": 4.5 + }, + "smooth_width": { + "unit": "AA", + "value": 0.5 + }, + "type": "RadialScaling" + }, + "expansion_by_species_method": "environment wise", + "gaussian_density": { + "gaussian_sigma": { + "unit": "AA", + "value": 0.5 + }, + "type": "Constant" + }, + "global_species": [], + "inversion_symmetry": true, + "max_angular": 2, + "max_radial": 4, + "normalize": true, + "radial_contribution": { + "optimization": {}, + "type": "GTO" + }, + "soap_type": "PowerSpectrum" + } + }, "init_params": { "compute_gradients": true, "cutoff_function_parameters": { @@ -5236,4 +5332,4 @@ }, "module_name": "rascal.models.krr", "version": "0.1" -} +} \ No newline at end of file From ee6fc99fc221ff49cc2e274ccf03e5c8be850f6e Mon Sep 17 00:00:00 2001 From: alexgo Date: Tue, 30 Nov 2021 07:11:40 +0100 Subject: [PATCH 03/18] change warning to logger --- bindings/rascal/models/kernels.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bindings/rascal/models/kernels.py b/bindings/rascal/models/kernels.py index b2140b4d0..7d8877e39 100644 --- a/bindings/rascal/models/kernels.py +++ b/bindings/rascal/models/kernels.py @@ -9,9 +9,11 @@ from .sparse_points import SparsePoints import json +import logging import numpy as np +LOGGER = logging.getLogger(__name__) class Kernel(BaseIO): @@ -111,7 +113,7 @@ def _set_data(self, data): if "cpp_kernel" in data.keys(): self._kernel = self._kernel.from_dict(data["cpp_kernel"]) else: - print( + LOGGER.warn( "WARNING: a deprecated model was loaded. Key 'cpp_kernel' " "was not found in model. Please dump and reload the model " "to update it. The model parameters will not change, only " From 26456d71d25afb560f29b05a2c8bd93e4b0e396d Mon Sep 17 00:00:00 2001 From: alexgo Date: Tue, 30 Nov 2021 16:36:29 +0100 Subject: [PATCH 04/18] adapt cpp hypers to python hypers for invariants and expansion coeffs; make gaussian_sigma_type Constant default parameter --- CMakeLists.txt | 5 + .../representations/spherical_invariants.py | 2 +- .../calculator_spherical_expansion.hh | 343 +++++++++--------- .../calculator_spherical_invariants.hh | 95 +++-- .../representations/cutoff_functions.hh | 34 +- src/rascal/utils/json_io.cc | 1 + src/rascal/utils/json_io.hh | 65 ++++ 7 files changed, 339 insertions(+), 206 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d00bc3c33..b9a569d6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,11 @@ if(SKBUILD) message(STATUS "The project is built using scikit-build") endif() +# it determines the size of the PATH up to librascal and +# is used to output relative path information in the code using __FILE__ +string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE) +add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}") + add_subdirectory(src) enable_testing() diff --git a/bindings/rascal/representations/spherical_invariants.py b/bindings/rascal/representations/spherical_invariants.py index 767004d9a..e5ecc3e65 100644 --- a/bindings/rascal/representations/spherical_invariants.py +++ b/bindings/rascal/representations/spherical_invariants.py @@ -211,7 +211,7 @@ def __init__( cutoff_smooth_width, max_radial, max_angular, - gaussian_sigma_type, + gaussian_sigma_type="Constant", gaussian_sigma_constant=0.3, cutoff_function_type="ShiftedCosine", soap_type="PowerSpectrum", diff --git a/src/rascal/representations/calculator_spherical_expansion.hh b/src/rascal/representations/calculator_spherical_expansion.hh index e7bbb5b90..65fba36aa 100644 --- a/src/rascal/representations/calculator_spherical_expansion.hh +++ b/src/rascal/representations/calculator_spherical_expansion.hh @@ -31,6 +31,9 @@ #ifndef SRC_RASCAL_REPRESENTATIONS_CALCULATOR_SPHERICAL_EXPANSION_HH_ #define SRC_RASCAL_REPRESENTATIONS_CALCULATOR_SPHERICAL_EXPANSION_HH_ +// relative path of file with respect to librascal directory +#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE) + #include "rascal/math/bessel.hh" #include "rascal/math/gauss_legendre.hh" #include "rascal/math/hyp1f1.hh" @@ -131,8 +134,8 @@ namespace rascal { : AtomicSmearingSpecificationBase { using Hypers_t = typename AtomicSmearingSpecificationBase::Hypers_t; explicit AtomicSmearingSpecification(const Hypers_t & hypers) { - this->constant_gaussian_sigma = - hypers.at("gaussian_sigma").at("value").get(); + this->constant_gaussian_sigma = json_io::read_hyperparameter( + __FILENAME__, __LINE__, hypers, "gaussian_sigma_constant", 0.3); if (this->constant_gaussian_sigma < 1e-2) { std::stringstream err_str{}; err_str << "Constant gaussian sigma is too small: " @@ -354,33 +357,32 @@ namespace rascal { this->max_radial = hypers.at("max_radial"); this->max_angular = hypers.at("max_angular"); - if (hypers.count("compute_gradients")) { - this->compute_gradients = hypers.at("compute_gradients").get(); - } else { // Default false (don't compute gradients) - this->compute_gradients = false; - } - - this->init_matrices(); + this->compute_gradients = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "compute_gradients", false); // find the cutoff radius of the representation - auto fc_hypers = hypers.at("cutoff_function").get(); this->interaction_cutoff = - fc_hypers.at("cutoff").at("value").get(); + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "interaction_cutoff"); // define the type of smearing to use - auto smearing_hypers = hypers.at("gaussian_density").get(); - auto smearing_type = smearing_hypers.at("type").get(); + std::string smearing_type{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "gaussian_sigma_type", + "Constant")}; if (smearing_type == "Constant") { this->atomic_smearing_type = AtomicSmearingType::Constant; this->atomic_smearing = - make_atomic_smearing( - smearing_hypers); + make_atomic_smearing(hypers); } else { throw std::logic_error( - "Requested Gaussian sigma type \'" + smearing_type + - "\' has not been implemented. Must be one of" + - ": \'Constant\'."); + "Requested Gaussian sigma type '" + smearing_type + + "' has not been implemented. Must be one of : 'Constant' at " + "file " + + std::string(__FILENAME__) + ":" + std::to_string(__LINE__)); } + + this->init_matrices(); } // initialize Eigen matrices/vectors, contains both @@ -767,40 +769,51 @@ namespace rascal { void set_hyperparameters(const Hypers_t & hypers) override { this->hypers = hypers; - this->max_radial = hypers.at("max_radial"); - this->max_angular = hypers.at("max_angular"); + this->compute_gradients = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "compute_gradients", false); - if (hypers.count("compute_gradients")) { - this->compute_gradients = hypers.at("compute_gradients").get(); - } else { // Default false (don't compute gradients) - this->compute_gradients = false; + int max_radial_int{json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "max_radial")}; + if (max_radial_int <= 0) { + std::stringstream error{}; + error << "Parameter 'max_radial' has to be > 0" + << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; + throw std::runtime_error(error.str()); } + this->max_radial = static_cast(max_radial_int); + + int max_angular_int{json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "max_angular")}; + if (max_angular_int < 0) { + std::stringstream error{}; + error << "Parameter 'max_angular' has to be >= 0" + << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; + throw std::runtime_error(error.str()); + } + this->max_angular = static_cast(max_angular_int); - this->init_matrices(); - - // find the cutoff radius of the representation - auto fc_hypers = hypers.at("cutoff_function").get(); this->interaction_cutoff = - fc_hypers.at("cutoff").at("value").get(); - this->smooth_width = - fc_hypers.at("smooth_width").at("value").get(); - + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "interaction_cutoff"); + + std::string smearing_type{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "gaussian_sigma_type", + "Constant")}; + this->smooth_width = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "gaussian_sigma_constant"); // define the type of smearing to use - auto smearing_hypers = hypers.at("gaussian_density").get(); - auto smearing_type = smearing_hypers.at("type").get(); if (smearing_type == "Constant") { this->atomic_smearing_type = AtomicSmearingType::Constant; this->atomic_smearing = - make_atomic_smearing( - smearing_hypers); - this->smearing = - smearing_hypers.at("gaussian_sigma").at("value").get(); + make_atomic_smearing(hypers); } else { throw std::logic_error( - "Requested Gaussian sigma type \'" + smearing_type + - "\' has not been implemented. Must be one of" + - ": \'Constant\'."); + "Requested Gaussian sigma type '" + smearing_type + + "' has not been implemented. Must be one of" + ": 'Constant'."); } + + this->init_matrices(); } // initialize Eigen matrices/vectors, contains both @@ -1105,10 +1118,9 @@ namespace rascal { } void init_interpolator(const Hypers_t & hypers) { - auto radial_contribution_hypers = - hypers.at("radial_contribution").template get(); - auto optimization_hypers = - radial_contribution_hypers.at("optimization").template get(); + json optimization_hypers{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "optimization")}; double accuracy{this->get_interpolator_accuracy(optimization_hypers)}; // minimal distance such that it is still stable with the interpolated @@ -1135,20 +1147,16 @@ namespace rascal { } double get_interpolator_accuracy(const Hypers_t & optimization_hypers) { - auto spline_hypers = - optimization_hypers.at("Spline").template get(); - if (spline_hypers.count("accuracy")) { - return spline_hypers.at("accuracy").template get(); - } else { - std::stringstream err_str{}; - err_str << "No Spline accuracy was given."; - throw std::logic_error(err_str.str()); - } + json spline_hypers{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, optimization_hypers, "Spline")}; + return json_io::template read_hyperparameter( + __FILENAME__, __LINE__, spline_hypers, "accuracy"); } double get_cutoff(const Hypers_t & hypers) { - auto fc_hypers = hypers.at("cutoff_function").template get(); - return fc_hypers.at("cutoff").at("value").template get(); + return json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "interaction_cutoff"); } double fac_a{}; @@ -1186,30 +1194,21 @@ namespace rascal { } void set_hyperparameters(const Hypers_t & hypers) override { - auto radial_contribution_hypers = - hypers.at("radial_contribution").template get(); - auto optimization_hypers = - radial_contribution_hypers.at("optimization").template get(); - auto radial_dim_reduction_hypers = - optimization_hypers.at("RadialDimReduction").template get(); + json optimization_hypers{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "optimization")}; + json radial_dim_reduction_hypers{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "RadialDimReduction")}; if (radial_dim_reduction_hypers.count("projection_matrices")) { std::map>>> json_projection_matrices{}; - try { // hyper keys are converted to string so we also use here strings // for species - json_projection_matrices = - radial_dim_reduction_hypers.at("projection_matrices") - .template get>>>>(); - } catch (const std::exception & e) { - std::stringstream err_str{}; - err_str << "Projection matrices should be of type " - "std::map>>>."; - throw std::logic_error(err_str.str()); - } + + json_projection_matrices = + json_io::template read_hyperparameter>>>>( + __FILENAME__, __LINE__, radial_dim_reduction_hypers, "projection_matrices"); this->n_species = json_projection_matrices.size(); this->n_components = this->max_radial; @@ -1451,10 +1450,9 @@ namespace rascal { } void init_interpolator(const Hypers_t & hypers) { - auto radial_contribution_hypers = - hypers.at("radial_contribution").template get(); - auto optimization_hypers = - radial_contribution_hypers.at("optimization").template get(); + json optimization_hypers{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "optimization")}; double accuracy{this->get_interpolator_accuracy(optimization_hypers)}; // minimal distance such that it is still stable with the interpolated @@ -1486,20 +1484,16 @@ namespace rascal { } double get_interpolator_accuracy(const Hypers_t & optimization_hypers) { - auto spline_hypers = - optimization_hypers.at("Spline").template get(); - if (spline_hypers.count("accuracy")) { - return spline_hypers.at("accuracy").template get(); - } else { - std::stringstream err_str{}; - err_str << "No Spline accuracy was given."; - throw std::logic_error(err_str.str()); - } + json spline_hypers{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, optimization_hypers, "Spline")}; + return json_io::template read_hyperparameter( + __FILENAME__, __LINE__, spline_hypers, "accuracy"); } double get_cutoff(const Hypers_t & hypers) { - auto fc_hypers = hypers.at("cutoff_function").template get(); - return fc_hypers.at("cutoff").at("value").template get(); + return json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "interaction_cutoff"); } Matrix_t reduced_radial_integral_neighbour{}; @@ -1600,38 +1594,37 @@ namespace rascal { using internal::RadialBasisType; this->hypers = hypers; - this->max_radial = hypers.at("max_radial").get(); - this->max_angular = hypers.at("max_angular").get(); - if (hypers.count("compute_gradients")) { - this->compute_gradients = hypers.at("compute_gradients").get(); - } else { // Default false (don't compute gradients) - this->compute_gradients = false; - } - - if (hypers.count("expansion_by_species_method")) { - std::set possible_expansion_by_species{ - {"environment wise", "user defined", "structure wise"}}; - auto expansion_by_species_tmp = - hypers.at("expansion_by_species_method").get(); - if (possible_expansion_by_species.count(expansion_by_species_tmp)) { - this->expansion_by_species = expansion_by_species_tmp; - } else { - std::stringstream err_str{}; - err_str << "expansion_by_species_method provided:'" - << expansion_by_species_tmp - << "' is not part of the implemented methods: '"; - for (const auto & val : possible_expansion_by_species) { - err_str << val << "', "; - } - throw std::logic_error(err_str.str()); - } - } else { - // default value for backward compatibility - this->expansion_by_species = "environment wise"; + int max_radial_int{json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "max_radial")}; + if (max_radial_int <= 0) { + std::stringstream error{}; + error << "Parameter 'max_radial' has to be > 0" + << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; + throw std::runtime_error(error.str()); + } + this->max_radial = static_cast(max_radial_int); + + int max_angular_int{json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "max_angular")}; + if (max_angular_int < 0) { + std::stringstream error{}; + error << "Parameter 'max_angular' has to be >= 0" + << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; + throw std::runtime_error(error.str()); } + this->max_angular = static_cast(max_angular_int); + + this->compute_gradients = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "compute_gradients", false); + + std::string expansion_by_species_method{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "expansion_by_species_method", "environment wise")}; if (hypers.count("global_species")) { - auto species = hypers.at("global_species").get(); + Key_t species{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "global_species")}; for (const auto & sp : species) { this->global_species.insert({sp}); } @@ -1639,7 +1632,9 @@ namespace rascal { if (this->expansion_by_species == "user defined") { std::stringstream err_str{}; err_str << "expansion_by_species_method is 'user defined'" - << " but global_species is not defined."; + << " but global_species is not defined" + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; throw std::logic_error(err_str.str()); } this->global_species.clear(); @@ -1651,29 +1646,36 @@ namespace rascal { // create the class that will compute the radial terms of the // expansion. the atomic smearing is an integral part of the // radial contribution - auto smearing_hypers = hypers.at("gaussian_density").get(); - auto smearing_type = smearing_hypers.at("type").get(); + std::string smearing_type{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "gaussian_sigma_type", + "Constant")}; if (smearing_type == "Constant") { this->atomic_smearing_type = AtomicSmearingType::Constant; } else if (smearing_type == "PerSpecies") { - throw std::logic_error("Requested Smearing type \'PerSpecies\'" - "\' has not been implemented. Must be one of" - ": \'Constant\'."); + throw std::logic_error("Requested Smearing type 'PerSpecies'" + " has not been implemented. Must be one of" + ": 'Constant' at file " + + std::string(__FILENAME__) + ":" + + std::to_string(__LINE__)); } else if (smearing_type == "Radial") { - throw std::logic_error("Requested Smearing type \'Radial\'" - "\' has not been implemented. Must be one of" - ": \'Constant\'."); + throw std::logic_error("Requested Smearing type 'Radial'" + "' has not been implemented. Must be one of" + ": 'Constant' at file " + + std::string(__FILENAME__) + ":" + + std::to_string(__LINE__)); } else { - throw std::logic_error("Requested Smearing type \'" + smearing_type + - "\' is unknown. Must be one of" + - ": \'Constant\'."); + throw std::logic_error( + "Requested Smearing type '" + smearing_type + + "' is unknown. Must be one of" + ": 'Constant' at file " + + std::string(__FILENAME__) + ":" + std::to_string(__LINE__)); } - auto radial_contribution_hypers = - hypers.at("radial_contribution").get(); - auto radial_contribution_type = - radial_contribution_hypers.at("type").get(); + std::string radial_contribution_type{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "radial_basis", + "GTO")}; // create the class that will compute the radial terms of the // expansion. the atomic smearing is an integral part of the @@ -1692,25 +1694,32 @@ namespace rascal { this->radial_integral = rc_shared; this->radial_integral_type = RadialBasisType::DVR; } else { - throw std::logic_error("Requested Radial contribution type \'" + + throw std::logic_error("Requested Radial contribution type '" + radial_contribution_type + - "\' has not been implemented. Must be one of" + - ": \'GTO\' or \'DVR\'. "); - } - - if (radial_contribution_hypers.count("optimization")) { - auto optimization_hypers = - radial_contribution_hypers.at("optimization").get(); - // Checks for all optimization args used for the computation of the - // spherical expansion - if (optimization_hypers.count("Spline") && - optimization_hypers.count("RadialDimReduction")) { - this->optimization_type = OptimizationType::RadialDimReductionSpline; - } else if (optimization_hypers.count("Spline")) { - this->optimization_type = OptimizationType::Spline; - } else if (optimization_hypers.count("RadialDimReduction")) { - throw std::logic_error("RadialDimReduction requires\'" - "\' Spline to be set."); + "' has not been implemented. Must be one of" + + ": 'GTO' or 'DVR' at file " + + std::string(__FILENAME__) + ":" + + std::to_string(__LINE__)); + } + + if (hypers.count("optimization")) { + json optimization_hypers{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "optimization")}; + if (optimization_hypers.size() != 0) { + // Checks for all optimization args used for the computation of the + // spherical expansion + if (optimization_hypers.count("Spline") && + optimization_hypers.count("RadialDimReduction")) { + this->optimization_type = OptimizationType::RadialDimReductionSpline; + } else if (optimization_hypers.count("Spline")) { + this->optimization_type = OptimizationType::Spline; + } else if (optimization_hypers.count("RadialDimReduction")) { + throw std::logic_error("RadialDimReduction requires '" + "' Spline to be set at file " + + std::string(__FILENAME__) + ":" + + std::to_string(__LINE__)); + } } else { this->optimization_type = OptimizationType::None; } @@ -1720,22 +1729,28 @@ namespace rascal { this->set_radial_integral(hypers); - auto fc_hypers = hypers.at("cutoff_function").get(); - auto fc_type = fc_hypers.at("type").get(); - this->interaction_cutoff = fc_hypers.at("cutoff").at("value"); - this->cutoff_smooth_width = fc_hypers.at("smooth_width").at("value"); - if (fc_type == "ShiftedCosine") { + this->interaction_cutoff = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "interaction_cutoff"); + this->cutoff_smooth_width = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "cutoff_smooth_width"); + + std::string cutoff_function_type_description{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "cutoff_function_type", + "ShiftedCosine")}; + if (cutoff_function_type_description == "ShiftedCosine") { this->cutoff_function_type = CutoffFunctionType::ShiftedCosine; this->cutoff_function = - make_cutoff_function(fc_hypers); - } else if (fc_type == "RadialScaling") { + make_cutoff_function(hypers); + } else if (cutoff_function_type_description == "RadialScaling") { this->cutoff_function_type = CutoffFunctionType::RadialScaling; this->cutoff_function = - make_cutoff_function(fc_hypers); + make_cutoff_function(hypers); } else { - throw std::logic_error("Requested cutoff function type \'" + fc_type + - "\' has not been implemented. Must be one of" + - ": \'ShiftedCosine\' or 'RadialScaling'."); + throw std::logic_error("Requested cutoff function type '" + + cutoff_function_type_description + + "' has not been implemented. Must be one of" + + ": 'ShiftedCosine' or 'RadialScaling'."); } this->set_name(hypers); diff --git a/src/rascal/representations/calculator_spherical_invariants.hh b/src/rascal/representations/calculator_spherical_invariants.hh index ad543d970..3d24dc3fa 100644 --- a/src/rascal/representations/calculator_spherical_invariants.hh +++ b/src/rascal/representations/calculator_spherical_invariants.hh @@ -31,6 +31,9 @@ #ifndef SRC_RASCAL_REPRESENTATIONS_CALCULATOR_SPHERICAL_INVARIANTS_HH_ #define SRC_RASCAL_REPRESENTATIONS_CALCULATOR_SPHERICAL_INVARIANTS_HH_ +// relative path of file with respect to librascal directory +#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE) + #include "rascal/math/utils.hh" #include "rascal/representations/calculator_base.hh" #include "rascal/representations/calculator_spherical_expansion.hh" @@ -257,20 +260,39 @@ namespace rascal { void set_hyperparameters(const Hypers_t & hypers) override { using internal::SphericalInvariantsType; - this->normalize = hypers.at("normalize").get(); - auto soap_type = hypers.at("soap_type").get(); - - if (hypers.find("compute_gradients") != hypers.end()) { - this->compute_gradients = hypers.at("compute_gradients").get(); - } else { // Default false (don't compute gradients) - this->compute_gradients = false; + this->normalize = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "normalize", true); + std::string soap_type{json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "soap_type", "PowerSpectrum")}; + this->compute_gradients = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "compute_gradients", false); + + int max_radial_int{json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "max_radial")}; + if (max_radial_int <= 0) { + std::stringstream error{}; + error << "CalculatorSphericalInvariants.set_hyperparameters: " + "'max_radial' has to be > 0" + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; + throw std::runtime_error(error.str()); } - - this->max_radial = hypers.at("max_radial").get(); - this->max_angular = hypers.at("max_angular").get(); + this->max_radial = static_cast(max_radial_int); + + int max_angular_int{json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "max_angular")}; + if (max_angular_int < 0) { + std::stringstream error{}; + error << "CalculatorSphericalInvariants.set_hyperparameters: " + "'max_angular' has to be >= 0" + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; + throw std::runtime_error(error.str()); + } + this->max_angular = static_cast(max_angular_int); if (soap_type == "PowerSpectrum") { - this->set_hyperparameters_powerspectrum(hypers); + this->set_coefficient_subselection(hypers); } else if (soap_type == "RadialSpectrum") { this->type = SphericalInvariantsType::RadialSpectrum; if (this->max_angular > 0) { @@ -278,13 +300,14 @@ namespace rascal { } } else if (soap_type == "BiSpectrum") { this->type = internal::SphericalInvariantsType::BiSpectrum; - this->inversion_symmetry = hypers.at("inversion_symmetry").get(); + this->inversion_symmetry = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "inversion_symmetry", true); this->wigner_w3js = internal::precompute_wigner_w3js( this->max_angular, this->inversion_symmetry); } else { throw std::logic_error( - "Requested SphericalInvariants type \'" + soap_type + - "\' has not been implemented. Must be one of" + + "Requested SphericalInvariants type '" + soap_type + + "' has not been implemented. Must be one of" + ": 'PowerSpectrum', 'RadialSpectrum', or 'BiSpectrum'."); } @@ -308,29 +331,39 @@ namespace rascal { * Note that values in 'n1', 'n2', 'l' should not exceed max_radial-1 * and max_angular. */ - void set_hyperparameters_powerspectrum(const Hypers_t & hypers) { + void set_coefficient_subselection(const Hypers_t & hypers) { using internal::SphericalInvariantsType; this->type = SphericalInvariantsType::PowerSpectrum; - if (hypers.find("coefficient_subselection") != hypers.end()) { + if (hypers.count("coefficient_subselection")) { this->is_sparsified = true; - auto coefficient_subselection = - hypers.at("coefficient_subselection").get(); + + json coefficient_subselection{ + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "coefficient_subselection")}; // get the indices of the subselected PowerSpectrum coefficients: // p_{abn_1n_2l} where a and b refer to atomic species and should be // lexicographically sorted so that a <= b, n_1 and n_2 refer to // radial basis index and l refer to the angular index of the // spherical harmonic - auto sp_a = coefficient_subselection.at("a") - .get>(); - auto sp_b = coefficient_subselection.at("b") - .get>(); - auto radial_n1 = - coefficient_subselection.at("n1").get>(); - auto radial_n2 = - coefficient_subselection.at("n2").get>(); - auto angular_l = - coefficient_subselection.at("l").get>(); + std::vector sp_a, sp_b; + std::vector radial_n1, radial_n2, angular_l; + + sp_a = json_io::template read_hyperparameter< + std::vector>(__FILENAME__, __LINE__, + hypers, "a"); + sp_b = json_io::template read_hyperparameter< + std::vector>(__FILENAME__, __LINE__, + hypers, "b"); + radial_n1 = + json_io::template read_hyperparameter>( + __FILENAME__, __LINE__, hypers, "n1"); + radial_n2 = + json_io::template read_hyperparameter>( + __FILENAME__, __LINE__, hypers, "n2"); + angular_l = + json_io::template read_hyperparameter>( + __FILENAME__, __LINE__, hypers, "l"); std::uint32_t angular_max{ *std::max_element(angular_l.begin(), angular_l.end())}; @@ -656,9 +689,9 @@ namespace rascal { size_t max_angular{}; // shape of the inner dense section of the computed invariant coefficients std::array inner_invariants_shape{{0, 0}}; - bool normalize{}; - bool compute_gradients{}; - bool inversion_symmetry{false}; + bool normalize{true}; + bool compute_gradients{false}; + bool inversion_symmetry{true}; CalculatorSphericalExpansion rep_expansion; diff --git a/src/rascal/representations/cutoff_functions.hh b/src/rascal/representations/cutoff_functions.hh index 32eff4062..66d4b9194 100644 --- a/src/rascal/representations/cutoff_functions.hh +++ b/src/rascal/representations/cutoff_functions.hh @@ -29,6 +29,9 @@ #ifndef SRC_RASCAL_REPRESENTATIONS_CUTOFF_FUNCTIONS_HH_ #define SRC_RASCAL_REPRESENTATIONS_CUTOFF_FUNCTIONS_HH_ +// relative path of file with respect to librascal directory +#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE) + #include "rascal/math/utils.hh" #include "rascal/representations/calculator_base.hh" #include "rascal/utils/utils.hh" @@ -152,9 +155,10 @@ namespace rascal { } void set_hyperparameters(const Hypers_t & hypers) override { - this->cutoff = hypers.at("cutoff").at("value").get(); - this->smooth_width = - hypers.at("smooth_width").at("value").get(); + this->cutoff = json_io::read_hyperparameter( + __FILENAME__, __LINE__, hypers, "cutoff"); + this->smooth_width = json_io::read_hyperparameter( + __FILENAME__, __LINE__, hypers, "cutoff_smooth_width"); } double f_c(double distance) { @@ -217,15 +221,25 @@ namespace rascal { } void set_hyperparameters(const Hypers_t & hypers) override { - this->cutoff = hypers.at("cutoff").at("value").get(); - this->smooth_width = - hypers.at("smooth_width").at("value").get(); - this->rate = hypers.at("rate").at("value").get(); + this->cutoff = json_io::read_hyperparameter( + __FILENAME__, __LINE__, hypers, "interaction_cutoff"); + this->smooth_width = json_io::read_hyperparameter( + __FILENAME__, __LINE__, hypers, "cutoff_smooth_width"); + json cutoff_function_parameters = json_io::read_hyperparameter( + __FILENAME__, __LINE__, hypers, "cutoff_function_parameters"); + + this->rate = json_io::read_hyperparameter( + __FILENAME__, __LINE__, cutoff_function_parameters, "rate"); if (this->rate < 0) { - throw std::runtime_error("RadialScaling's rate should be positive"); + std::stringstream error{}; + error << "RadialScaling's 'rate' should be positive " + << "at file " << __FILENAME__ << ":" << __LINE__ << std::endl; + throw std::runtime_error(error.str()); } - this->exponent = hypers.at("exponent").at("value").get(); - this->scale = hypers.at("scale").at("value").get(); + this->exponent = json_io::read_hyperparameter( + __FILENAME__, __LINE__, cutoff_function_parameters, "exponent"); + this->scale = json_io::read_hyperparameter( + __FILENAME__, __LINE__, cutoff_function_parameters, "scale"); } double value(double distance) { diff --git a/src/rascal/utils/json_io.cc b/src/rascal/utils/json_io.cc index 32c4a7391..1aa4da0b7 100644 --- a/src/rascal/utils/json_io.cc +++ b/src/rascal/utils/json_io.cc @@ -28,6 +28,7 @@ #include "rascal/utils/json_io.hh" namespace rascal { + namespace json_io { json load(const std::string & filename) { diff --git a/src/rascal/utils/json_io.hh b/src/rascal/utils/json_io.hh index 7f8786048..6cf56e235 100644 --- a/src/rascal/utils/json_io.hh +++ b/src/rascal/utils/json_io.hh @@ -48,6 +48,7 @@ #include #include +#include // For convenience using json = nlohmann::json; @@ -301,6 +302,14 @@ namespace Eigen { namespace rascal { namespace json_io { + //! find if element appears in vector. + template + bool is_element_in(const T & element, const Vec & vector) { + Vec s_element{{element}}; + return not(std::search(vector.begin(), vector.end(), s_element.begin(), + s_element.end()) == vector.end()); + } + //! load a json file json load(const std::string & filename); @@ -356,6 +365,62 @@ namespace rascal { */ double check_units(const std::string & expected_unit, const json & parameter); + + /** + * Returns a typed property of the given name. + * + * @tparam T return type. Return type must support << operator. + * + * @param hypers + * @param key + * @param default_value is a unique_ptr to allow hyperparamaters with no default value in which case it is null ptr. Starting with C++17 one could solve this more transparent with std::optional. + * + * @throw runtime_error when value cannot be read from hypers + * @throw runtime_error when key is not present in hypers and no default_value is null ptr + */ + template + T read_hyperparameter(const char * file, int line, const json & hypers, + std::string key) { + if (hypers.count(key)) { + try { + return hypers.at(key).get(); + } catch (const std::exception & e) { + std::stringstream error{}; + error << "Reading '" << key << "' from json hypers failed " + << "at file " << file << ":" << line << "\n" + << " what(): " << e.what() << std::endl; + throw std::runtime_error(error.str()); + } + } else { + std::stringstream error{}; + error << "Reading '" << key << "' from json hypers failed. No '" << key + << "' was found in json hypers " + << "at file " << file << ":" << line << std::endl; + throw std::runtime_error(error.str()); + } + } + + template + T read_hyperparameter(const char * file, int line, const json & hypers, + std::string key, T default_value) { + if (hypers.count(key)) { + try { + return hypers.at(key).get(); + } catch (const std::exception & e) { + std::stringstream error{}; + error << "Reading '" << key << "' from json hypers failed " + << "at file " << file << ":" << line << "\n" + << " what(): " << e.what() << std::endl; + throw std::runtime_error(error.str()); + } + } else { + std::cout << "WARNING: Reading '" << key + << "' from json hypers failed. Setting " << key << " to '" + << default_value << "' " + << "at file " << file << ":" << line << std::endl; + return default_value; + } + } } // namespace json_io } // namespace rascal From fa53a04cddc4a822c8f2157f02c89c4b1ef47887 Mon Sep 17 00:00:00 2001 From: alexgo Date: Tue, 30 Nov 2021 22:12:18 +0100 Subject: [PATCH 05/18] debug tests --- .../calculator_spherical_expansion.hh | 273 +++++++++--------- .../calculator_spherical_invariants.hh | 14 +- .../representations/cutoff_functions.hh | 2 +- 3 files changed, 150 insertions(+), 139 deletions(-) diff --git a/src/rascal/representations/calculator_spherical_expansion.hh b/src/rascal/representations/calculator_spherical_expansion.hh index 65fba36aa..0340c45cc 100644 --- a/src/rascal/representations/calculator_spherical_expansion.hh +++ b/src/rascal/representations/calculator_spherical_expansion.hh @@ -368,8 +368,8 @@ namespace rascal { // define the type of smearing to use std::string smearing_type{ json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "gaussian_sigma_type", - "Constant")}; + __FILENAME__, __LINE__, hypers, "gaussian_sigma_type")}; + //,"Constant")}; // TODO(alex) SET BACK TO "Constant" if (smearing_type == "Constant") { this->atomic_smearing_type = AtomicSmearingType::Constant; this->atomic_smearing = @@ -777,7 +777,8 @@ namespace rascal { if (max_radial_int <= 0) { std::stringstream error{}; error << "Parameter 'max_radial' has to be > 0" - << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; throw std::runtime_error(error.str()); } this->max_radial = static_cast(max_radial_int); @@ -787,7 +788,8 @@ namespace rascal { if (max_angular_int < 0) { std::stringstream error{}; error << "Parameter 'max_angular' has to be >= 0" - << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; throw std::runtime_error(error.str()); } this->max_angular = static_cast(max_angular_int); @@ -1118,9 +1120,9 @@ namespace rascal { } void init_interpolator(const Hypers_t & hypers) { - json optimization_hypers{ + json optimization_hypers = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "optimization")}; + __FILENAME__, __LINE__, hypers, "optimization"); double accuracy{this->get_interpolator_accuracy(optimization_hypers)}; // minimal distance such that it is still stable with the interpolated @@ -1147,9 +1149,9 @@ namespace rascal { } double get_interpolator_accuracy(const Hypers_t & optimization_hypers) { - json spline_hypers{ + json spline_hypers = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, optimization_hypers, "Spline")}; + __FILENAME__, __LINE__, optimization_hypers, "Spline"); return json_io::template read_hyperparameter( __FILENAME__, __LINE__, spline_hypers, "accuracy"); } @@ -1194,140 +1196,144 @@ namespace rascal { } void set_hyperparameters(const Hypers_t & hypers) override { - json optimization_hypers{ + json optimization_hypers = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "optimization")}; - json radial_dim_reduction_hypers{ + __FILENAME__, __LINE__, hypers, "optimization"); + json radial_dim_reduction_hypers = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "RadialDimReduction")}; - if (radial_dim_reduction_hypers.count("projection_matrices")) { - std::map>>> - json_projection_matrices{}; - // hyper keys are converted to string so we also use here strings - // for species + __FILENAME__, __LINE__, optimization_hypers, "RadialDimReduction"); + std::map>>> + json_projection_matrices{}; + // hyper keys are converted to string so we also use here strings + // for species - json_projection_matrices = - json_io::template read_hyperparameter>>>>( - __FILENAME__, __LINE__, radial_dim_reduction_hypers, "projection_matrices"); + json_projection_matrices = + json_io::template read_hyperparameter>>>>( + __FILENAME__, __LINE__, radial_dim_reduction_hypers, "projection_matrices"); - this->n_species = json_projection_matrices.size(); - this->n_components = this->max_radial; + this->n_species = json_projection_matrices.size(); + this->n_components = this->max_radial; - if (json_projection_matrices.begin()->second.size() == 0) { - std::stringstream err_str{}; - err_str << "projection_matrices should have the shape " - "(max_angular+1, max_radial, expanded_max_radial)"; - throw std::logic_error(err_str.str()); - } - if (json_projection_matrices.begin()->second.at(0).size() == 0) { - std::stringstream err_str{}; - err_str << "projection_matrices should have the shape " - "(max_angular+1, max_radial, expanded_max_radial)"; - throw std::logic_error(err_str.str()); - } - if (json_projection_matrices.begin()->second.at(0).at(0).size() == - 0) { + if (json_projection_matrices.begin()->second.size() == 0) { + std::stringstream err_str{}; + err_str << "projection_matrices should have the shape " + << "(max_angular+1, max_radial, expanded_max_radial)" + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; + throw std::logic_error(err_str.str()); + } + if (json_projection_matrices.begin()->second.at(0).size() == 0) { + std::stringstream err_str{}; + err_str << "projection_matrices should have the shape " + << "(max_angular+1, max_radial, expanded_max_radial)" + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; + throw std::logic_error(err_str.str()); + } + if (json_projection_matrices.begin()->second.at(0).at(0).size() == + 0) { + std::stringstream err_str{}; + err_str << "projection_matrices should have the shape " + << "(max_angular+1, max_radial, expanded_max_radial)" + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; + throw std::logic_error(err_str.str()); + } + // overwrite max_radial to expanded max_radial + this->max_radial = + json_projection_matrices.begin()->second.at(0).at(0).size(); + + // check projection matrices sizes + std::string species; + for (auto it = json_projection_matrices.begin(); + it != json_projection_matrices.end(); ++it) { + species = it->first; + if (json_projection_matrices.at(species).size() != + this->max_angular + 1) { std::stringstream err_str{}; - err_str << "projection_matrices should have the shape " - "(max_angular+1, max_radial, expanded_max_radial)"; + err_str << "Projection matrices at species=" << species + << " does not match the size max_angular=" + << this->max_angular << " but is " + << json_projection_matrices.at(species).size() + << ", should be max_angular+1" + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; throw std::logic_error(err_str.str()); } - // overwrite max_radial to expanded max_radial - this->max_radial = - json_projection_matrices.begin()->second.at(0).at(0).size(); - - // check projection matrices sizes - std::string species; - for (auto it = json_projection_matrices.begin(); - it != json_projection_matrices.end(); ++it) { - species = it->first; - if (json_projection_matrices.at(species).size() != - this->max_angular + 1) { + for (size_t angular_l = 0; angular_l < this->max_angular + 1; + angular_l++) { + if (json_projection_matrices.at(species).at(angular_l).size() != + this->n_components) { std::stringstream err_str{}; - err_str << "Projection matrices at species=" << species - << " does not match the size max_angular=" - << this->max_angular << " but is " - << json_projection_matrices.at(species).size() - << ", should be max_angular+1"; + // be aware that `max_radial` in hyperparameters is + // this->n_components within in this class + err_str + << "Projection matrices at species=" << species + << " and angular_l=" << angular_l + << " does not match the max_radial=" << this->n_components + << " in hyperparameters but is " + << json_projection_matrices.at(species).at(angular_l).size() + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; throw std::logic_error(err_str.str()); } - for (size_t angular_l = 0; angular_l < this->max_angular + 1; - angular_l++) { - if (json_projection_matrices.at(species).at(angular_l).size() != - this->n_components) { + for (size_t radial_c = 0; radial_c < this->n_components; + radial_c++) { + if (json_projection_matrices.at(species) + .at(angular_l) + .at(radial_c) + .size() != this->max_radial) { std::stringstream err_str{}; // be aware that `max_radial` in hyperparameters is // this->n_components within in this class - err_str - << "Projection matrices at species=" << species - << " and angular_l=" << angular_l - << " does not match the max_radial=" << this->n_components - << " in hyperparameters but is " - << json_projection_matrices.at(species).at(angular_l).size() - << "."; + err_str << "Projection matrices at species=" << species + << ", angular_l=" << angular_l + << " and max_radial=" << this->n_components + << " is not consistent in expanded_max_radial=" + << this->max_radial + << " with species=0, angular_l=0 and max_radial=0" + << json_projection_matrices.at(species) + .at(angular_l) + .at(radial_c) + .size() + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; throw std::logic_error(err_str.str()); } - for (size_t radial_c = 0; radial_c < this->n_components; - radial_c++) { - if (json_projection_matrices.at(species) - .at(angular_l) - .at(radial_c) - .size() != this->max_radial) { - std::stringstream err_str{}; - // be aware that `max_radial` in hyperparameters is - // this->n_components within in this class - err_str << "Projection matrices at species=" << species - << ", angular_l=" << angular_l - << " and max_radial=" << this->n_components - << " is not consistent in expanded_max_radial=" - << this->max_radial - << " with species=0, angular_l=0 and max_radial=0" - << json_projection_matrices.at(species) - .at(angular_l) - .at(radial_c) - .size() - << "."; - throw std::logic_error(err_str.str()); - } - } } } + } - // init projection matrices - Matrix_t projection_matrix{}; - std::vector angular_projection_matrices(this->max_angular + - 1); - for (auto it = json_projection_matrices.begin(); - it != json_projection_matrices.end(); ++it) { - species = it->first; - for (size_t angular_l = 0; angular_l < this->max_angular + 1; - angular_l++) { - projection_matrix.resize(this->n_components, this->max_radial); - projection_matrix.setZero(); - for (size_t radial_c = 0; radial_c < this->n_components; - radial_c++) { - for (size_t radial_n = 0; radial_n < this->max_radial; - radial_n++) { - projection_matrix(radial_c, radial_n) = - json_projection_matrices.at(species) - .at(angular_l) - .at(radial_c) - .at(radial_n); - } + // init projection matrices + Matrix_t projection_matrix{}; + std::vector angular_projection_matrices(this->max_angular + + 1); + for (auto it = json_projection_matrices.begin(); + it != json_projection_matrices.end(); ++it) { + species = it->first; + for (size_t angular_l = 0; angular_l < this->max_angular + 1; + angular_l++) { + projection_matrix.resize(this->n_components, this->max_radial); + projection_matrix.setZero(); + for (size_t radial_c = 0; radial_c < this->n_components; + radial_c++) { + for (size_t radial_n = 0; radial_n < this->max_radial; + radial_n++) { + projection_matrix(radial_c, radial_n) = + json_projection_matrices.at(species) + .at(angular_l) + .at(radial_c) + .at(radial_n); } - angular_projection_matrices.at(angular_l) = projection_matrix; } - this->projection_matrices.insert( - std::pair>( - std::stoi(species), angular_projection_matrices)); + angular_projection_matrices.at(angular_l) = projection_matrix; } - - this->init_matrices(); - } else { - std::stringstream err_str{}; - err_str << "No projection matrices were given."; - throw std::logic_error(err_str.str()); + this->projection_matrices.insert( + std::pair>( + std::stoi(species), angular_projection_matrices)); } + + this->init_matrices(); Parent::init_matrices(); } @@ -1450,9 +1456,9 @@ namespace rascal { } void init_interpolator(const Hypers_t & hypers) { - json optimization_hypers{ + json optimization_hypers = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "optimization")}; + __FILENAME__, __LINE__, hypers, "optimization"); double accuracy{this->get_interpolator_accuracy(optimization_hypers)}; // minimal distance such that it is still stable with the interpolated @@ -1484,9 +1490,9 @@ namespace rascal { } double get_interpolator_accuracy(const Hypers_t & optimization_hypers) { - json spline_hypers{ + json spline_hypers = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, optimization_hypers, "Spline")}; + __FILENAME__, __LINE__, optimization_hypers, "Spline"); return json_io::template read_hyperparameter( __FILENAME__, __LINE__, spline_hypers, "accuracy"); } @@ -1617,9 +1623,9 @@ namespace rascal { this->compute_gradients = json_io::template read_hyperparameter( __FILENAME__, __LINE__, hypers, "compute_gradients", false); - std::string expansion_by_species_method{ + this->expansion_by_species = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "expansion_by_species_method", "environment wise")}; + __FILENAME__, __LINE__, hypers, "expansion_by_species_method", "environment wise"); if (hypers.count("global_species")) { Key_t species{ @@ -1631,7 +1637,7 @@ namespace rascal { } else { if (this->expansion_by_species == "user defined") { std::stringstream err_str{}; - err_str << "expansion_by_species_method is 'user defined'" + err_str << "expansion_by_species is 'user defined'" << " but global_species is not defined" << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; @@ -1674,8 +1680,8 @@ namespace rascal { std::string radial_contribution_type{ json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "radial_basis", - "GTO")}; + __FILENAME__, __LINE__, hypers, "radial_basis")}; + //,"GTO")}; // TODO(alex) SET BACK TO "GTO" // create the class that will compute the radial terms of the // expansion. the atomic smearing is an integral part of the @@ -1703,9 +1709,9 @@ namespace rascal { } if (hypers.count("optimization")) { - json optimization_hypers{ + json optimization_hypers = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "optimization")}; + __FILENAME__, __LINE__, hypers, "optimization"); if (optimization_hypers.size() != 0) { // Checks for all optimization args used for the computation of the // spherical expansion @@ -2240,7 +2246,12 @@ namespace rascal { this->initialize_expansion_structure_wise( manager, expansions_coefficients, expansions_coefficients_gradient); } else { - throw std::runtime_error("should not arrive here"); + std::stringstream error{}; + error << "Requested expansion by species method '" << this->expansion_by_species + << "' is unknown. Must be one of : 'environment wise', 'user defined' or 'structure wise' file " << __FILENAME__ << ":" << __LINE__ + << std::endl; + + throw std::runtime_error(error.str()); } // coeff C^{ij}_{nlm} diff --git a/src/rascal/representations/calculator_spherical_invariants.hh b/src/rascal/representations/calculator_spherical_invariants.hh index 3d24dc3fa..a5a675271 100644 --- a/src/rascal/representations/calculator_spherical_invariants.hh +++ b/src/rascal/representations/calculator_spherical_invariants.hh @@ -338,9 +338,9 @@ namespace rascal { if (hypers.count("coefficient_subselection")) { this->is_sparsified = true; - json coefficient_subselection{ + json coefficient_subselection = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "coefficient_subselection")}; + __FILENAME__, __LINE__, hypers, "coefficient_subselection"); // get the indices of the subselected PowerSpectrum coefficients: // p_{abn_1n_2l} where a and b refer to atomic species and should be // lexicographically sorted so that a <= b, n_1 and n_2 refer to @@ -351,19 +351,19 @@ namespace rascal { sp_a = json_io::template read_hyperparameter< std::vector>(__FILENAME__, __LINE__, - hypers, "a"); + coefficient_subselection, "a"); sp_b = json_io::template read_hyperparameter< std::vector>(__FILENAME__, __LINE__, - hypers, "b"); + coefficient_subselection, "b"); radial_n1 = json_io::template read_hyperparameter>( - __FILENAME__, __LINE__, hypers, "n1"); + __FILENAME__, __LINE__, coefficient_subselection, "n1"); radial_n2 = json_io::template read_hyperparameter>( - __FILENAME__, __LINE__, hypers, "n2"); + __FILENAME__, __LINE__, coefficient_subselection, "n2"); angular_l = json_io::template read_hyperparameter>( - __FILENAME__, __LINE__, hypers, "l"); + __FILENAME__, __LINE__, coefficient_subselection, "l"); std::uint32_t angular_max{ *std::max_element(angular_l.begin(), angular_l.end())}; diff --git a/src/rascal/representations/cutoff_functions.hh b/src/rascal/representations/cutoff_functions.hh index 66d4b9194..e313eb904 100644 --- a/src/rascal/representations/cutoff_functions.hh +++ b/src/rascal/representations/cutoff_functions.hh @@ -156,7 +156,7 @@ namespace rascal { void set_hyperparameters(const Hypers_t & hypers) override { this->cutoff = json_io::read_hyperparameter( - __FILENAME__, __LINE__, hypers, "cutoff"); + __FILENAME__, __LINE__, hypers, "interaction_cutoff"); this->smooth_width = json_io::read_hyperparameter( __FILENAME__, __LINE__, hypers, "cutoff_smooth_width"); } From fb387c27faab3b83afc68b355a12a96b80e361d5 Mon Sep 17 00:00:00 2001 From: alexgo Date: Tue, 30 Nov 2021 23:16:38 +0100 Subject: [PATCH 06/18] finished debugging --- .../calculator_spherical_expansion.hh | 129 +++++++++--------- .../calculator_spherical_invariants.hh | 14 +- src/rascal/utils/json_io.hh | 13 +- 3 files changed, 79 insertions(+), 77 deletions(-) diff --git a/src/rascal/representations/calculator_spherical_expansion.hh b/src/rascal/representations/calculator_spherical_expansion.hh index 0340c45cc..e654e450d 100644 --- a/src/rascal/representations/calculator_spherical_expansion.hh +++ b/src/rascal/representations/calculator_spherical_expansion.hh @@ -368,8 +368,8 @@ namespace rascal { // define the type of smearing to use std::string smearing_type{ json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "gaussian_sigma_type")}; - //,"Constant")}; // TODO(alex) SET BACK TO "Constant" + __FILENAME__, __LINE__, hypers, "gaussian_sigma_type", + "Constant")}; if (smearing_type == "Constant") { this->atomic_smearing_type = AtomicSmearingType::Constant; this->atomic_smearing = @@ -777,8 +777,7 @@ namespace rascal { if (max_radial_int <= 0) { std::stringstream error{}; error << "Parameter 'max_radial' has to be > 0" - << " at file " << __FILENAME__ << ":" << __LINE__ - << std::endl; + << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; throw std::runtime_error(error.str()); } this->max_radial = static_cast(max_radial_int); @@ -788,8 +787,7 @@ namespace rascal { if (max_angular_int < 0) { std::stringstream error{}; error << "Parameter 'max_angular' has to be >= 0" - << " at file " << __FILENAME__ << ":" << __LINE__ - << std::endl; + << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; throw std::runtime_error(error.str()); } this->max_angular = static_cast(max_angular_int); @@ -797,18 +795,24 @@ namespace rascal { this->interaction_cutoff = json_io::template read_hyperparameter( __FILENAME__, __LINE__, hypers, "interaction_cutoff"); + this->cutoff_smooth_width = + json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "cutoff_smooth_width"); std::string smearing_type{ json_io::template read_hyperparameter( __FILENAME__, __LINE__, hypers, "gaussian_sigma_type", "Constant")}; - this->smooth_width = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "gaussian_sigma_constant"); // define the type of smearing to use if (smearing_type == "Constant") { this->atomic_smearing_type = AtomicSmearingType::Constant; + auto atomic_smearing_constant{std::make_shared< + AtomicSmearingSpecification>( + hypers)}; + this->smearing = atomic_smearing_constant->get_gaussian_sigma(); this->atomic_smearing = - make_atomic_smearing(hypers); + std::static_pointer_cast( + atomic_smearing_constant); } else { throw std::logic_error( "Requested Gaussian sigma type '" + smearing_type + @@ -941,7 +945,7 @@ namespace rascal { Hypers_t hypers{}; // some useful parameters double interaction_cutoff{}; - double smooth_width{}; + double cutoff_smooth_width{}; double smearing{}; size_t max_radial{}; size_t max_angular{}; @@ -1120,9 +1124,8 @@ namespace rascal { } void init_interpolator(const Hypers_t & hypers) { - json optimization_hypers = - json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "optimization"); + json optimization_hypers = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "optimization"); double accuracy{this->get_interpolator_accuracy(optimization_hypers)}; // minimal distance such that it is still stable with the interpolated @@ -1149,11 +1152,10 @@ namespace rascal { } double get_interpolator_accuracy(const Hypers_t & optimization_hypers) { - json spline_hypers = - json_io::template read_hyperparameter( - __FILENAME__, __LINE__, optimization_hypers, "Spline"); + json spline_hypers = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, optimization_hypers, "Spline"); return json_io::template read_hyperparameter( - __FILENAME__, __LINE__, spline_hypers, "accuracy"); + __FILENAME__, __LINE__, spline_hypers, "accuracy"); } double get_cutoff(const Hypers_t & hypers) { @@ -1196,20 +1198,22 @@ namespace rascal { } void set_hyperparameters(const Hypers_t & hypers) override { - json optimization_hypers = - json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "optimization"); - json radial_dim_reduction_hypers = - json_io::template read_hyperparameter( - __FILENAME__, __LINE__, optimization_hypers, "RadialDimReduction"); + json optimization_hypers = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "optimization"); + json radial_dim_reduction_hypers = + json_io::template read_hyperparameter(__FILENAME__, __LINE__, + optimization_hypers, + "RadialDimReduction"); std::map>>> json_projection_matrices{}; - // hyper keys are converted to string so we also use here strings - // for species + // hyper keys are converted to string so we also use here strings + // for species - json_projection_matrices = - json_io::template read_hyperparameter>>>>( - __FILENAME__, __LINE__, radial_dim_reduction_hypers, "projection_matrices"); + json_projection_matrices = + json_io::template read_hyperparameter>>>>( + __FILENAME__, __LINE__, radial_dim_reduction_hypers, + "projection_matrices"); this->n_species = json_projection_matrices.size(); this->n_components = this->max_radial; @@ -1218,25 +1222,24 @@ namespace rascal { std::stringstream err_str{}; err_str << "projection_matrices should have the shape " << "(max_angular+1, max_radial, expanded_max_radial)" - << " at file " << __FILENAME__ << ":" << __LINE__ - << std::endl; + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; throw std::logic_error(err_str.str()); } if (json_projection_matrices.begin()->second.at(0).size() == 0) { std::stringstream err_str{}; err_str << "projection_matrices should have the shape " << "(max_angular+1, max_radial, expanded_max_radial)" - << " at file " << __FILENAME__ << ":" << __LINE__ - << std::endl; + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; throw std::logic_error(err_str.str()); } - if (json_projection_matrices.begin()->second.at(0).at(0).size() == - 0) { + if (json_projection_matrices.begin()->second.at(0).at(0).size() == 0) { std::stringstream err_str{}; err_str << "projection_matrices should have the shape " << "(max_angular+1, max_radial, expanded_max_radial)" - << " at file " << __FILENAME__ << ":" << __LINE__ - << std::endl; + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; throw std::logic_error(err_str.str()); } // overwrite max_radial to expanded max_radial @@ -1456,9 +1459,8 @@ namespace rascal { } void init_interpolator(const Hypers_t & hypers) { - json optimization_hypers = - json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "optimization"); + json optimization_hypers = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "optimization"); double accuracy{this->get_interpolator_accuracy(optimization_hypers)}; // minimal distance such that it is still stable with the interpolated @@ -1490,11 +1492,10 @@ namespace rascal { } double get_interpolator_accuracy(const Hypers_t & optimization_hypers) { - json spline_hypers = - json_io::template read_hyperparameter( - __FILENAME__, __LINE__, optimization_hypers, "Spline"); + json spline_hypers = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, optimization_hypers, "Spline"); return json_io::template read_hyperparameter( - __FILENAME__, __LINE__, spline_hypers, "accuracy"); + __FILENAME__, __LINE__, spline_hypers, "accuracy"); } double get_cutoff(const Hypers_t & hypers) { @@ -1625,12 +1626,12 @@ namespace rascal { this->expansion_by_species = json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "expansion_by_species_method", "environment wise"); + __FILENAME__, __LINE__, hypers, "expansion_by_species_method", + "environment wise"); if (hypers.count("global_species")) { - Key_t species{ - json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "global_species")}; + Key_t species{json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "global_species")}; for (const auto & sp : species) { this->global_species.insert({sp}); } @@ -1680,8 +1681,7 @@ namespace rascal { std::string radial_contribution_type{ json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "radial_basis")}; - //,"GTO")}; // TODO(alex) SET BACK TO "GTO" + __FILENAME__, __LINE__, hypers, "radial_basis", "GTO")}; // create the class that will compute the radial terms of the // expansion. the atomic smearing is an integral part of the @@ -1700,31 +1700,30 @@ namespace rascal { this->radial_integral = rc_shared; this->radial_integral_type = RadialBasisType::DVR; } else { - throw std::logic_error("Requested Radial contribution type '" + - radial_contribution_type + - "' has not been implemented. Must be one of" + - ": 'GTO' or 'DVR' at file " + - std::string(__FILENAME__) + ":" + - std::to_string(__LINE__)); + throw std::logic_error( + "Requested Radial contribution type '" + radial_contribution_type + + "' has not been implemented. Must be one of" + + ": 'GTO' or 'DVR' at file " + std::string(__FILENAME__) + ":" + + std::to_string(__LINE__)); } if (hypers.count("optimization")) { - json optimization_hypers = - json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "optimization"); + json optimization_hypers = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "optimization"); if (optimization_hypers.size() != 0) { // Checks for all optimization args used for the computation of the // spherical expansion if (optimization_hypers.count("Spline") && optimization_hypers.count("RadialDimReduction")) { - this->optimization_type = OptimizationType::RadialDimReductionSpline; + this->optimization_type = + OptimizationType::RadialDimReductionSpline; } else if (optimization_hypers.count("Spline")) { this->optimization_type = OptimizationType::Spline; } else if (optimization_hypers.count("RadialDimReduction")) { throw std::logic_error("RadialDimReduction requires '" "' Spline to be set at file " + - std::string(__FILENAME__) + ":" + - std::to_string(__LINE__)); + std::string(__FILENAME__) + ":" + + std::to_string(__LINE__)); } } else { this->optimization_type = OptimizationType::None; @@ -2247,9 +2246,11 @@ namespace rascal { manager, expansions_coefficients, expansions_coefficients_gradient); } else { std::stringstream error{}; - error << "Requested expansion by species method '" << this->expansion_by_species - << "' is unknown. Must be one of : 'environment wise', 'user defined' or 'structure wise' file " << __FILENAME__ << ":" << __LINE__ - << std::endl; + error << "Requested expansion by species method '" + << this->expansion_by_species + << "' is unknown. Must be one of : 'environment wise', 'user " + "defined' or 'structure wise' file " + << __FILENAME__ << ":" << __LINE__ << std::endl; throw std::runtime_error(error.str()); } diff --git a/src/rascal/representations/calculator_spherical_invariants.hh b/src/rascal/representations/calculator_spherical_invariants.hh index a5a675271..894b88be8 100644 --- a/src/rascal/representations/calculator_spherical_invariants.hh +++ b/src/rascal/representations/calculator_spherical_invariants.hh @@ -273,8 +273,7 @@ namespace rascal { std::stringstream error{}; error << "CalculatorSphericalInvariants.set_hyperparameters: " "'max_radial' has to be > 0" - << " at file " << __FILENAME__ << ":" << __LINE__ - << std::endl; + << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; throw std::runtime_error(error.str()); } this->max_radial = static_cast(max_radial_int); @@ -285,8 +284,7 @@ namespace rascal { std::stringstream error{}; error << "CalculatorSphericalInvariants.set_hyperparameters: " "'max_angular' has to be >= 0" - << " at file " << __FILENAME__ << ":" << __LINE__ - << std::endl; + << " at file " << __FILENAME__ << ":" << __LINE__ << std::endl; throw std::runtime_error(error.str()); } this->max_angular = static_cast(max_angular_int); @@ -350,11 +348,11 @@ namespace rascal { std::vector radial_n1, radial_n2, angular_l; sp_a = json_io::template read_hyperparameter< - std::vector>(__FILENAME__, __LINE__, - coefficient_subselection, "a"); + std::vector>( + __FILENAME__, __LINE__, coefficient_subselection, "a"); sp_b = json_io::template read_hyperparameter< - std::vector>(__FILENAME__, __LINE__, - coefficient_subselection, "b"); + std::vector>( + __FILENAME__, __LINE__, coefficient_subselection, "b"); radial_n1 = json_io::template read_hyperparameter>( __FILENAME__, __LINE__, coefficient_subselection, "n1"); diff --git a/src/rascal/utils/json_io.hh b/src/rascal/utils/json_io.hh index 6cf56e235..66080f421 100644 --- a/src/rascal/utils/json_io.hh +++ b/src/rascal/utils/json_io.hh @@ -366,17 +366,20 @@ namespace rascal { double check_units(const std::string & expected_unit, const json & parameter); - /** + /** * Returns a typed property of the given name. * * @tparam T return type. Return type must support << operator. * - * @param hypers + * @param hypers * @param key - * @param default_value is a unique_ptr to allow hyperparamaters with no default value in which case it is null ptr. Starting with C++17 one could solve this more transparent with std::optional. + * @param default_value is a unique_ptr to allow hyperparamaters with no + * default value in which case it is null ptr. Starting with C++17 one could + * solve this more transparent with std::optional. * - * @throw runtime_error when value cannot be read from hypers - * @throw runtime_error when key is not present in hypers and no default_value is null ptr + * @throw runtime_error when value cannot be read from hypers + * @throw runtime_error when key is not present in hypers and no + * default_value is null ptr */ template T read_hyperparameter(const char * file, int line, const json & hypers, From ecb70b88db99e73342ed494c79d7a1e0e68f34d4 Mon Sep 17 00:00:00 2001 From: alexgo Date: Tue, 30 Nov 2021 23:19:18 +0100 Subject: [PATCH 07/18] adapt tests and inputs --- .../tests_only/kernel_reference.ubjson | Bin 384155 -> 384311 bytes .../tests_only/simple_gap_model.json | 96 +--- .../tests_only/sparse_kernel_inputs.json | 78 +-- .../tests_only/sparsification_inputs.json | 324 +++++-------- .../spherical_covariants_reference.ubjson | Bin 3611328 -> 3611796 bytes .../spherical_expansion_reference.ubjson | Bin 3023280 -> 3016848 bytes .../spherical_invariants_reference.ubjson | Bin 11374614 -> 11375862 bytes tests/test_calculator.cc | 50 +- tests/test_calculator.hh | 452 +++++++++++------- tests/test_cutoff_functions.cc | 134 +++--- tests/test_kernels.hh | 56 ++- tests/test_math_interpolator.hh | 13 +- tests/test_pseudo_points.cc | 26 +- tests/test_sparse_kernels.hh | 53 +- 14 files changed, 638 insertions(+), 644 deletions(-) diff --git a/reference_data/tests_only/kernel_reference.ubjson b/reference_data/tests_only/kernel_reference.ubjson index d15163c7b9f3858400b1ce52e6e4fba1fb3c6b88..1caf4145059bfeb9a53e70cf37f44c019bdadbce 100644 GIT binary patch delta 4941 zcmeI0zi-n(6vuOpW71O6run5bfDl2<3@{K;6$ErbLRGkh*0Qe7B{>nFBj1I#L>~AH zkh#GFQ~m=4Lj)27Ol+t_#fpT4%2suQGI04>6%mQa8L%h&?w#(v_todUJHL37>%PsU z+whdx;&!#l*6-Y$i}WAw$Fdi_zBFG$Eyf6<1|u~KNrROyLxXpPC9Q#Jjn`oep0?1o z;h+jZ4Ym$7U0em1g_2(eK)lao{8v%s;v!TjvT#{$hAGDmbK8C=0aitFA*;A;;l(fc zYY9-0@BQ)fBYTZ;hnU>e;cR`UDHj?JZni}yo4wZG7SUR(fgBitv&UXQ4bDiXo7g0n zK_EYD$3hMA1V8W(zN+W$Es~xS$mGPP#vuH0@GvzPFqmcAyl!lf3a^hNhw0&LwM7TZ z#cm>VKX)=!hG|pA5#`70Qh!)*8BH0+Zx0RO+#rF*CSrt%PO5kpCQaLFwm3Fwy*ZgT zwh9Y)yNM|4`MtR_3em7IuiKR}T)^}(acpWy;|p7aVOOlpq{JieT_*N{V)?rV(fsR;{HMcds1kxQ5tMFe9_)=oxe@k~X&ljA6vylIY?3BQLqeKH4O5HQ3KK;FDMUqGK?=uGMb_b5k`wkh^__v%IF-bhOMT=sMi4c-m@>k*qm_8{A8nXjcWFe5a#%cx zX)@Ax&_7aErU*^TrQ9Qr{Nw${S>@~5WlhMfdbJqiY{Lr{raXcs?`ta=5rl{H+Jbzk zZ^Z8hdtgaw#g&U9+S4@LU{OYkPa`_AlxqS_h(MOJ-%roq_>=!(v7z|?C;vtv0e@Bh z>D7NLGK#!XNJaEU!Tm zBAJ68MAVIY)t)rQ#*nAl#Ar-ov+2Q$ZQ7uvArN|K55$e3hqlkk?ys4d!awjllYEn% z%(I!vC!hU3*>B-$B@Y0AKW+Kuczv$m1hOa8*Vs1V^qc|hszjz3$< zb$C zW3TQg6J?8N<3Ha@9|=@$TA__cgdoa0nOTU6HXf7f<5f`&BKzsi zbEq_=NRgN(aN+btLDtldQI#+j;bk@b#C_wO8WBRGpjL8{pbaYhK~y5hBVtsMC9-<| zsHh5Y|6+5+!({z>06;k#7^eTnJD1Ta~A%3(fbe46w11|F8(tCs+l$ti{^`_sd> zD{ZMc;AD|%JCiCS70!8JtNR5=nT%qbz^K{FInEov$zqgo+smPN+ruTb_T>d2WipC! z${IDpZJ+0M#2SE<#VKQ-)9jSq*0=+=HRk%h0a_-n7^|#T`m3c}lAZX~QeNvh;AOGP z*zHu?rM2YiT1x>*A=X-omSv!3vWzhU%bwpU!q4yQ@@-+5vFq&=?}>U>Y8UQG75mpV zGmEhTvr?-c=&98boLVjYE&;qO{bg)?s_pX3l#6#h#lpokxj5D@B)y5?gReCb9m!z7chGZYfev%JyGEp0Q0u)UK(!;Q3 z^YP%+RL}cSssrEca{uH2Ru3vyR)7z$AOf|D8>nl`r&)e-&+`E zY;%ey6E56ZUH4{UGou(MFzUjsy3f7>PL_@`wmH>C9c@3*lmb$wj$)j$M(HmD_4s9= z;m66}%@TB+P z7fzsMvWl_FTBV<8KZsAX`;scKvY2ITcZ$v0t&h$7NSg52e6#T1zh#qMj2E#>C$F-R z9K!xZ|CyD|! z!e&YOT9E8TBJx;72qL&%M^IQeoWfp&5bTA$h#p-2J;+s$mWTe!YnOELRj(_jN*D2j1e?+|vz^>a;Y^X9RG&HWO$sm2Pi{1A~S#qjR#QIXSBrVuNTqagzo)m^36Cm&L(BLmaLt zk_?jqnj)zU9YTZ2p9Yf-lK~?2ncJi|NQh|EGMfonX0wcZg`|nvg0;m(Vp$*( zQ`CInsdFeCMAQjHv$;St2Lz(W*QSLCp;}<;qbIoa(Oj53us*8%xG4@2A{wb(`JCFN zf+>JG2~!BvuA*3t5G_PQjGGoCaevrR-~Q(2l%f;Fd+Zo5zEa z7#6}|p$e?s)&?}c3a1^&j7a^ZUEH{NDkD$$b(4 diff --git a/reference_data/tests_only/spherical_expansion_reference.ubjson b/reference_data/tests_only/spherical_expansion_reference.ubjson index 07d034c2da8d35201fd58059f5fb7ccc49d2a7ad..b06efbfe3d94d6f5e2ebc31c3c7b6df1123cebd1 100644 GIT binary patch delta 24754 zcmeHPZEO=|9OwGZHfrha*v4RQ-55g|E(^q0W?(Y6F~PwlnlZau*NrA?JK8I3&IQ>R z8Zc1|ctJzZ55B|+Y)tkvlKF;-5#k3k!9+~dNc`YS-~$?sVtlUcdN*kA>Mi%=^5pty zTf1hz-~E2S|I0n=`1vUD;^8Ra7^JP92pjC~4!6+;+Sq=W*gbLJ=Y3pfm7U}^yi>fP zGuzMfyO}^wq?ZZNMmmfCHpF!Km|ogMJADDx8)7`HFBovg-w3`Ky6X#K51LFo+Z_qSe~;U>zk=G5*TY1@VILE4hkZSM#_b6P!YmVD>+3#0#y?)6 zb8mSCJJ9FdM%y+fUP$M}|15VW6ZVC<(&0tFX`rR;}V2eo(Ut>W)vLX6)F zO%xuaZQlOAV89z-q0h`=57X-vTw@9`td}N+=z00X$vaBID2*hy{$7I>)YckwdXhPk z-geO(aBj-5Sy$3*~i;TFe>437(oDgzPSCik25CRkj7Q-dwL^Yh2%0Tm#Anv|N%E84JFrw_|7O-p zg+P^@2@hSjz+TT$Xq(gPfsR2-ie|6x8A~f{_MWzMgwVEiGIizq#MGm3cma?Ejnx&! zh;H*n%b*q3mF7XK#_Ec4gz89|G;@J6n+0?(vtbvt8E`E*wD1OjrRcjiAU`uFbbf^G zM|!)#Qq<;Jh+QdCE+yH1@XCs;782w|7dC2ZYRLd{iiuz7;~*|9s!OV=<@iJvtS+xk zWMNTVGMQT7)r3*_!Q=%Tu`0Xc z@#lirgI52J2L;}G{tnav&@d@tYtU;QIy3Rqhj)@CQlGyYOM=zc9A|Ne{Mpff1W$5{ zaX}>3^~pLXYF*202$dagke>%gQ1O=&^(EA5x(T|TdOcSsMQCS}CrT*bZ6Z-yL&I{B ziF^vIH&LkRl1UO}+o0KlQWOZjiwz=ibkjq_ROYwSNFC~#;18$@Dh z&wPpxtn|9%7mgIzR9b{ul*$5b_TPR`tnqO7r%pcbW8BVW+<^tKYzy4El$;%>-$LT5&F#7Wv+ z6u9Rf|A?F}RkAVG2*FRefJZc|U8n`179z2(xdD7&r57cD zI~_gPl3Ur>d3_2TEiFeaX{}}&^tsp-5BhaxGV1MkK%O#XCb1ulrh z(jFbf2UhyPk1z52Zy?92EZ|U{$scK5fm+uZCPi$Gv2mT5|FOisSzNgWhsfu9d;m}D zY{UeNSkk+$RH8P!%+#X%wuE%rlfcuo615(+8f?P;KKS-Z)B?~jDPn7ImMWc@gZs~#3~-LQQ%YF%rX6tOjeXLM#VTH+hq+lT%GJ|8)A delta 30943 zcmeI4ZEO>D9LKr#`mhbU2fB^1(QOPBQHYXEj6`r58!#WTIL{aA)|^`zjav)r6~R%L zkxAkU17zYkAENNW=p0Nk^gm;G3PvP8p#)!Om`@}N5y;*t8WXQ~Yp;X*Uwi#g(&PW{ zyFOjFPk-Ov_xEtu-FwEFk4}y=Oz)n8Epr_0VIjC-L+EMF!dVXuTLT3iPyl zkPBluYW}5Y$b$CXo7d<-7o6oy4of7W#LC!l*JI3B74r~-s#fIY; z#pe4hEUFo0)^|ftGUseJPGKC|!wbHc2stKEeVi@S&UeM1OjKx}s%EEe>!x797ZBnH zu_hiQO$jGaa0%a)nuJdjMyWec!*WX_rJgKtrb+#}baC>13oKpG81L}oVqBt)&qoJH zHSg-9tZd%xZgk>nYZFN8Caz(sR}{sZ+gi^`&dt=bFe#cF23{$=Tb#Pc+R=qSSn3Q( zOX@V8A*M$jZeZe&kOg9F| zGg;j%cMdZi7_2I0(Yr6&AGvjW?AOHh-as!dN+9j1@?ZP9#4bzg(P@IBgwz>*!*B@F zW@VM{8H1NlkB{~^+_%mY!!U--DpWk^aoW-Tc~0tSDSH~`E5tQB>P${c@dFmEN3YET zZFcn8n@(6NCCUj6en&IY&6kDfFHa7oohe1=w*OMyanDZ+6Y7o!^2JS`=GalkSPm>n znb;0vO^5~@wDP`OSg4wri`p;rjpRzRg2+fNtY0uU4BcX3rmS{uhm@AoOmy0+={eqY zVtp_lZ9kJoS0|bBm4wNmk`4ZAoDItcG|Y9v95+1>E778I^yAsthu?#w7|l#PV=-LnO%QY^NDQLU05+KXZ1JP)vsB~pwXqW!?Ecqs_%CmWw zu3+B$Qa&sKDQ3JAs6zi{X#vHYa(RO}w+lB&!nV!P5TA!yCJR0$)o`Qzu|lDFS0T9+ zq;6O-+~-yl!E|Wi;tRXgQUYXjst6V!)CurTpz83->vJjQOgTZc(N%>0aGe__bQ;Y% z(TweI<=*axe}L?>D#>CtCOT)SDwXwj`-@=_XkrR#;d`;Egk%bO9qux=6o!VV6oru? zt|y2tmlYj$k5J6Xud9ij1ZWVmD)iG&%%jnqa$RE_GbWQ1Ix5Rhv#Sio-o#cTSJpCx zM?WE$LcH+pY@1JREMV(WIY35A%VB7!;p+4R(Mgkx`Ojk%bH)r;?Qqv_tf0}HDZ|Cj z%H$pHnd$`x*Wd6Ru6Zt{Rx0aLUF1?w3*Vm+(G;}nQX~z6PJtAn>9y%9#L)Uy{jq{< zU*A@sC%v8zDdr4b`>afpKN$AF@;!}aeC3E;-y*4;ge4KpzBb(?lIG7Hr1^^_vA(t( z)jVD~0@ApdDa8BQ+P5oV5;QjjZJSjZF5xN=4b4vY>=e^s89K103KoGBvkvCC(5<^E z=G4ar22Yj3_qFoocHk0_eO4t|%#c0l=C*f5HB9Ixrl9tIyck$;yG}H<3PN3?L&tC-7A;qkNIWBbc6vdn|!^L*ENZQ=4f98fSZPUG? z@a9gF)zcvlxo=xWDh0LXZRjDIf}Yp1zX8!`nn1cTF|@fg(}lN3R^1NMA;paMT2<(S zZ&A#td#%A~GQPQ$PXv55?+#dqYqoXiW|Et0xa!&{&rdLgc+LCH7erIQ7_Kanw%Wxo znNTOdJAtah(m{$jV@{x+mV9}NV$LLHOeT@{Qdhip!ZJx#87^kho^*ZdJ3=l6weY<< ze+jX%fUiqsnT)>-L_?I}Vq})V`&d~0ou{15fBH%I^g diff --git a/reference_data/tests_only/spherical_invariants_reference.ubjson b/reference_data/tests_only/spherical_invariants_reference.ubjson index eb6b2c67c18f7b0725f8984506ea50c68c8af66c..88eed4f616f407e40b344deaf442613d9722fd9a 100644 GIT binary patch delta 30394 zcmeI5eNYr-9LK#EK;G^^;OArg^oW7N#ja$5u zh&1V)I=z{6l+e>pYZccH15%I%oOB`nRzoWZ#NeR2u zq~2k(8TGI~BWcp>iY#WEU2nGMWSl?3d^HhqW8Pt}vKn%Usmq7oNJP1RXHOiP$2G$?C8hbR@IVV7A*<64MP%tKMv5e&xcdkx%!K&SbEcT8eXt7=yXOSZ*)F;}{*CsSg^it$ja>Oj8cm!5ph29*y!i@-i}`wXi#p`-IaQ(j?DQ(lx{ zj?j@X3}~id)g~|!z!6#ixmF;YTnh%TVb%EN8iK0hij3|}muToan~#@;aH`JsD^`8juap|aIF5S1=KUI$`vy3c5y))vS z3Xc50M_U>lCnmJLY6WXN;k^wCJ{^z%r~oyfflr*6DVT957~FMGif-ObJX6RVkqL`f zv$qmfl`8c-t2SFzkT`j&d#o6r`EF)}#)@IZp!ss&dMd*nyYStNTQUUSFXsy*&4MKV zv2HwPZn57c*89Y|dC_gA=bmv*&9<#{?2lvu+Obp{AITAJ{x{lXqHDBgsSDItFdkPX zfM6>0MWNO(eO!lmIXU-uDTgQ>h6Uqu?ThP>{BxgRGAz&q8jS_xd3BXbu(Z?KVu55> za5xML=KJ+~jKe7TB`uO)nz_)`79TTh#-7HWNW(ysBc+;ZE=U4qq2_|wzx8mG82)!! zL@At#8cKK=cm#M9cnp{W%mp3?<^fNjp@jL4ZVpk|ZuC;Od2AYrRMh_d`BZ=Z0^ms? z8F&gv0iFh)0iFdG0*ip>fW^QPU@4G_`um^n7~~L~?P4rAbIr3WGY3wlp@Eajgp!#- zF)~wRS~`${$h1tMWM(i3r=rdcWdd11Hn1GX0agGjfmOh2bZ+Pcp=4%oh}zh`hH7kI z3%m%t1grzr0~>&iz{@}`kOvUJCSWtL1$YHDw!bQr%nY>P6l5mKQtQ|5<``rA@63vB zP{(@lJ5$DbVZH8WPnK$!SArVmkwVF@fag8di`RXW*k3&J3;XN;{_?5kdh-;S9>P(C z`QLLD-_6ag>31v`ui0c3`u;q5Cu&@Wd6`P`*mD)7!?0jHdakJZ21y7cz5-o?VXgRG zEuuzeeg1t$aTj#adyl;0dGm z{$ZW2`RtheyT24jXazdp-IE+xFrJefSTHP@Uk@DisgaqISa&;wqxkZ_ktw>X$=o@H z1><>G-dJ3BLNTtxyv+D`Y-EbmVOTJq9fmHhstXAn*IZsEwI7_h0$qk-t$aTpqG3)# zgX%ZcbqFN60&OlV7|+MWxQmI_in^BT9P!0&D|v}8kKGV)j*V1X-X7GJw>Q0(Lo{{^ z35zy*lU?@Jy;Sy93V0iM2Y44{U)`6^^?X0J^So4Llg)X9sqayPsrA77zz4vGKm)KJ zH~=)F!PJ9u$Z?&CMICV_Dm#8qDESxg5!Q9Ttf}@8GS$*T$-m$bO(8!_Ddb0hCZHMk z2r1-8g_3{4Az~MKlzR`BNsB;2E6@Qy+%3R@`TUhCt3R^i?E0hr=**7J?)szay$w8`<(}0Zylc<%8M}c|G3wT)#r(PUkCvQ1eZj+yTZIbt6{7v0VlGWs5S)0jTTxzkiHs=mJgmXug#mK}gbJ$s@$?jw( z-?|NJvsRkwm|Wk(=I4HO$n$Ync$dk(e{OM!!|trMnO&oQao@eFR}`&ww_Vodv>8-$ z+74(9p3nUUv_HpCRku^se_8iQsz6N~ts=%-MO2OG6Rba{$S(K%xoxEVyZoVg#Hy#R ze`j%?+;b=N>Y;i9FYYAc%X>Oh8)9BHiuZbIRrHN1#L%wlna|-8s6ix-L^WLysPpT&Xh}ldpEEqgxF?#2y0q3C ziF|g)=;yCBnf#i0(eudQkY>&Dz~ATaeGm;|KrDy@@%VGv>#W!hfYz=zUdg7_2@M+0 zrBn718scI-K0XisUkRDqtdRsVYh-dwvY^oX79Tkjnly9XkmR*F$!R2eW#XRs z-m4t0f+TPk4&PlN`?!=WaV#!5s033$3ebU6kVdpQQ)|x&YSC}iQFtvDSOjuZ!flWU zVK%nq;O^LnNY@aVX@2~M*bRJ@^Q z+Tg9PXRAq9`Si8xWuHzGmO$#zJEsXSg9*N2>3Nn?ht%P%8DEHlyJcg8yAYqtZuiCw z{0}2+%GvDnDe;2D^E+`8A8!7)c1%5fzWD#2Zt{g!(o?CRz&peqK{_&Al5UwMC?UV| z9fg+=H6+%Vd7ort(LM#lP>5Mg4S9d-M&#VbXK3J1da3MlNKy?^LxI;a4r>`HyfUL; zpI|BT>xP01jO5=Aaa!|CFpFr-8Nc_7sS2{oDSK5q&XGDB+zaM_`@mc<56lOd;C|vr z&2pUwfn^{cEC)}66<{TCjI2^X z>`BsS?0beY_7#9$tUf=?HzCaMW9 z033aB--OKwN%bkKAxh9F`E83$Ff-%{A|1z^uz@Y0oG>RUKK(+V%da_7azXiYHL{glBWni^ zPzAPvYSPHE>UuGCO0Tq3a&v_3l7C!DS@XEa7AJ{pab?Rtvm|Ni>2z^Doi$(^>FL}) zApgvgr0bG-2Y1O_3+lkDzztp_m(2Al`Da#$>d3C&c7D?=Nc1~7mJ74qf!YzS%;zn;rrZ-)W5;Q}8TTK%=HVLy|QSv?4 zs3DQ5foxaMCFJL{&6OsMmB9} z>Xm)^gjha2HRO3ib+H=qu3*mErmpYBB4|SABjMNvaSiL5NyEC`hFxNsCUh1OmYVce zcXRry9C#hP0rn96)x8F@K$~BGM5}Aq@Fq8G*a!B51E2-8g10~$XeYylj=5Gbjf$^6 z;ym7=fE){TG4w<|*U)^BG&J)H$T3Np^f7O9`j|uDFz5tFh(6}10&+}}w&C)l+;Djp zcn5TYW1t7T3*H00WVpOf0XZf`BdI@eyz5&*)ZfVwT{t!xR8jD*o>o!N6CbK5sG{zL iA1EM;B*isVM5_q@yIjccTIw6L$hwO1rN5!(M)%+4PZE^? diff --git a/tests/test_calculator.cc b/tests/test_calculator.cc index 10ef11c5b..97b998ae7 100644 --- a/tests/test_calculator.cc +++ b/tests/test_calculator.cc @@ -473,6 +473,7 @@ namespace rascal { for (const auto & rep_info : rep_infos.at(manager_i)) { const auto & representation_hypers = rep_info.at("hypers").template get(); + const auto & ref_representation = rep_info.at("feature_matrix").template get(); @@ -793,17 +794,22 @@ namespace rascal { this->factory_args.emplace_back(parameters); this->representation_hypers.emplace_back(); - auto fc_hyper = json::object( - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", cutoffs[i_filename]}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}}); + json fc_hyp = json::object({{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", cutoffs[i_filename]}, + {"cutoff_smooth_width", 0.5}}); for (auto & ri_hyp : this->radial_contribution_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyper; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; this->representation_hypers.back().push_back(rep_hyp); } } @@ -827,20 +833,22 @@ namespace rascal { std::vector> representation_hypers{}; std::vector fc_hypers{}; - std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}}; - std::vector radial_contribution_hypers{{{"type", "GTO"}}}; - std::vector rep_hypers{{{"max_radial", 2}, - {"max_angular", 2}, - {"normalize", true}, - {"soap_type", "PowerSpectrum"}, - {"compute_gradients", true}}, - {{"max_radial", 3}, - {"max_angular", 0}, - {"normalize", true}, - {"soap_type", "RadialSpectrum"}, - {"compute_gradients", true}}}; + std::vector density_hypers{{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.4}}}; + std::vector radial_contribution_hypers{{{"radial_basis", "GTO"}}}; + std::vector rep_hypers{ + {{"max_radial", 2}, + {"max_angular", 2}, + {"normalize", true}, + {"soap_type", "PowerSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", true}}, + {{"max_radial", 3}, + {"max_angular", 0}, + {"normalize", true}, + {"soap_type", "RadialSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", true}}}; }; /** Contains some simple periodic structures for testing complicated things diff --git a/tests/test_calculator.hh b/tests/test_calculator.hh index d48bf549c..7092663b1 100644 --- a/tests/test_calculator.hh +++ b/tests/test_calculator.hh @@ -29,6 +29,9 @@ #ifndef TESTS_TEST_CALCULATOR_HH_ #define TESTS_TEST_CALCULATOR_HH_ +// relative path of file with respect to librascal directory +#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE) + #include "test_adaptor.hh" #include "test_math.hh" #include "test_structure.hh" @@ -103,9 +106,19 @@ namespace rascal { for (auto & fc_hyp : this->fc_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyp; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + if (fc_hyp.count("cutoff_function_parameters")) { + rep_hyp["cutoff_function_parameters"] = + fc_hyp["cutoff_function_parameters"]; + } + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; this->representation_hypers.push_back(rep_hyp); } } @@ -117,42 +130,53 @@ namespace rascal { std::vector representation_hypers{}; - std::vector fc_hypers{ - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 3.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}}}; + std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}}}; - std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.2}, {"unit", "AA"}}}}}; - std::vector radial_contribution_hypers{{{"type", "GTO"}}}; - - std::vector rep_hypers{{{"max_radial", 3}, - {"max_angular", 0}, - {"soap_type", "RadialSpectrum"}, - {"normalize", true}}, - {{"max_radial", 3}, - {"max_angular", 0}, - {"soap_type", "RadialSpectrum"}, - {"normalize", true}}, - {{"max_radial", 3}, - {"max_angular", 3}, - {"soap_type", "PowerSpectrum"}, - {"normalize", true}}, - {{"max_radial", 4}, - {"max_angular", 3}, - {"soap_type", "PowerSpectrum"}, - {"normalize", true}}, - {{"max_radial", 3}, - {"max_angular", 1}, - {"soap_type", "BiSpectrum"}, - {"inversion_symmetry", true}, - {"normalize", true}}, - {{"max_radial", 3}, - {"max_angular", 1}, - {"soap_type", "BiSpectrum"}, - {"inversion_symmetry", false}, - {"normalize", true}}}; + std::vector density_hypers{{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.2}}}; + std::vector radial_contribution_hypers{{{"radial_basis", "GTO"}}}; + + std::vector rep_hypers{ + {{"max_radial", 3}, + {"max_angular", 0}, + {"soap_type", "RadialSpectrum"}, + {"normalize", true}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}}, + {{"max_radial", 3}, + {"max_angular", 0}, + {"soap_type", "RadialSpectrum"}, + {"normalize", true}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}}, + {{"max_radial", 3}, + {"max_angular", 3}, + {"soap_type", "PowerSpectrum"}, + {"normalize", true}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}}, + {{"max_radial", 4}, + {"max_angular", 3}, + {"soap_type", "PowerSpectrum"}, + {"normalize", true}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}}, + {{"max_radial", 3}, + {"max_angular", 1}, + {"soap_type", "BiSpectrum"}, + {"inversion_symmetry", true}, + {"normalize", true}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}}, + {{"max_radial", 3}, + {"max_angular", 1}, + {"soap_type", "BiSpectrum"}, + {"inversion_symmetry", false}, + {"normalize", true}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}}}; }; template @@ -166,9 +190,19 @@ namespace rascal { for (auto & fc_hyp : this->fc_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyp; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + if (fc_hyp.count("cutoff_function_parameters")) { + rep_hyp["cutoff_function_parameters"] = + fc_hyp["cutoff_function_parameters"]; + } + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; this->representation_hypers.push_back(rep_hyp); } } @@ -180,29 +214,32 @@ namespace rascal { std::vector representation_hypers{}; - std::vector fc_hypers{ - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 2.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 1.0}, {"unit", "AA"}}}}}; + std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 2.0}, + {"cutoff_smooth_width", 1.0}}}; std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.2}, {"unit", "AA"}}}}, - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}}; - std::vector radial_contribution_hypers{{{"type", "GTO"}}}; - std::vector rep_hypers{{{"max_radial", 1}, - {"max_angular", 2}, - {"soap_type", "LambdaSpectrum"}, - {"covariant_lambda", 2}, - {"inversion_symmetry", true}, - {"normalize", true}}, - {{"max_radial", 2}, - {"max_angular", 2}, - {"soap_type", "LambdaSpectrum"}, - {"covariant_lambda", 2}, - {"inversion_symmetry", false}, - {"normalize", true}}}; + {{"gaussian_sigma_type", "Constant"}, {"gaussian_sigma_constant", 0.2}}, + {{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.4}}}; + std::vector radial_contribution_hypers{{{"radial_basis", "GTO"}}}; + std::vector rep_hypers{ + {{"max_radial", 1}, + {"max_angular", 2}, + {"soap_type", "LambdaSpectrum"}, + {"covariant_lambda", 2}, + {"inversion_symmetry", true}, + {"normalize", true}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}}, + {{"max_radial", 2}, + {"max_angular", 2}, + {"soap_type", "LambdaSpectrum"}, + {"covariant_lambda", 2}, + {"inversion_symmetry", false}, + {"normalize", true}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}}}; }; struct SphericalInvariantsTestData : TestData { @@ -242,9 +279,19 @@ namespace rascal { for (auto & fc_hyp : this->fc_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyp; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + if (fc_hyp.count("cutoff_function_parameters")) { + rep_hyp["cutoff_function_parameters"] = + fc_hyp["cutoff_function_parameters"]; + } + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; this->representation_hypers.push_back(rep_hyp); } } @@ -256,33 +303,34 @@ namespace rascal { std::vector representation_hypers{}; std::vector fc_hypers{ - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 3.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}}, - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 2.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 1.0}, {"unit", "AA"}}}}, - {{"type", "RadialScaling"}, - {"cutoff", {{"value", 4.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}, - {"rate", {{"value", .0}, {"unit", "AA"}}}, - {"exponent", {{"value", 4}, {"unit", ""}}}, - {"scale", {{"value", 2.5}, {"unit", "AA"}}}}, - {{"type", "RadialScaling"}, - {"cutoff", {{"value", 4.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}, - {"rate", {{"value", 1.}, {"unit", "AA"}}}, - {"exponent", {{"value", 3}, {"unit", ""}}}, - {"scale", {{"value", 2.}, {"unit", "AA"}}}}}; - - std::vector radial_contribution_hypers{{{"type", "GTO"}}, - {{"type", "DVR"}}}; + {{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}}, + {{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 2.0}, + {"cutoff_smooth_width", 1.0}}, + {{"cutoff_function_type", "RadialScaling"}, + {"interaction_cutoff", 4.0}, + {"cutoff_smooth_width", 0.5}, + {"cutoff_function_parameters", + {{"rate", .0}, {"exponent", 4}, {"scale", 2.5}}}}, + {{"cutoff_function_type", "RadialScaling"}, + {"interaction_cutoff", 4.0}, + {"cutoff_smooth_width", 0.5}, + {"cutoff_function_parameters", + {{"rate", 1.}, {"exponent", 3}, {"scale", 2.}}}}}; + + std::vector radial_contribution_hypers{{{"radial_basis", "GTO"}}, + {{"radial_basis", "DVR"}}}; + + std::vector density_hypers{{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.5}}}; - std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.5}, {"unit", "AA"}}}}}; - - std::vector rep_hypers{{{"max_radial", 2}, {"max_angular", 2}}}; + std::vector rep_hypers{ + {{"max_radial", 2}, + {"max_angular", 2}, + {"compute_gradients", false}, + {"expansion_by_species_method", "environment wise"}}}; }; /** @@ -343,9 +391,22 @@ namespace rascal { for (auto & fc_hyp : this->fc_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyp; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + if (fc_hyp.count("cutoff_function_parameters")) { + rep_hyp["cutoff_function_parameters"] = + fc_hyp["cutoff_function_parameters"]; + } + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; + if (ri_hyp.count("optimization")) { + rep_hyp["optimization"] = ri_hyp["optimization"]; + } this->representation_hypers.push_back(rep_hyp); } } @@ -356,19 +417,17 @@ namespace rascal { ~MultipleHypersSphericalExpansion() = default; std::vector representation_hypers{}; - std::vector fc_hypers{ - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 3.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}}, - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 2.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 1.0}, {"unit", "AA"}}}}}; + std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}}, + {{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 2.0}, + {"cutoff_smooth_width", 1.0}}}; std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.2}, {"unit", "AA"}}}}, - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}}; + {{"gaussian_sigma_type", "Constant"}, {"gaussian_sigma_constant", 0.2}}, + {{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.4}}}; // nested json definitions dont work properly in this case: // if not defined seperately, radial dimension reduction_hypers // are interpreted as arrays @@ -389,16 +448,22 @@ namespace rascal { {"Spline", {{"accuracy", 1e-8}}}, {"RadialDimReduction", projection_matrices_hypers}}; std::vector radial_contribution_hypers{ - {{"type", "GTO"}, {"optimization", {}}}, - {{"type", "DVR"}, {"optimization", {}}}, - {{"type", "GTO"}, + {{"radial_basis", "GTO"}, {"optimization", {}}}, + {{"radial_basis", "DVR"}, {"optimization", {}}}, + {{"radial_basis", "GTO"}, {"optimization", {{"Spline", {{"accuracy", 1e-12}}}}}}, - {{"type", "DVR"}, {"optimization", {{"Spline", {{"accuracy", 1e-5}}}}}}, - {{"type", "GTO"}, {"optimization", radial_dim_reduction_spline_hypers}}, - {{"type", "DVR"}, {"optimization", radial_dim_reduction_spline_hypers}}, + {{"radial_basis", "DVR"}, + {"optimization", {{"Spline", {{"accuracy", 1e-5}}}}}}, + {{"radial_basis", "GTO"}, + {"optimization", radial_dim_reduction_spline_hypers}}, + {{"radial_basis", "DVR"}, + {"optimization", radial_dim_reduction_spline_hypers}}, }; std::vector rep_hypers{ - {{"max_radial", 3}, {"max_angular", 3}, {"compute_gradients", true}}}; + {{"max_radial", 3}, + {"max_angular", 3}, + {"compute_gradients", true}, + {"expansion_by_species_method", "environment wise"}}}; }; /** Contains some simple periodic structures for testing complicated things @@ -564,9 +629,19 @@ namespace rascal { for (auto & fc_hyp : this->fc_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyp; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + if (fc_hyp.count("cutoff_function_parameters")) { + rep_hyp["cutoff_function_parameters"] = + fc_hyp["cutoff_function_parameters"]; + } + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; this->representation_hypers.push_back(rep_hyp); } } @@ -577,14 +652,12 @@ namespace rascal { ~SingleHypersSphericalExpansion() = default; std::vector representation_hypers{}; - std::vector fc_hypers{ - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 2.5}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}}}; + std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 2.5}, + {"cutoff_smooth_width", 0.5}}}; - std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}}; + std::vector density_hypers{{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.4}}}; std::map>>> projection_matrices{ {"1", @@ -648,16 +721,20 @@ namespace rascal { {"Spline", {{"accuracy", 1e-8}}}, {"RadialDimReduction", projection_matrices_hypers}}; std::vector radial_contribution_hypers{ - {{"type", "GTO"}, {"optimization", {}}}, - {{"type", "DVR"}, {"optimization", {}}}, - {{"type", "GTO"}, {"optimization", {{"Spline", {{"accuracy", 1e-8}}}}}}, - {{"type", "GTO"}, + {{"radial_basis", "GTO"}, {"optimization", {}}}, + {{"radial_basis", "DVR"}, {"optimization", {}}}, + {{"radial_basis", "GTO"}, + {"optimization", {{"Spline", {{"accuracy", 1e-8}}}}}}, + {{"radial_basis", "GTO"}, {"optimization", radial_dim_reduction_spline_hypers}}}; // if new hypers are added or current ones changed there will be problems // with the projection_matrices defined above since their size depend on // max_radial and max_angular std::vector rep_hypers{ - {{"max_radial", 2}, {"max_angular", 2}, {"compute_gradients", true}}}; + {{"max_radial", 2}, + {"max_angular", 2}, + {"compute_gradients", true}, + {"expansion_by_species_method", "environment wise"}}}; }; template @@ -671,9 +748,19 @@ namespace rascal { for (auto & fc_hyp : this->fc_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyp; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + if (fc_hyp.count("cutoff_function_parameters")) { + rep_hyp["cutoff_function_parameters"] = + fc_hyp["cutoff_function_parameters"]; + } + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; this->representation_hypers.push_back(rep_hyp); } } @@ -685,25 +772,26 @@ namespace rascal { std::vector representation_hypers{}; - std::vector fc_hypers{ - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 2.5}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}}}; + std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 2.5}, + {"cutoff_smooth_width", 0.5}}}; - std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}}; - std::vector radial_contribution_hypers{{{"type", "GTO"}}}; - std::vector rep_hypers{{{"max_radial", 2}, - {"max_angular", 2}, - {"normalize", true}, - {"soap_type", "PowerSpectrum"}, - {"compute_gradients", true}}, - {{"max_radial", 2}, - {"max_angular", 0}, - {"normalize", true}, - {"soap_type", "RadialSpectrum"}, - {"compute_gradients", true}}}; + std::vector density_hypers{{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.4}}}; + std::vector radial_contribution_hypers{{{"radial_basis", "GTO"}}}; + std::vector rep_hypers{ + {{"max_radial", 2}, + {"max_angular", 2}, + {"normalize", true}, + {"soap_type", "PowerSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", true}}, + {{"max_radial", 2}, + {"max_angular", 0}, + {"normalize", true}, + {"soap_type", "RadialSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", true}}}; }; struct ComplexHypersSphericalInvariants : ComplexPeriodicNLCCStrictFixture { @@ -716,9 +804,19 @@ namespace rascal { for (auto & fc_hyp : this->fc_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyp; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + if (fc_hyp.count("cutoff_function_parameters")) { + rep_hyp["cutoff_function_parameters"] = + fc_hyp["cutoff_function_parameters"]; + } + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; this->representation_hypers.push_back(rep_hyp); } } @@ -729,25 +827,26 @@ namespace rascal { ~ComplexHypersSphericalInvariants() = default; std::vector representation_hypers{}; - std::vector fc_hypers{ - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 3.5}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 1.0}, {"unit", "AA"}}}}}; + std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 3.5}, + {"cutoff_smooth_width", 1.0}}}; - std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}}; - std::vector radial_contribution_hypers{{{"type", "GTO"}}}; - std::vector rep_hypers{{{"max_radial", 2}, - {"max_angular", 2}, - {"normalize", false}, - {"soap_type", "PowerSpectrum"}, - {"compute_gradients", true}}, - {{"max_radial", 2}, - {"max_angular", 2}, - {"normalize", true}, - {"soap_type", "PowerSpectrum"}, - {"compute_gradients", true}}}; + std::vector density_hypers{{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.4}}}; + std::vector radial_contribution_hypers{{{"radial_basis", "GTO"}}}; + std::vector rep_hypers{ + {{"max_radial", 2}, + {"max_angular", 2}, + {"normalize", false}, + {"soap_type", "PowerSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", true}}, + {{"max_radial", 2}, + {"max_angular", 2}, + {"normalize", true}, + {"soap_type", "PowerSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", true}}}; }; struct SphericalExpansionTestData : TestData { @@ -822,15 +921,16 @@ namespace rascal { // the fixture. This way we do not have to create a fixture for each // type while not using the wrong templated RadialIntegralHandler // constructor - auto radial_contribution_hypers = - hyper.at("radial_contribution").template get(); - auto radial_contribution_type_name = - radial_contribution_hypers.at("type").template get(); - auto density_hypers = hyper.at("gaussian_density").template get(); + // auto radial_contribution_type_name = + // radial_contribution_hypers.at("radial_basis").template + // get(); + std::string radial_contribution_type_name = + json_io::read_hyperparameter(__FILENAME__, __LINE__, + hyper, "radial_basis"); auto smearing_type_name = - density_hypers.at("type").template get(); + hyper.at("gaussian_sigma_type").template get(); auto optimization_hypers = - radial_contribution_hypers.at("optimization").template get(); + hyper.at("optimization").template get(); bool using_spline = optimization_hypers.count("Spline"); bool using_radial_dim_reduction = optimization_hypers.count("RadialDimReduction"); diff --git a/tests/test_cutoff_functions.cc b/tests/test_cutoff_functions.cc index c45d8318a..a8f87fabd 100644 --- a/tests/test_cutoff_functions.cc +++ b/tests/test_cutoff_functions.cc @@ -41,13 +41,14 @@ namespace rascal { */ BOOST_AUTO_TEST_CASE(shifted_cosine_gradient_test) { static const bool verbose{false}; - std::vector fc_hypers{ - R"({ - "type": "ShiftedCosine", - "cutoff": {"value": 3, "unit": "AA"}, - "smooth_width": {"value": 0.5, "unit": "AA"} - })"_json, - }; + std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}}}; + // R"({ + // "type": "ShiftedCosine", + // "cutoff": {"value": 3, "unit": "AA"}, + // "smooth_width": {"value": 0.5, "unit": "AA"} + // })"_json, using Cutoff_t = internal::CutoffFunction; @@ -73,31 +74,47 @@ namespace rascal { BOOST_AUTO_TEST_CASE(radial_scaling_gradient_test) { static const bool verbose{false}; std::vector fc_hypers{ - R"({ - "type": "RadialScaling", - "cutoff": {"value": 3, "unit": "AA"}, - "smooth_width": {"value": 0.5, "unit": "AA"}, - "rate": {"value": 1, "unit": "AA"}, - "scale": {"value": 2, "unit": "AA"} , - "exponent": {"value": 3, "unit": ""} - })"_json, - R"({ - "type": "RadialScaling", - "cutoff": {"value": 3, "unit": "AA"}, - "smooth_width": {"value": 0.5, "unit": "AA"}, - "rate": {"value": 0, "unit": "AA"}, - "scale": {"value": 2, "unit": "AA"} , - "exponent": {"value": 3, "unit": ""} - })"_json, - R"({ - "type": "RadialScaling", - "cutoff": {"value": 3, "unit": "AA"}, - "smooth_width": {"value": 0.5, "unit": "AA"}, - "rate": {"value": 0, "unit": "AA"}, - "scale": {"value": 2, "unit": "AA"} , - "exponent": {"value": 0, "unit": ""} - })"_json, - }; + {{"cutoff_function_type", "RadialScaling"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}, + {"cutoff_function_parameters", + {{"rate", 1}, {"scale", 2}, {"exponent", 3}}}}, + {{"cutoff_function_type", "RadialScaling"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}, + {"cutoff_function_parameters", + {{"rate", 0}, {"scale", 2}, {"exponent", 3}}}}, + {{"cutoff_function_type", "RadialScaling"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}, + {"cutoff_function_parameters", + {{"rate", 0}, {"scale", 2}, {"exponent", 0}}}}}; + + // R"({ + // "type": "RadialScaling", + // "cutoff": {"value": 3, "unit": "AA"}, + // "smooth_width": {"value": 0.5, "unit": "AA"}, + // "rate": {"value": 1, "unit": "AA"}, + // "scale": {"value": 2, "unit": "AA"} , + // "exponent": {"value": 3, "unit": ""} + // })"_json, + // R"({ + // "type": "RadialScaling", + // "cutoff": {"value": 3, "unit": "AA"}, + // "smooth_width": {"value": 0.5, "unit": "AA"}, + // "rate": {"value": 0, "unit": "AA"}, + // "scale": {"value": 2, "unit": "AA"} , + // "exponent": {"value": 3, "unit": ""} + // })"_json, + // R"({ + // "type": "RadialScaling", + // "cutoff": {"value": 3, "unit": "AA"}, + // "smooth_width": {"value": 0.5, "unit": "AA"}, + // "rate": {"value": 0, "unit": "AA"}, + // "scale": {"value": 2, "unit": "AA"} , + // "exponent": {"value": 0, "unit": ""} + // })"_json, + //}; using Cutoff_t = internal::CutoffFunction; @@ -124,39 +141,26 @@ namespace rascal { BOOST_AUTO_TEST_CASE(radial_scaling_exponent_zero_test) { static const bool verbose{false}; std::vector fc_hypers{ - R"({ - "type": "RadialScaling", - "cutoff": {"value": 3, "unit": "AA"}, - "smooth_width": {"value": 0.5, "unit": "AA"}, - "rate": {"value": 1, "unit": "AA"}, - "scale": {"value": 1, "unit": "AA"} , - "exponent": {"value": 0, "unit": ""} - })"_json, - R"({ - "type": "RadialScaling", - "cutoff": {"value": 3, "unit": "AA"}, - "smooth_width": {"value": 0.5, "unit": "AA"}, - "rate": {"value": 0, "unit": "AA"}, - "scale": {"value": 0, "unit": "AA"} , - "exponent": {"value": 0, "unit": ""} - })"_json, - R"({ - "type": "RadialScaling", - "cutoff": {"value": 3, "unit": "AA"}, - "smooth_width": {"value": 0.5, "unit": "AA"}, - "rate": {"value": 0, "unit": "AA"}, - "scale": {"value": 1, "unit": "AA"} , - "exponent": {"value": 0, "unit": ""} - })"_json, - R"({ - "type": "RadialScaling", - "cutoff": {"value": 3, "unit": "AA"}, - "smooth_width": {"value": 0.5, "unit": "AA"}, - "rate": {"value": 1, "unit": "AA"}, - "scale": {"value": 0, "unit": "AA"} , - "exponent": {"value": 0, "unit": ""} - })"_json, - }; + {{"cutoff_function_type", "RadialScaling"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}, + {"cutoff_function_parameters", + {{"rate", 1}, {"scale", 1}, {"exponent", 0}}}}, + {{"cutoff_function_type", "RadialScaling"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}, + {"cutoff_function_parameters", + {{"rate", 0}, {"scale", 0}, {"exponent", 0}}}}, + {{"cutoff_function_type", "RadialScaling"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}, + {"cutoff_function_parameters", + {{"rate", 0}, {"scale", 1}, {"exponent", 0}}}}, + {{"cutoff_function_type", "RadialScaling"}, + {"interaction_cutoff", 3.0}, + {"cutoff_smooth_width", 0.5}, + {"cutoff_function_parameters", + {{"rate", 1}, {"scale", 0}, {"exponent", 0}}}}}; using Cutoff_t = internal::CutoffFunction; diff --git a/tests/test_kernels.hh b/tests/test_kernels.hh index 8abf7910e..a99f12bcb 100644 --- a/tests/test_kernels.hh +++ b/tests/test_kernels.hh @@ -48,9 +48,22 @@ namespace rascal { for (auto & fc_hyp : this->fc_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyp; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + if (fc_hyp.count("cutoff_function_parameters")) { + rep_hyp["cutoff_function_parameters"] = + fc_hyp["cutoff_function_parameters"]; + } + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; + if (ri_hyp.count("optimization")) { + rep_hyp["optimization"] = ri_hyp["optimization"]; + } this->representation_hypers.push_back(rep_hyp); } } @@ -61,23 +74,26 @@ namespace rascal { std::vector representation_hypers{}; - std::vector fc_hypers{ - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 2.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}}}; - - std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}}; - std::vector radial_contribution_hypers{{{"type", "GTO"}}}; - std::vector rep_hypers{{{"max_radial", 3}, - {"max_angular", 0}, - {"soap_type", "RadialSpectrum"}, - {"normalize", true}}, - {{"max_radial", 2}, - {"max_angular", 2}, - {"soap_type", "PowerSpectrum"}, - {"normalize", true}}}; + std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 2.0}, + {"cutoff_smooth_width", 0.5}}}; + + std::vector density_hypers{{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.4}}}; + std::vector radial_contribution_hypers{{{"radial_basis", "GTO"}}}; + std::vector rep_hypers{ + {{"max_radial", 3}, + {"max_angular", 0}, + {"soap_type", "RadialSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}, + {"normalize", true}}, + {{"max_radial", 2}, + {"max_angular", 2}, + {"soap_type", "PowerSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}, + {"normalize", true}}}; std::vector kernel_hypers{ {{"zeta", 2}, {"target_type", "Structure"}, {"name", "Cosine"}}, diff --git a/tests/test_math_interpolator.hh b/tests/test_math_interpolator.hh index 2b17510e2..59637e857 100644 --- a/tests/test_math_interpolator.hh +++ b/tests/test_math_interpolator.hh @@ -204,13 +204,12 @@ namespace rascal { math::Hyp1f1 hyp1f1{0.5 * (5 + 4 + 3), 4 + 1.5, 200, 1e-15}; const int max_radial{3}; const int max_angular{max_radial - 1}; - const json fc_hypers{{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.5}, {"unit", "AA"}}}}; - const json hypers{ - {"gaussian_density", fc_hypers}, - {"max_radial", max_radial}, - {"max_angular", max_angular}, - {"cutoff_function", {{"cutoff", {{"value", 2.0}, {"unit", "AA"}}}}}}; + + const json hypers{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.5}, + {"max_radial", max_radial}, + {"max_angular", max_angular}, + {"interaction_cutoff", 3.0}}; // a=0.5*(n+l+3), b = l+1.5, mmax, tolerance RadialIntegral_t radial_contr{hypers}; diff --git a/tests/test_pseudo_points.cc b/tests/test_pseudo_points.cc index 911e8b3a5..277ea8064 100644 --- a/tests/test_pseudo_points.cc +++ b/tests/test_pseudo_points.cc @@ -52,9 +52,19 @@ namespace rascal { using SparsePoints_t = SparsePoints; SparsePointsFixture() { - hypers["cutoff_function"] = fc_hypers; - hypers["gaussian_density"] = sigma_hypers; - hypers["radial_contribution"] = {{"type", "GTO"}}; + hypers["cutoff_function_type"] = fc_hypers["cutoff_function_type"]; + hypers["interaction_cutoff"] = fc_hypers["interaction_cutoff"]; + hypers["cutoff_smooth_width"] = fc_hypers["cutoff_smooth_width"]; + if (fc_hypers.count("cutoff_function_parameters")) { + hypers["cutoff_function_parameters"] = + fc_hypers["cutoff_function_parameters"]; + } + + hypers["gaussian_sigma_type"] = sigma_hypers["gaussian_sigma_type"]; + hypers["gaussian_sigma_constant"] = + sigma_hypers["gaussian_sigma_constant"]; + + hypers["radial_contribution"] = {{"radial_basis", "GTO"}}; json ad1a{{"name", "AdaptorNeighbourList"}, {"initialization_arguments", {{"cutoff", cutoff}}}}; @@ -81,11 +91,11 @@ namespace rascal { {"normalize", true}, {"expansion_by_species_method", "environment wise"}}; - json fc_hypers{{"type", "ShiftedCosine"}, - {"cutoff", {{"value", cutoff}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}}; - json sigma_hypers{{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}; + json fc_hypers{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", cutoff}, + {"cutoff_smooth_width", 0.5}}; + json sigma_hypers{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.4}}; }; using multiple_fixtures = boost::mpl::list< diff --git a/tests/test_sparse_kernels.hh b/tests/test_sparse_kernels.hh index c9fe85783..4efb9f89e 100644 --- a/tests/test_sparse_kernels.hh +++ b/tests/test_sparse_kernels.hh @@ -51,9 +51,19 @@ namespace rascal { for (auto & fc_hyp : this->fc_hypers) { for (auto & sig_hyp : this->density_hypers) { for (auto & rep_hyp : this->rep_hypers) { - rep_hyp["cutoff_function"] = fc_hyp; - rep_hyp["gaussian_density"] = sig_hyp; - rep_hyp["radial_contribution"] = ri_hyp; + rep_hyp["cutoff_function_type"] = fc_hyp["cutoff_function_type"]; + rep_hyp["interaction_cutoff"] = fc_hyp["interaction_cutoff"]; + rep_hyp["cutoff_smooth_width"] = fc_hyp["cutoff_smooth_width"]; + if (fc_hyp.count("cutoff_function_parameters")) { + rep_hyp["cutoff_function_parameters"] = + fc_hyp["cutoff_function_parameters"]; + } + + rep_hyp["gaussian_sigma_type"] = sig_hyp["gaussian_sigma_type"]; + rep_hyp["gaussian_sigma_constant"] = + sig_hyp["gaussian_sigma_constant"]; + + rep_hyp["radial_basis"] = ri_hyp["radial_basis"]; this->representation_hypers.push_back(rep_hyp); } } @@ -64,23 +74,26 @@ namespace rascal { std::vector representation_hypers{}; - std::vector fc_hypers{ - {{"type", "ShiftedCosine"}, - {"cutoff", {{"value", 2.0}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.5}, {"unit", "AA"}}}}}; - - std::vector density_hypers{ - {{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}}; - std::vector radial_contribution_hypers{{{"type", "GTO"}}}; - std::vector rep_hypers{{{"max_radial", 3}, - {"max_angular", 0}, - {"soap_type", "RadialSpectrum"}, - {"normalize", true}}, - {{"max_radial", 2}, - {"max_angular", 2}, - {"soap_type", "PowerSpectrum"}, - {"normalize", true}}}; + std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, + {"interaction_cutoff", 2.0}, + {"cutoff_smooth_width", 0.5}}}; + + std::vector density_hypers{{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.4}}}; + std::vector radial_contribution_hypers{{{"radial_basis", "GTO"}}}; + std::vector rep_hypers{ + {{"max_radial", 3}, + {"max_angular", 0}, + {"soap_type", "RadialSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}, + {"normalize", true}}, + {{"max_radial", 2}, + {"max_angular", 2}, + {"soap_type", "PowerSpectrum"}, + {"expansion_by_species_method", "environment wise"}, + {"compute_gradients", false}, + {"normalize", true}}}; std::vector kernel_hypers{ {{"zeta", 2}, {"target_type", "Structure"}, {"name", "GAP"}}, From 550b75a104b8cff14bea3c2651a328551bb6ed74 Mon Sep 17 00:00:00 2001 From: alexgo Date: Wed, 1 Dec 2021 10:06:05 +0100 Subject: [PATCH 08/18] adapt python classes; empty lists and dict is now properly handled on cpp side for global_species coefficient_subselection optimization --- bindings/rascal/models/kernels.py | 11 -- .../representations/spherical_covariants.py | 79 ++++----- .../representations/spherical_expansion.py | 88 +++------- .../representations/spherical_invariants.py | 158 ++++++++++-------- .../calculator_spherical_expansion.hh | 12 +- .../calculator_spherical_invariants.hh | 14 +- tests/python/python_models_test.py | 16 +- 7 files changed, 162 insertions(+), 216 deletions(-) diff --git a/bindings/rascal/models/kernels.py b/bindings/rascal/models/kernels.py index 7d8877e39..9db56e154 100644 --- a/bindings/rascal/models/kernels.py +++ b/bindings/rascal/models/kernels.py @@ -109,20 +109,9 @@ def _get_init_params(self): def _set_data(self, data): super()._set_data(data) - # allows to load deprecated models - if "cpp_kernel" in data.keys(): - self._kernel = self._kernel.from_dict(data["cpp_kernel"]) - else: - LOGGER.warn( - "WARNING: a deprecated model was loaded. Key 'cpp_kernel' " - "was not found in model. Please dump and reload the model " - "to update it. The model parameters will not change, only " - "the format." - ) def _get_data(self): data = super()._get_data() - data.update(cpp_kernel=self._kernel.to_dict()) return data def __call__(self, X, Y=None, grad=(False, False), compute_neg_stress=False): diff --git a/bindings/rascal/representations/spherical_covariants.py b/bindings/rascal/representations/spherical_covariants.py index 9c67cf82a..32c61ef6e 100644 --- a/bindings/rascal/representations/spherical_covariants.py +++ b/bindings/rascal/representations/spherical_covariants.py @@ -151,7 +151,7 @@ def __init__( cutoff_smooth_width, max_radial, max_angular, - gaussian_sigma_type, + gaussian_sigma_type="Constant", gaussian_sigma_constant=0.3, cutoff_function_type="ShiftedCosine", normalize=True, @@ -169,53 +169,51 @@ def __init__( class documentation """ self.name = "sphericalcovariants" - self.hypers = dict() - self.update_hyperparameters( - max_radial=max_radial, - max_angular=max_angular, - soap_type=soap_type, - normalize=normalize, - inversion_symmetry=inversion_symmetry, - covariant_lambda=covariant_lambda, + optimization = check_optimization_for_spherical_representations( + optimization, optimization_args ) - self.cutoff_function_parameters = deepcopy(cutoff_function_parameters) + if global_species is None: + global_species = [] + elif not isinstance(global_species, list): + # TODO(veit) I think we should raise an error in this case, maybe we can still make an integer to a list, but in any other case I find it dangours to make a list out of this. I did not change this to ensure backwards compatibility + global_species = list(global_species) + + if cutoff_function_parameters is None: + cutoff_function_parameters = dict() + elif not isinstance(cutoff_function_parameters, dict): + raise ValueError("\'cutoff_function_parameters\' should be None or a dictionary with \'rate\', \'scale\' and \'expontent\'") - cutoff_function_parameters.update( + self.hypers = dict( interaction_cutoff=interaction_cutoff, cutoff_smooth_width=cutoff_smooth_width, - ) - cutoff_function = cutoff_function_dict_switch( - cutoff_function_type, **cutoff_function_parameters - ) - - gaussian_density = dict( - type=gaussian_sigma_type, - gaussian_sigma=dict(value=gaussian_sigma_constant, unit="AA"), - ) - optimization = check_optimization_for_spherical_representations( - optimization, optimization_args - ) - - radial_contribution = dict(type=radial_basis, optimization=optimization) - radial_contribution = dict( - type=radial_basis, + max_radial=max_radial, + max_angular=max_angular, + gaussian_sigma_type=gaussian_sigma_type, + gaussian_sigma_constant=gaussian_sigma_constant, + cutoff_function_type=cutoff_function_type, + soap_type=soap_type, + inversion_symmetry=inversion_symmetry, + radial_basis=radial_basis, + normalize=normalize, + optimization=optimization, + optimization_args=optimization_args, + covariant_lambda=covariant_lambda, + expansion_by_species_method=expansion_by_species_method, + global_species=global_species, + compute_gradients=compute_gradients, + cutoff_function_parameters=cutoff_function_parameters, ) - self.update_hyperparameters( - cutoff_function=cutoff_function, - gaussian_density=gaussian_density, - radial_contribution=radial_contribution, - ) self.nl_options = [ - dict(name="centers", args=dict()), + dict(name="centers", args=[]), dict(name="neighbourlist", args=dict(cutoff=interaction_cutoff)), dict(name="centercontribution", args=dict()), dict(name="strict", args=dict(cutoff=interaction_cutoff)), ] - self.rep_options = dict(name=self.name, args=[self.hypers]) + self._representation = CalculatorFactory(self.rep_options) @@ -377,20 +375,7 @@ def _get_init_params(self): def _set_data(self, data): super()._set_data(data) - # allows to load deprecated models - if "cpp_representation" in data.keys(): - self._representation = self._representation.from_dict( - data["cpp_representation"] - ) - else: - print( - "WARNING: a deprecated model was loaded. Key " - "'cpp_representation' was not found in model. Please dump and " - "reload the model to update it. The model parameters will not " - "change, only the format." - ) def _get_data(self): data = super()._get_data() - data.update(cpp_representation=self._representation.to_dict()) return data diff --git a/bindings/rascal/representations/spherical_expansion.py b/bindings/rascal/representations/spherical_expansion.py index 0b8b32095..66f36a3c0 100644 --- a/bindings/rascal/representations/spherical_expansion.py +++ b/bindings/rascal/representations/spherical_expansion.py @@ -170,7 +170,7 @@ def __init__( cutoff_smooth_width, max_radial, max_angular, - gaussian_sigma_type, + gaussian_sigma_type="Constant", gaussian_sigma_constant=0.3, cutoff_function_type="ShiftedCosine", radial_basis="GTO", @@ -188,55 +188,47 @@ class documentation """ self.name = "sphericalexpansion" - self.hypers = dict() + + optimization = check_optimization_for_spherical_representations( + optimization, optimization_args + ) if global_species is None: global_species = [] elif not isinstance(global_species, list): - global_species = list(global_species) + raise ValueError("\'global_species\' should be None, empty list, or list of atomic numbers") + + if cutoff_function_parameters is None: + cutoff_function_parameters = dict() + elif not isinstance(cutoff_function_parameters, dict): + raise ValueError("\'cutoff_function_parameters\' should be None or a dictionary with \'rate\', \'scale\' and \'expontent\'") - self.update_hyperparameters( + self.hypers = dict( + interaction_cutoff=interaction_cutoff, + cutoff_smooth_width=cutoff_smooth_width, max_radial=max_radial, max_angular=max_angular, + gaussian_sigma_type=gaussian_sigma_type, + gaussian_sigma_constant=gaussian_sigma_constant, + cutoff_function_type=cutoff_function_type, + radial_basis=radial_basis, + optimization=optimization, + optimization_args=optimization_args, expansion_by_species_method=expansion_by_species_method, global_species=global_species, compute_gradients=compute_gradients, - ) - self.cutoff_function_parameters = deepcopy(cutoff_function_parameters) - cutoff_function_parameters.update( - interaction_cutoff=interaction_cutoff, - cutoff_smooth_width=cutoff_smooth_width, - ) - cutoff_function = cutoff_function_dict_switch( - cutoff_function_type, **cutoff_function_parameters + cutoff_function_parameters=cutoff_function_parameters, ) - gaussian_density = dict( - type=gaussian_sigma_type, - gaussian_sigma=dict(value=gaussian_sigma_constant, unit="A"), - ) - optimization = check_optimization_for_spherical_representations( - optimization, optimization_args - ) - - radial_contribution = dict(type=radial_basis, optimization=optimization) - - self.update_hyperparameters( - cutoff_function=cutoff_function, - gaussian_density=gaussian_density, - radial_contribution=radial_contribution, - ) self.nl_options = [ - dict(name="centers", args=dict()), + dict(name="centers", args=[]), dict(name="neighbourlist", args=dict(cutoff=interaction_cutoff)), dict(name="centercontribution", args=dict()), dict(name="strict", args=dict(cutoff=interaction_cutoff)), ] - self.rep_options = dict(name=self.name, args=[self.hypers]) - - n_features = self.get_num_coefficients() + self._representation = CalculatorFactory(self.rep_options) @@ -305,43 +297,11 @@ def get_keys(self, species): return keys def _get_init_params(self): - gaussian_density = self.hypers["gaussian_density"] - cutoff_function = self.hypers["cutoff_function"] - radial_contribution = self.hypers["radial_contribution"] - - init_params = dict( - interaction_cutoff=cutoff_function["cutoff"]["value"], - cutoff_smooth_width=cutoff_function["smooth_width"]["value"], - max_radial=self.hypers["max_radial"], - max_angular=self.hypers["max_angular"], - expansion_by_species_method=self.hypers["expansion_by_species_method"], - global_species=self.hypers["global_species"], - compute_gradients=self.hypers["compute_gradients"], - gaussian_sigma_type=gaussian_density["type"], - gaussian_sigma_constant=gaussian_density["gaussian_sigma"]["value"], - cutoff_function_type=cutoff_function["type"], - radial_basis=radial_contribution["type"], - optimization=radial_contribution["optimization"], - cutoff_function_parameters=self.cutoff_function_parameters, - ) - return init_params + return self.hypers def _set_data(self, data): super()._set_data(data) - # allows to load deprecated models - if "cpp_representation" in data.keys(): - self._representation = self._representation.from_dict( - data["cpp_representation"] - ) - else: - print( - "WARNING: a deprecated model was loaded. Key " - "'cpp_representation' was not found in model. Please dump and " - "reload the model to update it. The model parameters will not " - "change, only the format." - ) def _get_data(self): data = super()._get_data() - data.update(cpp_representation=self._representation.to_dict()) return data diff --git a/bindings/rascal/representations/spherical_invariants.py b/bindings/rascal/representations/spherical_invariants.py index e5ecc3e65..82a9ecaf9 100644 --- a/bindings/rascal/representations/spherical_invariants.py +++ b/bindings/rascal/representations/spherical_invariants.py @@ -232,54 +232,48 @@ def __init__( class documentation """ self.name = "sphericalinvariants" - self.hypers = dict() + + optimization = check_optimization_for_spherical_representations( + optimization, optimization_args + ) + if global_species is None: global_species = [] elif not isinstance(global_species, list): + # TODO(veit) I think we should raise an error in this case, maybe we can still make an integer to a list, but in any other case I find it dangours to make a list out of this. I did not change this to ensure backwards compatibility global_species = list(global_species) - self.update_hyperparameters( + if cutoff_function_parameters is None: + cutoff_function_parameters = dict() + elif not isinstance(cutoff_function_parameters, dict): + raise ValueError("\'cutoff_function_parameters\' should be None or a dictionary with \'rate\', \'scale\' and \'expontent\'") + + if coefficient_subselection is None: + coefficient_subselection = dict() + elif not isinstance(coefficient_subselection, dict): + raise ValueError("\'coefficient_subselection\' should be None or a dictionary with \'a\', \'b\', \'n1\', \'n2\' and \'l\'") + + self.hypers = dict( + interaction_cutoff=interaction_cutoff, + cutoff_smooth_width=cutoff_smooth_width, max_radial=max_radial, max_angular=max_angular, + gaussian_sigma_type=gaussian_sigma_type, + gaussian_sigma_constant=gaussian_sigma_constant, + cutoff_function_type=cutoff_function_type, soap_type=soap_type, - normalize=normalize, inversion_symmetry=inversion_symmetry, + radial_basis=radial_basis, + normalize=normalize, + optimization=optimization, + optimization_args=optimization_args, expansion_by_species_method=expansion_by_species_method, global_species=global_species, compute_gradients=compute_gradients, + cutoff_function_parameters=cutoff_function_parameters, coefficient_subselection=coefficient_subselection, ) - if self.hypers["coefficient_subselection"] is None: - del self.hypers["coefficient_subselection"] - - self.cutoff_function_parameters = deepcopy(cutoff_function_parameters) - cutoff_function_parameters.update( - interaction_cutoff=interaction_cutoff, - cutoff_smooth_width=cutoff_smooth_width, - ) - cutoff_function = cutoff_function_dict_switch( - cutoff_function_type, **cutoff_function_parameters - ) - - gaussian_density = dict( - type=gaussian_sigma_type, - gaussian_sigma=dict(value=gaussian_sigma_constant, unit="AA"), - ) - optimization = check_optimization_for_spherical_representations( - optimization, optimization_args - ) - - radial_contribution = dict(type=radial_basis, optimization=optimization) - - self.update_hyperparameters( - cutoff_function=cutoff_function, - gaussian_density=gaussian_density, - radial_contribution=radial_contribution, - ) - - if soap_type == "RadialSpectrum": - self.update_hyperparameters(max_angular=0) self.nl_options = [ dict(name="centers", args=[]), @@ -287,11 +281,66 @@ class documentation dict(name="centercontribution", args=dict()), dict(name="strict", args=dict(cutoff=interaction_cutoff)), ] - self.rep_options = dict(name=self.name, args=[self.hypers]) + self._representation = CalculatorFactory(self.rep_options) + + #self.update_hyperparameters( + # max_radial=max_radial, + # max_angular=max_angular, + # soap_type=soap_type, + # normalize=normalize, + # inversion_symmetry=inversion_symmetry, + # expansion_by_species_method=expansion_by_species_method, + # global_species=global_species, + # compute_gradients=compute_gradients, + # coefficient_subselection=coefficient_subselection, + #) + + #if self.hypers["coefficient_subselection"] is None: + # del self.hypers["coefficient_subselection"] + + #self.cutoff_function_parameters = deepcopy(cutoff_function_parameters) + #cutoff_function_parameters.update( + # interaction_cutoff=interaction_cutoff, + # cutoff_smooth_width=cutoff_smooth_width, + #) + #cutoff_function = cutoff_function_dict_switch( + # cutoff_function_type, **cutoff_function_parameters + #) + + #gaussian_density = dict( + # type=gaussian_sigma_type, + # gaussian_sigma=dict(value=gaussian_sigma_constant, unit="AA"), + #) + #optimization = check_optimization_for_spherical_representations( + # optimization, optimization_args + #) + + #radial_contribution = dict(type=radial_basis, optimization=optimization) + + #self.update_hyperparameters( + # cutoff_function=cutoff_function, + # gaussian_density=gaussian_density, + # radial_contribution=radial_contribution, + #) + + #if soap_type == "RadialSpectrum": + # self.update_hyperparameters(max_angular=0) + + #self.nl_options = [ + # dict(name="centers", args=[]), + # dict(name="neighbourlist", args=dict(cutoff=interaction_cutoff)), + # dict(name="centercontribution", args=dict()), + # dict(name="strict", args=dict(cutoff=interaction_cutoff)), + #] + + #self.rep_options = dict(name=self.name, args=[self.hypers]) + + #self._representation = CalculatorFactory(self.rep_options) + def update_hyperparameters(self, **hypers): """Store the given dict of hyperparameters @@ -446,50 +495,11 @@ def get_feature_index_mapping(self, managers): return feature_index_mapping def _get_init_params(self): - gaussian_density = self.hypers["gaussian_density"] - cutoff_function = self.hypers["cutoff_function"] - radial_contribution = self.hypers["radial_contribution"] - - init_params = dict( - interaction_cutoff=cutoff_function["cutoff"]["value"], - cutoff_smooth_width=cutoff_function["smooth_width"]["value"], - max_radial=self.hypers["max_radial"], - max_angular=self.hypers["max_angular"], - soap_type=self.hypers["soap_type"], - inversion_symmetry=self.hypers["inversion_symmetry"], - normalize=self.hypers["normalize"], - expansion_by_species_method=self.hypers["expansion_by_species_method"], - global_species=self.hypers["global_species"], - compute_gradients=self.hypers["compute_gradients"], - gaussian_sigma_type=gaussian_density["type"], - gaussian_sigma_constant=gaussian_density["gaussian_sigma"]["value"], - cutoff_function_type=cutoff_function["type"], - radial_basis=radial_contribution["type"], - optimization=radial_contribution["optimization"], - cutoff_function_parameters=self.cutoff_function_parameters, - ) - if "coefficient_subselection" in self.hypers: - init_params["coefficient_subselection"] = self.hypers[ - "coefficient_subselection" - ] - return init_params + return self.hypers def _set_data(self, data): super()._set_data(data) - # allows to load deprecated models - if "cpp_representation" in data.keys(): - self._representation = self._representation.from_dict( - data["cpp_representation"] - ) - else: - print( - "WARNING: a deprecated model was loaded. Key " - "'cpp_representation' was not found in model. Please dump and " - "reload the model to update it. The model parameters will not " - "change, only the format." - ) def _get_data(self): data = super()._get_data() - data.update(cpp_representation=self._representation.to_dict()) return data diff --git a/src/rascal/representations/calculator_spherical_expansion.hh b/src/rascal/representations/calculator_spherical_expansion.hh index e654e450d..95b143703 100644 --- a/src/rascal/representations/calculator_spherical_expansion.hh +++ b/src/rascal/representations/calculator_spherical_expansion.hh @@ -1630,8 +1630,16 @@ namespace rascal { "environment wise"); if (hypers.count("global_species")) { - Key_t species{json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "global_species")}; + Key_t species = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "global_species"); + if (species.size() == 0 && this->expansion_by_species == "user defined") { + std::stringstream err_str{}; + err_str << "expansion_by_species is 'user defined'" + << " but global_species is empty" + << " at file " << __FILENAME__ << ":" << __LINE__ + << std::endl; + throw std::logic_error(err_str.str()); + } for (const auto & sp : species) { this->global_species.insert({sp}); } diff --git a/src/rascal/representations/calculator_spherical_invariants.hh b/src/rascal/representations/calculator_spherical_invariants.hh index 894b88be8..64b5a506e 100644 --- a/src/rascal/representations/calculator_spherical_invariants.hh +++ b/src/rascal/representations/calculator_spherical_invariants.hh @@ -333,12 +333,20 @@ namespace rascal { using internal::SphericalInvariantsType; this->type = SphericalInvariantsType::PowerSpectrum; + json coefficient_subselection; + bool is_coefficient_subselection_set{false}; if (hypers.count("coefficient_subselection")) { - this->is_sparsified = true; - - json coefficient_subselection = + coefficient_subselection = json_io::template read_hyperparameter( __FILENAME__, __LINE__, hypers, "coefficient_subselection"); + if (coefficient_subselection.size() != 0) { + is_coefficient_subselection_set = true; + } + } + + if (is_coefficient_subselection_set) { + this->is_sparsified = true; + // get the indices of the subselected PowerSpectrum coefficients: // p_{abn_1n_2l} where a and b refer to atomic species and should be // lexicographically sorted so that a <= b, n_1 and n_2 refer to diff --git a/tests/python/python_models_test.py b/tests/python/python_models_test.py index 05d852ce2..370e34e8b 100644 --- a/tests/python/python_models_test.py +++ b/tests/python/python_models_test.py @@ -132,21 +132,7 @@ def test_numerical_kernel_stress(self): # a general function transformation c++ parameters to # python would be more suitable here # future work - calculator = SphericalInvariants( - soap_type=hypers["soap_type"], - radial_basis=hypers["radial_contribution"]["type"], - max_radial=hypers["max_radial"], - max_angular=hypers["max_angular"], - cutoff_function_type=hypers["cutoff_function"]["type"], - interaction_cutoff=hypers["cutoff_function"]["cutoff"]["value"], - cutoff_smooth_width=hypers["cutoff_function"]["smooth_width"]["value"], - gaussian_sigma_type=hypers["gaussian_density"]["type"], - gaussian_sigma_constant=hypers["gaussian_density"]["gaussian_sigma"][ - "value" - ], - compute_gradients=hypers["compute_gradients"], - normalize=hypers["normalize"], - ) + calculator = SphericalInvariants(**hypers) kernel = Kernel(calculator, kernel_type="Sparse", **kernel_input["kernel"]) for j in range(len(frames)): # we do this frame by frame to be able to use the function From f4dcde94f485853b4af1cae381343565c5632486 Mon Sep 17 00:00:00 2001 From: alexgo Date: Wed, 1 Dec 2021 10:13:50 +0100 Subject: [PATCH 09/18] cleaning commented code --- .../representations/spherical_invariants.py | 55 ------------------- tests/test_cutoff_functions.cc | 30 ---------- 2 files changed, 85 deletions(-) diff --git a/bindings/rascal/representations/spherical_invariants.py b/bindings/rascal/representations/spherical_invariants.py index 82a9ecaf9..046cae799 100644 --- a/bindings/rascal/representations/spherical_invariants.py +++ b/bindings/rascal/representations/spherical_invariants.py @@ -286,61 +286,6 @@ class documentation self._representation = CalculatorFactory(self.rep_options) - - #self.update_hyperparameters( - # max_radial=max_radial, - # max_angular=max_angular, - # soap_type=soap_type, - # normalize=normalize, - # inversion_symmetry=inversion_symmetry, - # expansion_by_species_method=expansion_by_species_method, - # global_species=global_species, - # compute_gradients=compute_gradients, - # coefficient_subselection=coefficient_subselection, - #) - - #if self.hypers["coefficient_subselection"] is None: - # del self.hypers["coefficient_subselection"] - - #self.cutoff_function_parameters = deepcopy(cutoff_function_parameters) - #cutoff_function_parameters.update( - # interaction_cutoff=interaction_cutoff, - # cutoff_smooth_width=cutoff_smooth_width, - #) - #cutoff_function = cutoff_function_dict_switch( - # cutoff_function_type, **cutoff_function_parameters - #) - - #gaussian_density = dict( - # type=gaussian_sigma_type, - # gaussian_sigma=dict(value=gaussian_sigma_constant, unit="AA"), - #) - #optimization = check_optimization_for_spherical_representations( - # optimization, optimization_args - #) - - #radial_contribution = dict(type=radial_basis, optimization=optimization) - - #self.update_hyperparameters( - # cutoff_function=cutoff_function, - # gaussian_density=gaussian_density, - # radial_contribution=radial_contribution, - #) - - #if soap_type == "RadialSpectrum": - # self.update_hyperparameters(max_angular=0) - - #self.nl_options = [ - # dict(name="centers", args=[]), - # dict(name="neighbourlist", args=dict(cutoff=interaction_cutoff)), - # dict(name="centercontribution", args=dict()), - # dict(name="strict", args=dict(cutoff=interaction_cutoff)), - #] - - #self.rep_options = dict(name=self.name, args=[self.hypers]) - - #self._representation = CalculatorFactory(self.rep_options) - def update_hyperparameters(self, **hypers): """Store the given dict of hyperparameters diff --git a/tests/test_cutoff_functions.cc b/tests/test_cutoff_functions.cc index a8f87fabd..c48d89917 100644 --- a/tests/test_cutoff_functions.cc +++ b/tests/test_cutoff_functions.cc @@ -44,11 +44,6 @@ namespace rascal { std::vector fc_hypers{{{"cutoff_function_type", "ShiftedCosine"}, {"interaction_cutoff", 3.0}, {"cutoff_smooth_width", 0.5}}}; - // R"({ - // "type": "ShiftedCosine", - // "cutoff": {"value": 3, "unit": "AA"}, - // "smooth_width": {"value": 0.5, "unit": "AA"} - // })"_json, using Cutoff_t = internal::CutoffFunction; @@ -90,31 +85,6 @@ namespace rascal { {"cutoff_function_parameters", {{"rate", 0}, {"scale", 2}, {"exponent", 0}}}}}; - // R"({ - // "type": "RadialScaling", - // "cutoff": {"value": 3, "unit": "AA"}, - // "smooth_width": {"value": 0.5, "unit": "AA"}, - // "rate": {"value": 1, "unit": "AA"}, - // "scale": {"value": 2, "unit": "AA"} , - // "exponent": {"value": 3, "unit": ""} - // })"_json, - // R"({ - // "type": "RadialScaling", - // "cutoff": {"value": 3, "unit": "AA"}, - // "smooth_width": {"value": 0.5, "unit": "AA"}, - // "rate": {"value": 0, "unit": "AA"}, - // "scale": {"value": 2, "unit": "AA"} , - // "exponent": {"value": 3, "unit": ""} - // })"_json, - // R"({ - // "type": "RadialScaling", - // "cutoff": {"value": 3, "unit": "AA"}, - // "smooth_width": {"value": 0.5, "unit": "AA"}, - // "rate": {"value": 0, "unit": "AA"}, - // "scale": {"value": 2, "unit": "AA"} , - // "exponent": {"value": 0, "unit": ""} - // })"_json, - //}; using Cutoff_t = internal::CutoffFunction; From 9061314988ba2e15ed7f7ca3b92c424fc97384d4 Mon Sep 17 00:00:00 2001 From: alexgo Date: Wed, 1 Dec 2021 11:05:10 +0100 Subject: [PATCH 10/18] fix global species --- bindings/rascal/models/kernels.py | 1 + .../representations/spherical_covariants.py | 46 ++++++------------- .../representations/spherical_expansion.py | 22 +++++---- .../representations/spherical_invariants.py | 33 +++++++------ .../calculator_spherical_expansion.hh | 3 +- .../calculator_spherical_invariants.hh | 5 +- 6 files changed, 50 insertions(+), 60 deletions(-) diff --git a/bindings/rascal/models/kernels.py b/bindings/rascal/models/kernels.py index 9db56e154..732f623f4 100644 --- a/bindings/rascal/models/kernels.py +++ b/bindings/rascal/models/kernels.py @@ -15,6 +15,7 @@ LOGGER = logging.getLogger(__name__) + class Kernel(BaseIO): """ diff --git a/bindings/rascal/representations/spherical_covariants.py b/bindings/rascal/representations/spherical_covariants.py index 32c61ef6e..b92327c30 100644 --- a/bindings/rascal/representations/spherical_covariants.py +++ b/bindings/rascal/representations/spherical_covariants.py @@ -175,14 +175,19 @@ class documentation if global_species is None: global_species = [] - elif not isinstance(global_species, list): - # TODO(veit) I think we should raise an error in this case, maybe we can still make an integer to a list, but in any other case I find it dangours to make a list out of this. I did not change this to ensure backwards compatibility + elif isinstance(global_species, int): global_species = list(global_species) + elif not (isinstance(global_species, list)): + raise ValueError( + "'global_species' should be None, an integer, an empty list or a list of atomic numbers" + ) if cutoff_function_parameters is None: cutoff_function_parameters = dict() elif not isinstance(cutoff_function_parameters, dict): - raise ValueError("\'cutoff_function_parameters\' should be None or a dictionary with \'rate\', \'scale\' and \'expontent\'") + raise ValueError( + "'cutoff_function_parameters' should be None or a dictionary with 'rate', 'scale' and 'expontent'" + ) self.hypers = dict( interaction_cutoff=interaction_cutoff, @@ -199,13 +204,11 @@ class documentation optimization=optimization, optimization_args=optimization_args, covariant_lambda=covariant_lambda, - expansion_by_species_method=expansion_by_species_method, global_species=global_species, compute_gradients=compute_gradients, cutoff_function_parameters=cutoff_function_parameters, ) - self.nl_options = [ dict(name="centers", args=[]), dict(name="neighbourlist", args=dict(cutoff=interaction_cutoff)), @@ -213,7 +216,6 @@ class documentation dict(name="strict", args=dict(cutoff=interaction_cutoff)), ] self.rep_options = dict(name=self.name, args=[self.hypers]) - self._representation = CalculatorFactory(self.rep_options) @@ -226,22 +228,22 @@ def update_hyperparameters(self, **hypers): allowed_keys = { "interaction_cutoff", "cutoff_smooth_width", + "cutoff_function_type", "max_radial", "max_angular", + "radial_basis", + "optimization", "gaussian_sigma_type", "gaussian_sigma_constant", "soap_type", "inversion_symmetry", - "covariant_lambda", - "cutoff_function", "normalize", - "gaussian_density", - "radial_contribution", "cutoff_function_parameters", + "global_species", + "covariant_lambda", } hypers_clean = {key: hypers[key] for key in hypers if key in allowed_keys} self.hypers.update(hypers_clean) - return def transform(self, frames): """Compute the representation. @@ -351,27 +353,7 @@ def get_keys(self, species): return keys def _get_init_params(self): - gaussian_density = self.hypers["gaussian_density"] - cutoff_function = self.hypers["cutoff_function"] - radial_contribution = self.hypers["radial_contribution"] - - init_params = dict( - interaction_cutoff=cutoff_function["cutoff"]["value"], - cutoff_smooth_width=cutoff_function["smooth_width"]["value"], - max_radial=self.hypers["max_radial"], - max_angular=self.hypers["max_angular"], - soap_type=self.hypers["soap_type"], - inversion_symmetry=self.hypers["inversion_symmetry"], - normalize=self.hypers["normalize"], - gaussian_sigma_type=gaussian_density["type"], - gaussian_sigma_constant=gaussian_density["gaussian_sigma"]["value"], - lam=self.hypers["covariant_lambda"], - cutoff_function_type=cutoff_function["type"], - radial_basis=radial_contribution["type"], - optimization=radial_contribution["optimization"], - cutoff_function_parameters=self.cutoff_function_parameters, - ) - return init_params + return self.hypers def _set_data(self, data): super()._set_data(data) diff --git a/bindings/rascal/representations/spherical_expansion.py b/bindings/rascal/representations/spherical_expansion.py index 66f36a3c0..be79188b5 100644 --- a/bindings/rascal/representations/spherical_expansion.py +++ b/bindings/rascal/representations/spherical_expansion.py @@ -195,13 +195,19 @@ class documentation if global_species is None: global_species = [] - elif not isinstance(global_species, list): - raise ValueError("\'global_species\' should be None, empty list, or list of atomic numbers") + elif isinstance(global_species, int): + global_species = list(global_species) + elif not (isinstance(global_species, list)): + raise ValueError( + "'global_species' should be None, an integer, an empty list or a list of atomic numbers" + ) if cutoff_function_parameters is None: cutoff_function_parameters = dict() elif not isinstance(cutoff_function_parameters, dict): - raise ValueError("\'cutoff_function_parameters\' should be None or a dictionary with \'rate\', \'scale\' and \'expontent\'") + raise ValueError( + "'cutoff_function_parameters' should be None or a dictionary with 'rate', 'scale' and 'expontent'" + ) self.hypers = dict( interaction_cutoff=interaction_cutoff, @@ -220,7 +226,6 @@ class documentation cutoff_function_parameters=cutoff_function_parameters, ) - self.nl_options = [ dict(name="centers", args=[]), dict(name="neighbourlist", args=dict(cutoff=interaction_cutoff)), @@ -228,7 +233,6 @@ class documentation dict(name="strict", args=dict(cutoff=interaction_cutoff)), ] self.rep_options = dict(name=self.name, args=[self.hypers]) - self._representation = CalculatorFactory(self.rep_options) @@ -241,17 +245,17 @@ def update_hyperparameters(self, **hypers): allowed_keys = { "interaction_cutoff", "cutoff_smooth_width", + "cutoff_function_type", "max_radial", "max_angular", + "radial_basis", + "optimization", "gaussian_sigma_type", "gaussian_sigma_constant", - "gaussian_density", - "cutoff_function", - "radial_contribution", - "compute_gradients", "cutoff_function_parameters", "expansion_by_species_method", "global_species", + "compute_gradients", } hypers_clean = {key: hypers[key] for key in hypers if key in allowed_keys} self.hypers.update(hypers_clean) diff --git a/bindings/rascal/representations/spherical_invariants.py b/bindings/rascal/representations/spherical_invariants.py index 046cae799..02049cce2 100644 --- a/bindings/rascal/representations/spherical_invariants.py +++ b/bindings/rascal/representations/spherical_invariants.py @@ -218,12 +218,12 @@ def __init__( inversion_symmetry=True, radial_basis="GTO", normalize=True, + compute_gradients=False, + expansion_by_species_method="environment wise", optimization=None, optimization_args=None, - expansion_by_species_method="environment wise", global_species=None, - compute_gradients=False, - cutoff_function_parameters=dict(), + cutoff_function_parameters=None, coefficient_subselection=None, ): """Construct a SphericalExpansion representation @@ -239,19 +239,26 @@ class documentation if global_species is None: global_species = [] - elif not isinstance(global_species, list): - # TODO(veit) I think we should raise an error in this case, maybe we can still make an integer to a list, but in any other case I find it dangours to make a list out of this. I did not change this to ensure backwards compatibility + elif isinstance(global_species, int): global_species = list(global_species) + elif not (isinstance(global_species, list)): + raise ValueError( + "'global_species' should be None, an integer, an empty list or a list of atomic numbers" + ) if cutoff_function_parameters is None: cutoff_function_parameters = dict() elif not isinstance(cutoff_function_parameters, dict): - raise ValueError("\'cutoff_function_parameters\' should be None or a dictionary with \'rate\', \'scale\' and \'expontent\'") + raise ValueError( + "'cutoff_function_parameters' should be None or a dictionary with 'rate', 'scale' and 'expontent'" + ) if coefficient_subselection is None: coefficient_subselection = dict() elif not isinstance(coefficient_subselection, dict): - raise ValueError("\'coefficient_subselection\' should be None or a dictionary with \'a\', \'b\', \'n1\', \'n2\' and \'l\'") + raise ValueError( + "'coefficient_subselection' should be None or a dictionary with 'a', 'b', 'n1', 'n2' and 'l'" + ) self.hypers = dict( interaction_cutoff=interaction_cutoff, @@ -274,7 +281,6 @@ class documentation coefficient_subselection=coefficient_subselection, ) - self.nl_options = [ dict(name="centers", args=[]), dict(name="neighbourlist", args=dict(cutoff=interaction_cutoff)), @@ -283,7 +289,6 @@ class documentation ] self.rep_options = dict(name=self.name, args=[self.hypers]) - self._representation = CalculatorFactory(self.rep_options) def update_hyperparameters(self, **hypers): @@ -295,26 +300,24 @@ def update_hyperparameters(self, **hypers): allowed_keys = { "interaction_cutoff", "cutoff_smooth_width", + "cutoff_function_type", "max_radial", "max_angular", + "radial_basis", + "optimization", "gaussian_sigma_type", "gaussian_sigma_constant", "soap_type", "inversion_symmetry", - "cutoff_function", "normalize", - "gaussian_density", - "radial_contribution", "cutoff_function_parameters", "expansion_by_species_method", - "compute_gradients", "global_species", + "compute_gradients", "coefficient_subselection", } hypers_clean = {key: hypers[key] for key in hypers if key in allowed_keys} - self.hypers.update(hypers_clean) - return def transform(self, frames): """Compute the representation. diff --git a/src/rascal/representations/calculator_spherical_expansion.hh b/src/rascal/representations/calculator_spherical_expansion.hh index 95b143703..e76436ed4 100644 --- a/src/rascal/representations/calculator_spherical_expansion.hh +++ b/src/rascal/representations/calculator_spherical_expansion.hh @@ -1632,7 +1632,8 @@ namespace rascal { if (hypers.count("global_species")) { Key_t species = json_io::template read_hyperparameter( __FILENAME__, __LINE__, hypers, "global_species"); - if (species.size() == 0 && this->expansion_by_species == "user defined") { + if (species.size() == 0 && + this->expansion_by_species == "user defined") { std::stringstream err_str{}; err_str << "expansion_by_species is 'user defined'" << " but global_species is empty" diff --git a/src/rascal/representations/calculator_spherical_invariants.hh b/src/rascal/representations/calculator_spherical_invariants.hh index 64b5a506e..0ee48b8a2 100644 --- a/src/rascal/representations/calculator_spherical_invariants.hh +++ b/src/rascal/representations/calculator_spherical_invariants.hh @@ -336,9 +336,8 @@ namespace rascal { json coefficient_subselection; bool is_coefficient_subselection_set{false}; if (hypers.count("coefficient_subselection")) { - coefficient_subselection = - json_io::template read_hyperparameter( - __FILENAME__, __LINE__, hypers, "coefficient_subselection"); + coefficient_subselection = json_io::template read_hyperparameter( + __FILENAME__, __LINE__, hypers, "coefficient_subselection"); if (coefficient_subselection.size() != 0) { is_coefficient_subselection_set = true; } From ad67a18bb850a3c936279de6b0e28747914f8b88 Mon Sep 17 00:00:00 2001 From: alexgo Date: Wed, 1 Dec 2021 11:14:18 +0100 Subject: [PATCH 11/18] reset simple_gap_model json --- reference_data/tests_only/simple_gap_model.json | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/reference_data/tests_only/simple_gap_model.json b/reference_data/tests_only/simple_gap_model.json index b800505be..207836a14 100644 --- a/reference_data/tests_only/simple_gap_model.json +++ b/reference_data/tests_only/simple_gap_model.json @@ -5152,12 +5152,7 @@ "description": "Simple fit of methane dimer energies, just for testing. Generated by fit_gap.py on 2021-03-25 at 13:17:33 CET", "kernel": { "class_name": "Kernel", - "data": { - "cpp_kernel": { - "name": "GAP", - "target_type": "Structure", - "zeta": 2 - } + "data": {} }, "init_params": { "kernel_type": "Sparse", From 07e8ecb953b46c616d04a2109a29af50a7a23d26 Mon Sep 17 00:00:00 2001 From: alexgo Date: Wed, 1 Dec 2021 12:28:43 +0100 Subject: [PATCH 12/18] order representation input parameters the same way --- .../representations/spherical_covariants.py | 25 ++++++++++--------- .../representations/spherical_expansion.py | 17 +++++++------ .../representations/spherical_invariants.py | 4 +-- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/bindings/rascal/representations/spherical_covariants.py b/bindings/rascal/representations/spherical_covariants.py index b92327c30..ab946a935 100644 --- a/bindings/rascal/representations/spherical_covariants.py +++ b/bindings/rascal/representations/spherical_covariants.py @@ -154,14 +154,15 @@ def __init__( gaussian_sigma_type="Constant", gaussian_sigma_constant=0.3, cutoff_function_type="ShiftedCosine", - normalize=True, - radial_basis="GTO", - optimization=None, - optimization_args=None, soap_type="LambdaSpectrum", inversion_symmetry=True, + radial_basis="GTO", + normalize=True, covariant_lambda=0, - cutoff_function_parameters=dict(), + optimization=None, + optimization_args=None, + global_species=None, + cutoff_function_parameters=None, ): """Construct a SphericalExpansion representation @@ -201,11 +202,10 @@ class documentation inversion_symmetry=inversion_symmetry, radial_basis=radial_basis, normalize=normalize, + covariant_lambda=covariant_lambda, optimization=optimization, optimization_args=optimization_args, - covariant_lambda=covariant_lambda, global_species=global_species, - compute_gradients=compute_gradients, cutoff_function_parameters=cutoff_function_parameters, ) @@ -228,20 +228,21 @@ def update_hyperparameters(self, **hypers): allowed_keys = { "interaction_cutoff", "cutoff_smooth_width", - "cutoff_function_type", "max_radial", "max_angular", - "radial_basis", - "optimization", "gaussian_sigma_type", "gaussian_sigma_constant", + "cutoff_function_type", "soap_type", "inversion_symmetry", + "radial_basis", "normalize", - "cutoff_function_parameters", - "global_species", "covariant_lambda", + "optimization", + "global_species", + "cutoff_function_parameters", } + hypers_clean = {key: hypers[key] for key in hypers if key in allowed_keys} self.hypers.update(hypers_clean) diff --git a/bindings/rascal/representations/spherical_expansion.py b/bindings/rascal/representations/spherical_expansion.py index be79188b5..5503ec396 100644 --- a/bindings/rascal/representations/spherical_expansion.py +++ b/bindings/rascal/representations/spherical_expansion.py @@ -174,12 +174,12 @@ def __init__( gaussian_sigma_constant=0.3, cutoff_function_type="ShiftedCosine", radial_basis="GTO", + compute_gradients=False, + expansion_by_species_method="environment wise", optimization=None, optimization_args=None, - expansion_by_species_method="environment wise", global_species=None, - compute_gradients=False, - cutoff_function_parameters=dict(), + cutoff_function_parameters=None, ): """Construct a SphericalExpansion representation @@ -218,11 +218,11 @@ class documentation gaussian_sigma_constant=gaussian_sigma_constant, cutoff_function_type=cutoff_function_type, radial_basis=radial_basis, + compute_gradients=compute_gradients, + expansion_by_species_method=expansion_by_species_method, optimization=optimization, optimization_args=optimization_args, - expansion_by_species_method=expansion_by_species_method, global_species=global_species, - compute_gradients=compute_gradients, cutoff_function_parameters=cutoff_function_parameters, ) @@ -245,13 +245,14 @@ def update_hyperparameters(self, **hypers): allowed_keys = { "interaction_cutoff", "cutoff_smooth_width", - "cutoff_function_type", "max_radial", "max_angular", - "radial_basis", - "optimization", "gaussian_sigma_type", "gaussian_sigma_constant", + "cutoff_function_type", + "radial_basis", + "compute_gradients", + "optimization", "cutoff_function_parameters", "expansion_by_species_method", "global_species", diff --git a/bindings/rascal/representations/spherical_invariants.py b/bindings/rascal/representations/spherical_invariants.py index 02049cce2..6652b383d 100644 --- a/bindings/rascal/representations/spherical_invariants.py +++ b/bindings/rascal/representations/spherical_invariants.py @@ -272,11 +272,11 @@ class documentation inversion_symmetry=inversion_symmetry, radial_basis=radial_basis, normalize=normalize, + compute_gradients=compute_gradients, + expansion_by_species_method=expansion_by_species_method, optimization=optimization, optimization_args=optimization_args, - expansion_by_species_method=expansion_by_species_method, global_species=global_species, - compute_gradients=compute_gradients, cutoff_function_parameters=cutoff_function_parameters, coefficient_subselection=coefficient_subselection, ) From fec2c0cccda55240d87859b34ce930453aff2771 Mon Sep 17 00:00:00 2001 From: alexgo Date: Wed, 1 Dec 2021 12:29:30 +0100 Subject: [PATCH 13/18] fix typo --- reference_data/tests_only/simple_gap_model.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reference_data/tests_only/simple_gap_model.json b/reference_data/tests_only/simple_gap_model.json index 207836a14..2dcb57db9 100644 --- a/reference_data/tests_only/simple_gap_model.json +++ b/reference_data/tests_only/simple_gap_model.json @@ -5152,8 +5152,7 @@ "description": "Simple fit of methane dimer energies, just for testing. Generated by fit_gap.py on 2021-03-25 at 13:17:33 CET", "kernel": { "class_name": "Kernel", - "data": {} - }, + "data": {}, "init_params": { "kernel_type": "Sparse", "name": "GAP", From 6213b64e246a678ba9d569d862a02685a7d09cff Mon Sep 17 00:00:00 2001 From: alexgo Date: Mon, 6 Dec 2021 17:00:21 +0100 Subject: [PATCH 14/18] adapt changed cpp hyperparamaters in benchmarks --- .../benchmarks/benchmark_interpolator.hh | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/performance/benchmarks/benchmark_interpolator.hh b/performance/benchmarks/benchmark_interpolator.hh index 8dc2678d9..de70ecfd3 100644 --- a/performance/benchmarks/benchmark_interpolator.hh +++ b/performance/benchmarks/benchmark_interpolator.hh @@ -447,13 +447,12 @@ namespace rascal { data, "radial_angular", state); this->max_radial = std::get<0>(radial_angular); this->max_angular = std::get<1>(radial_angular); - json fc_hypers{{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.5}, {"unit", "A"}}}}; - json hypers{ - {"gaussian_density", fc_hypers}, - {"max_radial", this->max_radial}, - {"max_angular", this->max_angular}, - {"cutoff_function", {{"cutoff", {{"value", 2.0}, {"unit", "A"}}}}}}; + + json hypers{{"gaussian_sigma_type", "Constant"}, + {"gaussian_sigma_constant", 0.5}, + {"max_radial", this->max_radial}, + {"max_angular", this->max_angular}, + {"interaction_cutoff", 2.0}}; // we cannot copy radial contribution to the lambda function, because // the copying has been disabled this->radial_contr = @@ -567,24 +566,21 @@ namespace rascal { {"compute_gradients", this->compute_gradients}, {"soap_type", "PowerSpectrum"}}; - json fc_hypers{{"type", "ShiftedCosine"}, - {"cutoff", {{"value", this->cutoff}, {"unit", "AA"}}}, - {"smooth_width", {{"value", 0.}, {"unit", "AA"}}}}; - json sigma_hypers{{"type", "Constant"}, - {"gaussian_sigma", {{"value", 0.4}, {"unit", "AA"}}}}; + hypers["cutoff_function_type"] = "ShiftedCosine"; + hypers["interaction_cutoff"] = this->cutoff; + hypers["cutoff_smooth_width"] = 0.; - hypers["cutoff_function"] = fc_hypers; - hypers["gaussian_density"] = sigma_hypers; + hypers["gaussian_sigma_type"] = "Constant"; + hypers["gaussian_sigma_constant"] = 0.4; if (this->use_interpolator) { - hypers["radial_contribution"] = { - {"type", "GTO"}, - {"optimization", - {{"type", "Spline"}, - {"accuracy", this->error_bound}, - {"range", {{"begin", 0.}, {"end", cutoff}}}}}}; + hypers["radial_basis"] = "GTO"; + hypers["optimization"] = { + {{"Spline", + {{"accuracy", this->error_bound}, + {"range", {{"begin", 0.}, {"end", cutoff}}}}}}}; } else { - hypers["radial_contribution"] = {{"type", "GTO"}}; + hypers["radial_basis"] = "GTO"; } this->hypers = hypers; this->representation_ptr = std::make_shared(hypers); From 4d25fa27839bbe887352244f410d9358e7804cab Mon Sep 17 00:00:00 2001 From: alexgo Date: Mon, 6 Dec 2021 17:00:42 +0100 Subject: [PATCH 15/18] improved `read_hyperparameter` documentation and parameter names` --- src/rascal/utils/json_io.hh | 75 +++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/src/rascal/utils/json_io.hh b/src/rascal/utils/json_io.hh index 66080f421..eb4e83860 100644 --- a/src/rascal/utils/json_io.hh +++ b/src/rascal/utils/json_io.hh @@ -367,30 +367,34 @@ namespace rascal { const json & parameter); /** - * Returns a typed property of the given name. + * Reads a hyperparameter from a json and handles the error properly in case + * of failure * - * @tparam T return type. Return type must support << operator. + * @tparam Hyperparameter_T the type of the returned hyperparameter. The + * type must support the << operator. * - * @param hypers - * @param key - * @param default_value is a unique_ptr to allow hyperparamaters with no - * default value in which case it is null ptr. Starting with C++17 one could - * solve this more transparent with std::optional. + * @param filename the name of the file where the function is invoked + * @param line the line number where the function is invoked + * @param hypers the json with all hyperparameters + * @param key the name of the hyperparameter in the json `hypers` * - * @throw runtime_error when value cannot be read from hypers - * @throw runtime_error when key is not present in hypers and no - * default_value is null ptr + * @throw runtime_error when the hyperparameter could not be read, because + * e.g. the `Hyperparameters_T` does not match hyperparameter type + * @throw runtime_error when the hyperparameter was not found in the json + * `hypers` + * + * @return the hyperparamater described by the `key` in the json `hypers` */ - template - T read_hyperparameter(const char * file, int line, const json & hypers, - std::string key) { + template + Hyperparameter_T read_hyperparameter(const char * filename, int line, + const json & hypers, std::string key) { if (hypers.count(key)) { try { - return hypers.at(key).get(); + return hypers.at(key).get(); } catch (const std::exception & e) { std::stringstream error{}; error << "Reading '" << key << "' from json hypers failed " - << "at file " << file << ":" << line << "\n" + << "at file " << filename << ":" << line << "\n" << " what(): " << e.what() << std::endl; throw std::runtime_error(error.str()); } @@ -398,30 +402,53 @@ namespace rascal { std::stringstream error{}; error << "Reading '" << key << "' from json hypers failed. No '" << key << "' was found in json hypers " - << "at file " << file << ":" << line << std::endl; + << "at file " << filename << ":" << line << std::endl; throw std::runtime_error(error.str()); } } - template - T read_hyperparameter(const char * file, int line, const json & hypers, - std::string key, T default_value) { + /** + * Reads a hyperparameter from a json and handles the error properly in case + * of failure + * + * @tparam Hyperparameter_T the type of the returned hyperparameter. The + * type must support the << operator. + * + * @param filename the name of the file where the function is invoked + * @param line the line number where the function is invoked + * @param hypers the json with all hyperparameters + * @param key the name of the hyperparameter in the json `hypers` + * @param default_hyperparameter this value is not used when the + * hyperparameter was not found in the json `hypers` + * + * @throw runtime_error when the hyperparameter could not be read, because + * e.g. the `Hyperparameters_T` does not match hyperparameter type + * @throw warning when key was not found in the json and + * `default_hyperparameter` is used + * + * @return the hyperparamater described by the `key` in the json `hypers` + */ + template + Hyperparameter_T + read_hyperparameter(const char * filename, int line, const json & hypers, + std::string key, + Hyperparameter_T default_hyperparameter) { if (hypers.count(key)) { try { - return hypers.at(key).get(); + return hypers.at(key).get(); } catch (const std::exception & e) { std::stringstream error{}; error << "Reading '" << key << "' from json hypers failed " - << "at file " << file << ":" << line << "\n" + << "at file " << filename << ":" << line << "\n" << " what(): " << e.what() << std::endl; throw std::runtime_error(error.str()); } } else { std::cout << "WARNING: Reading '" << key << "' from json hypers failed. Setting " << key << " to '" - << default_value << "' " - << "at file " << file << ":" << line << std::endl; - return default_value; + << default_hyperparameter << "' " + << "at file " << filename << ":" << line << std::endl; + return default_hyperparameter; } } } // namespace json_io From 93da3ce9a86378ab4732fd2f7bd8311fd3e90c35 Mon Sep 17 00:00:00 2001 From: alexgo Date: Mon, 6 Dec 2021 17:00:56 +0100 Subject: [PATCH 16/18] fix undef SOURCE_PATH_SIZE for clang compilers --- .../representations/calculator_spherical_expansion.hh | 11 ++++++++++- .../calculator_spherical_invariants.hh | 11 ++++++++++- src/rascal/representations/cutoff_functions.hh | 11 ++++++++++- tests/test_calculator.hh | 11 ++++++++++- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/rascal/representations/calculator_spherical_expansion.hh b/src/rascal/representations/calculator_spherical_expansion.hh index e76436ed4..a10dc14a7 100644 --- a/src/rascal/representations/calculator_spherical_expansion.hh +++ b/src/rascal/representations/calculator_spherical_expansion.hh @@ -31,8 +31,17 @@ #ifndef SRC_RASCAL_REPRESENTATIONS_CALCULATOR_SPHERICAL_EXPANSION_HH_ #define SRC_RASCAL_REPRESENTATIONS_CALCULATOR_SPHERICAL_EXPANSION_HH_ +// This variable stores the length of the absolute path of this file up to the +// librascal directory It is set in the CMakeLists.txt, but for clang > 4 it is +// not stored, so we set it here to zero in this case +#ifndef SOURCE_PATH_SIZE +#define SOURCE_PATH_SIZE 0 +#endif + // relative path of file with respect to librascal directory -#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE) +#ifndef __FILENAME__ +#define __FILENAME__ ((const char *)&__FILE__[SOURCE_PATH_SIZE]) +#endif #include "rascal/math/bessel.hh" #include "rascal/math/gauss_legendre.hh" diff --git a/src/rascal/representations/calculator_spherical_invariants.hh b/src/rascal/representations/calculator_spherical_invariants.hh index 0ee48b8a2..06c0a22f8 100644 --- a/src/rascal/representations/calculator_spherical_invariants.hh +++ b/src/rascal/representations/calculator_spherical_invariants.hh @@ -31,8 +31,17 @@ #ifndef SRC_RASCAL_REPRESENTATIONS_CALCULATOR_SPHERICAL_INVARIANTS_HH_ #define SRC_RASCAL_REPRESENTATIONS_CALCULATOR_SPHERICAL_INVARIANTS_HH_ +// This variable stores the length of the absolute path of this file up to the +// librascal directory It is set in the CMakeLists.txt, but for clang > 4 it is +// not stored, so we set it here to zero in this case +#ifndef SOURCE_PATH_SIZE +#define SOURCE_PATH_SIZE 0 +#endif + // relative path of file with respect to librascal directory -#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE) +#ifndef __FILENAME__ +#define __FILENAME__ ((const char *)&__FILE__[SOURCE_PATH_SIZE]) +#endif #include "rascal/math/utils.hh" #include "rascal/representations/calculator_base.hh" diff --git a/src/rascal/representations/cutoff_functions.hh b/src/rascal/representations/cutoff_functions.hh index e313eb904..47c8c9c3e 100644 --- a/src/rascal/representations/cutoff_functions.hh +++ b/src/rascal/representations/cutoff_functions.hh @@ -29,8 +29,17 @@ #ifndef SRC_RASCAL_REPRESENTATIONS_CUTOFF_FUNCTIONS_HH_ #define SRC_RASCAL_REPRESENTATIONS_CUTOFF_FUNCTIONS_HH_ +// This variable stores the length of the absolute path of this file up to the +// librascal directory It is set in the CMakeLists.txt, but for clang > 4 it is +// not stored, so we set it here to zero in this case +#ifndef SOURCE_PATH_SIZE +#define SOURCE_PATH_SIZE 0 +#endif + // relative path of file with respect to librascal directory -#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE) +#ifndef __FILENAME__ +#define __FILENAME__ ((const char *)&__FILE__[SOURCE_PATH_SIZE]) +#endif #include "rascal/math/utils.hh" #include "rascal/representations/calculator_base.hh" diff --git a/tests/test_calculator.hh b/tests/test_calculator.hh index 7092663b1..6a00634b6 100644 --- a/tests/test_calculator.hh +++ b/tests/test_calculator.hh @@ -29,8 +29,17 @@ #ifndef TESTS_TEST_CALCULATOR_HH_ #define TESTS_TEST_CALCULATOR_HH_ +// This variable stores the length of the absolute path of this file up to the +// librascal directory It is set in the CMakeLists.txt, but for clang > 4 it is +// not stored, so we set it here to zero in this case +#ifndef SOURCE_PATH_SIZE +#define SOURCE_PATH_SIZE 0 +#endif + // relative path of file with respect to librascal directory -#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE) +#ifndef __FILENAME__ +#define __FILENAME__ ((const char *)&__FILE__[SOURCE_PATH_SIZE]) +#endif #include "test_adaptor.hh" #include "test_math.hh" From b9f5decabf8a539e06fd4334db9c5c8fce61181a Mon Sep 17 00:00:00 2001 From: alexgo Date: Mon, 6 Dec 2021 17:17:59 +0100 Subject: [PATCH 17/18] remove remains from first approach --- bindings/rascal/representations/spherical_covariants.py | 3 +-- bindings/rascal/representations/spherical_expansion.py | 3 +-- bindings/rascal/representations/spherical_invariants.py | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bindings/rascal/representations/spherical_covariants.py b/bindings/rascal/representations/spherical_covariants.py index ab946a935..045d27dc0 100644 --- a/bindings/rascal/representations/spherical_covariants.py +++ b/bindings/rascal/representations/spherical_covariants.py @@ -360,5 +360,4 @@ def _set_data(self, data): super()._set_data(data) def _get_data(self): - data = super()._get_data() - return data + return super()._get_data() diff --git a/bindings/rascal/representations/spherical_expansion.py b/bindings/rascal/representations/spherical_expansion.py index 5503ec396..168ec8dd1 100644 --- a/bindings/rascal/representations/spherical_expansion.py +++ b/bindings/rascal/representations/spherical_expansion.py @@ -308,5 +308,4 @@ def _set_data(self, data): super()._set_data(data) def _get_data(self): - data = super()._get_data() - return data + return super()._get_data() diff --git a/bindings/rascal/representations/spherical_invariants.py b/bindings/rascal/representations/spherical_invariants.py index 6652b383d..744d994d1 100644 --- a/bindings/rascal/representations/spherical_invariants.py +++ b/bindings/rascal/representations/spherical_invariants.py @@ -449,5 +449,4 @@ def _set_data(self, data): super()._set_data(data) def _get_data(self): - data = super()._get_data() - return data + return super()._get_data() From 0db77ae5d58626eae7a976f4bb88b5c4c4972df7 Mon Sep 17 00:00:00 2001 From: alexgo Date: Mon, 6 Dec 2021 17:18:12 +0100 Subject: [PATCH 18/18] add new line fo simple gap model --- reference_data/tests_only/simple_gap_model.json | 1 + 1 file changed, 1 insertion(+) diff --git a/reference_data/tests_only/simple_gap_model.json b/reference_data/tests_only/simple_gap_model.json index 2dcb57db9..a9fe797b3 100644 --- a/reference_data/tests_only/simple_gap_model.json +++ b/reference_data/tests_only/simple_gap_model.json @@ -5237,3 +5237,4 @@ "module_name": "rascal.models.krr", "version": "0.1" } +