35#ifndef MADNESS_CHEM_RESTARTPLAN_H__INCLUDED
36#define MADNESS_CHEM_RESTARTPLAN_H__INCLUDED
63 return {
"auto",
"none",
"iterate",
"read_only",
"ao",
"nwchem"};
106 default:
return "initial_guess";
123 std::optional<RestartMetadata>
meta;
169 const double tol = 1.e-6) {
171 for (std::size_t i = 0; i < requested.
natom(); ++i) {
175 for (std::size_t i = 0; i < requested.
natom(); ++i) {
226 : std::string(
"no iterations")) +
231 template <
typename Archive>
233 int m =
static_cast<int>(
mode);
234 int s =
static_cast<int>(
source);
244 std::stringstream ss;
245 ss << std::scientific << std::setprecision(0) << t;
255inline std::optional<std::size_t>
257 for (std::size_t i = 0; i < protocol.size(); ++i)
258 if (protocol[i] < achieved * 0.999)
return i;
282 const std::vector<double>& protocol,
283 const double user_dconv,
const Molecule& requested,
285 const double eprec = 0.0,
286 const std::string&
xc =
"",
287 const std::string&
ncf =
"",
288 const std::size_t nmo_alpha = 0) {
291 const std::size_t last = protocol.size() - 1;
298 const double target_thresh = protocol.back();
299 const double target_dconv = std::max(target_thresh, user_dconv);
307 const bool pads_virtuals = nmo_alpha > 0 and disk.
nmo_alpha > 0 and disk.
nmo_alpha < nmo_alpha;
320 if (meta.eprec != 0.0 and
eprec != 0.0 and
322 return "archive was written at eprec " +
format_thresh(meta.eprec) +
324 if (not meta.xc.empty() and not
xc.empty() and meta.xc !=
xc)
325 return "archive was written with xc '" + meta.xc +
"', this run uses '" +
327 if (not meta.ncf.empty() and not
ncf.empty() and meta.
ncf !=
ncf)
328 return "archive was written with the nuclear correlation factor '" +
329 meta.ncf +
"', this run uses '" +
ncf +
"'";
330 return std::string();
334 auto give_up = [&](
const std::string& why) {
349 auto continue_from_archive = [&](
const RestartMetadata& meta,
const std::string& why) {
352 describe_archive(meta);
366 "restart none together with `nwfile`: the AO basis is read from the "
367 "nwchem file, so there is no atomic guess to fall back to. Use "
368 "restart=nwchem, or drop the `nwfile` keyval.");
369 return give_up(
"restart none: ignoring anything on disk");
379 "restart nwchem: this calculation cannot read NWChem orbitals");
381 "restart nwchem: no nwchem file given -- set the `nwfile` keyval");
385 plan.
why =
"restart nwchem: as requested";
391 "restart ao: this calculation cannot read AO projections");
393 "restart ao: no restartaodata file found");
397 plan.
why =
"restart ao: as requested";
403 "restart iterate/read_only: no restartdata archive found");
405 "restart iterate/read_only: the restartdata archive could not be read");
408 "restart iterate/read_only: the restartdata archive holds a different "
409 "kind of orbital than this calculation uses");
420 "restart read_only: archive geometry does not match the requested geometry");
422 "restart read_only: the archive holds fewer orbitals than requested");
430 describe_archive(meta);
431 const std::string other = hamiltonian_mismatch(meta);
432 if (not other.empty()) {
437 plan.
why =
"restart read_only: " + other +
438 " -- returning the archive's energy for a DIFFERENT "
439 "Hamiltonian, as requested";
443 plan.
warn = not good;
445 ?
"restart read_only: archive is converged to the requested precision"
446 :
"restart read_only: archive is converged only to thresh " +
450 " -- returning its energy anyway, as requested";
455 return continue_from_archive(meta,
"restart iterate: as requested");
468 if (nwchem_available) {
470 plan.
why =
"restart auto: no restartdata, but an nwchem file was given";
475 plan.
why =
"restart auto: no restartdata, using the AO projections";
478 return give_up(
"restart auto: nothing on disk");
483 auto reject_archive = [&](
const std::string& why) {
489 plan.
why = why +
"; using the AO projections instead";
492 return give_up(why +
"; starting from the initial guess instead");
495 if (not disk.
meta.has_value())
496 return reject_archive(
"restart auto: restartdata exists but its header could "
497 "not be read (truncated, or written by a newer MADNESS)");
502 return reject_archive(
"restart auto: restartdata holds '" +
504 "' orbitals, this calculation wants '" +
512 return give_up(
"restart auto: restartdata is for a different molecule");
522 plan.
why =
"restart auto: geometry moved, using the AO projections";
528 double dmax = 0.0; std::size_t imax = 0;
529 for (std::size_t i = 0; i < requested.
natom(); ++i) {
532 if (
d > dmax) { dmax =
d; imax = i; }
535 std::snprintf(buf,
sizeof buf,
" (max |dR| = %.3e bohr at atom %zu; tolerance 1e-6)", dmax, imax);
536 return give_up(std::string(
"restart auto: geometry moved and no AO projections available") + buf);
545 const std::string other = hamiltonian_mismatch(meta);
546 if (not other.empty())
547 return continue_from_archive(meta,
"restart auto: " + other +
548 " -- a different Hamiltonian, so re-converging");
551 return continue_from_archive(meta,
"restart auto: archive holds " + std::to_string(disk.
nmo_alpha) +
552 " alpha orbitals, " + std::to_string(nmo_alpha) +
553 " requested; the missing virtuals start from the atomic guess");
560 describe_archive(meta);
561 plan.
why =
"restart auto: archive is converged to thresh " +
567 return continue_from_archive(meta,
"restart auto: archive converged only to thresh " +
580 const bool nwfile_named) {
584 int flags[2] = {0, 0};
585 if (world.
rank() == 0) {
587 flags[1] = std::filesystem::exists(prefix +
".restartaodata") ? 1 : 0;
624 const std::string&
ncf =
"") {
634 if (world.
rank() == 0 and
param.print_level() > 1) {
637 if (disk.
meta.has_value() and
param.print_level() > 2)
638 print(
" archive:", disk.
meta.value().print_to_string());
the header of a restartdata archive, in one place
Definition molecule.h:129
const Atom & get_atom(unsigned int i) const
Definition molecule.cc:502
size_t natom() const
Definition molecule.h:463
unsigned int get_atomic_number(unsigned int i) const
Definition molecule.cc:430
GeometryParameters parameters
Definition molecule.h:334
void broadcast_serializable(objT &obj, ProcessID root)
Broadcast a serializable object.
Definition worldgop.h:774
void broadcast(void *buf, size_t nbyte, ProcessID root, bool dowork=true, Tag bcast_tag=-1)
Broadcasts bytes from process root while still processing AM & tasks.
Definition worldgop.cc:189
A parallel world class.
Definition world.h:134
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:344
WorldGopInterface & gop
Global operations.
Definition world.h:216
static const double eprec
Definition hatom_sf_dirac.cc:18
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:182
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
std::string to_string(const Representation r)
Definition Restart.h:64
std::optional< std::size_t > first_rung_tighter_than(const std::vector< double > &protocol, const double achieved)
Definition RestartPlan.h:256
RestartPlan plan_restart(const RestartMode mode, const RestartSources &disk, const RestartCapabilities &can, const std::vector< double > &protocol, const double user_dconv, const Molecule &requested, const Representation wanted, const double eprec=0.0, const std::string &xc="", const std::string &ncf="", const std::size_t nmo_alpha=0)
Definition RestartPlan.h:280
std::string format_thresh(const double t)
format a threshold compactly for a log line ("1e-06", not "0.000001")
Definition RestartPlan.h:243
bool restartdata_exists(const std::string &filename)
Definition Restart.h:298
std::optional< RestartSummary > peek_restartdata_summary(World &world, const std::string &filename)
Definition Restart.h:260
RestartMode
Definition RestartPlan.h:51
@ automatic
look at what is on disk and choose (the default)
@ none
ignore everything on disk, start from the initial guess
@ iterate
read restartdata and keep iterating
@ ao
read the AO projections (restartaodata) and iterate
@ nwchem
read an NWChem movecs file and iterate
RestartMode restart_mode_from_string(const std::string &s)
Definition RestartPlan.h:83
RestartPlan make_restart_plan(World &world, const RestartMode mode, const CalculationParameters ¶m, const Molecule &requested, const Representation wanted, const RestartCapabilities &can, const std::string &ncf="")
Definition RestartPlan.h:619
RestartSources survey_restart_sources(World &world, const std::string &prefix, const bool nwfile_named)
Definition RestartPlan.h:579
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:227
std::optional< RestartMetadata > peek_restartdata(World &world, const std::string &filename)
Definition Restart.h:223
RestartSource
where the initial orbitals will come from
Definition RestartPlan.h:94
@ initial_guess
atomic guess, i.e. no restart at all
@ restartdata
<prefix>.restartdata, MRA orbitals
@ restartao
<prefix>.restartaodata, AO expansion coefficients
@ nwchem
an NWChem movecs file
GeometryMatch compare_geometry(const Molecule &archive, const Molecule &requested, const double tol=1.e-6)
Definition RestartPlan.h:168
GeometryMatch
how the requested geometry relates to the one in an archive
Definition RestartPlan.h:151
@ different_composition
different atoms altogether
@ same
same atoms at the same places
@ displaced
same atoms, moved – e.g. a geometry optimization step
Representation
Definition Restart.h:57
std::vector< std::string > restart_mode_names()
the six spellings accepted by the restart keyval, for allowed_values
Definition RestartPlan.h:62
static long abs(long a)
Definition tensor.h:219
XCfunctional xc
Definition newsolver_lda.cc:53
static const double b
Definition nonlinschro.cc:119
static const double d
Definition nonlinschro.cc:121
static const double a
Definition nonlinschro.cc:118
static const double m
Definition relops.cc:9
Definition CalculationParameters.h:51
double eprec() const
Definition molecule.h:306
Definition RestartPlan.h:142
static RestartCapabilities restartdata_only()
Definition RestartPlan.h:147
bool nwchem
can read an NWChem movecs file
Definition RestartPlan.h:144
static RestartCapabilities all()
Definition RestartPlan.h:146
bool ao
can read <prefix>.restartaodata
Definition RestartPlan.h:143
the decision: one source, one starting rung, one reason
Definition RestartPlan.h:186
RestartSource source
Definition RestartPlan.h:189
bool warn
Definition RestartPlan.h:205
bool needs_load() const
true if orbitals have to be read from disk before anything else happens
Definition RestartPlan.h:220
std::size_t protocol_start
rung of protocol() to start at; rungs below it are already covered
Definition RestartPlan.h:195
bool iterate
false means "return what is on disk without solving anything"
Definition RestartPlan.h:192
std::size_t archive_nmo_alpha
Definition RestartPlan.h:212
bool archive_same_hamiltonian
Definition RestartPlan.h:217
double stale_energy
energy from the archive, meaningful only when iterate==false
Definition RestartPlan.h:198
std::string why
one line, for the log and for the results json
Definition RestartPlan.h:208
RestartMode mode
what was asked for
Definition RestartPlan.h:188
std::string print_to_string() const
Definition RestartPlan.h:222
bool archive_converged
Definition RestartPlan.h:216
void serialize(Archive &ar)
serialization, so the plan can be decided on one rank and broadcast
Definition RestartPlan.h:232
Definition RestartPlan.h:115
bool restartao_present
<prefix>.restartaodata exists
Definition RestartPlan.h:129
bool restartdata_present
<prefix>.restartdata.00000 exists
Definition RestartPlan.h:118
bool nwfile_named
an NWChem file was named in the input
Definition RestartPlan.h:132
std::size_t nmo_alpha
alpha orbitals in the archive, 0 when unknown
Definition RestartPlan.h:126
std::optional< RestartMetadata > meta
Definition RestartPlan.h:123
Definition dirac-hatom.cc:112
ncf(double gamma, double a, double Z)
Definition dirac-hatom.cc:116
InputParameters param
Definition tdse.cc:203