DiagMC
Diagrammatic Monte Carlo simulation of a 2-level spin system in a magnetic field
Loading...
Searching...
No Matches
Typedefs | Functions
setup.h File Reference

Header file of the functions to read settings from file, launch the calculations and save the results. More...

#include <nlohmann/json.hpp>
Include dependency graph for setup.h:

Go to the source code of this file.

Typedefs

using json = nlohmann::json
 

Functions

void check_required_keys_presence (const json &settings, std::vector< std::string > list_of_keys)
 Check that all keys in list_of_keys are present in settings, otherwise terminate the program with EXIT_FAILURE. More...
 
std::vector< double > range_generator (const json &settings, std::string which)
 If "which"_min, "which"_max and "which"_step parameter are present in settings, returns a vector of linearly spaced values from min to max (spaced by step). If "which"_min, "which"_max and "which"_step are not present but "which" is, returns a vector with the single value specified by the setting parameter "which". If both previous conditions are not satisfied, terminates the program with EXIT_FAILURE. More...
 
std::vector< double > log_range_generator (const json &settings, std::string which)
 If "which"_min, "which"_max and "which"_points_per_decade parameter are present in settings, returns a vector of log10-spaced values from min to max (with points_per_decade between each power of 10). If "which"_min, "which"_max and "which"_step are not present but "which" is, returns a vector with the single value specified by the setting parameter "which". If both previous conditions are not satisfied, terminates the program with EXIT_FAILURE. More...
 
void print_progress_bar (double progress)
 Prints a progress bar on standard output. More...
 
json read_settings (std::string filename="settings.json")
 Read settings for the simulation from json file, and returns them as a json dictionary-like object If file cannot be opened, or it is not correctly parsed, or the "CALC_TYPE" key is missing, terminates the program with EXIT_FAILURE. More...
 
void single_run (const json &settings)
 Perform a single run for the given parameters in setting, printing a summary of the results on standard output. More...
 
void sweep (const json &settings)
 Perform multiple runs for different values of the beta, H and GAMMA parameters, sweeping the range between the min and max values indicated in settings, with the step value also specified in settings. If min/max/step values for more than one parameter are provided, all combinations are calculated. The results are written in a csv file, with each row corresponding to a single run. More...
 
void convergence_test (const json &settings)
 Perform a convergence test on the number of steps for the MCMC algorithm, by performing multiple runs for different number of steps (keeping the same seed), to avoid random fluctuations that could make the result unclear. The values of the N_total_steps are taken the range between the min and max values indicated in settings, in log10-scale, with the specified "points_per_decade". The results are written in a csv file, with each row corresponding to a single run. More...
 
void launch_calculations (std::string settings_filename)
 Call the read_settings function to read settings from file, and select which calculation to run. More...
 

Detailed Description

Header file of the functions to read settings from file, launch the calculations and save the results.

Author
Enrico Pedretti
Date
2023-09-03

Definition in file setup.h.

Typedef Documentation

◆ json

using json = nlohmann::json

Definition at line 11 of file setup.h.

Function Documentation

◆ check_required_keys_presence()

void check_required_keys_presence ( const json &  settings,
std::vector< std::string >  list_of_keys 
)

Check that all keys in list_of_keys are present in settings, otherwise terminate the program with EXIT_FAILURE.

Parameters
settingsdictionary-like nlohmann::json object, with the settings for running the algorithm
list_of_keysList of strings containing the keys whose presence in settings dictionary has to be checked

◆ convergence_test()

void convergence_test ( const json &  settings)

Perform a convergence test on the number of steps for the MCMC algorithm, by performing multiple runs for different number of steps (keeping the same seed), to avoid random fluctuations that could make the result unclear. The values of the N_total_steps are taken the range between the min and max values indicated in settings, in log10-scale, with the specified "points_per_decade". The results are written in a csv file, with each row corresponding to a single run.

Parameters
settingsdictionary-like nlohmann::json object, with the settings for running the algorithm

◆ launch_calculations()

void launch_calculations ( std::string  settings_filename)

Call the read_settings function to read settings from file, and select which calculation to run.

Parameters
settings_filenameName (path) of the json file containing the settings for the calculation

◆ log_range_generator()

std::vector< double > log_range_generator ( const json &  settings,
std::string  which 
)

If "which"_min, "which"_max and "which"_points_per_decade parameter are present in settings, returns a vector of log10-spaced values from min to max (with points_per_decade between each power of 10). If "which"_min, "which"_max and "which"_step are not present but "which" is, returns a vector with the single value specified by the setting parameter "which". If both previous conditions are not satisfied, terminates the program with EXIT_FAILURE.

Parameters
settingsdictionary-like nlohmann::json object, with the settings for running the algorithm
whichName of the parameter for the algorithm, e.g. "N_total_steps"
Returns
std::vector<double> containing a the (one or more) values of the 'which' parameter

◆ print_progress_bar()

void print_progress_bar ( double  progress)

Prints a progress bar on standard output.

Parameters
progressFraction of completion (in range [0,1])

◆ range_generator()

std::vector< double > range_generator ( const json &  settings,
std::string  which 
)

If "which"_min, "which"_max and "which"_step parameter are present in settings, returns a vector of linearly spaced values from min to max (spaced by step). If "which"_min, "which"_max and "which"_step are not present but "which" is, returns a vector with the single value specified by the setting parameter "which". If both previous conditions are not satisfied, terminates the program with EXIT_FAILURE.

Parameters
settingsdictionary-like nlohmann::json object, with the settings for running the algorithm
whichName of the parameter for the algorithm, e.g. "H", or "GAMMA"
Returns
std::vector<double> containing a the (one or more) values of the 'which' parameter

◆ read_settings()

json read_settings ( std::string  filename = "settings.json")

Read settings for the simulation from json file, and returns them as a json dictionary-like object If file cannot be opened, or it is not correctly parsed, or the "CALC_TYPE" key is missing, terminates the program with EXIT_FAILURE.

Parameters
filenameName (path) of the json file containing the settings for the calculation
Returns
json (dictionry-like object containing the settings for the simulation)

◆ single_run()

void single_run ( const json &  settings)

Perform a single run for the given parameters in setting, printing a summary of the results on standard output.

Parameters
settingsdictionary-like nlohmann::json object, with the settings for running the algorithm

◆ sweep()

void sweep ( const json &  settings)

Perform multiple runs for different values of the beta, H and GAMMA parameters, sweeping the range between the min and max values indicated in settings, with the step value also specified in settings. If min/max/step values for more than one parameter are provided, all combinations are calculated. The results are written in a csv file, with each row corresponding to a single run.

Parameters
settingsdictionary-like nlohmann::json object, with the settings for running the algorithm