Skip to content

Commit

Permalink
Add options
Browse files Browse the repository at this point in the history
  • Loading branch information
siuwuncheung authored and dreamer2368 committed Apr 17, 2024
1 parent eaba2ad commit 4a247f1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
7 changes: 7 additions & 0 deletions src/Control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Control::Control()
rom_offline = true; // TODO
rom_online = false;
rom_restore = false;
snapshot_basename = "coords.in_H2O_64_000000"; // TODO
}

void Control::setup(const MPI_Comm comm_global, const bool with_spin,
Expand Down Expand Up @@ -1910,6 +1911,12 @@ void Control::setOptions(const boost::program_options::variables_map& vm)

maxDistanceAtomicInfo_ = vm["Parallel.atomic_info_radius"].as<float>();

// ROM flags
//rom_offline = vm["ROM.offline"].as<bool>() ? 1 : 0;
//rom_online = vm["ROM.online"].as<bool>() ? 1 : 0;
//rom_restore = vm["ROM.restore"].as<bool>() ? 1 : 0;
//snapshot_basename = vm["atomicCoordinates"].as<std::vector<std::string>>()[0];

// options not available in configure file
lr_updates_type = 0;
precond_factor_computed = false;
Expand Down
1 change: 1 addition & 0 deletions src/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ class Control
bool rom_offline;
bool rom_online;
bool rom_restore;
std::string snapshot_basename;
};

#endif
17 changes: 9 additions & 8 deletions src/MGmol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1143,16 +1143,17 @@ void MGmol<OrbitalsType>::cleanup()

if (ierr < 0)
os_ << "WARNING: writing restart data failed!!!" << std::endl;
}

// Save orbital snapshots
if (ct.rom_offline > 0)
{
int ierr = save_orbital_snapshot(
h5restartfile.filename(), *current_orbitals_);
// Save orbital snapshots
if (ct.rom_offline > 0 && ct.AtomsDynamic() == AtomsDynamicType::Quench)
{
ct.snapshot_basename = "coords.in_H2O_64_000000";
int ierr = save_orbital_snapshot(
ct.snapshot_basename + "_quench", *current_orbitals_);

if (ierr < 0)
os_ << "WARNING: writing ROM snapshot data failed!!!" << std::endl;
}
if (ierr < 0)
os_ << "WARNING: writing ROM snapshot data failed!!!" << std::endl;
}

MPI_Barrier(comm_);
Expand Down
16 changes: 14 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,16 @@ int main(int argc, char** argv)
"Modulos or parameter to control how often clusters are "
"recomputed during md")("LoadBalancing.output_file",
po::value<string>()->default_value(""),
"Output file for dumping cluster information in vtk format");
"Output file for dumping cluster information in vtk format")(
"ROM.offline",
po::value<bool>()->default_value(false),
"online phase in ROM")(
"ROM.online",
po::value<bool>()->default_value(false),
"online phase in ROM")(
"ROM.restore",
po::value<bool>()->default_value(false),
"restore phase in ROM");

// Hidden options, will be allowed in config file, but will not be
// shown to the user.
Expand Down Expand Up @@ -434,7 +443,10 @@ int main(int argc, char** argv)
"approximation of density matrix. ")("DensityMatrix.tol",
po::value<float>()->default_value(1.e-7),
"tolerance, used in iterative DM computation convergence "
"criteria");
"criteria")(
"ROM.snapshot_basename",
po::value<string>()->default_value(""),
"ROM snapshot basename");

po::options_description cmdline_options;
cmdline_options.add(generic);
Expand Down
10 changes: 10 additions & 0 deletions src/md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,16 @@ void MGmol<OrbitalsType>::md(OrbitalsType** orbitals, Ions& ions)
}
}

// Save orbital snapshots
if (ct.rom_offline > 0)
{
int ierr = save_orbital_snapshot(
ct.snapshot_basename + "_MD" + std::to_string(mdstep), **orbitals);

if (ierr < 0)
os_ << "WARNING md(): writing ROM snapshot data failed!!!" << std::endl;
}

if (onpe0)
os_ << std::setprecision(12) << std::fixed << "%% "
<< md_iteration_ << " IONIC CONFIGURATION ENERGY = " << eks
Expand Down
6 changes: 2 additions & 4 deletions src/rom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
template <class OrbitalsType>
int MGmol<OrbitalsType>::save_orbital_snapshot(std::string file_path, OrbitalsType& orbitals)
{
std::cout << "rom.cc: save_orbital_snapshot: " << file_path << std::endl;
std::string snapshot_filename = file_path;
struct stat s;
if (stat(file_path.c_str(), &s) == 0)
Expand All @@ -30,9 +31,7 @@ int MGmol<OrbitalsType>::save_orbital_snapshot(std::string file_path, OrbitalsTy
snapshot_filename = file_path + "/orbital";
else if (s.st_mode & S_IFREG)
{
std::string::size_type pos = file_path.rfind("/");
file_path = (pos == std::string::npos) ? "" : file_path.substr(0, pos);
snapshot_filename = file_path + "/orbital";
snapshot_filename = file_path + "_orbital";
}
else
{
Expand All @@ -41,7 +40,6 @@ int MGmol<OrbitalsType>::save_orbital_snapshot(std::string file_path, OrbitalsTy
}
}


const int dim = orbitals.getLocNumpt();
const int totalSamples = orbitals.chromatic_number();

Expand Down

0 comments on commit 4a247f1

Please sign in to comment.