Remove SimParams class

This commit is contained in:
Max Luebke 2024-04-02 20:36:32 +00:00
parent 6c3761bb92
commit 8a78ed718e
3 changed files with 0 additions and 540 deletions

View File

@ -1,258 +0,0 @@
/*
** Copyright (C) 2018-2021 Alexander Lindemann, Max Luebke (University of
** Potsdam)
**
** Copyright (C) 2018-2022 Marco De Lucia, Max Luebke (GFZ Potsdam)
**
** Copyright (C) 2018-2022 Marco De Lucia (GFZ Potsdam), Max Luebke (University
** of Potsdam)
**
** POET is free software; you can redistribute it and/or modify it under the
** terms of the GNU General Public License as published by the Free Software
** Foundation; either version 2 of the License, or (at your option) any later
** version.
**
** POET is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
** A PARTICULAR PURPOSE. See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along with
** this program; if not, write to the Free Software Foundation, Inc., 51
** Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "SimParams.hpp"
#include "Base/Macros.hpp"
#include <cstdint>
#include <cstdint>
#include <string>
#include "Base/RInsidePOET.hpp"
#include "argh.hpp" // Argument handler https://github.com/adishavit/argh
using namespace poet;
RuntimeParameters::RuntimeParameters(RInsidePOET &R, char *argv[],
int world_rank_)
: world_rank(world_rank_) {
// initialize argh object
argh::parser cmdl(argv);
// if user asked for help
if (cmdl[{"help", "h"}]) {
if (this->world_rank == 0) {
MSG("Todo");
MSG("See README.md for further information.");
}
return poet::PARSER_HELP;
}
// if positional arguments are missing
else if (!cmdl(2)) {
if (simparams.world_rank == 0) {
ERRMSG("Kin needs 2 positional arguments: ");
ERRMSG("1) the R script defining your simulation and");
ERRMSG("2) the directory prefix where to save results and profiling");
}
return poet::PARSER_ERROR;
}
// collect all parameters which are not known, print them to stderr and return
// with PARSER_ERROR
std::list<std::string> optionsError = validateOptions(cmdl);
if (!optionsError.empty()) {
if (simparams.world_rank == 0) {
ERRMSG("Unrecognized option(s):\n");
for (auto option : optionsError) {
ERRMSG(std::string(option));
}
ERRMSG("Make sure to use available options. Exiting!");
}
return poet::PARSER_ERROR;
}
simparams.print_progressbar = cmdl[{"P", "progress"}];
// simparams.print_progressbar = cmdl[{"P", "progress"}];
/* Parse DHT arguments */
chem_params.use_dht = cmdl["dht"];
chem_params.use_interp = cmdl["interp"];
// cout << "CPP: DHT is " << ( dht_enabled ? "ON" : "OFF" ) << '\n';
cmdl("dht-size", DHT_SIZE_PER_PROCESS_MB) >> chem_params.dht_size;
// cout << "CPP: DHT size per process (Byte) = " << dht_size_per_process <<
// endl;
cmdl("dht-snaps", 0) >> chem_params.dht_snaps;
cmdl("dht-file") >> chem_params.dht_file;
/*Parse work package size*/
cmdl("work-package-size", WORK_PACKAGE_SIZE_DEFAULT) >> simparams.wp_size;
cmdl("interp-size", 100) >> chem_params.pht_size;
cmdl("interp-min", 5) >> chem_params.interp_min_entries;
cmdl("interp-bucket-entries", 20) >> chem_params.pht_max_entries;
/*Parse output options*/
simparams.store_result = !cmdl["ignore-result"];
/*Parse work package size*/
cmdl("work-package-size", WORK_PACKAGE_SIZE_DEFAULT) >> simparams.wp_size;
chem_params.use_interp = cmdl["interp"];
cmdl("interp-size", 100) >> chem_params.pht_size;
cmdl("interp-min", 5) >> chem_params.interp_min_entries;
cmdl("interp-bucket-entries", 20) >> chem_params.pht_max_entries;
/*Parse output options*/
simparams.store_result = !cmdl["ignore-result"];
if (simparams.world_rank == 0) {
MSG("Complete results storage is " + BOOL_PRINT(simparams.store_result));
MSG("Work Package Size: " + std::to_string(simparams.wp_size));
MSG("DHT is " + BOOL_PRINT(chem_params.use_dht));
if (chem_params.use_dht) {
MSG("DHT strategy is " + std::to_string(simparams.dht_strategy));
// MDL: these should be outdated (?)
// MSG("DHT key default digits (ignored if 'signif_vector' is "
// "defined) = "
// << simparams.dht_significant_digits);
// MSG("DHT logarithm before rounding: "
// << (simparams.dht_log ? "ON" : "OFF"));
MSG("DHT size per process (Megabyte) = " +
std::to_string(chem_params.dht_size));
MSG("DHT save snapshots is " + BOOL_PRINT(chem_params.dht_snaps));
MSG("DHT load file is " + chem_params.dht_file);
}
if (chem_params.use_interp) {
MSG("PHT interpolation enabled: " + BOOL_PRINT(chem_params.use_interp));
MSG("PHT interp-size = " + std::to_string(chem_params.pht_size));
MSG("PHT interp-min = " +
std::to_string(chem_params.interp_min_entries));
MSG("PHT interp-bucket-entries = " +
std::to_string(chem_params.pht_max_entries));
}
}
cmdl(1) >> filesim;
cmdl(2) >> out_dir;
chem_params.dht_outdir = out_dir;
/* distribute information to R runtime */
// if local_rank == 0 then master else worker
R["local_rank"] = simparams.world_rank;
// assign a char* (string) to 'filesim'
R["filesim"] = wrap(filesim);
// assign a char* (string) to 'fileout'
R["fileout"] = wrap(out_dir);
// pass the boolean "store_result" to the R process
R["store_result"] = simparams.store_result;
// worker count
R["n_procs"] = simparams.world_size - 1;
// work package size
R["work_package_size"] = simparams.wp_size;
// dht enabled?
R["dht_enabled"] = chem_params.use_dht;
// log before rounding?
R["dht_log"] = simparams.dht_log;
// eval the init string, ignoring any returns
R.parseEvalQ("source(filesim)");
R.parseEvalQ("mysetup <- setup");
this->chem_params.initFromR(R);
return poet::PARSER_OK;
};
// poet::GridParams::s_GridParams(RInside &R) {
// auto tmp_n_cells =
// Rcpp::as<std::vector<uint32_t>>(R.parseEval("mysetup$grid$n_cells"));
// assert(tmp_n_cells.size() < 3);
// this->dim = tmp_n_cells.size();
// std::copy(tmp_n_cells.begin(), tmp_n_cells.end(), this->n_cells.begin());
// auto tmp_s_cells =
// Rcpp::as<std::vector<double>>(R.parseEval("mysetup$grid$s_cells"));
// assert(tmp_s_cells.size() == this->dim);
// std::copy(tmp_s_cells.begin(), tmp_s_cells.end(), this->s_cells.begin());
// this->total_n =
// (dim == 1 ? this->n_cells[0] : this->n_cells[0] * this->n_cells[1]);
// this->type = Rcpp::as<std::string>(R.parseEval("mysetup$grid$type"));
// }
// poet::DiffusionParams::s_DiffusionParams(RInside &R) {
// this->initial_t =
// Rcpp::as<Rcpp::DataFrame>(R.parseEval("mysetup$diffusion$init"));
// this->alpha =
// Rcpp::as<Rcpp::NumericVector>(R.parseEval("mysetup$diffusion$alpha"));
// if (Rcpp::as<bool>(
// R.parseEval("'vecinj_inner' %in% names(mysetup$diffusion)"))) {
// this->vecinj_inner =
// Rcpp::as<Rcpp::List>(R.parseEval("mysetup$diffusion$vecinj_inner"));
// }
// this->vecinj =
// Rcpp::as<Rcpp::DataFrame>(R.parseEval("mysetup$diffusion$vecinj"));
// this->vecinj_index =
// Rcpp::as<Rcpp::DataFrame>(R.parseEval("mysetup$diffusion$vecinj_index"));
// }
void poet::ChemistryParams::initFromR(RInsidePOET &R) {
// this->database_path =
// Rcpp::as<std::string>(R.parseEval("mysetup$chemistry$database"));
// this->input_script =
// Rcpp::as<std::string>(R.parseEval("mysetup$chemistry$input_script"));
if (R.checkIfExists("dht_species", "mysetup$chemistry")) {
this->dht_signifs = Rcpp::as<NamedVector<std::uint32_t>>(
R.parseEval(("mysetup$chemistry$dht_species")));
}
if (R.checkIfExists("pht_species", "mysetup$chemistry")) {
this->pht_signifs = Rcpp::as<NamedVector<std::uint32_t>>(
R.parseEval(("mysetup$chemistry$pht_species")));
}
this->hooks.dht_fill =
RHookFunction<bool>(R, "mysetup$chemistry$hooks$dht_fill");
this->hooks.dht_fuzz =
RHookFunction<std::vector<double>>(R, "mysetup$chemistry$hooks$dht_fuzz");
this->hooks.interp_pre = RHookFunction<std::vector<std::size_t>>(
R, "mysetup$chemistry$hooks$interp_pre_func");
this->hooks.interp_post =
RHookFunction<bool>(R, "mysetup$chemistry$hooks$interp_post_func");
}
void RuntimeParameters::initVectorParams(RInside &R) {}
std::list<std::string> RuntimeParameters::validateOptions(argh::parser cmdl) {
/* store all unknown parameters here */
std::list<std::string> retList;
/* loop over all flags and compare to given flaglist*/
for (auto &flag : cmdl.flags()) {
if (!(flaglist.find(flag) != flaglist.end()))
retList.push_back(flag);
}
/* and loop also over params and compare to given paramlist */
for (auto &param : cmdl.params()) {
if (!(paramlist.find(param.first) != paramlist.end()))
retList.push_back(param.first);
}
return retList;
}

