Skip to content

Commit 3008e6a

Browse files
authored
Merge pull request #233 from bpuchala/v0.2a2_install
sample CASM project and some small Monte Carlo changes
2 parents 3d61541 + d81cd4a commit 3008e6a

36 files changed

Lines changed: 2358 additions & 333 deletions

File tree

include/casm/casm_io/Log.hh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ namespace CASM {
125125
int verbosity() const;
126126

127127
void set_verbosity(int _verbosity);
128+
129+
template<int _required_verbosity>
130+
Log& require() {
131+
static_assert(_required_verbosity >= none && _required_verbosity <= debug, "CASM::Log _required_verbosity must be <= 100");
132+
m_print = (m_verbosity >= _required_verbosity);
133+
return *this;
134+
}
128135

129136

130137
void reset(std::ostream &_ostream = std::cout, int _verbosity = standard, bool _show_clock = false);
@@ -136,6 +143,10 @@ namespace CASM {
136143
friend Log &operator<<(Log &log, std::ostream & (*fptr)(std::ostream &));
137144

138145
operator std::ostream &();
146+
147+
explicit operator bool () {
148+
return m_print;
149+
}
139150

140151
/// \brief Read verbosity level from a string
141152
static std::pair<bool, int> verbosity_level(std::string s);

include/casm/clex/Configuration.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,12 @@ namespace CASM {
185185
return multiplicity;
186186
}
187187

188+
/// \brief SCELV_A_B_C_D_E_F/i
188189
std::string name() const;
189190

191+
/// \brief SCELV_A_B_C_D_E_F.i (only use this when 'name' won't work)
192+
std::string altname() const;
193+
190194
std::string calc_status() const;
191195

192196
std::string failure_type() const;

include/casm/completer/Complete.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace CASM {
6565
const ARG_TYPE m_expected_arg;
6666

6767
///Make sure values make sense
68-
bool _sanity_throw() const;
68+
void _sanity_throw() const;
6969
};
7070

7171
namespace Suboption_impl {

include/casm/completer/Handlers.hh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ namespace CASM {
146146

147147
//-------------------------------------------------------------------------------------//
148148

149+
///Add --config suboption (no default)
150+
void add_configlist_nodefault_suboption();
151+
152+
//----------------------------//
153+
154+
///Add --configs suboption (no default)
155+
void add_configlists_nodefault_suboption();
156+
157+
//-------------------------------------------------------------------------------------//
158+
149159
///Add a plain --help suboption
150160
void add_help_suboption();
151161

include/casm/monte_carlo/MCData.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ namespace CASM {
117117
///
118118
bool is_converged(double prec) const {
119119
return m_calculated_prec <= prec;
120-
121120
}
122121

123122
/// \brief <X>

include/casm/monte_carlo/MonteCarlo.hh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
#include "casm/monte_carlo/MonteCounter.hh"
1414

1515
namespace CASM {
16+
17+
struct SamplerNameCompare {
18+
19+
SamplerNameCompare() {};
20+
21+
bool operator()(const std::string& A, const std::string& B) const;
22+
23+
};
1624

1725

1826
/// \brief Interface base class for all types of Monte Carlo simulations (not meant to be used polymorphically)
@@ -43,7 +51,7 @@ namespace CASM {
4351
/// - scalar example: m_sampler["formation_energy"]
4452
/// - vector example: m_sampler["corr(12)"]
4553
///
46-
typedef std::map<std::string, notstd::cloneable_ptr<MonteSampler> > SamplerMap;
54+
typedef std::map<std::string, notstd::cloneable_ptr<MonteSampler>, SamplerNameCompare> SamplerMap;
4755

4856
/// \brief a vector of std::pair(pass, step) indicating when samples were taken
4957
typedef std::vector<std::pair<MonteCounter::size_type, MonteCounter::size_type> > SampleTimes;
@@ -319,8 +327,6 @@ namespace CASM {
319327
}
320328
}
321329

322-
// canonical_equivalent_lattice(superlat, prim.point_group(), crystallography_tol())
323-
324330
}
325331
#endif
326332

include/casm/monte_carlo/MonteDriver.hh

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -151,54 +151,59 @@ namespace CASM {
151151
}
152152
m_log << std::endl;
153153

154-
// save initial configdof if not dependent runs
155-
ConfigDoF initial_configdof;
156-
if(!m_settings.dependent_runs()) {
157-
initial_configdof = m_mc.configdof();
158-
}
154+
if(m_settings.dependent_runs()) {
159155

160-
// if starting from initial condition
161-
if(start_i == 0) {
162-
// perform any requested explicit equilibration passes
163-
if(m_settings.is_equilibration_passes_first_run()) {
164-
auto equil_passes = m_settings.equilibration_passes_first_run();
156+
// if starting from initial condition
157+
if(start_i == 0) {
165158

166-
m_log.write("DoF");
167-
m_log << "write: " << m_dir.initial_state_firstruneq_json(0) << "\n" << std::endl;
159+
// set intial state
160+
m_mc.set_state(m_conditions_list[0], m_settings);
168161

169-
jsonParser json;
170-
fs::create_directories(m_dir.conditions_dir(0));
171-
to_json(m_mc.configdof(), json).write(m_dir.initial_state_firstruneq_json(0));
162+
// perform any requested explicit equilibration passes
163+
if(m_settings.dependent_runs() && m_settings.is_equilibration_passes_first_run()) {
172164

173-
m_log.begin("Equilibration passes");
174-
m_log << equil_passes << " equilibration passes\n" << std::endl;
165+
auto equil_passes = m_settings.equilibration_passes_first_run();
175166

176-
MonteCounter equil_counter(m_settings, m_mc.steps_per_pass());
177-
while(equil_counter.pass() != equil_passes) {
178-
monte_carlo_step(m_mc);
179-
equil_counter++;
180-
}
167+
m_log.write("DoF");
168+
m_log << "write: " << m_dir.initial_state_firstruneq_json(0) << "\n" << std::endl;
169+
170+
jsonParser json;
171+
fs::create_directories(m_dir.conditions_dir(0));
172+
to_json(m_mc.configdof(), json).write(m_dir.initial_state_firstruneq_json(0));
181173

174+
m_log.begin("Equilibration passes");
175+
m_log << equil_passes << " equilibration passes\n" << std::endl;
176+
177+
MonteCounter equil_counter(m_settings, m_mc.steps_per_pass());
178+
while(equil_counter.pass() != equil_passes) {
179+
monte_carlo_step(m_mc);
180+
equil_counter++;
181+
}
182+
}
182183
}
183-
}
184-
else if(m_settings.dependent_runs()) {
185-
// read end state of previous condition
186-
ConfigDoF configdof = m_mc.configdof();
187-
from_json(configdof, jsonParser(m_dir.final_state_json(start_i - 1)));
184+
else {
185+
186+
// read end state of previous condition
187+
ConfigDoF configdof = m_mc.configdof();
188+
from_json(configdof, jsonParser(m_dir.final_state_json(start_i - 1)));
188189

189-
m_mc.set_configdof(configdof, std::string("Using: ") + m_dir.final_state_json(start_i - 1).string());
190+
m_mc.set_configdof(configdof, std::string("Using: ") + m_dir.final_state_json(start_i - 1).string());
191+
}
190192
}
191193

192194
// Run for all conditions, outputting data as you finish each one
193195
for(Index i = start_i; i < m_conditions_list.size(); i++) {
194196
if(!m_settings.dependent_runs()) {
195-
m_mc.set_configdof(initial_configdof, "reset to initial DoF");
197+
m_mc.set_state(m_conditions_list[i], m_settings);
196198
}
197199
else {
200+
m_mc.set_conditions(m_conditions_list[i]);
201+
198202
m_log.custom("Continue with existing DoF");
199203
m_log << std::endl;
200204
}
201205
single_run(i);
206+
m_log << std::endl;
202207
}
203208

204209
return;
@@ -293,8 +298,6 @@ namespace CASM {
293298

294299
fs::create_directories(m_dir.conditions_dir(cond_index));
295300

296-
m_mc.set_conditions(m_conditions_list[cond_index]);
297-
298301
// perform any requested explicit equilibration passes
299302
if(m_settings.is_equilibration_passes_each_run()) {
300303

@@ -335,7 +338,7 @@ namespace CASM {
335338
while(true) {
336339

337340
if(debug()) {
338-
m_log.custom("Counter info");
341+
m_log.custom<Log::debug>("Counter info");
339342
m_log << "pass: " << run_counter.pass() << " "
340343
<< "step: " << run_counter.step() << " "
341344
<< "samples: " << run_counter.samples() << "\n" << std::endl;
@@ -356,12 +359,12 @@ namespace CASM {
356359
else {
357360

358361
if(m_mc.check_convergence_time()) {
359-
360-
m_log.check<Log::verbose>("Convergence");
361-
m_log << std::boolalpha;
362-
m_log << "is equilibrated: " << m_mc.is_equilibrated().first << std::endl;
363-
m_log << "is converged: " << m_mc.is_converged() << std::endl;
364-
362+
363+
m_log.require<Log::verbose>() << "\n";
364+
m_log.custom<Log::verbose>("Begin convergence checks");
365+
m_log << "samples: " << m_mc.sample_times().size() << std::endl;
366+
m_log << std::endl;
367+
365368
if(m_mc.is_converged()) {
366369
break;
367370
}
@@ -386,7 +389,7 @@ namespace CASM {
386389
run_counter++;
387390

388391
if(run_counter.sample_time()) {
389-
m_log.custom<Log::verbose>("Sample data");
392+
m_log.custom<Log::debug>("Sample data");
390393
m_log << "pass: " << run_counter.pass() << " "
391394
<< "step: " << run_counter.step() << " "
392395
<< "take sample " << m_mc.sample_times().size() << "\n" << std::endl;

include/casm/monte_carlo/MonteSampler.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ namespace CASM {
6565
bool must_converge() const {
6666
return m_must_converge;
6767
}
68+
69+
/// \brief Returns requested precision on the mean
70+
double requested_precision() const {
71+
return m_prec;
72+
}
6873

6974
/// \brief Returns true if convergence criteria have been met for data sampled in range [equil_samples, end)
7075
///

include/casm/monte_carlo/grand_canonical/GrandCanonical.hh

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ namespace CASM {
5454
/// \brief Set configdof and clear previously collected data
5555
void set_configdof(const ConfigDoF &configdof, const std::string &msg = "");
5656

57+
/// \brief Set configdof and conditions and clear previously collected data
58+
std::pair<ConfigDoF, std::string> set_state(
59+
const GrandCanonicalConditions &new_conditions,
60+
const GrandCanonicalSettings &settings);
61+
62+
/// \brief Set configdof and conditions and clear previously collected data
63+
void set_state(const CondType &new_conditions,
64+
const ConfigDoF &configdof,
65+
const std::string &msg = "");
66+
5767
/// \brief Propose a new event, calculate delta properties, and return reference to it
5868
const EventType &propose();
5969

@@ -133,6 +143,21 @@ namespace CASM {
133143
return m_formation_energy_clex.eci();
134144
}
135145

146+
/// \brief Calculate delta correlations for an event
147+
void _set_dCorr(GrandCanonicalEvent &event,
148+
Index mutating_site,
149+
int sublat,
150+
int current_occupant,
151+
int new_occupant,
152+
bool use_deltas,
153+
bool all_correlations) const;
154+
155+
/// \brief Print correlations to _log()
156+
void _print_correlations(const Eigen::VectorXd &corr,
157+
std::string title,
158+
std::string colheader,
159+
bool all_correlations) const;
160+
136161
/// \brief Calculate delta properties for an event and update the event with those properties
137162
void _update_deltas(GrandCanonicalEvent &event,
138163
Index mutating_site,
@@ -143,8 +168,17 @@ namespace CASM {
143168
/// \brief Calculate properties given current conditions
144169
void _update_properties();
145170

146-
/// \brief Select initial configdof
147-
ConfigDoF _initial_configdof(const GrandCanonicalSettings &settings, Log &_log);
171+
/// \brief Generate supercell filling ConfigDoF from default configuration
172+
ConfigDoF _default_motif() const;
173+
174+
/// \brief Generate minimum potential energy ConfigDoF
175+
std::pair<ConfigDoF, std::string> _auto_motif(const GrandCanonicalConditions &cond) const;
176+
177+
/// \brief Generate minimum potential energy ConfigDoF for this supercell
178+
std::pair<ConfigDoF, std::string> _restricted_auto_motif(const GrandCanonicalConditions &cond) const;
179+
180+
/// \brief Generate supercell filling ConfigDoF from configuration
181+
ConfigDoF _configname_motif(const std::string &configname) const;
148182

149183

150184
///Keeps track of what sites can change to what

include/casm/monte_carlo/grand_canonical/GrandCanonicalIO.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace CASM {
5555
DataFormatter<ConstMonteCarloPtr> make_results_formatter(const GrandCanonical &mc);
5656

5757
/// \brief Make a results formatter
58-
DataFormatter<ConstMonteCarloPtr> make_lte_results_formatter(const GrandCanonical &mc, const double &phi_LTE1);
58+
DataFormatter<ConstMonteCarloPtr> make_lte_results_formatter(const GrandCanonical &mc, const double &phi_LTE1, const std::string &configname);
5959

6060
/// \brief Make a observation formatter
6161
DataFormatter<std::pair<ConstMonteCarloPtr, Index> > make_observation_formatter(const GrandCanonical &mc);
@@ -99,7 +99,7 @@ namespace CASM {
9999
GenericDatumFormatter<double, ConstMonteCarloPtr> GrandCanonicalLTEFormatter(const double &phi_LTE1);
100100

101101
/// \brief Will create new file or append to existing results file the results of the latest run
102-
void write_lte_results(const MonteSettings &settings, const GrandCanonical &mc, const double &phi_LTE1, Log &_log);
102+
void write_lte_results(const MonteSettings &settings, const GrandCanonical &mc, const double &phi_LTE1, const std::string &configname, Log &_log);
103103

104104
}
105105

0 commit comments

Comments
 (0)