Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework of the CLI argument parser and add the option to define inputs through a JSON file #93

Merged
merged 34 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b99a7f0
Add first parser attempt
Sep 24, 2022
ab653cb
Use argparser
Sep 25, 2022
27c7749
Convert all execs to use new argparser
Sep 25, 2022
2f0446e
Add json option and example files for all parameters
Sep 25, 2022
5e4cbeb
Include json in dependencies
Sep 25, 2022
9eacdb7
Add json to readme
Sep 25, 2022
053cba4
Bump version
Sep 25, 2022
3619132
Bump version
Sep 25, 2022
48ff460
Fix missing json check and add install to workflows
Sep 25, 2022
2df8035
Run ubuntu on 22.04
Sep 25, 2022
8d4a132
Add unit tests and documentation for parser
Sep 30, 2022
f604cbe
Fix unit test
Sep 30, 2022
49d0441
Use template function to convert value in types
Sep 30, 2022
5dd35b6
Fix windows uint problem and get catch2 through conan
phbasler Sep 30, 2022
9383965
Unify spelling
Oct 4, 2022
8affdcd
Unify spelling of arguments
Oct 4, 2022
8531dc6
Merge branch 'master' into JSON
phbasler Oct 13, 2022
be6fbce
Update cpp-linter.yml
phbasler Oct 14, 2022
16c9d8d
Update cpp-linter.yml
phbasler Oct 14, 2022
3b290bb
Merge branch 'master' into JSON
Oct 14, 2022
3b4012f
apply cmake-format
Oct 14, 2022
43d853d
Automated commit of cmake-format changes.
phbasler Oct 14, 2022
94ed5fc
logger docu
Oct 15, 2022
47c5b3b
Merge branch 'JSON' of https://github.com/phbasler/BSMPT into JSON
Oct 15, 2022
fba4d53
Merge branch 'master' into JSON
phbasler Oct 17, 2022
ef039fb
Apply suggestions from code review
phbasler Nov 5, 2022
e21d647
Remove duplicate cmakedefs
Nov 5, 2022
0c2d39e
Fix missing install on mac
Nov 5, 2022
a9e6954
Only print help output once
Nov 5, 2022
75cb672
Update CMakeLists.txt
phbasler Nov 5, 2022
de31f39
Fix openmp missing on
Nov 5, 2022
d3b896d
Merge branch 'JSON' of https://github.com/phbasler/BSMPT into JSON
Nov 5, 2022
d30d228
opt openmp
Nov 5, 2022
c984ea8
link to openmp target
Nov 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
persist-credentials: false
- name: installPackages
run: brew install eigen && brew install gsl && brew install nlopt && brew install boost && brew install libomp
run: brew install eigen && brew install gsl && brew install nlopt && brew install boost && brew install libomp && brew install nlohmann-json
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v1
id: cpu-cores
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
if: "!contains(github.event.head_commit.message, 'skip-ci')"

steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name : installPackages
run : sudo apt-get install --no-install-recommends --yes libgsl-dev libeigen3-dev libnlopt-dev libnlopt-cxx-dev libboost-all-dev
run : sudo apt-get install --no-install-recommends --yes libgsl-dev libeigen3-dev libnlopt-dev libnlopt-cxx-dev libboost-all-dev nlohmann-json3-dev
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v1
id: cpu-cores
Expand Down
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cmake_minimum_required(VERSION 3.13)
project(
BSMPT
VERSION 2.4.0
VERSION 2.5.0
LANGUAGES C CXX
DESCRIPTION "BSMPT - Beyond the Standard Model Phase Transitions : A C++ package for the computation of the EWPT in BSM models")

Expand Down Expand Up @@ -62,7 +62,8 @@ if(UseConan)
include(conan)
set(ConanPkgList eigen/3.4.0
gsl/2.7
boost/1.78.0)
boost/1.78.0
nlohmann_json/3.10.5)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(ConanPkgList ${ConanPkgList} benchmark/1.6.1)
Expand All @@ -88,6 +89,7 @@ find_package(PkgConfig)
find_package(Eigen3 3.3.0 REQUIRED)
find_package(Boost 1.66)
find_package(GSL 2.1 REQUIRED)
find_package(nlohmann_json 3.10.0)
phbasler marked this conversation as resolved.
Show resolved Hide resolved



Expand Down Expand Up @@ -117,6 +119,10 @@ if(Boost_FOUND)
endif()
endif()

if(nlohmann_json_FOUND)
set(CodeCoverageExcludesFromOtherPkgs ${CodeCoverageExcludesFromOtherPkgs} "${nlohmann_json}/*")
endif()

set(EXPORT_CMAES FALSE)
include(FetchContent)
if(UseLibCMAES AND NOT WIN32)
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas M
SPDX-License-Identifier: GPL-3.0-or-later
-->

Program: BSMPT version 2.4.0
Program: BSMPT version 2.5.0

Released by: Philipp Basler and Lisa Biermann and Margarete Mühlleitner and Jonas Müller

Expand Down Expand Up @@ -137,6 +137,9 @@ Also contact us if you have a custom model for BSMPT v1.x and you have trouble c

## Executables
BSMPT provides multiple executables. Here we give a quick overview of them. For every executable you can call them with the `--help` option to get an overview of possible input parameters.

Additionally, every executable has the option to set the `--json=/path/to/your/file.json` which contains a json string with the parameters you can set through the CLI. This can be useful if you want to store the parameters you used for a given call. Please beware that all paths in the json file are considered relative to the current working directory and not to the location of the json file. Examples can be found in `example/JSON`.
phbasler marked this conversation as resolved.
Show resolved Hide resolved

For the following examples the C2HDM with the example/C2HDM_Input.dat file is used.

### BSMPT
Expand Down
17 changes: 17 additions & 0 deletions example/JSON/BSMPT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"FirstLine": "2",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"LastLine": "2",
"input": "./example/C2HDM_Input.dat",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"output": "test.tsv",
"model": "c2hdm",
"UseNLopt": "true",
"UseCMAES": "true",
"UseGSL": "true",
"UseMultiThreading": "true",
"logginglevel::default": "true",
"logginglevel::minimizerdetailed": "false",
"logginglevel::ewbgdetailed": "false",
"logginglevel::debug": "false",
"logginglevel::progdetailed": "false",
"logginglevel::disabled_comment": "remove _comment from key to disable logger"
}
13 changes: 13 additions & 0 deletions example/JSON/CalcCT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"FirstLine": "2",
"LastLine": "2",
"input": "./example/C2HDM_Input.dat",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"output": "test.tsv",
"model": "c2hdm",
"logginglevel::default": "true",
"logginglevel::minimizerdetailed": "false",
"logginglevel::ewbgdetailed": "false",
"logginglevel::debug": "false",
"logginglevel::progdetailed": "false",
"logginglevel::disabled_comment": "remove _comment from key to disable logger"
}
19 changes: 19 additions & 0 deletions example/JSON/CalculateEWBG.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"FirstLine": "2",
"LastLine": "2",
"input": "./example/C2HDM_Input.dat",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"output": "test.tsv",
"model": "c2hdm",
"config": "./example/EWBG_config.txt",
phbasler marked this conversation as resolved.
Show resolved Hide resolved

