n2p2 - A neural network potential package
nnp-train.cpp File Reference
#include "Training.h"
#include "utility.h"
#include <mpi.h>
#include <cstddef>
#include <cstdlib>
#include <fstream>
#include <string>
Include dependency graph for nnp-train.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 28 of file nnp-train.cpp.

29{
30 int numProcs = 0;
31 int myRank = 0;
32 size_t stage = 0;
33 ofstream myLog;
34
35 string suffix = "";
36 if (argc > 1)
37 {
38 stage = (size_t)atoi(argv[1]);
39 suffix = strpr(".stage-%zu", stage);
40 }
41
42 MPI_Init(&argc, &argv);
43 MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
44 MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
45
46 // Basic setup.
47 Training training;
48 if (myRank != 0) training.log.writeToStdout = false;
49
50 myLog.open((strpr("nnp-train.log.%04d", myRank) + suffix).c_str());
51 training.log.registerStreamPointer(&myLog);
52 training.setupMPI();
53 training.initialize();
54 training.loadSettingsFile();
55 training.setStage(stage);
56 // If initial-weights-based normalization is enabled skip normalization
57 // setup here.
58 training.setupGeneric(
59 "",
60 training.settingsKeywordExists("normalize_data_set"),
61 stage == 1
62 );
64 training.setupSymmetryFunctionStatistics(false, false, false, false);
66
67 // Distribute structures to MPI processes.
68 training.distributeStructures(true);
69
70 // Randomly select training/test set and write them to separate files
71 // (train.data/test.data, same format as input.data).
72 training.selectSets();
73 training.writeSetsToFiles();
74
75 // Initialize weights and biases for neural networks.
76 training.initializeWeights();
77
78 // Run data set normalization if keyword present.
79 if (training.settingsKeywordExists("normalize_data_set"))
80 {
81 training.dataSetNormalization();
82 }
83
84 // Switch to normalized units, convert all structures.
85 if (training.useNormalization()) training.toNormalizedUnits();
86
87 // General training settings and weight update routine.
88 training.setupTraining();
89
90 // Calculate neighbor lists for all structures.
91 training.calculateNeighborLists();
92
93 // The main training loop.
94 training.loop();
95
96 myLog.close();
97
98 MPI_Finalize();
99
100 return 0;
101}
int distributeStructures(bool randomize, bool excludeRank0=false, std::string const &fileName="input.data")
Read data file and distribute structures among processors.
Definition: Dataset.cpp:724
void setupMPI()
Initialize MPI with MPI_COMM_WORLD.
Definition: Dataset.cpp:52
void setupRandomNumberGenerator()
Initialize random number generator.
Definition: Dataset.cpp:110
void toNormalizedUnits()
Switch all structures to normalized units.
Definition: Dataset.cpp:952
void registerStreamPointer(std::ofstream *const &streamPointer)
Register new C++ ofstream pointer.
Definition: Log.cpp:91
bool writeToStdout
Turn on/off output to stdout.
Definition: Log.h:85
void initialize()
Write welcome message with version information.
Definition: Mode.cpp:55
void setupGeneric(std::string const &nnpDir="", bool skipNormalize=false, bool initialHardness=false)
Combine multiple setup routines and provide a basic NNP setup.
Definition: Mode.cpp:212
bool useNormalization() const
Check if normalization is enabled.
Definition: Mode.h:703
virtual void setupSymmetryFunctionScaling(std::string const &fileName="scaling.data")
Set up symmetry function scaling from file.
Definition: Mode.cpp:712
bool settingsKeywordExists(std::string const &keyword) const
Check if keyword was found in settings file.
Definition: Mode.cpp:2193
Log log
Global log file.
Definition: Mode.h:593
void setupSymmetryFunctionStatistics(bool collectStatistics, bool collectExtrapolationWarnings, bool writeExtrapolationWarnings, bool stopOnExtrapolationWarnings)
Set up symmetry function statistics collection.
Definition: Mode.cpp:1103
void loadSettingsFile(std::string const &fileName="input.nn")
Open settings file and load all keywords into memory.
Definition: Mode.cpp:161
Training methods.
Definition: Training.h:36
void setupTraining()
General training settings and setup of weight update routine.
Definition: Training.cpp:737
void selectSets()
Randomly select training and test set structures.
Definition: Training.cpp:82
void dataSetNormalization()
Apply normalization based on initial weights prediction.
Definition: Training.cpp:429
void loop()
Execute main training loop.
Definition: Training.cpp:2147
void initializeWeights()
Initialize weights for all elements.
Definition: Training.cpp:292
void calculateNeighborLists()
Calculate neighbor lists for all structures.
Definition: Training.cpp:1247
void writeSetsToFiles()
Write training and test set to separate files (train.data and test.data, same format as input....
Definition: Training.cpp:230
void setStage(std::size_t stage)
Set training stage (if multiple stages are needed for NNP type).
Definition: Training.cpp:379
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90

References nnp::Training::calculateNeighborLists(), nnp::Training::dataSetNormalization(), nnp::Dataset::distributeStructures(), nnp::Mode::initialize(), nnp::Training::initializeWeights(), nnp::Mode::loadSettingsFile(), nnp::Mode::log, nnp::Training::loop(), nnp::Log::registerStreamPointer(), nnp::Training::selectSets(), nnp::Training::setStage(), nnp::Mode::settingsKeywordExists(), nnp::Mode::setupGeneric(), nnp::Dataset::setupMPI(), nnp::Dataset::setupRandomNumberGenerator(), nnp::Mode::setupSymmetryFunctionScaling(), nnp::Mode::setupSymmetryFunctionStatistics(), nnp::Training::setupTraining(), nnp::strpr(), nnp::Dataset::toNormalizedUnits(), nnp::Mode::useNormalization(), nnp::Training::writeSetsToFiles(), and nnp::Log::writeToStdout.

Here is the call graph for this function: