2 #include "../Eval/Eval.hpp"
3 #include "../Math/RNG.hpp"
4 #include "../Param/RunParameters.hpp"
6 #include "../nomad_version.hpp"
12 void NOMAD::RunParameters::init()
18 #include "../Attribute/runAttributesDefinition.hpp"
23 " NOMAD precision for comparison of values ",
24 " \n \n . NOMAD precision for comparison of values \n ",
" advanced precision double(s) value(s) number(s) ");
26 "String for undefined values ",
27 " \n \n String for undefined values \n ",
" advanced undef(ined) value(s) string(s) ");
29 " NOMAD version number (for runner) ",
30 " \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) " );
32 "String for infinite values",
33 " \n \n . String for infinite values \n ",
" advanced string(s) inf(inite) value(s) ");
34 registerAttribute<std::string>(
"PROBLEM_DIR", std::string(
".") +
NOMAD::DIR_SEP ,
false,
35 "Problem directory " ,
36 "\n \n . Problem directory \n . To complete \n ",
" problem dir(ectory) folder(s) ");
40 catch (NOMAD::Exception & e)
42 std::string errorMsg =
"Attribute registration failed: ";
44 throw NOMAD::Exception(__FILE__,__LINE__, errorMsg);
52 void NOMAD::RunParameters::checkAndComply(
53 const std::shared_ptr<NOMAD::EvaluatorControlParameters>& evaluatorControlParams)
68 const std::shared_ptr<NOMAD::ParameterEntry> pe = getNonInterpretedParamEntry();
71 string err =
"File " + pe->getParamFile() +
" line " + std::to_string(pe->getLine());
72 err +=
": Unrecognized parameter: " + pe->getName() +
".";
73 if (getAttributeValueProtected<bool>(
"REJECT_UNKNOWN_PARAMETERS",
false))
75 throw NOMAD::Exception(__FILE__,__LINE__, err);
79 std::cerr << err <<
" Ignore unknown parameter and continue." << std::endl;
83 auto problemDir = getAttributeValueProtected<std::string>(
"PROBLEM_DIR",
false);
85 auto seed = getAttributeValueProtected<int>(
"SEED" ,
false);
88 throw NOMAD::Exception(__FILE__,__LINE__,
"Parameters check: SEED must be non-negative" );
92 auto version_number = getAttributeValueProtected<std::string>(
"NOMAD_VERSION",
false);
95 throw NOMAD::Exception(__FILE__,__LINE__,
"Parameters check: VERSION_NUMBER is not compatible" );
98 auto anisotropyFactor = getAttributeValueProtected<NOMAD::Double>(
"ANISOTROPY_FACTOR",
false);
99 if ( anisotropyFactor <= 0)
101 throw NOMAD::Exception(__FILE__,__LINE__,
"Parameters check: ANISOTROPY_FACTOR must be positive" );
104 setStaticParameters();
110 if (evaluatorControlParams->toBeChecked())
112 evaluatorControlParams->checkAndComply();
114 auto blockSize = evaluatorControlParams->getAttributeValue<
size_t>(
"BB_MAX_BLOCK_SIZE");
117 throw NOMAD::Exception(__FILE__, __LINE__,
"Parameter BB_MAX_BLOCK_SIZE must be positive");
120 else if (blockSize > 1)
122 if (getAttributeValueProtected<int>(
"NB_THREADS_OPENMP",
false) != 1)
124 std::cerr <<
"Warning: Parallelism management: BB_MAX_BLOCK_SIZE is ";
125 std::cerr <<
"larger than 1 (value is " << blockSize <<
"). ";
126 std::cerr <<
"Setting parameter NB_THREADS_OPENMP to 1." << std::endl;
128 setAttributeValue(
"NB_THREADS_OPENMP", 1);
136 std::string hotRestartFileName = getAttributeValueProtected<std::string>(
"HOT_RESTART_FILE",
false);
137 if (!hotRestartFileName.empty())
140 setAttributeValue(
"HOT_RESTART_FILE", hotRestartFileName);
144 auto hMax = getAttributeValueProtected<NOMAD::Double>(
"H_MAX_0",
false);
147 throw NOMAD::Exception(__FILE__,__LINE__,
"Parameters check: H_MAX_0 must be positive");
150 _toBeChecked =
false;
156 void NOMAD::RunParameters::setStaticParameters()
159 NOMAD::RNG::setSeed ( getAttributeValueProtected<int>(
"SEED",
false) );
160 NOMAD::Double::setEpsilon ( getAttributeValueProtected<NOMAD::Double>(
"EPSILON",
false).todouble() );
161 NOMAD::Double::setUndefStr ( getAttributeValueProtected<std::string>(
"UNDEF_STR",
false) );
162 NOMAD::Double::setInfStr ( getAttributeValueProtected<std::string>(
"INF_STR",
false) );
166 setAttributeValue (
"SEED", NOMAD::RNG::getSeed() );
167 setAttributeValue (
"EPSILON", NOMAD::Double(NOMAD::Double::getEpsilon()) );
168 setAttributeValue (
"UNDEF_STR", NOMAD::Double::getUndefStr() );
169 setAttributeValue (
"INF_STR", NOMAD::Double::getInfStr() );
#define NOMAD_VERSION_NUMBER
Define version number.
const std::string DEFAULT_UNDEF_STR
Default undefined value string used by Double.
const char DIR_SEP
Directory separator.
const std::string DEFAULT_INF_STR
Default infinity string used by Double.
void completeFileName(std::string &filename, const std::string &problemDir, bool addSeed=false, int seed=0)
const double DEFAULT_EPSILON
Default epsilon used by Double.