View File

@ -1,281 +0,0 @@
/*
** Copyright (C) 2018-2021 Alexander Lindemann, Max Luebke (University of
** Potsdam)
**
** Copyright (C) 2018-2022 Marco De Lucia, Max Luebke (GFZ Potsdam)
**
** Copyright (C) 2018-2022 Marco De Lucia (GFZ Potsdam), Max Luebke (University
** of Potsdam)
**
** POET is free software; you can redistribute it and/or modify it under the
** terms of the GNU General Public License as published by the Free Software
** Foundation; either version 2 of the License, or (at your option) any later
** version.
**
** POET is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
** A PARTICULAR PURPOSE. See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along with
** this program; if not, write to the Free Software Foundation, Inc., 51
** Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#pragma once
#include "DataStructures/NamedVector.hpp"
#include "RInsidePOET.hpp"
#include <cstdint>
#include <string>
#include <vector>
#include <RInside.h>
#include <Rcpp.h>
// BSD-licenced
/** Standard DHT Size. Defaults to 1 GB (1000 MB) */
constexpr uint32_t DHT_SIZE_PER_PROCESS_MB = 1.5E3;
/** Standard work package size */
#define WORK_PACKAGE_SIZE_DEFAULT 32
namespace poet {
enum { PARSER_OK, PARSER_ERROR, PARSER_HELP };
/**
* @brief Defining all simulation parameters
*
*/
// struct RuntimeParameters {
// /** Count of processes in MPI_COMM_WORLD */
// int world_size;
// /** rank of proces in MPI_COMM_WORLD */
// int world_rank;
// /** indicates if DHT should be used */
// bool dht_enabled;
// /** apply logarithm to key before rounding */
// bool dht_log;
// /** indicates if timestep dt differs between iterations */
// bool dt_differ;
// /** Indicates, when a DHT snapshot should be written */
// int dht_snaps;
// /** <b>not implemented</b>: How a DHT is distributed over processes */
// int dht_strategy;
// /** Size of DHt per process in byter */
// unsigned int dht_size_per_process;
// /** Default significant digit for rounding */
// int dht_significant_digits;
// /** Default work package size */
// unsigned int wp_size;
// /** indicates if resulting grid should be stored after every iteration */
// bool store_result;
// /** indicating whether the progress bar during chemistry simulation should
// be
// * printed or not */
// bool print_progressbar;
// bool interp_enabled;
// };
// using GridParams = struct s_GridParams {
// std::array<uint32_t, 2> n_cells;
// std::array<double, 2> s_cells;
// std::uint8_t dim;
// std::uint32_t total_n;
// std::string type;
// Rcpp::DataFrame init_df;
// std::string input_script;
// std::string database_path;
// std::vector<std::string> props;
// s_GridParams(RInside &R);
// };
// using DiffusionParams = struct s_DiffusionParams {
// Rcpp::DataFrame initial_t;
// Rcpp::NumericVector alpha;
// Rcpp::List vecinj_inner;
// Rcpp::DataFrame vecinj;
// Rcpp::DataFrame vecinj_index;
// s_DiffusionParams(RInside &R);
// };
struct ChemistryParams {
// std::string database_path;
// std::string input_script;
bool use_dht;
std::uint64_t dht_size;
int dht_snaps;
std::string dht_file;
std::string dht_outdir;
NamedVector<std::uint32_t> dht_signifs;
bool use_interp;
std::uint64_t pht_size;
std::uint32_t pht_max_entries;
std::uint32_t interp_min_entries;
NamedVector<std::uint32_t> pht_signifs;
struct Chem_Hook_Functions {
RHookFunction<bool> dht_fill;
RHookFunction<std::vector<double>> dht_fuzz;
RHookFunction<std::vector<std::size_t>> interp_pre;
RHookFunction<bool> interp_post;
} hooks;
void initFromR(RInsidePOET &R);
};
} // namespace poet
/**
* @brief Reads information from program arguments and R runtime
*
* Providing functions to initialize parameters of the simulation using command
* line parameters and parameters from the R runtime. This class will also parse
* arguments from the commandline and decides if argument is known or unknown.
*
* Stores and distribute current simulation parameters at any time.
*
*/
// class SimParams {
// public:
// /**
// * @brief Construct a new SimParams object
// *
// * With all given parameters a new instance of this class will be created.
// *
// * @param world_rank Rank of process inside MPI_COMM_WORLD
// * @param world_size Size of communicator MPI_COMM_WORLD
// */
// SimParams(int world_rank);
// /**
// * @brief Parse program arguments
// *
// * This is done by the argh.h library.
// *
// * First, the function will check if there is a flag 'help' or 'h'. If this
// is
// * the case a help message is printed and the function will return with
// * PARSER_HELP.
// *
// * Second, if there are not 2 positional arguments an error will be printed
// to
// * stderr and the function returns with PARSER_ERROR.
// *
// * Then all given program parameters and flags will be read and checked, if
// * there are known by validateOptions. A list of all unknown options might
// be
// * returned, printed out and the function will return with PARSER_ERROR.
// * Oterhwise the function continuos.
// *
// * Now all program arguments will be stored inside t_simparams struct,
// printed
// * out and the function returns with PARSER_OK.
// *
// * Also, all parsed agruments are distributed to the R runtime.
// *
// * @param argv Argument value of the program
// * @param R Instantiated R runtime
// * @return int Returns with 0 if no error occured, otherwise value less
// than 0
// * is returned.
// */
// int parseFromCmdl(char *argv[], RInsidePOET &R);
// /**
// * @brief Init std::vector values
// *
// * This will initialize dht_signif_vector and dht_prop_type_vector
// internally
// * depending on whether vectors are defined by R-Simulation file or not.
// * 'init_chemistry' must be run beforehand.
// *
// * @param R R runtime
// */
// void initVectorParams(RInside &R);
// /**
// * @brief Get the numerical params struct
// *
// * Returns a struct which contains all numerical or boolean simulation
// * parameters.
// *
// * @return t_simparams Parameter struct
// */
// auto getNumParams() const { return this->simparams; };
// /**
// * @brief Get the DHT_Signif_Vector
// *
// * Returns a vector indicating which significant values are used for each
// * variable of a grid cell.
// *
// * @return std::vector<int> Vector of integers containing information about
// * significant digits
// */
// auto getDHTSignifVector() const { return this->dht_signif_vector; };
// auto getPHTSignifVector() const { return this->pht_signif_vector; };
// auto getPHTBucketSize() const { return this->pht_bucket_size; };
// auto getPHTMinEntriesNeeded() const { return this->pht_min_entries_needed;
// };
// /**
// * @brief Get the filesim name
// *
// * Returns a string containing the absolute path to a R file defining the
// * simulation.
// *
// * @return std::string Absolute path to R file
// */
// auto getFilesim() const { return this->filesim; };
// /**
// * @brief Get the output directory
// *
// * Returns the name of an absolute path where all output files should be
// * stored.
// *
// * @return std::string Absolute path to output path
// */
// auto getOutDir() const { return this->out_dir; };
// const auto &getChemParams() const { return chem_params; }
// private:
// std::list<std::string> validateOptions(argh::parser cmdl);
// const std::set<std::string> flaglist{"ignore-result", "dht", "P",
// "progress",
// "interp"};
// const std::set<std::string> paramlist{
// "work-package-size", "dht-strategy",
// "dht-size", "dht-snaps",
// "dht-file", "interp-size",
// "interp-min", "interp-bucket-entries"};
// t_simparams simparams;
// std::vector<uint32_t> dht_signif_vector;
// std::vector<uint32_t> pht_signif_vector;
// uint32_t pht_bucket_size;
// uint32_t pht_min_entries_needed;
// std::string filesim;
// std::string out_dir;
// ChemistryParams chem_params;
// };
// } // namespace poet

View File

@ -26,7 +26,6 @@
#include "Base/RInsidePOET.hpp"
#include "DataStructures/NamedVector.hpp"
#include "../../Base/SimParams.hpp"
#include "Chemistry/ChemistryDefs.hpp"
#include "Init/InitialList.hpp"