32 #ifdef HAVE_LMY_ENGINE 33 #include "formic/utils/matrix.h" 34 #include "formic/utils/random.h" 35 #include "formic/utils/lmyengine/var_dependencies.h" 53 :
QMCDriver(project_data, w, psi, h,
comm,
"QMCFixedSampleLinearOptimize"),
54 #ifdef HAVE_LMY_ENGINE
55 vdeps(1,
std::vector<double>()),
62 StabilizerMethod(
"best"),
70 max_relative_cost_change(10.0),
71 max_param_change(0.3),
72 cost_increase_tol(0.0),
74 targetExcitedStr(
"no"),
86 MinMethod(
"OneShiftOnly"),
89 do_output_matrices_(false),
90 output_matrices_initialized_(false),
91 freeze_parameters_(false),
129 #ifdef HAVE_LMY_ENGINE 131 std::vector<double> shift_scales(3, 1.0);
132 EngineObj =
new cqmc::engine::LMYEngine<ValueType>(&vdeps,
185 #ifdef HAVE_LMY_ENGINE 192 for (
int i = 0; i <
optparam.size(); i++)
217 size_t numParams =
optTarget->getNumParams();
218 size_t N = numParams + 1;
226 app_log() <<
"Doing gradient test run" << std::endl;
230 #ifdef HAVE_LMY_ENGINE 233 #if !defined(QMC_COMPLEX) 234 app_log() <<
"Doing hybrid run" << std::endl;
242 #if !defined(QMC_COMPLEX) 261 int Total_iterations(0);
263 size_t numParams =
optTarget->getNumParams();
264 size_t N = numParams + 1;
266 std::vector<RealType> currentParameterDirections(
N, 0);
267 std::vector<RealType> currentParameters(numParams, 0);
268 std::vector<RealType> bestParameters(numParams, 0);
269 for (
int i = 0; i < numParams; i++)
272 optdir.resize(numParams, 0);
277 Total_iterations += 1;
284 for (
int i = 0; i < numParams; i++)
285 optTarget->Params(i) = currentParameters[i];
299 optTarget->fillOverlapHamiltonianMatrices(Right, Left);
301 bool apply_inverse(
true);
316 for (
int i = 0; i <
N; i++)
317 for (
int j = 0; j <
N; j++)
318 od_largest = std::max(std::max(od_largest,
std::abs(Left(i, j)) -
std::abs(Left(i, i))),
320 app_log() <<
"od_largest " << od_largest << std::endl;
329 app_log() <<
" stabilityBase " << stabilityBase << std::endl;
332 bool acceptedOneMove(
false);
333 for (
int stability = 0; stability <
nstabilizers; stability++)
337 for (
int i = 0; i <
N; i++)
338 for (
int j = 0; j <
N; j++)
339 Right(i, j) = Left(j, i);
341 for (
int i = 1; i <
N; i++)
343 app_log() <<
" Using XS:" << XS <<
" " << failedTries <<
" " << stability << std::endl;
352 for (
int i = 0; i < numParams; i++)
353 bigVec = std::max(bigVec,
std::abs(currentParameterDirections[i + 1]));
361 app_log() <<
" Failed Step. Magnitude of largest parameter change: " <<
std::abs(Lambda * bigVec)
371 for (
int i = 0; i < numParams; i++)
372 optTarget->Params(i) = currentParameters[i] + Lambda * currentParameterDirections[i + 1];
377 for (
int i = 0; i < numParams; i++)
379 for (
int i = 0; i < numParams; i++)
380 optdir[i] = currentParameterDirections[i + 1];
384 LambdaMax = 0.5 * Lambda;
391 Valid = lineoptimization3(npts, evaluated_cost);
394 Valid = lineoptimization2();
401 app_log() <<
" Failed Step. Largest LM parameter change:" << biggestParameterChange << std::endl;
409 for (
int i = 0; i < numParams; i++)
411 app_log() <<
" Good Step. Largest LM parameter change:" << biggestParameterChange << std::endl;
421 app_log() <<
" OldCost: " << lastCost <<
" NewCost: " << newCost <<
" Delta Cost:" << (newCost - lastCost)
431 app_log() <<
" Good Step, but cost function invalid" << std::endl;
438 if (newCost < lastCost && goodStep)
441 for (
int i = 0; i < numParams; i++)
444 acceptedOneMove =
true;
452 else if (stability > 0)
460 if (failedTries > 20)
467 app_log() <<
"Setting new Parameters" << std::endl;
468 for (
int i = 0; i < numParams; i++)
469 optTarget->Params(i) = bestParameters[i];
473 app_log() <<
"Reverting to old Parameters" << std::endl;
474 for (
int i = 0; i < numParams; i++)
475 optTarget->Params(i) = currentParameters[i];
481 return (
optTarget->getReportCounter() > 0);
491 std::string vmcMove(
"pbyp");
492 std::string ReportToH5(
"no");
493 std::string OutputMatrices(
"no");
494 std::string FreezeParameters(
"no");
496 oAttrib.
add(vmcMove,
"move");
497 oAttrib.
add(ReportToH5,
"hdf5");
499 m_param.
add(OutputMatrices,
"output_matrices_csv");
500 m_param.
add(FreezeParameters,
"freeze_parameters");
514 app_warning() <<
" The option 'freeze_parameters' is enabled. Variational parameters will not be updated. This " 515 "run will not perform variational parameter optimization!" 521 processChildren(q, [&](
const std::string& cname,
const xmlNodePtr element) {
522 if (cname ==
"optimize")
525 if (!att.empty() && att ==
"gradient_test")
528 test_grad_input.
readXML(element);
530 testEngineObj = std::make_unique<GradientTest>(std::move(test_grad_input));
536 std::stringstream error_msg;
537 app_log() <<
"Unknown or missing 'method' attribute in optimize tag: " << att <<
"\n";
571 throw std::runtime_error(
"Unknown MinMethod!\n");
598 app_log() <<
"test version of OpenMP threading with AdaptiveThreeShift optimizer" << std::endl;
604 throw std::runtime_error(
"max_param_change must be positive in QMCFixedSampleLinearOptimize::put");
608 throw std::runtime_error(
"max_relative_cost_change must be positive in QMCFixedSampleLinearOptimize::put");
612 throw std::runtime_error(
"shift_i must be positive in QMCFixedSampleLinearOptimize::put");
614 throw std::runtime_error(
"shift_s must be positive in QMCFixedSampleLinearOptimize::put");
618 throw std::runtime_error(
"cost_increase_tol must be non-negative in QMCFixedSampleLinearOptimize::put");
628 xmlNodePtr qsave = opt_xml;
629 xmlNodePtr cur = qsave->children;
633 std::string cname((
const char*)(cur->name));
634 if (cname ==
"mcwalkerset")
648 vmcEngine->setUpdateMode(vmcMove[0] ==
'p');
677 throw std::runtime_error(
"number of shifts must be odd in QMCFixedSampleLinearOptimize::prepare_shifts");
684 if (i < central_index)
685 retval.at(i) = central_shift / (4.0 * (central_index - i));
686 else if (i > central_index)
687 retval.at(i) = central_shift * (4.0 * (i - central_index));
688 else if (i == central_index)
689 retval.at(i) = central_shift;
704 app_log() <<
" " << std::right << std::setw(12) <<
"shift_i";
705 app_log() <<
" " << std::right << std::setw(12) <<
"shift_s";
706 app_log() <<
" " << std::right << std::setw(20) <<
"max param change";
707 app_log() <<
" " << std::right << std::setw(20) <<
"cost function value";
709 app_log() <<
" " << std::right << std::setw(12) <<
"------------";
710 app_log() <<
" " << std::right << std::setw(12) <<
"------------";
711 app_log() <<
" " << std::right << std::setw(20) <<
"--------------------";
712 app_log() <<
" " << std::right << std::setw(20) <<
"--------------------";
740 app_log() <<
" " << std::scientific << std::right << std::setw(12) << std::setprecision(4) << si;
741 app_log() <<
" " << std::scientific << std::right << std::setw(12) << std::setprecision(4) << ss;
742 app_log() <<
" " << std::scientific << std::right << std::setw(20) << std::setprecision(4) << mc;
743 app_log() <<
" " << std::fixed << std::right << std::setw(20) << std::setprecision(12) << cv;
748 app_log() <<
" " << std::right << std::setw(12) <<
"N/A";
749 app_log() <<
" " << std::right << std::setw(12) <<
"N/A";
750 app_log() <<
" " << std::right << std::setw(20) <<
"N/A";
751 app_log() <<
" " << std::right << std::setw(20) <<
"N/A";
752 app_log() <<
" " << std::right << std::setw(12) <<
"bad update";
757 app_log() <<
" " << std::right << std::setw(12) <<
"N/A";
758 app_log() <<
" " << std::right << std::setw(12) <<
"N/A";
759 app_log() <<
" " << std::right << std::setw(20) <<
"N/A";
760 app_log() <<
" " << std::fixed << std::right << std::setw(20) << std::setprecision(12) << cv;
761 app_log() <<
" " << std::right << std::setw(12) <<
"initial";
778 const std::vector<RealType>& cv,
779 const std::vector<double>& sh,
790 for (
int i = 0; i < cv.size(); i++)
806 const bool cost_is_much_lower = (!cost_is_similar && cv.at(ii) < cv.at(i) -
cost_increase_tol);
807 if (cost_is_much_lower || (closer_to_target && cost_is_similar))
808 retval = (retval &&
true);
816 retval = (retval && cv.at(ii) <= cv.at(i));
852 const std::vector<double>& shifts_s,
853 std::vector<std::vector<RealType>>& parameterDirections)
856 const int nshifts = shifts_i.size();
859 size_t numParams =
optTarget->getNumParams();
862 size_t N = numParams + 1;
865 parameterDirections.resize(nshifts);
866 for (
int i = 0; i < parameterDirections.size(); i++)
867 parameterDirections.at(i).assign(
N, 0.0);
870 Matrix<RealType> ovlMat(
N,
N);
872 Matrix<RealType> hamMat(
N,
N);
874 Matrix<RealType> invMat(
N,
N);
876 Matrix<RealType> sftMat(
N,
N);
878 Matrix<RealType> prdMat(
N,
N);
882 optTarget->fillOverlapHamiltonianMatrices(hamMat, ovlMat);
896 for (
int shift_index = 0; shift_index < nshifts; shift_index++)
902 for (
int i = 1; i <
N; i++)
903 sftMat(i, i) += shifts_i.at(shift_index);
906 for (
int i = 1; i <
N; i++)
907 for (
int j = 1; j <
N; j++)
908 sftMat(i, j) += shifts_s.at(shift_index) * ovlMat(i, j);
914 for (
int i = 0; i <
N; i++)
915 for (
int j = i + 1; j <
N; j++)
916 std::swap(prdMat(i, j), prdMat(j, i));
925 for (
int i = 0; i < numParams; i++)
926 parameterDirections.at(shift_index).at(i + 1) *= Lambda;
942 #ifdef HAVE_LMY_ENGINE 946 const bool saved_grads_flag =
optTarget->getneedGrads();
949 const int init_num_samp =
optTarget->getNumSamples();
955 size_t numParams =
optTarget->getNumParams();
960 std::vector<double> shift_scales(shifts_i.size(), 1.0);
961 for (
int i = 0; i < shift_scales.size(); i++)
971 previous_update.push_back(formic::ColVec<double>(numParams));
972 for (
int i = 0; i < numParams; i++)
973 previous_update.at(count).at(i) = 2.0 * (formic::random_number<double>() - 0.5);
977 if (!EngineObj->full_init())
980 formic::VarDeps real_vdeps(numParams, std::vector<double>());
982 EngineObj->get_param(&vdeps,
993 EngineObj->shift_update(shift_scales);
996 EngineObj->turn_on_update();
999 EngineObj->initialize(
nblocks, 0,
nkept, previous_update,
false);
1008 size_t N = numParams + 1;
1011 EngineObj->energy_target_compute();
1012 const RealType starting_cost = EngineObj->target_value();
1013 const RealType init_energy = EngineObj->energy_mean();
1017 <<
"*************************************************************************************************" 1019 <<
"Solving the linear method equations on the initial sample with initial energy" << std::setw(20)
1020 << std::setprecision(12) << init_energy << std::endl
1021 <<
"*************************************************************************************************" 1027 EngineObj->wfn_update_prep();
1033 int numOptParams =
optTarget->getNumParams();
1047 <<
"*********************************************************" << std::endl
1048 <<
"Solving the linear method equations on the initial sample" << std::endl
1049 <<
"*********************************************************" << std::endl
1053 std::vector<std::vector<RealType>> parameterDirections;
1054 #ifdef HAVE_LMY_ENGINE 1056 EngineObj->wfn_update_compute();
1062 parameterDirections.resize(shifts_i.size());
1063 for (
int i = 0; i < shifts_i.size(); i++)
1065 parameterDirections.at(i).assign(
N, 0.0);
1068 for (
int j = 0; j <
N; j++)
1069 parameterDirections.at(i).at(j) =
std::real(EngineObj->wfn_update().at(i *
N + j));
1072 parameterDirections.at(i).at(0) = 1.0;
1079 std::vector<RealType> currParams(numParams, 0.0);
1082 for (
int i = 0; i < numParams; i++)
1083 currParams.at(i) =
optTarget->Params(i);
1086 std::vector<bool> good_update(parameterDirections.size(),
true);
1089 std::vector<RealType> max_change(parameterDirections.size(), 0.0);
1090 for (
int k = 0; k < parameterDirections.size(); k++)
1092 for (
int i = 0; i < numParams; i++)
1094 std::max(max_change.at(k),
std::abs(parameterDirections.at(k).at(i + 1) / parameterDirections.at(k).at(0)));
1095 good_update.at(k) = (good_update.at(k) && max_change.at(k) <=
max_param_change);
1099 for (
int i = 0; i < numParams; i++)
1100 optTarget->Params(i) = currParams.at(i) + parameterDirections.at(central_index).at(i + 1);
1104 <<
"************************************************************" << std::endl
1105 <<
"Updating the guiding function with the middle shift's update" << std::endl
1106 <<
"************************************************************" << std::endl
1113 <<
"*************************************************************" << std::endl
1114 <<
"Generating a new sample based on the updated guiding function" << std::endl
1115 <<
"*************************************************************" << std::endl
1118 std::string old_name =
vmcEngine->getCommunicator()->getName();
1119 vmcEngine->getCommunicator()->setName(old_name +
".middleShift");
1121 vmcEngine->getCommunicator()->setName(old_name);
1125 <<
"******************************************************************" << std::endl
1126 <<
"Comparing different shifts' cost function values on updated sample" << std::endl
1127 <<
"******************************************************************" << std::endl
1131 for (
int i = 0; i < numParams; i++)
1132 currParams.at(i) =
optTarget->Params(i);
1135 for (
int i = 0; i < numParams; i++)
1136 optTarget->Params(i) = currParams.at(i) - parameterDirections.at(central_index).at(i + 1);
1141 for (
int i = 0; i < numParams; i++)
1143 for (
int j = 0; j < parameterDirections.size(); j++)
1145 if (j != central_index)
1146 parameterDirections.at(j).at(i + 1) -= parameterDirections.at(central_index).at(i + 1);
1151 std::vector<RealType> costValues(
num_shifts, 0.0);
1154 for (
int k = 0; k < parameterDirections.size(); k++)
1156 for (
int i = 0; i < numParams; i++)
1157 optTarget->Params(i) = currParams.at(i) + (k == central_index ? 0.0 : parameterDirections.at(k).at(i + 1));
1159 costValues.at(k) =
optTarget->LMYEngineCost(
false, EngineObj);
1162 if (!good_update.at(k))
1163 costValues.at(k) =
std::abs(1.5 * initCost) + 1.0;
1167 const std::vector<RealType>* bestDirection = 0;
1168 int best_shift = -1;
1170 if (
is_best_cost(k, costValues, shifts_i, initCost) && good_update.at(k))
1173 bestDirection = ¶meterDirections.at(k);
1180 for (
int k = 0; k < good_update.size(); k++)
1181 print_cost_summary(shifts_i.at(k), shifts_s.at(k), max_change.at(k), costValues.at(k), k, best_shift,
1189 for (
int i = 0; i < numParams; i++)
1190 optTarget->Params(i) = currParams.at(i) + (best_shift == central_index ? 0.0 : bestDirection->at(i + 1));
1192 <<
"*****************************************************************************" << std::endl
1193 <<
"Applying the update for shift_i = " << std::scientific << std::right << std::setw(12)
1194 << std::setprecision(4) <<
bestShift_i <<
" and shift_s = " << std::scientific << std::right
1195 << std::setw(12) << std::setprecision(4) <<
bestShift_s << std::endl
1196 <<
"*****************************************************************************" << std::endl
1205 for (
int i = 0; i < numParams; i++)
1206 optTarget->Params(i) = currParams.at(i) - parameterDirections.at(central_index).at(i + 1);
1208 <<
"***********************************************************" << std::endl
1209 <<
"Reverting to old parameters and increasing shift magnitudes" << std::endl
1210 <<
"***********************************************************" << std::endl
1218 formic::ColVec<RealType> update_dirs(numParams, 0.0);
1219 for (
int i = 0; i < numParams; i++)
1221 update_dirs.at(i) =
std::real(bestDirection->at(i + 1) + parameterDirections.at(central_index).at(i + 1));
1222 previous_update.insert(previous_update.begin(), update_dirs);
1225 while (previous_update.size() >
nolds)
1226 previous_update.pop_back();
1230 optTarget->setneedGrads(saved_grads_flag);
1236 optTarget->setNumSamples(init_num_samp);
1241 return (
optTarget->getReportCounter() > 0);
1254 size_t numParams =
optTarget->getNumParams();
1257 size_t N = numParams + 1;
1260 std::vector<RealType> currentParameters(numParams, 0.0);
1263 for (
int i = 0; i < numParams; i++)
1267 std::vector<RealType> parameterDirections;
1268 parameterDirections.assign(
N, 0.0);
1275 <<
"*****************************************" << std::endl
1276 <<
"Building overlap and Hamiltonian matrices" << std::endl
1277 <<
"*****************************************" << std::endl;
1280 Matrix<RealType> ovlMat(
N,
N);
1282 Matrix<RealType> hamMat(
N,
N);
1284 Matrix<RealType> invMat(
N,
N);
1286 Matrix<RealType> prdMat(
N,
N);
1290 optTarget->fillOverlapHamiltonianMatrices(hamMat, ovlMat);
1291 invMat.copy(ovlMat);
1300 for (
int i = 1; i <
N; i++)
1303 if (invMat(i, i) == 0)
1314 for (
int i = 1; i <
N; i++)
1315 for (
int j = 1; j <
N; j++)
1322 for (
int i = 0; i <
N; i++)
1323 for (
int j = i + 1; j <
N; j++)
1324 std::swap(prdMat(i, j), prdMat(j, i));
1336 for (
int i = 0; i < numParams; i++)
1337 parameterDirections.at(i + 1) *= Lambda;
1345 for (
int i = 0; i < numParams; i++)
1346 optTarget->Params(i) = currentParameters.at(i) + parameterDirections.at(i + 1);
1350 int max_element = 0;
1351 for (
int i = 0; i < numParams; i++)
1352 if (
std::abs(parameterDirections.at(i + 1)) > largestChange)
1354 largestChange =
std::abs(parameterDirections.at(i + 1));
1358 <<
"Among totally " << numParams <<
" optimized parameters, " 1359 <<
"largest LM parameter change : " << largestChange <<
" at parameter " << max_element << std::endl;
1366 <<
"******************************************************************************" << std::endl
1367 <<
"Init Cost = " << std::scientific << std::right << std::setw(12) << std::setprecision(4) << initCost
1368 <<
" New Cost = " << std::scientific << std::right << std::setw(12) << std::setprecision(4) << newCost
1369 <<
" Delta Cost = " << std::scientific << std::right << std::setw(12) << std::setprecision(4)
1370 << newCost - initCost << std::endl
1371 <<
"******************************************************************************" << std::endl;
1375 app_log() << std::endl <<
"The new set of parameters is not valid. Revert to the old set!" << std::endl;
1376 for (
int i = 0; i < numParams; i++)
1377 optTarget->Params(i) = currentParameters.at(i);
1391 app_log() << std::endl <<
"The new set of parameters is valid. Updating the trial wave function!" << std::endl;
1397 <<
"*****************************************************************************" << std::endl
1398 <<
"Applying the update for shift_i = " << std::scientific << std::right << std::setw(12)
1399 << std::setprecision(4) <<
bestShift_i <<
" and shift_s = " << std::scientific << std::right
1400 << std::setw(12) << std::setprecision(4) <<
bestShift_s << std::endl
1401 <<
"*****************************************************************************" << std::endl;
1407 return (
optTarget->getReportCounter() > 0);
1410 #ifdef HAVE_LMY_ENGINE 1414 const bool saved_grads_flag =
optTarget->getneedGrads();
1425 if (descent_num == 0)
1437 for (
int i = 0; i < results.size(); i++)
1456 return (
optTarget->getReportCounter() > 0);
1462 #ifdef HAVE_LMY_ENGINE 1463 bool QMCFixedSampleLinearOptimize::hybrid_run()
1476 std::vector<std::vector<ValueType>> hybridBLM_Input =
descentEngineObj->retrieveHybridBLM_Input();
1477 #if !defined(QMC_COMPLEX) 1479 EngineObj->setHybridBLM_Input(hybridBLM_Input);
1484 app_log() <<
"Update descent engine parameter values after Blocked LM step" << std::endl;
1485 for (
int i = 0; i <
optTarget->getNumParams(); i++)
1495 app_log() <<
"Finished a hybrid step" << std::endl;
1496 return (
optTarget->getReportCounter() > 0);
1510 app_log() <<
"<opt stage=\"setup\">" << std::endl;
1511 app_log() <<
" <log>" << std::endl;
1515 app_log() <<
" Reading configurations from h5FileRoot " <<
h5FileRoot << std::endl;
1524 NullEngineHandle handle;
1529 auto sigma2_check =
optTarget->getVariance();
1530 if (
optTarget->getNumSamples() > 1 && (sigma2_check > 2.0 * sigma2_vmc || sigma2_check < 0.5 * sigma2_vmc))
1531 throw std::runtime_error(
1532 "Safeguard failure: checkConfigurations variance out of [0.5, 2.0] * reference! Please report this bug.\n");
1533 app_log() <<
" Execution time = " << std::setprecision(4) << t2.elapsed() << std::endl;
1535 app_log() <<
" </log>" << std::endl;
1536 app_log() <<
"</opt>" << std::endl;
1537 app_log() << R
"(<opt stage="main" walkers=")" << optTarget->getNumSamples() << "\">" << std::endl;
1538 app_log() <<
" <log>" << std::endl;
1542 #ifdef HAVE_LMY_ENGINE 1543 void QMCFixedSampleLinearOptimize::engine_start(cqmc::engine::LMYEngine<ValueType>* EngineObj,
1544 DescentEngine& descentEngineObj,
1545 std::string MinMethod)
1547 app_log() <<
"entering engine_start function" << std::endl;
1557 app_log() <<
"<opt stage=\"setup\">" << std::endl;
1558 app_log() <<
" <log>" << std::endl;
1563 app_log() <<
" Reading configurations from h5FileRoot " <<
h5FileRoot << std::endl;
1572 app_log() <<
" Execution time = " << std::setprecision(4) << t2.elapsed() << std::endl;
1574 app_log() <<
" </log>" << std::endl;
1575 app_log() <<
"</opt>" << std::endl;
1576 app_log() << R
"(<opt stage="main" walkers=")" << optTarget->getNumSamples() << "\">" << std::endl;
1577 app_log() <<
" <log>" << std::endl;
1585 app_log() <<
" Execution time = " << std::setprecision(4) <<
t1.
elapsed() << std::endl;
1586 app_log() <<
" </log>" << std::endl;
1594 app_log() <<
" Restore the number of walkers to " <<
NumOfVMCWalkers <<
", removing " << nw_removed <<
" walkers." 1600 app_log() <<
"</opt>" << std::endl;
1601 app_log() <<
"</optimization-report>" << std::endl;
1606 app_log() <<
"<optimization-report>" << std::endl;
1623 app_log() << R
"(<vmc stage="main" blocks=")" << nBlocks << "\">" << std::endl;
1629 app_log() <<
" Execution time = " << std::setprecision(4) <<
t1.
elapsed() << std::endl;
1630 app_log() <<
"</vmc>" << std::endl;
std::unique_ptr< HybridEngine > hybridEngineObj
bool targetExcited
whether we are targeting an excited state
std::unique_ptr< QMCDriver > vmcEngine
vmc engine
MatrixA::value_type invert_matrix(MatrixA &M, bool getdet=true)
invert a matrix
std::string h5FileRoot
the root of h5File
bool run() override
Run the Optimization algorithm.
NewTimer & eigenvalue_timer_
int nkept
number of directions kept
NewTimer & initialize_timer_
int nolds
number of old updates kept
void finish()
common operation to finish optimization, used by the derived classes
std::bitset< 2 > accept_history
accept history, remember the last 2 iterations, value 00, 01, 10, 11
RealType max_param_change
max amount a parameter may change relative to current wave function weight
A set of walkers that are to be advanced by Metropolis Monte Carlo.
std::ostream & app_warning()
helper functions for EinsplineSetBuilder
NewTimer & generate_samples_timer_
std::unique_ptr< GradientTest > testEngineObj
bool block_lm
whether we are doing block algorithm
int rank() const
return the rank
const std::map< std::string, OptimizerType > OptimizerNames
QTBase::RealType RealType
size_t getActiveWalkers() const
return the number of active walkers
std::unique_ptr< QMCCostFunctionBase > optTarget
target cost function to optimize
std::string RootName
root of all the output files
bool ValidCostFunction(bool valid)
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
OutputMatrix output_overlap_
bool put(xmlNodePtr cur)
assign attributes to the set
RealType Func(RealType dl) override
RealType max_relative_cost_change
the maximum relative change in the cost function for the adaptive three-shift scheme ...
void print_cost_summary_header()
Collection of Local Energy Operators.
int nsamp_comp
number of samples to do in correlated sampling part
ScopeGuard< NewTimer > ScopedTimer
std::string block_lmStr
whether we are doing block algorithm
RealType bestShift_i
the previous best identity shift
abstract base class for QMC engines
bool AppendRun
flag to append or restart the run
Communicate * Controller
Global Communicator for a process.
xmlNodePtr wfNode
xml node to be dumped
NewTimer & cost_function_timer_
void copy(const This_t &rhs)
bool adaptive_three_shift_run()
bool put(std::istream &is) override
read from std::istream
iterator destroyWalkers(iterator first, iterator last)
destroy Walkers from itstart to itend
ParameterSet m_param
store any parameter that has to be read from a file
RealType shift_i_input
current shift_i, shift_s input values
std::vector< RealType > optdir
RealType shift_s_base
Shift_s adjustment base.
Wrapping information on parallelism.
OptimizerType previous_optimizer_type_
const std::string & get_root_name() const override
omp_int_t omp_get_max_threads()
void product(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
static function to perform C=AB for real matrices
std::bitset< QMC_MODE_MAX > qmc_driver_mode
bits to classify QMCDriver
std::vector< double > prepare_shifts(const double central_shift) const
Real getLowestEigenvector(Matrix< Real > &A, std::vector< Real > &ev) const
Communicate * myComm
pointer to Communicate
class to handle a set of attributes of an xmlNode
std::unique_ptr< BranchEngineType > branchEngine
branch engine
This a subclass for runtime errors that will occur on all ranks.
OptimizerType current_optimizer_type_
Tests for variational parameter derivatives.
std::string lowerCase(const std::string_view s)
++17
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
QMCHamiltonian & H
Hamiltonian.
OutputMatrix output_hamiltonian_
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
MCWalkerConfiguration & W
walker ensemble
static UPtrVector< RandomBase< FullPrecRealType > > Children
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
void start()
common operation to start optimization, used by the derived classes
std::vector< RealType > optparam
void solveShiftsWithoutLMYEngine(const std::vector< double > &shifts_i, const std::vector< double > &shiffts_s, std::vector< std::vector< RealType >> ¶meterDirections)
bool IsQMCDriver
true, if it is a real QMC engine
void output(Matrix< RealType > &mat)
Print matrix to text-formatted scalar.dat file.
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
QMCTraits::RealType RealType
void readXML(xmlNodePtr xml_input)
RealType omega_shift
the shift to use when targeting an excited state
std::unique_ptr< DescentEngine > descentEngineObj
void processChildren(const xmlNodePtr cur, const F &functor)
process through all the children of an XML element F is a lambda or functor void F/[](const std::stri...
bool processOptXML(xmlNodePtr cur, const std::string &vmcMove, bool reportH5)
process xml node value (parameters for both VMC and OPT) for the actual optimization ...
Class to represent a many-body trial wave function.
IndexType nTargetSamples
the number of saved samples
RealType cost_increase_tol
the tolerance to cost function increases when choosing the best shift in the adaptive shift method ...
std::string targetExcitedStr
whether we are targeting an excited state
int nblocks
number of blocks used in block algorithm
TrialWaveFunction & Psi
trial function
std::vector< xmlNodePtr > mcwalkerNodePtr
a list of mcwalkerset element
RealType target_shift_i
the shift_i value that the adaptive shift method should aim for
void print_cost_summary(const double si, const double ss, const RealType mc, const RealType cv, const int ind, const int bi, const bool gu)
const ProjectData & project_data_
top-level project data information
IndexType nBlocks
maximum number of blocks
int num_shifts
number of shifts we will try
bool put(xmlNodePtr cur) override
preprocess xml node
Definition of QMCDriver which performs VMC and optimization.
void createWalkers(int numWalkers)
create numWalkers Walkers
void addWalkers(int nwalkers)
Add walkers to the end of the ensemble of walkers.
void barrier_and_abort(const std::string &msg) const
int Max_iterations
Number of iterations maximum before generating new configurations.
bool output_matrices_initialized_
int NumOfVMCWalkers
total number of VMC walkers
void init_file(const std::string &root_name, const std::string &name, int N)
Open a text-formatted scalar.dat file and print the header line.
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
int MyCounter
the number of times this QMCDriver is executed
NewTimer & line_min_timer_
RealType bestShift_s
the previous best overlap shift
QMCFixedSampleLinearOptimize(const ProjectData &project_data, MCWalkerConfiguration &w, TrialWaveFunction &psi, QMCHamiltonian &h, Communicate *)
Constructor.
~QMCFixedSampleLinearOptimize() override
Destructor.
Real getNonLinearRescale(std::vector< Real > &dP, Matrix< Real > &S, const QMCCostFunctionBase &optTarget) const
bool is_best_cost(const int ii, const std::vector< RealType > &cv, const std::vector< double > &sh, const RealType ic) const
bool isnan(float a)
return true if the value is NaN.
NewTimer & involvmat_timer_