"UseNLopt": "true",
"UseCMAES": "true",
"UseGSL": "true",
"UseMultiThreading": "true",
"logginglevel::default": "true",
"logginglevel::minimizerdetailed": "false",
"logginglevel::ewbgdetailed": "false",
"logginglevel::debug": "false",
"logginglevel::progdetailed": "false",
"logginglevel::disabled_comment": "remove _comment from key to disable logger"
}
17 changes: 17 additions & 0 deletions example/JSON/NLOVEV.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"FirstLine": "2",
"LastLine": "2",
"input": "./example/C2HDM_Input.dat",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"output": "test.tsv",
"model": "c2hdm",
"UseNLopt": "true",
"UseCMAES": "true",
"UseGSL": "true",
"UseMultiThreading": "true",
"logginglevel::default": "true",
"logginglevel::minimizerdetailed": "false",
"logginglevel::ewbgdetailed": "false",
"logginglevel::debug": "false",
"logginglevel::progdetailed": "false",
"logginglevel::disabled_comment": "remove _comment from key to disable logger"
}
19 changes: 19 additions & 0 deletions example/JSON/PlotEWBG_nL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Line": "2",
"input": "./example/C2HDM_Input.dat",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"output": "test.tsv",
"model": "c2hdm",
"config": "./example/EWBG_config.txt",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"vw": "0.1",

"UseNLopt": "true",
"UseCMAES": "true",
"UseGSL": "true",
"UseMultiThreading": "true",
"logginglevel::default": "true",
"logginglevel::minimizerdetailed": "false",
"logginglevel::ewbgdetailed": "false",
"logginglevel::debug": "false",
"logginglevel::progdetailed": "false",
"logginglevel::disabled_comment": "remove _comment from key to disable logger"
}
21 changes: 21 additions & 0 deletions example/JSON/PlotEWBG_vw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"Line": "2",
"input": "./example/C2HDM_Input.dat",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"output": "test.tsv",
"model": "c2hdm",
"config": "./example/EWBG_config.txt",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"vw_min": "0.1",
"vw_max": "0.2",
"vw_stepsize": "0.05",

"UseNLopt": "true",
"UseCMAES": "true",
"UseGSL": "true",
"UseMultiThreading": "true",
"logginglevel::default": "true",
"logginglevel::minimizerdetailed": "false",
"logginglevel::ewbgdetailed": "false",
"logginglevel::debug": "false",
"logginglevel::progdetailed": "false",
"logginglevel::disabled_comment": "remove _comment from key to disable logger"
}
14 changes: 14 additions & 0 deletions example/JSON/Test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"line": "2",
"input": "./example/C2HDM_Input.dat",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"model": "c2hdm",
"UseNLopt": "true",
"UseCMAES": "true",
"UseGSL": "true",
"logginglevel::default": "true",
"logginglevel::minimizerdetailed": "false",
"logginglevel::ewbgdetailed": "false",
"logginglevel::debug": "false",
"logginglevel::progdetailed": "false",
"logginglevel::disabled_comment": "remove _comment from key to disable logger"
}
13 changes: 13 additions & 0 deletions example/JSON/TripleHiggsCouplingsNLO.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"FirstLine": "2",
"LastLine": "2",
"input": "./example/C2HDM_Input.dat",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"output": "test.tsv",
"model": "c2hdm",
"logginglevel::default": "true",
"logginglevel::minimizerdetailed": "false",
"logginglevel::ewbgdetailed": "false",
"logginglevel::debug": "false",
"logginglevel::progdetailed": "false",
"logginglevel::disabled_comment": "remove _comment from key to disable logger"
}
20 changes: 20 additions & 0 deletions example/JSON/VEVEVO.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Line": "2",
"input": "./example/C2HDM_Input.dat",
phbasler marked this conversation as resolved.
Show resolved Hide resolved
"output": "test.tsv",
"model": "c2hdm",
"TemperatureStart": "0",
"TemperatureEnd": "100",
"TemperatureStep": "5",

