NRP Core  1.4.1
simulation_parameters.h
Go to the documentation of this file.
1 /* * NRP Core - Backend infrastructure to synchronize simulations
2  *
3  * Copyright 2020-2023 NRP Team
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * This project has received funding from the European Union’s Horizon 2020
18  * Framework Programme for Research and Innovation under the Specific Grant
19  * Agreement No. 945539 (Human Brain Project SGA3).
20  */
21 
22 #ifndef SIMULATION_PARAMS_H
23 #define SIMULATION_PARAMS_H
24 
27 
28 #include <filesystem>
29 #include <iostream>
30 #include <fstream>
31 #include <string>
32 #include <cxxopts.hpp>
33 #include <nlohmann/json.hpp>
34 
35 using jsonSharedPtr = std::shared_ptr<nlohmann::json>;
36 
37 
42 {
43  static constexpr std::string_view NRPProgramName = "NRPCoreSim";
44  static constexpr std::string_view ProgramDescription = "Brain and physics simulator";
45 
46  // Simulation Executable parameters
47  static constexpr std::string_view ParamHelp = "h";
48  static constexpr std::string_view ParamHelpLong = "h,help";
49  static constexpr std::string_view ParamHelpDesc = "Print this message";
50  using ParamHelpT = bool;
51 
52  static constexpr std::string_view ParamSimCfgFile = "c";
53  static constexpr std::string_view ParamSimCfgFileLong = "c,config";
54  static constexpr std::string_view ParamSimCfgFileDesc = "Simulation config file";
55  using ParamSimCfgFileT = std::string;
56 
57  static constexpr std::string_view ParamPlugins = "p";
58  static constexpr std::string_view ParamPluginsLong = "p,plugins";
59  static constexpr std::string_view ParamPluginsDesc = "Engine plugins to load. If omitted, all engines compiled with nrp-core are loaded";
60  using ParamPluginsT = std::vector<std::string>;
61 
62  static constexpr std::string_view ParamExpDir = "d";
63  static constexpr std::string_view ParamExpDirLong = "d,dir";
64  static constexpr std::string_view ParamExpDirDesc = "The explicit location of the experiment folder";
65  using ParamExpDirT = std::string;
66 
67  // Log paramters
68  static constexpr std::string_view ParamConsoleLogLevelLong = "cloglevel";
69  static constexpr std::string_view ParamConsoleLogLevelDesc = "Console minimum level of log severity";
70  using ParamConsoleLogLevelT = std::string;
71 
72  static constexpr std::string_view ParamFileLogLevelLong = "floglevel";
73  static constexpr std::string_view ParamFileLogLevelDesc = "File minimum level of log severity";
74  using ParamFileLogLevelT = std::string;
75 
76  static constexpr std::string_view ParamLogOutputLong = "logoutput";
77  static constexpr std::string_view ParamLogOutputDesc = "Option for logging stdout and stderr in the experiment: engines, all, silent";
78  using ParamLogOutputT = std::string;
79 
80  static constexpr std::string_view ParamLogFilenameLong = "logfilename";
81  static constexpr std::string_view ParamLogFilenameDesc = "If 'logoutput' option is 'engines' or 'all', name of the log file";
82  using ParamFilenameT = std::string;
83 
84  static constexpr std::string_view ParamLogDirLong = "logdir";
85  static constexpr std::string_view ParamLogDirDesc = "Directory for the file logs";
86  using ParamLogDirT = std::string;
87 
88  static constexpr std::string_view ParamLogConfig = "l";
89  static constexpr std::string_view ParamLogConfigLong = "l,logconfig";
90  static constexpr std::string_view ParamLogConfigDesc = "Print the simulation config in use to DEBUG log";
91  using ParamLogConfigT = bool;
92 
93  static constexpr std::string_view ParamMode = "m";
94  static constexpr std::string_view ParamModeLong = "m,mode";
95  static constexpr std::string_view ParamModeDesc = "Operational mode, standalone or server";
96  using ParamModeT = std::string;
97 
98  static constexpr std::string_view ParamSimParam = "o";
99  static constexpr std::string_view ParamSimParamLong = "o,param";
100  static constexpr std::string_view ParamSimParamDesc = "Simulation config parameter, specified as param=value, overriding configuration file parameters";
101  using ParamSimParamT = std::vector<std::string>;
102 
103  static constexpr std::string_view ParamServerAddressLong = "server_address";
104  static constexpr std::string_view ParamServerAddressDesc = "Desired address of the server in server operational mode";
105  using ParamServerAddressT = std::string;
106 
107  static constexpr std::string_view ParamSlaveLong = "slave";
108  static constexpr std::string_view ParamSlaveDesc = "If present NRPCoreSim runs in slave mode. For internal use.";
109  using ParamSlaveT = bool;
110 
115  static cxxopts::Options createStartParamParser();
116 
117  // TODO: in this function the WD is also set with a kind of complex logic, it should be documented in the function
118  // declaration, i.e., here
124  static jsonSharedPtr setWorkingDirectoryAndGetConfigFile(const cxxopts::ParseResult &args);
125 
131  static void parseAndSetCLISimParams(const ParamSimParamT& parseResults, nlohmann::json &simulationConfig);
132 
137  static NRPLogger::level_t parseLogLevel(const std::string &logLevel);
138 
139 private:
140 
147  static void setCLISimParams(const std::string& fullKey, const std::string& value, nlohmann::json &simulationConfig);
148 
152  static const NRPLogger::level_t _defaultLogLevel = NRPLogger::level_t::info;
153 };
154 
155 #endif
SimulationParams::ParamExpDir
static constexpr std::string_view ParamExpDir
Definition: simulation_parameters.h:62
SimulationParams::ParamFileLogLevelLong
static constexpr std::string_view ParamFileLogLevelLong
Definition: simulation_parameters.h:72
nrp_logger.h
SimulationParams::ParamLogDirDesc
static constexpr std::string_view ParamLogDirDesc
Definition: simulation_parameters.h:85
SimulationParams::ParamSimCfgFileLong
static constexpr std::string_view ParamSimCfgFileLong
Definition: simulation_parameters.h:53
SimulationParams::ParamPluginsDesc
static constexpr std::string_view ParamPluginsDesc
Definition: simulation_parameters.h:59
SimulationParams::parseAndSetCLISimParams
static void parseAndSetCLISimParams(const ParamSimParamT &parseResults, nlohmann::json &simulationConfig)
Parse cmd line simulation parameters.
Definition: simulation_parameters.cpp:148
SimulationParams::ParamSimParam
static constexpr std::string_view ParamSimParam
Definition: simulation_parameters.h:98
SimulationParams::ParamLogConfig
static constexpr std::string_view ParamLogConfig
Definition: simulation_parameters.h:88
SimulationParams::ParamLogOutputT
std::string ParamLogOutputT
Definition: simulation_parameters.h:78
nrp_exceptions.h
SimulationParams::ParamSimCfgFileDesc
static constexpr std::string_view ParamSimCfgFileDesc
Definition: simulation_parameters.h:54
SimulationParams::ParamServerAddressLong
static constexpr std::string_view ParamServerAddressLong
Definition: simulation_parameters.h:103
SimulationParams::parseLogLevel
static NRPLogger::level_t parseLogLevel(const std::string &logLevel)
parsing input parameter string log level into enum type
Definition: simulation_parameters.cpp:130
SimulationParams::ParamPluginsLong
static constexpr std::string_view ParamPluginsLong
Definition: simulation_parameters.h:58
python_json_engine.args
Namespace args
Definition: python_json_engine.py:196
SimulationParams::ParamLogDirLong
static constexpr std::string_view ParamLogDirLong
Definition: simulation_parameters.h:84
SimulationParams::ParamLogFilenameLong
static constexpr std::string_view ParamLogFilenameLong
Definition: simulation_parameters.h:80
SimulationParams::ParamLogDirT
std::string ParamLogDirT
Definition: simulation_parameters.h:86
SimulationParams::ParamMode
static constexpr std::string_view ParamMode
Definition: simulation_parameters.h:93
SimulationParams::ParamServerAddressDesc
static constexpr std::string_view ParamServerAddressDesc
Definition: simulation_parameters.h:104
SimulationParams::ParamSlaveT
bool ParamSlaveT
Definition: simulation_parameters.h:109
SimulationParams::ParamSlaveLong
static constexpr std::string_view ParamSlaveLong
Definition: simulation_parameters.h:107
SimulationParams::ParamSimCfgFile
static constexpr std::string_view ParamSimCfgFile
Definition: simulation_parameters.h:52
SimulationParams::ParamConsoleLogLevelDesc
static constexpr std::string_view ParamConsoleLogLevelDesc
Definition: simulation_parameters.h:69
SimulationParams::ParamHelp
static constexpr std::string_view ParamHelp
Definition: simulation_parameters.h:47
jsonSharedPtr
std::shared_ptr< nlohmann::json > jsonSharedPtr
Definition: json_schema_utils.h:35
SimulationParams::ParamLogFilenameDesc
static constexpr std::string_view ParamLogFilenameDesc
Definition: simulation_parameters.h:81
SimulationParams
NRP Simulation Startup Parameters.
Definition: simulation_parameters.h:41
SimulationParams::ParamLogOutputLong
static constexpr std::string_view ParamLogOutputLong
Definition: simulation_parameters.h:76
SimulationParams::ParamModeLong
static constexpr std::string_view ParamModeLong
Definition: simulation_parameters.h:94
SimulationParams::ParamSimParamT
std::vector< std::string > ParamSimParamT
Definition: simulation_parameters.h:101
SimulationParams::ParamExpDirLong
static constexpr std::string_view ParamExpDirLong
Definition: simulation_parameters.h:63
SimulationParams::ParamExpDirDesc
static constexpr std::string_view ParamExpDirDesc
Definition: simulation_parameters.h:64
SimulationParams::NRPProgramName
static constexpr std::string_view NRPProgramName
Definition: simulation_parameters.h:43
SimulationParams::setWorkingDirectoryAndGetConfigFile
static jsonSharedPtr setWorkingDirectoryAndGetConfigFile(const cxxopts::ParseResult &args)
Get the simulation configuration from start parameters as a JSON object.
Definition: simulation_parameters.cpp:66
SimulationParams::createStartParamParser
static cxxopts::Options createStartParamParser()
Create a parser for start parameters.
Definition: simulation_parameters.cpp:27
SimulationParams::ParamFilenameT
std::string ParamFilenameT
Definition: simulation_parameters.h:82
SimulationParams::ParamSlaveDesc
static constexpr std::string_view ParamSlaveDesc
Definition: simulation_parameters.h:108
SimulationParams::ParamLogConfigLong
static constexpr std::string_view ParamLogConfigLong
Definition: simulation_parameters.h:89
SimulationParams::ParamModeT
std::string ParamModeT
Definition: simulation_parameters.h:96
SimulationParams::ParamPlugins
static constexpr std::string_view ParamPlugins
Definition: simulation_parameters.h:57
SimulationParams::ParamSimParamDesc
static constexpr std::string_view ParamSimParamDesc
Definition: simulation_parameters.h:100
SimulationParams::ParamFileLogLevelT
std::string ParamFileLogLevelT
Definition: simulation_parameters.h:74
SimulationParams::ParamPluginsT
std::vector< std::string > ParamPluginsT
Definition: simulation_parameters.h:60
SimulationParams::ParamSimCfgFileT
std::string ParamSimCfgFileT
Definition: simulation_parameters.h:55
SimulationParams::ParamHelpDesc
static constexpr std::string_view ParamHelpDesc
Definition: simulation_parameters.h:49
SimulationParams::ParamLogOutputDesc
static constexpr std::string_view ParamLogOutputDesc
Definition: simulation_parameters.h:77
SimulationParams::ParamConsoleLogLevelT
std::string ParamConsoleLogLevelT
Definition: simulation_parameters.h:70
NRPLogger::level_t
spdlog::level::level_enum level_t
The wrapper type for log levels.
Definition: nrp_logger.h:52
SimulationParams::ParamFileLogLevelDesc
static constexpr std::string_view ParamFileLogLevelDesc
Definition: simulation_parameters.h:73
SimulationParams::ParamExpDirT
std::string ParamExpDirT
Definition: simulation_parameters.h:65
SimulationParams::ParamServerAddressT
std::string ParamServerAddressT
Definition: simulation_parameters.h:105
SimulationParams::ParamLogConfigDesc
static constexpr std::string_view ParamLogConfigDesc
Definition: simulation_parameters.h:90
SimulationParams::ParamHelpT
bool ParamHelpT
Definition: simulation_parameters.h:50
SimulationParams::ParamModeDesc
static constexpr std::string_view ParamModeDesc
Definition: simulation_parameters.h:95
SimulationParams::ParamConsoleLogLevelLong
static constexpr std::string_view ParamConsoleLogLevelLong
Definition: simulation_parameters.h:68
SimulationParams::ParamLogConfigT
bool ParamLogConfigT
Definition: simulation_parameters.h:91
SimulationParams::ProgramDescription
static constexpr std::string_view ProgramDescription
Definition: simulation_parameters.h:44
SimulationParams::ParamSimParamLong
static constexpr std::string_view ParamSimParamLong
Definition: simulation_parameters.h:99
json
nlohmann::json json
Definition: engine_json_server.cpp:31
SimulationParams::ParamHelpLong
static constexpr std::string_view ParamHelpLong
Definition: simulation_parameters.h:48