35#ifndef MADNESS_CHEM_RESTARTPLAN_H__INCLUDED
36#define MADNESS_CHEM_RESTARTPLAN_H__INCLUDED
62 return {
"auto",
"none",
"iterate",
"read_only",
"ao",
"nwchem"};
105 default:
return "initial_guess";
122 std::optional<RestartMetadata>
meta;
159 const double tol = 1.e-8) {
161 for (std::size_t i = 0; i < requested.
natom(); ++i) {
165 for (std::size_t i = 0; i < requested.
natom(); ++i) {
207 : std::string(
"no iterations")) +
212 template <
typename Archive>
214 int m =
static_cast<int>(
mode);
215 int s =
static_cast<int>(
source);
224 std::stringstream ss;
225 ss << std::scientific << std::setprecision(0) << t;
235inline std::optional<std::size_t>
237 for (std::size_t i = 0; i < protocol.size(); ++i)
238 if (protocol[i] < achieved * 0.999)
return i;
262 const std::vector<double>& protocol,
263 const double user_dconv,
const Molecule& requested,
265 const double eprec = 0.0,
266 const std::string&
xc =
"",
267 const std::string&
ncf =
"") {
270 const std::size_t last = protocol.size() - 1;
277 const double target_thresh = protocol.back();
278 const double target_dconv = std::max(target_thresh, user_dconv);
294 if (meta.eprec != 0.0 and
eprec != 0.0 and
296 return "archive was written at eprec " +
format_thresh(meta.eprec) +
298 if (not meta.xc.empty() and not
xc.empty() and meta.xc !=
xc)
299 return "archive was written with xc '" + meta.xc +
"', this run uses '" +
301 if (not meta.ncf.empty() and not
ncf.empty() and meta.
ncf !=
ncf)
302 return "archive was written with the nuclear correlation factor '" +
303 meta.ncf +
"', this run uses '" +
ncf +
"'";
304 return std::string();
308 auto give_up = [&](
const std::string& why) {
317 auto continue_from_archive = [&](
const RestartMetadata& meta,
const std::string& why) {
333 "restart none together with `nwfile`: the AO basis is read from the "
334 "nwchem file, so there is no atomic guess to fall back to. Use "
335 "restart=nwchem, or drop the `nwfile` keyval.");
336 return give_up(
"restart none: ignoring anything on disk");
346 "restart nwchem: this calculation cannot read NWChem orbitals");
348 "restart nwchem: no nwchem file given -- set the `nwfile` keyval");
352 plan.
why =
"restart nwchem: as requested";
358 "restart ao: this calculation cannot read AO projections");
360 "restart ao: no restartaodata file found");
364 plan.
why =
"restart ao: as requested";
370 "restart iterate/read_only: no restartdata archive found");
372 "restart iterate/read_only: the restartdata archive could not be read");
375 "restart iterate/read_only: the restartdata archive holds a different "
376 "kind of orbital than this calculation uses");
387 "restart read_only: archive geometry does not match the requested geometry");
395 const std::string other = hamiltonian_mismatch(meta);
396 if (not other.empty()) {
401 plan.
why =
"restart read_only: " + other +
402 " -- returning the archive's energy for a DIFFERENT "
403 "Hamiltonian, as requested";
407 plan.
warn = not good;
409 ?
"restart read_only: archive is converged to the requested precision"
410 :
"restart read_only: archive is converged only to thresh " +
414 " -- returning its energy anyway, as requested";
419 return continue_from_archive(meta,
"restart iterate: as requested");
432 if (nwchem_available) {
434 plan.
why =
"restart auto: no restartdata, but an nwchem file was given";
439 plan.
why =
"restart auto: no restartdata, using the AO projections";
442 return give_up(
"restart auto: nothing on disk");
447 auto reject_archive = [&](
const std::string& why) {
453 plan.
why = why +
"; using the AO projections instead";
456 return give_up(why +
"; starting from the initial guess instead");
459 if (not disk.
meta.has_value())
460 return reject_archive(
"restart auto: restartdata exists but its header could "
461 "not be read (truncated, or written by a newer MADNESS)");
466 return reject_archive(
"restart auto: restartdata holds '" +
468 "' orbitals, this calculation wants '" +
476 return give_up(
"restart auto: restartdata is for a different molecule");
486 plan.
why =
"restart auto: geometry moved, using the AO projections";
489 return give_up(
"restart auto: geometry moved and no AO projections available");
497 const std::string other = hamiltonian_mismatch(meta);
498 if (not other.empty())
499 return continue_from_archive(meta,
"restart auto: " + other +
500 " -- a different Hamiltonian, so re-converging");
507 plan.
why =
"restart auto: archive is converged to thresh " +
513 return continue_from_archive(meta,
"restart auto: archive converged only to thresh " +
526 const bool nwfile_named) {
530 int flags[2] = {0, 0};
531 if (world.
rank() == 0) {
533 flags[1] = std::filesystem::exists(prefix +
".restartaodata") ? 1 : 0;
566 const std::string&
ncf =
"") {
576 if (world.
rank() == 0 and
param.print_level() > 1) {
579 if (disk.
meta.has_value() and
param.print_level() > 2)
580 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:188
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 DFParameters.h:13
GeometryMatch compare_geometry(const Molecule &archive, const Molecule &requested, const double tol=1.e-8)
Definition RestartPlan.h:158
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:236
std::string format_thresh(const double t)
format a threshold compactly for a log line ("1e-06", not "0.000001")
Definition RestartPlan.h:223
bool restartdata_exists(const std::string &filename)
Definition Restart.h:298
RestartMode
Definition RestartPlan.h:50
@ 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:82
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:561
RestartSources survey_restart_sources(World &world, const std::string &prefix, const bool nwfile_named)
Definition RestartPlan.h:525
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:93
@ 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
how the requested geometry relates to the one in an archive
Definition RestartPlan.h:147
@ different_composition
different atoms altogether
@ same
same atoms at the same places
@ displaced
same atoms, moved – e.g. a geometry optimization step
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="")
Definition RestartPlan.h:260
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:61
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 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:138
static RestartCapabilities restartdata_only()
Definition RestartPlan.h:143
bool nwchem
can read an NWChem movecs file
Definition RestartPlan.h:140
static RestartCapabilities all()
Definition RestartPlan.h:142
bool ao
can read <prefix>.restartaodata
Definition RestartPlan.h:139
the decision: one source, one starting rung, one reason
Definition RestartPlan.h:176
RestartSource source
Definition RestartPlan.h:179
bool warn
Definition RestartPlan.h:195
bool needs_load() const
true if orbitals have to be read from disk before anything else happens
Definition RestartPlan.h:201
std::size_t protocol_start
rung of protocol() to start at; rungs below it are already covered
Definition RestartPlan.h:185
bool iterate
false means "return what is on disk without solving anything"
Definition RestartPlan.h:182
double stale_energy
energy from the archive, meaningful only when iterate==false
Definition RestartPlan.h:188
std::string why
one line, for the log and for the results json
Definition RestartPlan.h:198
RestartMode mode
what was asked for
Definition RestartPlan.h:178
std::string print_to_string() const
Definition RestartPlan.h:203
void serialize(Archive &ar)
serialization, so the plan can be decided on one rank and broadcast
Definition RestartPlan.h:213
Definition RestartPlan.h:114
bool restartao_present
<prefix>.restartaodata exists
Definition RestartPlan.h:125
bool restartdata_present
<prefix>.restartdata.00000 exists
Definition RestartPlan.h:117
bool nwfile_named
an NWChem file was named in the input
Definition RestartPlan.h:128
std::optional< RestartMetadata > meta
Definition RestartPlan.h:122
Definition dirac-hatom.cc:112
ncf(double gamma, double a, double Z)
Definition dirac-hatom.cc:116
InputParameters param
Definition tdse.cc:203