"UseNLopt": "true",
"UseCMAES": "true",
"UseGSL": "true",
"UseMultiThreading": "true",
"logginglevel::default": "true",
"logginglevel::minimizerdetailed": "false",
"logginglevel::ewbgdetailed": "false",
"logginglevel::debug": "false",
"logginglevel::progdetailed": "false",
"logginglevel::disabled_comment": "remove _comment from key to disable logger"
}
3 changes: 3 additions & 0 deletions include/BSMPT/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
#cmakedefine libcmaes_FOUND
#cmakedefine NLopt_FOUND
#cmakedefine Boost_FOUND
#cmakedefine nlohmann_json_FOUND
#cmakedefine Nlohmann_json_FOUND
#cmakedefine NLOHMANN_JSON_FOUND
14 changes: 8 additions & 6 deletions include/BSMPT/utility/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ namespace BSMPT
{

class Logger;
class parser;

void ShowLoggerHelp();
void SetLogger(const parser &argparser);
void SetLogger(const std::vector<std::string> &args);

enum class LoggingLevel
Expand All @@ -37,10 +39,10 @@ class BSMPTLogger
public:
friend Logger;
BSMPTLogger(std::ostream &os) : mOstream{os.rdbuf()} {}
BSMPTLogger(const BSMPTLogger &) = delete;
BSMPTLogger(BSMPTLogger &&) = delete;
BSMPTLogger(const BSMPTLogger &) = delete;
BSMPTLogger(BSMPTLogger &&) = delete;
BSMPTLogger &operator=(const BSMPTLogger &) = delete;
BSMPTLogger &operator=(BSMPTLogger &&) = delete;
BSMPTLogger &operator=(BSMPTLogger &&) = delete;

private:
void SetOStream(std::ostream &Ostream);
Expand Down Expand Up @@ -81,10 +83,10 @@ class BSMPTLogger
class Logger
{
public:
Logger(const Logger &) = delete;
Logger(Logger &&) = delete;
Logger(const Logger &) = delete;
Logger(Logger &&) = delete;
Logger &operator=(const Logger &) = delete;
Logger &operator=(Logger &&) = delete;
Logger &operator=(Logger &&) = delete;

static void SetLevel(const std::map<LoggingLevel, bool> &Setup)
{
Expand Down
55 changes: 55 additions & 0 deletions include/BSMPT/utility/parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef PARSER_H
#define PARSER_H

#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

namespace BSMPT
{

class parserException : public std::exception
{
public:
virtual const char *what() const noexcept;
parserException(const std::string &msg);

private:
std::string message;
};

/**
* @brief The parser class provides the base class for parsing CLI options
*/
class parser
{
public:
parser();
void enable_minimizer_options();
void add_argument(const std::string &argument,
const std::string &description,
bool required);
void add_input(const std::vector<std::string> &input);
void print_help() const;
std::string get_value(const std::string &argument) const;
std::string get_value_lower_case(const std::string &argument) const;
bool all_required_set() const;
void check_required_parameters() const;
void set_help_header(const std::string &header);

private:
struct Options
{
std::string argument;
std::string description;
std::optional<std::string> value;
};
std::unordered_map<std::string, Options> mRequiredArguments;
std::unordered_map<std::string, Options> mOptionalArguments;
void add_cli_input(const std::vector<std::string> &input);
void add_json_input(const std::string &filename);
std::string mHeader;
};
} // namespace BSMPT
#endif // PARSER_H
8 changes: 8 additions & 0 deletions include/BSMPT/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ namespace BSMPT
*/
bool StringStartsWith(const std::string &str, const std::string &prefix);

/**
* @brief StringEndsWith tests if str ends with suffix
* @param str
* @param suffix
* @return
*/
bool StringEndsWith(const std::string &str, const std::string &suffix);

/**
* @brief seperator used to write into output files
*/
Expand Down
3 changes: 2 additions & 1 deletion src/models/IncludeAllModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ ModelIDs getModel(const std::string &s)
std::string ModelInput = s;
std::transform(
ModelInput.begin(), ModelInput.end(), ModelInput.begin(), ::tolower);
for (auto entry : ModelNames)

for (const auto &entry : ModelNames)
{
auto key = entry.first;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
Expand Down
Loading