eOn 3.2.0
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
MinimizationJob.cpp
Go to the documentation of this file.
1
/*
2
** This file is part of eOn.
3
**
4
** SPDX-License-Identifier: BSD-3-Clause
5
**
6
** Copyright (c) 2010--present, eOn Development Team
7
** All rights reserved.
8
**
9
** Repo:
10
** https://github.com/TheochemUI/eOn
11
*/
12
#include "
eon/MinimizationJob.h
"
13
#include "
eon/BaseStructures.h
"
14
#include "
eon/HelperFunctions.h
"
15
#include "
eon/JobResult.h
"
16
#include "
eon/Matter.h
"
17
#include "
eon/Optimizer.h
"
18
#include "
eon/XtsciEindir.h
"
19
20
#include <filesystem>
21
#include <format>
22
#include <fstream>
23
#include <iostream>
24
#include <stdexcept>
25
#include <string>
26
27
namespace
eonc
{
28
29
std::vector<std::string>
MinimizationJob::run
() {
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>(std::move(
ownedPot
),
params
);
46
if
(!
eonc::io::io_ok
(pos->inp2matter(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) {
59
status
=
RunStatus::GOOD
;
60
QUILL_LOG_DEBUG(
log
,
"Minimization converged within tolerence"
);
61
}
else
{
62
status
=
RunStatus::FAIL_MAX_ITERATIONS
;
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) {
68
status
=
RunStatus::FAIL_POTENTIAL_FAILED
;
69
}
else
{
70
throw
e;
71
}
72
}
catch
(
const
std::exception &e) {
73
QUILL_LOG_ERROR(
log
,
"Minimization potential failed: {}"
, e.what());
74
status
=
RunStatus::FAIL_POTENTIAL_FAILED
;
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
}
81
if
(
status
!=
RunStatus::FAIL_POTENTIAL_FAILED
) {
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;
90
auto
env =
JobResultEnvelope::fromMinimization
(
91
status
,
params
.potential_options().potential,
92
pos->getPotential()->forceCallCounter.load(), hasE, energy);
93
env.provenance =
provenanceForJob
(
params
);
94
env.tags.emplace_back(
"optimizer"
, std::string(magic_enum::enum_name(
95
params
.optimizer_options().method)));
96
if
(
params
.optimizer_options().method ==
OptType::XTSCI
) {
97
env.tags.emplace_back(
"xtsci_method"
,
98
params
.optimizer_options().xtsci.method);
99
}
else
if
(
auto
rgmin =
helpers::create::rgminBackendMethod
(
100
params
.optimizer_options().method,
params
)) {
101
env.tags.emplace_back(
"opt_backend"
,
"rgmin"
);
102
env.tags.emplace_back(
"xtsci_method"
, *rgmin);
103
}
104
if
(!
xtsci_eindir::provenance
().empty()) {
105
env.tags.emplace_back(
"eindir_abi"
,
xtsci_eindir::provenance
());
106
}
107
env.writeResultsDat(resultsFilename.string());
108
109
return
returnFiles;
110
}
111
112
}
// namespace eonc
BaseStructures.h
HelperFunctions.h
JobResult.h
Matter.h
MinimizationJob.h
Optimizer.h
The optimizer class is used to serve as an abstract class for all optimizers, as well as to call an o...
XtsciEindir.h
eonc::Job::params
Parameters params
Definition
Job.h:58
eonc::Job::ownedPot
std::unique_ptr< Potential > ownedPot
Exclusive until a multi-owner job promotes it in the public constructor.
Definition
Job.h:64
eonc::MinimizationJob::run
std::vector< std::string > run(void) override
Virtual run; used solely for dynamic dispatch.
Definition
MinimizationJob.cpp:29
eonc::MinimizationJob::log
eonc::log::Scoped log
Definition
MinimizationJob.h:29
eonc::MinimizationJob::status
RunStatus status
Definition
MinimizationJob.h:28
eonc::helpers::create::rgminBackendMethod
std::optional< std::string > rgminBackendMethod(OptType a_otype, const Parameters &a_params)
rgminMethodFor without the objective test: what a minimization of a potential energy runs under opt_b...
Definition
Optimizer.cpp:34
eonc::io::io_ok
constexpr bool io_ok(IoStatus s) noexcept
Definition
ConFileIO.h:38
eonc::xtsci_eindir::provenance
const std::string & provenance()
Stamp text from the last successful eindir bind. Empty when unused.
Definition
XtsciEindir.cpp:187
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:23
eonc::OptType::XTSCI
@ XTSCI
Definition
BaseStructures.h:112
eonc::RunStatus::GOOD
@ GOOD
Definition
BaseStructures.h:117
eonc::RunStatus::FAIL_MAX_ITERATIONS
@ FAIL_MAX_ITERATIONS
Definition
BaseStructures.h:117
eonc::RunStatus::FAIL_POTENTIAL_FAILED
@ FAIL_POTENTIAL_FAILED
Definition
BaseStructures.h:117
eonc::provenanceForJob
JobResultProvenance provenanceForJob(const Parameters ¶ms)
Optimizer backend, engine identity, rgpot pin, and xts ABI from a job.
Definition
JobResultProvenance.cpp:38
eonc::JobResultEnvelope::fromMinimization
static JobResultEnvelope fromMinimization(RunStatus status, PotType pot, std::uint64_t fcalls, bool hasE, double energy)
Definition
JobResult.h:251
client
MinimizationJob.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf