47 #include "../Math/RNG.hpp"
48 #include "../Param/RunParameters.hpp"
49 #include "../Util/fileutils.hpp"
51 #include "../nomad_version.hpp"
55 bool NOMAD::RunParameters::_warningUnknownParamShown =
false;
60 void NOMAD::RunParameters::init()
66 #include "../Attribute/runAttributesDefinition.hpp"
71 " NOMAD precision for comparison of values ",
72 " \n \n . NOMAD precision for comparison of values \n ",
" advanced precision double(s) value(s) number(s) ");
74 "String for undefined values ",
75 " \n \n String for undefined values \n ",
" advanced undef(ined) value(s) string(s) ");
77 " NOMAD version number (for runner) ",
78 " \n \n . NOMAD version number (optional) \n . If not compatible with current version will trigger exception \n " ,
" advanced nomad version(s) release(s) revision(s) " );
80 "String for infinite values",
81 " \n \n . String for infinite values \n ",
" advanced string(s) inf(inite) value(s) ");
82 registerAttribute<std::string>(
"PROBLEM_DIR", std::string(
".") +
NOMAD::DIR_SEP ,
false,
83 "Problem directory " ,
84 "\n \n . Problem directory \n . To complete \n ",
" problem dir(ectory) folder(s) ");
88 catch (NOMAD::Exception & e)
90 std::string errorMsg =
"Attribute registration failed: ";
92 throw NOMAD::Exception(__FILE__,__LINE__, errorMsg);
100 void NOMAD::RunParameters::checkAndComply(
101 const std::shared_ptr<NOMAD::EvaluatorControlGlobalParameters>& evaluatorControlGlobalParams,
102 const std::shared_ptr<NOMAD::PbParameters>& pbParams)
115 std::vector<std::shared_ptr<NOMAD::ParameterEntry>> allNonInterp = getAllNonInterpretedParamEntries();
116 if (allNonInterp.size() > 0)
118 err =
"Unrecognized parameters in file " + allNonInterp[0]->getParamFile() +
":\n";
119 for (
auto pe : allNonInterp)
121 err +=
"line " + std::to_string(pe->getLine());
122 err +=
": Unrecognized parameter: " + pe->getName() +
"\n";
124 if (getAttributeValueProtected<bool>(
"REJECT_UNKNOWN_PARAMETERS",
false))
126 throw NOMAD::Exception(__FILE__,__LINE__, err);
130 if (!_warningUnknownParamShown)
132 std::cerr <<
"Warning: " << err <<
"Ignoring unknown parameters." << std::endl;
137 auto problemDir = getAttributeValueProtected<std::string>(
"PROBLEM_DIR",
false);
139 auto seed = getAttributeValueProtected<int>(
"SEED" ,
false);
142 throw NOMAD::Exception(__FILE__,__LINE__,
"Parameters check: SEED must be non-negative" );
145 auto version_number = getAttributeValueProtected<std::string>(
"NOMAD_VERSION",
false);
148 err =
"Parameters check: NOMAD_VERSION is not compatible with registered version " + std::string(
NOMAD_VERSION_NUMBER) +
"\n";
149 throw NOMAD::Exception(__FILE__,__LINE__, err );
152 auto anisotropyFactor = getAttributeValueProtected<NOMAD::Double>(
"ANISOTROPY_FACTOR",
false);
153 if ( anisotropyFactor <= 0)
155 throw NOMAD::Exception(__FILE__,__LINE__,
"Parameters check: ANISOTROPY_FACTOR must be positive" );
158 setStaticParameters();
164 auto disabledConst = getAttributeValueProtected<NOMAD::ArrayOfString>(
"DISABLE",
false);
165 NOMAD::ArrayOfString disabled;
166 for (
size_t i = 0; i < disabledConst.size(); i++)
168 std::string disabledI = disabledConst[i];
170 disabled.add(disabledI);
172 setAttributeValue(
"DISABLE", disabled);
177 const size_t bigDim = 50;
178 size_t n = pbParams->getAttributeValue<
size_t>(
"DIMENSION");
180 bool showDisableWarn =
true;
183 disabled = getAttributeValueProtected<NOMAD::ArrayOfString>(
"DISABLE",
false);
186 if (-1 == disabled.find(
"MODELS"))
188 disabled.add(std::string(
"MODELS"));
189 setAttributeValue(
"DISABLE", disabled);
190 std::cerr <<
"Warning: Dimension " << n <<
" is greater than (or equal to) " << bigDim <<
". Models are disabled." << std::endl;
192 showDisableWarn =
false;
198 disabled = getAttributeValueProtected<NOMAD::ArrayOfString>(
"DISABLE",
false);
199 if (disabled.find(
"MODELS") >= 0)
201 if (getAttributeValueProtected<bool>(
"SGTELIB_SEARCH",
false))
205 std::cerr <<
"Warning: Models are disabled. SGTELIB_SEARCH set to false." << std::endl;
207 setAttributeValue(
"SGTELIB_SEARCH",
false);
209 if (getAttributeValueProtected<bool>(
"QUAD_MODEL_SEARCH",
false))
213 std::cerr <<
"Warning: Models are disabled. QUAD_MODEL_SEARCH set to false." << std::endl;
215 setAttributeValue(
"QUAD_MODEL_SEARCH",
false);
222 auto sgtelibModelDefinition = getAttributeValueProtected<NOMAD::ArrayOfString>(
"SGTELIB_MODEL_DEFINITION",
false);
223 if (sgtelibModelDefinition.size() == 0)
226 NOMAD::ArrayOfString aos(
"TYPE PRS DEGREE 2");
227 setAttributeValue(
"SGTELIB_MODEL_DEFINITION", aos );
230 auto sgtelibModelTrials = getAttributeValueProtected<size_t>(
"SGTELIB_MODEL_TRIALS",
false);
231 if (0 == sgtelibModelTrials)
233 throw NOMAD::Exception(__FILE__, __LINE__,
"Parameter SGTELIB_MODEL_TRIALS must be positive");
240 if (evaluatorControlGlobalParams->toBeChecked())
242 evaluatorControlGlobalParams->checkAndComply();
244 auto bbBlockSize = evaluatorControlGlobalParams->getAttributeValue<
size_t>(
"BB_MAX_BLOCK_SIZE");
245 if (0 == bbBlockSize)
247 throw NOMAD::Exception(__FILE__, __LINE__,
"Parameter BB_MAX_BLOCK_SIZE must be positive");
249 auto sgteBlockSize = evaluatorControlGlobalParams->getAttributeValue<
size_t>(
"SGTE_MAX_BLOCK_SIZE");
250 if (0 == sgteBlockSize)
252 throw NOMAD::Exception(__FILE__, __LINE__,
"Parameter SGTE_MAX_BLOCK_SIZE must be positive");
257 if (getAttributeValueProtected<bool>(
"SGTELIB_MODEL_EVAL",
false))
259 err =
"Sgtelib Model sampling cannot be used. Either set parameter ";
260 err +=
"SGTELIB_MODEL_EVAL to false, or recompile NOMAD using option USE_SGTELIB=1.";
261 throw NOMAD::Exception(__FILE__,__LINE__, err);
263 if (getAttributeValueProtected<bool>(
"SGTELIB_SEARCH",
false))
265 err =
"Warning: Parameter SGTELIB_SEARCH is set to true, but ";
266 err +=
"Sgtelib Model sampling cannot be used. To be able to use Sgtelib Model ";
267 err +=
"search method, NOMAD must be recompiled using option USE_SGTELIB=1.";
268 std::cerr << err << std::endl;
270 if (getAttributeValueProtected<bool>(
"QUAD_MODEL_SEARCH",
false))
272 err =
"Warning: Parameter QUAD_MODEL_SEARCH is set to true, but ";
273 err +=
"Quad Model sampling cannot be used. To be able to use Quad Model Search ";
274 err +=
"search method, NOMAD must be recompiled using option USE_SGTELIB=1.";
275 std::cerr << err << std::endl;
280 bool useAlgoPSDMads = getAttributeValueProtected<bool>(
"PSD_MADS_OPTIMIZATION",
false);
285 err =
"Error: PSD_MADS_OPTIMIZATION can only be used when OpenMP is available. If that is not the case, use SSD_MADS_OPTIMIZATION.";
286 throw NOMAD::Exception(__FILE__,__LINE__, err);
290 bool useAlgoSSDMads = getAttributeValueProtected<bool>(
"SSD_MADS_OPTIMIZATION",
false);
291 if (useAlgoPSDMads || useAlgoSSDMads)
293 std::string nbVarParamName = (useAlgoPSDMads ?
"PSD_MADS_NB_VAR_IN_SUBPROBLEM" :
"SSD_MADS_NB_VAR_IN_SUBPROBLEM");
294 const size_t nbVariablesInSubproblem = getAttributeValueProtected<size_t>(nbVarParamName,
false);
295 if (0 == nbVariablesInSubproblem || nbVariablesInSubproblem > n)
297 err =
"Parameter " + nbVarParamName +
" must be between 1 and " +
NOMAD::itos(n);
298 err +=
". Value provided: " +
NOMAD::itos(nbVariablesInSubproblem);
299 throw NOMAD::InvalidParameter(__FILE__,__LINE__, err);
302 size_t nbMadsSubproblem = getAttributeValueProtected<size_t>((useAlgoPSDMads ?
"PSD_MADS_NB_SUBPROBLEM" :
"SSD_MADS_NB_SUBPROBLEM"),
false);
304 bool nbMadsSubproblemSetByUser =
true;
307 nbMadsSubproblem = std::round(n/nbVariablesInSubproblem)+1;
308 nbMadsSubproblemSetByUser =
false;
313 size_t nbThreads = (size_t)getAttributeValueProtected<int>(
"NB_THREADS_OPENMP",
false);
314 if (nbMadsSubproblem > nbThreads)
316 nbMadsSubproblem = nbThreads;
317 if (nbMadsSubproblemSetByUser)
320 std::cerr <<
"Warning: parameter PSD_MADS_NB_SUBPROBLEM reset to number of available threads (" << nbThreads <<
")" << std::endl;
324 setAttributeValue((useAlgoPSDMads ?
"PSD_MADS_NB_SUBPROBLEM" :
"SSD_MADS_NB_SUBPROBLEM"), nbMadsSubproblem);
329 std::string covParamName =
"PSD_MADS_SUBPROBLEM_PCT_COVERAGE";
330 auto coverage = getAttributeValueProtected<NOMAD::Double>(covParamName,
false);
331 if (coverage < 0.0 || coverage > 100.0)
333 err =
"Parameter " + covParamName +
" must be between 0.0 and 100.0";
334 throw NOMAD::InvalidParameter(__FILE__,__LINE__, err);
341 bool useAlgoLH = (getAttributeValueProtected<size_t>(
"LH_EVAL",
false) > 0);
342 bool useAlgoNM = getAttributeValueProtected<bool>(
"NM_OPTIMIZATION",
false);
343 bool useAlgoQuadOpt = getAttributeValueProtected<bool>(
"QUAD_MODEL_OPTIMIZATION",
false);
344 bool useAlgoSgtelibModel = getAttributeValueProtected<bool>(
"SGTELIB_MODEL_EVAL",
false);
345 int totalAlgoSet = (int)useAlgoLH + (
int)useAlgoNM + (int)useAlgoQuadOpt
346 + (
int)useAlgoPSDMads + (int)useAlgoSgtelibModel + (
int)useAlgoSSDMads;
348 if (totalAlgoSet >= 2)
350 err =
"Multiple parameters for algorithms are set. ";
351 err +=
"These parameters are mutually exclusive:";
358 err +=
" NM_OPTIMIZATION";
362 err +=
" PSD_MADS_OPTIMIZATION";
366 err +=
" QUAD_MODEL_OPTIMIZATION";
368 if (useAlgoSgtelibModel)
370 err +=
" SGTELIB_MODEL_EVAL";
374 err +=
" SSD_MADS_OPTIMIZATION";
376 err +=
". Please review parameters settings and choose only one algorithm.";
377 throw NOMAD::Exception(__FILE__,__LINE__, err);
384 std::string hotRestartFileName = getAttributeValueProtected<std::string>(
"HOT_RESTART_FILE",
false);
385 if (!hotRestartFileName.empty())
388 setAttributeValue(
"HOT_RESTART_FILE", hotRestartFileName);
392 auto hMax = getAttributeValueProtected<NOMAD::Double>(
"H_MAX_0",
false);
395 throw NOMAD::Exception(__FILE__,__LINE__,
"Parameters check: H_MAX_0 must be positive");
398 _warningUnknownParamShown =
true;
400 _toBeChecked =
false;
405 void NOMAD::RunParameters::setStaticParameters()
408 NOMAD::RNG::setSeed ( getAttributeValueProtected<int>(
"SEED",
false) );
409 NOMAD::Double::setEpsilon ( getAttributeValueProtected<NOMAD::Double>(
"EPSILON",
false).todouble() );
410 NOMAD::Double::setUndefStr ( getAttributeValueProtected<std::string>(
"UNDEF_STR",
false) );
411 NOMAD::Double::setInfStr ( getAttributeValueProtected<std::string>(
"INF_STR",
false) );
415 setAttributeValue (
"SEED", NOMAD::RNG::getSeed() );
416 setAttributeValue (
"EPSILON", NOMAD::Double(NOMAD::Double::getEpsilon()) );
417 setAttributeValue (
"UNDEF_STR", NOMAD::Double::getUndefStr() );
418 setAttributeValue (
"INF_STR", NOMAD::Double::getInfStr() );