Loading...
Searching...
No Matches
eonc::MinimizationJob Class Reference

#include <MinimizationJob.h>

Inheritance diagram for eonc::MinimizationJob:

Public Member Functions

 MinimizationJob (std::unique_ptr< Parameters > parameters, Runtime &rt)
 ~MinimizationJob (void)=default
std::vector< std::string > run (void) override
 Virtual run; used solely for dynamic dispatch.
Public Member Functions inherited from eonc::Job
void adoptRuntime (std::unique_ptr< Runtime > rt)
 Take ownership of a Runtime previously passed as Runtime&.
 Job (std::unique_ptr< Parameters > parameters, Runtime &rt)
 Borrow: caller keeps Runtime alive (CLI stack / Python Session).
 Job (std::unique_ptr< Parameters > parameters, std::unique_ptr< Runtime > rt)
 Own a Runtime (one-shot makeJob / rvalue).
 Job (std::unique_ptr< Parameters > parameters)
 Own a default-constructed Runtime.
 Job (std::shared_ptr< Potential > potPassed, const Parameters &parameters)
virtual ~Job ()=default
JobType getType ()
PotRegistry & pots () noexcept
void releasePotential ()
 Drop the Potential so on_destroyed is recorded before Runtime dies.

Private Attributes

RunStatus status {RunStatus::GOOD}
eonc::log::Scoped log

Additional Inherited Members

Protected Attributes inherited from eonc::Job
JobType jtype
Parameters params
std::unique_ptr< Runtime > owned_runtime_
 Non-null when this Job owns the composition root (one-shot makeJob).
Runtime * runtime_
 Always valid: either owned_runtime_.get() or a caller-owned Runtime.
std::shared_ptr< Potential > pot

Detailed Description

Definition at line 20 of file MinimizationJob.h.

Constructor & Destructor Documentation

◆ MinimizationJob()

eonc::MinimizationJob::MinimizationJob ( std::unique_ptr< Parameters > parameters,
Runtime & rt )
inline

Definition at line 22 of file MinimizationJob.h.

23 : Job(std::move(parameters), rt) {}
Job(std::unique_ptr< Parameters > parameters, Runtime &rt)
Borrow: caller keeps Runtime alive (CLI stack / Python Session).
Definition Job.h:76

◆ ~MinimizationJob()

eonc::MinimizationJob::~MinimizationJob ( void )
default

Member Function Documentation

◆ run()

std::vector< std::string > eonc::MinimizationJob::run ( void )
overridevirtual

Virtual run; used solely for dynamic dispatch.

Implements eonc::Job.

Definition at line 29 of file MinimizationJob.cpp.

29 {
30 std::string posInFilename("pos.con");
31 std::string posOutFilename("min.con");
32
33 if (params.main_options().checkpoint) {
34 if (std::filesystem::exists("pos_cp.con")) {
35 posInFilename = "pos_cp.con";
36 QUILL_LOG_DEBUG(log, "[Minimization] Resuming from checkpoint");
37 } else {
38 QUILL_LOG_DEBUG(log, "[Minimization] No checkpoint files found");
39 }
40 }
41
42 std::vector<std::string> returnFiles;
43 returnFiles.push_back(posOutFilename);
44
45 auto pos = std::make_shared<Matter>(pot, params);
46 if (!eonc::io::io_ok(pos->con2matter(posInFilename))) {
47 QUILL_LOG_CRITICAL(log, "Failed to load {}", posInFilename);
48 throw std::runtime_error("failed to load " + posInFilename);
49 }
50
51 QUILL_LOG_DEBUG(log, "\nBeginning minimization of {}", posInFilename);
52
53 bool converged;
54 try {
55 converged =
56 pos->relax(false, params.debug_options().write_movies,
57 params.main_options().checkpoint, "minimization", "pos");
58 if (converged) {
60 QUILL_LOG_DEBUG(log, "Minimization converged within tolerence");
61 } else {
63 QUILL_LOG_DEBUG(log, "Minimization did not converge to tolerence!"
64 "Maybe try to increase max_iterations?");
65 }
66 } catch (int e) {
67 if (e == 100) {
69 } else {
70 throw e;
71 }
72 } catch (const std::exception &e) {
73 QUILL_LOG_ERROR(log, "Minimization potential failed: {}", e.what());
75 }
76
77 QUILL_LOG_DEBUG(log, "Saving result to {}", posOutFilename);
78 if (!eonc::io::io_ok(pos->matter2con(posOutFilename))) {
79 QUILL_LOG_ERROR(log, "Failed to write {}", posOutFilename);
80 }
82 QUILL_LOG_DEBUG(log, "Final Energy: {}", pos->getPotentialEnergy());
83 }
84
85 std::filesystem::path resultsFilename("results.dat");
86 returnFiles.push_back(resultsFilename.string());
87
88 const bool hasE = status != RunStatus::FAIL_POTENTIAL_FAILED;
89 const double energy = hasE ? pos->getPotentialEnergy() : 0.0;
91 status, params.potential_options().potential,
92 this->pot->forceCallCounter.load(), hasE, energy);
93 env.tags.emplace_back("optimizer", std::string(magic_enum::enum_name(
94 params.optimizer_options().method)));
95 if (params.optimizer_options().method == OptType::XTSCI) {
96 env.tags.emplace_back("xtsci_method",
97 params.optimizer_options().xtsci.method);
98 }
99 if (!xtsci_eindir::provenance().empty()) {
100 env.tags.emplace_back("eindir_abi", xtsci_eindir::provenance());
101 }
102 env.writeResultsDat(resultsFilename.string());
103
104 return returnFiles;
105}
std::shared_ptr< Potential > pot
Definition Job.h:63
Parameters params
Definition Job.h:58
eonc::log::Scoped log
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
const std::string & provenance()
Stamp text from the last successful eindir bind. Empty when unused.
static JobResultEnvelope fromMinimization(RunStatus status, PotType pot, std::uint64_t fcalls, bool hasE, double energy)
Definition JobResult.h:101

Member Data Documentation

◆ log

eonc::log::Scoped eonc::MinimizationJob::log
private

Definition at line 29 of file MinimizationJob.h.

◆ status

RunStatus eonc::MinimizationJob::status {RunStatus::GOOD}
private

Definition at line 28 of file MinimizationJob.h.


The documentation for this class was generated from the following files: