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

#include <MonteCarloJob.h>

Inheritance diagram for eonc::MonteCarloJob:

Public Member Functions

 MonteCarloJob (std::unique_ptr< Parameters > parameters, Runtime &rt)
 ~MonteCarloJob (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

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 MonteCarloJob.h.

Constructor & Destructor Documentation

◆ MonteCarloJob()

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

Definition at line 22 of file MonteCarloJob.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

◆ ~MonteCarloJob()

eonc::MonteCarloJob::~MonteCarloJob ( void )
default

Member Function Documentation

◆ run()

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

Virtual run; used solely for dynamic dispatch.

Implements eonc::Job.

Definition at line 28 of file MonteCarloJob.cpp.

28 {
29 std::string posInFilename("pos.con");
30 std::string posOutFilename("out.con");
31
32 if (params.main_options().checkpoint) {
33 if (std::filesystem::exists("pos_cp.con")) {
34 posInFilename = "pos_cp.con";
35 QUILL_LOG_DEBUG(log, "Resuming from checkpoint\n");
36 } else {
37 QUILL_LOG_DEBUG(log, "No checkpoint files found\n");
38 }
39 }
40
41 std::vector<std::string> returnFiles;
42
43 auto matter = std::make_shared<Matter>(pot, params);
44 if (!eonc::io::io_ok(matter->con2matter(posInFilename))) {
45 QUILL_LOG_CRITICAL(log, "Failed to load {}", posInFilename);
46 throw std::runtime_error("failed to load " + posInFilename);
47 }
48
49 MonteCarlo mc = MonteCarlo(matter, params);
50 mc.run(params.monte_carlo_options().steps, params.main_options().temperature,
51 params.monte_carlo_options().step_size);
52
53 QUILL_LOG_DEBUG(log, "Saving result to {}", posOutFilename);
54 if (eonc::io::io_ok(matter->matter2con(posOutFilename))) {
55 returnFiles.push_back(posOutFilename);
56 } else {
57 QUILL_LOG_ERROR(log, "Failed to write {}", posOutFilename);
58 }
59
60 std::string resultsFilename("results.dat");
62 RunStatus::GOOD, params.potential_options().potential,
64 matter->getPotentialEnergy());
65 env.job_type = "monte_carlo";
66 env.writeResultsDat(resultsFilename);
67 returnFiles.push_back(resultsFilename);
68
69 return returnFiles;
70}
std::shared_ptr< Potential > pot
Definition Job.h:63
Parameters params
Definition Job.h:58
eonc::log::Scoped log
static PotRegistry & get() noexcept
Process-lifetime singleton.
size_t total_force_calls() const noexcept
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
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::MonteCarloJob::log
private

Definition at line 28 of file MonteCarloJob.h.


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