Commit ed5ff185 authored by Martin Beseda's avatar Martin Beseda
Browse files

[CODE] [ENH] Minor code improvements.

parent aa00b162
......@@ -44,7 +44,6 @@ win_visual_studio_static_local:
- 'rmdir /s /q build external_dependencies/*'
script:
- 'echo %DEPENDENCIES_LINK_TYPE%'
- 'call build_scripts\windows\win_VS_build_x64_release.bat'
# Windows 10
......
......@@ -2,7 +2,7 @@
echo "Generating documentation into folder 'docs'...";
doxygen 2>&1;
cd docs/latex;
cd docs/latex || exit 1;
echo "Building LaTeX documentation../";
make >/dev/null && echo "Documentation was built." || exit -1;
cd ../..;
......@@ -3,10 +3,10 @@
####################
# VALIDATION TESTS #
####################
cd build/examples;
cd build/Examples || exit 1
for f in *; do
echo "Example ${f} starting..."
./${f} || exit 1
"./${f}" || exit 1
done
##############
......@@ -14,6 +14,6 @@ done
##############
for f in build/unit-tests/*_test; do
echo "Test ${f} starting..."
${f} || exit 1
"${f}" || exit 1
done
......@@ -53,14 +53,14 @@ niteration=100
layers_cardinality="100 1"
src_net_file="${home_dir}/nets/he3+.l4n"
target_net_file="${home_dir}/nets/he3+.l4n"
source_data_file="${home_dir}/data/he3+.xyz"
source_data_file="${home_dir}/data/HE4+T1.xyz" #he3+.xyz"
cross_validation_fn="he3+_cross_validation.txt"
out_file="he3+.txt"
echo $niteration $batch_size $tolerance $source_data_file $target_net_file $nlayers $layers_cardinality $nsym_g2 $g2_cutoffs $g2_extensions $g2_shifts $nsym_g5 $g5_cutoffs $g5_extensions $g5_shifts $g5_angles $src_net_file $cross_validation_k $cross_validation_ntests $cross_validation_fn
# mpirun -np 1 -env LD_PRELOAD /apps/tools/valgrind/3.9.0/impi/lib/valgrind/libmpiwrap-amd64-linux.so valgrind --leak-check=full ./acsf $niteration $batch_size $tolerance $source_data_file $target_net_file $nlayers $layers_cardinality $nsym_g2 $g2_cutoffs $g2_extensions $g2_shifts $nsym_g5 $g5_cutoffs $g5_extensions $g5_shifts $g5_angles $src_net_file $cross_validation_k $cross_validation_ntests $cross_validation_fn > out.txt
mpirun -np 1 ./acsf $niteration $batch_size $tolerance $source_data_file $target_net_file $nlayers $layers_cardinality $nsym_g2 $g2_cutoffs $g2_extensions $g2_shifts $nsym_g5 $g5_cutoffs $g5_extensions $g5_shifts $g5_angles $src_net_file $cross_validation_k $cross_validation_ntests $cross_validation_fn
valgrind mpirun -np 1 ./acsf $niteration $batch_size $tolerance $source_data_file $target_net_file $nlayers $layers_cardinality $nsym_g2 $g2_cutoffs $g2_extensions $g2_shifts $nsym_g5 $g5_cutoffs $g5_extensions $g5_shifts $g5_angles $src_net_file $cross_validation_k $cross_validation_ntests $cross_validation_fn
cd ../..
......@@ -4,7 +4,7 @@
#include "CrossValidator.h"
#include "message.h"
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
#include "../exceptions.h"
namespace lib4neuro {
......
#include <algorithm>
#include <limits>
#include <memory>
......@@ -7,9 +6,7 @@
#include <map>
#include <numeric>
#include <mpi.h>
//#include "../mpi_wrapper.h"
#define ARMA_ALLOW_FAKE_GCC
#include <armadillo>
#include <boost/serialization/export.hpp>
#include <ctime>
......@@ -22,9 +19,6 @@
#include "../message.h"
#include "DataSet.h"
//BOOST_CLASS_EXPORT_IMPLEMENT(lib4neuro::DataSet)
//BOOST_CLASS_EXPORT_IMPLEMENT(lib4neuro::ACSFDataSet)
namespace lib4neuro {
void DataSet::MPI_redistribute_data( ){
......
#ifndef INC_4NEURO_ERRORFUNCTION_H
#define INC_4NEURO_ERRORFUNCTION_H
#define ARMA_ALLOW_FAKE_GCC
//#include <armadillo>
#include "../settings.h"
#include "../Network/NeuralNetwork.h"
......
......@@ -2,8 +2,6 @@
// Created by martin on 20.08.19.
//
#define ARMA_ALLOW_FAKE_GCC
#include <4neuro.h>
#include <iomanip>
#include <vector>
......@@ -438,7 +436,6 @@ void dynamic_test(
}
}
int main( int argc, char** argv ) {
MPI_INIT
......
......@@ -13,7 +13,7 @@
#include "ExprtkWrapperSerialization.h"
#include "exceptions.h"
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
//BOOST_CLASS_EXPORT_IMPLEMENT(ExprtkWrapper);
......
......@@ -8,7 +8,7 @@
#include <random.hpp>
#include "GradientDescent.h"
#include "message.h"
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
namespace lib4neuro {
GradientDescent::GradientDescent(double epsilon,
......
......@@ -5,7 +5,7 @@
* @date 4.2.19 -
*/
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
#include "GradientDescentBB.h"
#include "message.h"
......
......@@ -5,7 +5,7 @@
* @date 19.2.19 -
*/
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
#include "GradientDescentSingleItem.h"
......
#define ARMA_ALLOW_FAKE_GCC
#include <armadillo>
#include <mpi.h>
......@@ -11,7 +10,7 @@
#include <petscksp.h>
#endif
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
#include "LevenbergMarquardt.h"
#include "../message.h"
......
......@@ -2,7 +2,6 @@
// Created by martin on 05.09.19.
//
#define ARMA_ALLOW_FAKE_GCC
#include <armadillo>
#include <utility>
#include <random>
......
......@@ -16,7 +16,7 @@
#include <iostream>
#include <format.hpp>
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
#include "message.h"
#include "../Network/NeuralNetwork.h"
......
......@@ -2,7 +2,7 @@
#include <stdexcept>
#include <boost/serialization/export.hpp>
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
#include "NormalizationStrategyACSF.h"
#include "NormalizationStrategyACSFSerialization.h"
......
......@@ -5,7 +5,7 @@
#ifndef LIB4NEURO_NORMALIZATIONSTRATEGYFINDDATAVEC_H
#define LIB4NEURO_NORMALIZATIONSTRATEGYFINDDATAVEC_H
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
/* Helper functions to find max and min values in inputs/outputs of DataSet */
double inline find_max_inp(const std::vector<std::pair<std::vector<double>, std::vector<double>>>& data) {
......
......@@ -8,7 +8,7 @@
#include <boost/algorithm/string/erase.hpp>
#include <mpi.h>
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
#include "CSVReader.h"
#include "exceptions.h"
......
......@@ -5,7 +5,7 @@
#include <algorithm>
#include <cctype>
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
#include "../exceptions.h"
#include "Reader.h"
......@@ -37,13 +37,15 @@ void lib4neuro::Reader::print_data() {
void lib4neuro::Reader::read() {
// TODO make filepath relative to an executable directory instead of the current one!
// TODO https://www.boost.org/doc/libs/1_36_0/libs/filesystem/doc/reference.html#initial_path
if( lib4neuro::mpi_rank == 0 ){
try {
if (lib4neuro::mpi_rank == 0) {
std::ifstream ifs(this->file_path);
if ( !ifs.is_open() ) {
// throw std::logic_error("File could not be opened! Possibly due to the lack of access privileges or an incorrect path.\n");
if (!ifs.is_open()) {
MPI_INTERRUPT
THROW_LOGIC_ERROR( "File \'" + this->file_path + "\' could not be opened! Possibly due to the lack of access privileges or an incorrect path.\n" );
// throw std::logic_error("File could not be opened! Possibly due to the lack of access privileges or an incorrect path.\n");
THROW_LOGIC_ERROR("File \'" + this->file_path +
"\' could not be opened! Possibly due to the lack of access privileges or an incorrect path.\n")
}
std::string line;
......@@ -80,7 +82,11 @@ void lib4neuro::Reader::read() {
ifs.close();
}
} catch(...) {
MPI_ERROR_CHECK
THROW_LOGIC_ERROR("read() function error!")
}
}
void lib4neuro::Reader::remove_white_characters_from_vector(std::vector<std::string>& v) {
......
......@@ -6,7 +6,7 @@
#include <limits>
#include <mpi.h>
#include "../mpi_wrapper.h"
#include "MPIWrapper/mpi_wrapper.h"
#include "../message.h"
#include "XYZReader.h"
......@@ -53,8 +53,6 @@ std::shared_ptr<lib4neuro::DataSet> lib4neuro::XYZReader::get_data_set( ) {
line = this->data.at(1);
this->remove_white_characters_from_vector(line);
n_particles = std::stoul(line.at(0));
// COUT_INFO( "# of particles in cluster: " << n_particles);
// COUT_INFO( "# of various particles: " << n_configurations);
unsigned int situation;
......@@ -69,15 +67,6 @@ std::shared_ptr<lib4neuro::DataSet> lib4neuro::XYZReader::get_data_set( ) {
if (situation == 1) {
data_set_contents.emplace_back(std::make_pair(inputs,
outputs));
// std::cout << "[" << data_set_contents.size() << "] inputs: ";
// for( auto el: inputs ){
// std::cout << el << ", ";
// }
// std::cout << "outputs: ";
// for( auto el: outputs ){
// std::cout << el << ", ";
// }
// std::cout << std::endl;
inputs.clear();
outputs.clear();
......@@ -135,7 +124,6 @@ std::shared_ptr<lib4neuro::DataSet> lib4neuro::XYZReader::get_data_set( ) {
MPI_Bcast( &n_clusters, 1, MPI_INT, 0, lib4neuro::mpi_active_comm );
MPI_Bcast( &n_elements, 1, MPI_INT, 0, lib4neuro::mpi_active_comm );
MPI_Bcast( &this->charge, 1, MPI_INT, 0, lib4neuro::mpi_active_comm );
// COUT_INFO("# number of configurations: " << n_clusters);
if( this->data_set == nullptr ){
/* synchronization of element list */
......@@ -208,8 +196,8 @@ void lib4neuro::XYZReader::transform_input_to_acsf(std::unordered_map<ELEMENT_SY
unsigned int n_particles = this->element_list->size();
unsigned int n_coords_per_particle = (this->charge && !this->ignore_charge) ? 4 : 3;
COUT_INFO("data contains charge " << this->charge );
COUT_INFO("should we ignore charge " << this->ignore_charge );
// COUT_INFO("data contains charge " << this->charge );
// COUT_INFO("should we ignore charge " << this->ignore_charge );
/* Create a new set of Atomic-Centered Symmetry Functions serving as coordinates */
std::vector<double> acsf_coords;
......@@ -222,31 +210,9 @@ void lib4neuro::XYZReader::transform_input_to_acsf(std::unordered_map<ELEMENT_SY
unsigned int idx;
this->acsf_data_set = std::make_shared<DataSet>();
/* normalization data for each element*/
// std::unordered_map<ELEMENT_SYMBOL, std::vector<double> > inputs_min, inputs_max;
// std::vector<double> outputs_min(out_dim), outputs_max(out_dim);
// std::fill(outputs_min.begin(), outputs_min.end(), std::numeric_limits<double>::max());
// std::fill(outputs_max.begin(), outputs_max.end(), std::numeric_limits<double>::min());
// for( auto el: element_description ){
// inputs_min[el.first] = std::vector<double>(element_description[el.first]->getSymmetryFunctions()->size());
// inputs_max[el.first] = std::vector<double>(element_description[el.first]->getSymmetryFunctions()->size());
// std::fill(inputs_min[el.first].begin(), inputs_min[el.first].end(), std::numeric_limits<double>::max());
// std::fill(inputs_max[el.first].begin(), inputs_max[el.first].end(), std::numeric_limits<double>::min());
// std::cout << "new element: " << inputs_min[el.first].size() << std::endl;
// }
std::vector<ELEMENT_SYMBOL> element_order;//used for input ordering
std::vector<ELEMENT_SYMBOL> element_order; //used for input ordering
for(auto configuration : *data) { /* Iterate over configurations */
// std::cout << "A" << std::endl;
/* update the output value ranges */
// for( size_t j = 0; j < outputs_min.size(); ++j ){
// outputs_min[ j ] = std::min( outputs_min[ j ], configuration.second[ j ] );
// outputs_max[ j ] = std::max( outputs_max[ j ], configuration.second[ j ] );
// }
// std::cout << "B" << std::endl;
idx = 0;
particles.clear();
......@@ -254,15 +220,12 @@ void lib4neuro::XYZReader::transform_input_to_acsf(std::unordered_map<ELEMENT_SY
for(auto el : *this->element_list) { /* Iterate over particles */
for(unsigned int i = 0; i < 3; i++) { /* Iterate over all coordinates of a single particle */
cartesian_coords.at(i) = configuration.first.at(idx);
// std::cout << "d[" << i << "] = i[" << idx << "](" << configuration.first.at(idx) << "), " ;
idx++;
}
if( this->charge && !this->ignore_charge ){
cartesian_coords.at(3) = configuration.first.at(idx);
// std::cout << "d[" << 3 << "] = i[" << idx << "](" << configuration.first.at(idx) << ") " ;
idx++;
}
// std::cout << std::endl;
if(this->ignore_charge && this->charge) {
idx++; //skips charge - TODO add support for charge!
......@@ -270,30 +233,18 @@ void lib4neuro::XYZReader::transform_input_to_acsf(std::unordered_map<ELEMENT_SY
particles.emplace_back(std::make_pair(el, cartesian_coords));
}
// std::cout << "C" << std::endl;
/* Transform Cartesian coordinates into ACSFs */
std::vector<double> single_particle_coords;
std::vector<std::pair<ELEMENT_SYMBOL, std::vector<double>>> acsf_coords_prep;
for(size_t i = 0; i < particles.size(); i++) { /* Iterate over all the particles */
single_particle_coords.clear();
// std::cout << "D" << std::endl;
/* Compute vector of ACSF coordinates for a single particle */
for (auto sym_func : *element_description[particles.at(i).first]->getSymmetryFunctions()) {
// std::cout << "E1" << std::endl;
single_particle_coords.emplace_back(sym_func->eval(i, particles));
// std::cout << "E2" << std::endl;
}
// std::cout << "X" << std::endl;
/* update the input value ranges */
// for( auto j = 0; j < single_particle_coords.size(); ++j ){
// inputs_min[particles.at(i).first][ j ] = std::min(inputs_min[particles.at(i).first][ j ], single_particle_coords[ j ]);
// inputs_max[particles.at(i).first][ j ] = std::max(inputs_max[particles.at(i).first][ j ], single_particle_coords[ j ]);
// }
// std::cout << "Y" << std::endl;
/* Store coordinates in a canonic order */
unsigned int element_ind = 0;
if(acsf_coords_prep.empty()) {
......@@ -326,69 +277,24 @@ void lib4neuro::XYZReader::transform_input_to_acsf(std::unordered_map<ELEMENT_SY
}
}
if( element_order.size() == 0 ){
for(auto e : acsf_coords_prep) {
if( element_order.empty() ){
for(const auto& e : acsf_coords_prep) {
element_order.push_back(e.first);
}
}
/* Rewrite coordinates without ELEMENT_SYMBOL labels */
for(auto e : acsf_coords_prep) {
for(const auto& e : acsf_coords_prep) {
for(auto coord : e.second) {
acsf_coords.emplace_back(coord);
}
}
/* Check for duplicates in new coordinates */
// std::vector<std::vector<double>> unique_coords = coords_check;
// std::sort(unique_coords.begin(), unique_coords.end());
// unique_coords.erase(std::unique(unique_coords.begin(), unique_coords.end()), unique_coords.end());
//
// if(unique_coords.size() != coords_check.size()) {
// MPI_INTERRUPT
// THROW_RUNTIME_ERROR("Not all descriptors are unique with currently specified symmetry functions!");
// }
this->acsf_data_set->add_data_pair(acsf_coords, configuration.second);
acsf_coords.clear();
acsf_coords_prep.clear();
}
/* sycnhronization of normalized data */
// MPI_Allreduce( MPI_IN_PLACE, &outputs_min[ 0 ], outputs_min.size(), MPI_DOUBLE, MPI_MIN, lib4neuro::mpi_active_comm );
// MPI_Allreduce( MPI_IN_PLACE, &outputs_max[ 0 ], outputs_max.size(), MPI_DOUBLE, MPI_MAX, lib4neuro::mpi_active_comm );
// for( auto el: element_description ){
// MPI_Allreduce( MPI_IN_PLACE, &inputs_min[el.first][ 0 ], inputs_min[el.first].size(), MPI_DOUBLE, MPI_MIN, lib4neuro::mpi_active_comm );
// MPI_Allreduce( MPI_IN_PLACE, &inputs_max[el.first][ 0 ], inputs_max[el.first].size(), MPI_DOUBLE, MPI_MAX, lib4neuro::mpi_active_comm );
// }
// std::vector<double> input_normalization_min, output_normalization_min;
// std::vector<double> input_normalization_max, output_normalization_max;
// for( auto el: element_order ){
// for( auto val: inputs_min[el] ){
// input_normalization_min.push_back( val );
// }
// for( auto val: inputs_max[el] ){
// input_normalization_max.push_back( val );
// }
// }
// output_normalization_min = outputs_min;
// output_normalization_max = outputs_max;
// if( lib4neuro::mpi_rank == 0 ){
// std::cout << "input ranges" << std::endl;
// for( size_t j = 0; j < input_normalization_min.size(); ++j ){
// std::cout << " " << input_normalization_min[j] << " - " << input_normalization_max[j] << std::endl;
// }
// std::cout << "output ranges" << std::endl;
// for( size_t j = 0; j < output_normalization_min.size(); ++j ){
// std::cout << " " << output_normalization_min[j] << " - " << output_normalization_max[j] << std::endl;
// }
// }
// this->acsf_data_set->normalize_inputs( input_normalization_min, input_normalization_max );
// this->acsf_data_set->normalize_outputs( output_normalization_min, output_normalization_max );
MPI_ERROR_CHECK
}
......@@ -401,7 +307,7 @@ std::shared_ptr<lib4neuro::DataSet> lib4neuro::XYZReader::get_acsf_data_set() {
return this->acsf_data_set;
}
lib4neuro::ELEMENT_SYMBOL lib4neuro::XYZReader::get_element_symbol(std::string symbol) {
lib4neuro::ELEMENT_SYMBOL lib4neuro::XYZReader::get_element_symbol(const std::string& symbol) {
//TODO implement in a more elegant way
std::unordered_map<std::string, ELEMENT_SYMBOL> element_symbols;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment