Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROM offline calculations for MD snapshots #272

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/PinnedH2O/job.basis
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/tcsh
#SBATCH -N 2
#SBATCH -t 0:10:00
#SBATCH -p pdebug

date

setenv OMP_NUM_THREADS 1
#setenv KMP_DETERMINISTIC_REDUCTION 1

set ncpus = 64

set maindir = /p/lustre2/cheung26/mgmol-20240815

setenv LD_LIBRARY_PATH ${maindir}/build_quartz/libROM/build/lib:$LD_LIBRARY_PATH

set exe = ${maindir}/build_quartz/libROM/build/examples/misc/combine_samples

set snapshot_files = ""
set increment_md_steps = 1
set num_md_steps = 500

foreach k (`seq $increment_md_steps $increment_md_steps $num_md_steps`)
set snapshot_files = "$snapshot_files MD_mdstep${k}_snapshot"
end
echo "Snapshot files: $snapshot_files"

set basis_file = "PinnedH2O_orbitals_basis"

srun -n $ncpus $exe -f $basis_file $snapshot_files > basis_${increment_md_steps}_${num_md_steps}_Pinned_H2O.out

date
35 changes: 35 additions & 0 deletions examples/PinnedH2O/job.rom
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/tcsh
#SBATCH -N 2
#SBATCH -t 1:00:00
#SBATCH -p pbatch

date

setenv OMP_NUM_THREADS 1
#setenv KMP_DETERMINISTIC_REDUCTION 1

set ncpus = 64

set maindir = /p/lustre2/cheung26/mgmol-20240815

setenv LD_LIBRARY_PATH ${maindir}/build_quartz/libROM/build/lib:$LD_LIBRARY_PATH

set exe = mgmol-opt

cp $maindir/install_quartz/bin/$exe .

set datadir = $maindir/examples/PinnedH2O

set cfg_rom = mgmol_rom.cfg
#cp $datadir/$cfg_rom .

cp $datadir/coords.in .

ln -s -f $maindir/potentials/pseudo.O_ONCV_PBE_SG15 .
ln -s -f $maindir/potentials/pseudo.H_ONCV_PBE_SG15 .

source $maindir/scripts/modules.quartz

srun -n $ncpus $exe -c $cfg_rom -i coords.in > rom_PinnedH2O.out

date
38 changes: 38 additions & 0 deletions examples/PinnedH2O/mgmol_rom.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
verbosity=1
xcFunctional=PBE
FDtype=Mehrstellen
[Mesh]
nx=64
ny=64
nz=64
[Domain]
ox=-6.
oy=-6.
oz=-6.
lx=12.
ly=12.
lz=12.
[Potentials]
pseudopotential=pseudo.O_ONCV_PBE_SG15
pseudopotential=pseudo.H_ONCV_PBE_SG15
[Run]
type=MD
[MD]
num_steps=500
dt=40.
thermostat=ON
[Thermostat]
type=Berendsen
temperature=1000.
relax_time=800.
[Quench]
max_steps=100
atol=1.e-8
[Orbitals]
initial_type=Random
initial_width=2.
[Restart]
output_level=4
[ROM.offline]
save_librom_snapshot=true
librom_snapshot_freq=1
27 changes: 27 additions & 0 deletions examples/PinnedH2O/postprocess_PinnedH2O.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess
import re

print("\\begin{tabular}{|c||c|c|c|c|c|c|c|}")
print("\\hline")
print("$k$ & $\\varepsilon = 10^{-1}$ & $\\varepsilon = 10^{-2}$ & $\\varepsilon = 10^{-3}$ & $\\varepsilon = 10^{-4}$ & $\\varepsilon = 10^{-5}$ & Snapshots \\\\")
print("\\hline")

pattern = r"For energy fraction: \d+\.\d+, take first (\d+) of \d+ basis vectors"
for t in range(10):
k = 50*(t+1)
snapshots = 4*k
grep_command = f"grep 'take first' basis_1_{k}_Pinned_H2O.out"
result = subprocess.run(grep_command, shell=True, capture_output=True, text=True)
matches = re.findall(pattern, result.stdout)
energy_fractions = {
"0.9": matches[0],
"0.99": matches[1],
"0.999": matches[2],
"0.9999": matches[3],
"0.99999": matches[4],
}
line = f"{k} & {energy_fractions['0.9']} & {energy_fractions['0.99']} & {energy_fractions['0.999']} & {energy_fractions['0.9999']} & {energy_fractions['0.99999']} & {snapshots} \\\\"
print(line)

print("\\hline")
print("\\end{tabular}")
2 changes: 1 addition & 1 deletion scripts/build_quartz_libROM.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ make -j 16
### Currently libROM does not have the installation procedure,
### so copying binary file to installation directory will disrupt the relative path to libROM.so,
### causing a run-time error.
#make install
make install

# -DBLAS_LIBRARIES=/usr/tce/packages/mkl/mkl-2022.1.0/mkl/2022.1.0/lib/intel64/lib \
# -DLAPACK_LIBRARIES=/usr/tce/packages/mkl/mkl-2022.1.0/mkl/2022.1.0/lib/intel64/lib \
6 changes: 5 additions & 1 deletion src/Control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,7 @@ void Control::setROMOptions(const boost::program_options::variables_map& vm)
rom_pri_option.variable = ROMVariable::NONE;

rom_pri_option.save_librom_snapshot = vm["ROM.offline.save_librom_snapshot"].as<bool>();
rom_pri_option.librom_snapshot_freq = vm["ROM.offline.librom_snapshot_freq"].as<int>();

rom_pri_option.num_potbasis = vm["ROM.basis.number_of_potential_basis"].as<int>();
} // onpe0
Expand Down Expand Up @@ -2092,6 +2093,9 @@ void Control::syncROMOptions()
mpirc = MPI_Bcast(&rom_pri_option.save_librom_snapshot, 1, MPI_C_BOOL, 0, comm_global_);
bcast_check(mpirc);

mpirc = MPI_Bcast(&rom_pri_option.librom_snapshot_freq, 1, MPI_INT, 0, comm_global_);
bcast_check(mpirc);

short rom_var = (short)static_cast<int>(rom_pri_option.variable);
mpirc = MPI_Bcast(&rom_var, 1, MPI_SHORT, 0, comm_global_);
bcast_check(mpirc);
Expand All @@ -2101,4 +2105,4 @@ void Control::syncROMOptions()

mpirc = MPI_Bcast(&rom_pri_option.num_potbasis, 1, MPI_INT, 0, comm_global_);
bcast_check(mpirc);
}
}
26 changes: 15 additions & 11 deletions src/md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ void MGmol<OrbitalsType>::md(OrbitalsType** orbitals, Ions& ions)
bool extrapolated_flag = true;
if (ct.dt <= 0.) extrapolated_flag = false;

int librom_snapshot_freq = ct.getROMOptions().librom_snapshot_freq;
if (librom_snapshot_freq == -1) librom_snapshot_freq = ct.md_print_freq;

MDfiles md_files;

// main MD iteration loop
Expand Down Expand Up @@ -625,21 +628,22 @@ void MGmol<OrbitalsType>::md(OrbitalsType** orbitals, Ions& ions)
count++;
}

printWithTimeStamp("dumped restart file...", std::cout);
}

#ifdef MGMOL_HAS_LIBROM
// Save orbital snapshots
if (ct.getROMOptions().save_librom_snapshot > 0)
{
int ierr = save_orbital_snapshot(
ct.md_print_filename + "_mdstep" + std::to_string(mdstep), **orbitals);
// Save orbital snapshots
if (md_iteration_ % librom_snapshot_freq == 0
&& ct.getROMOptions().save_librom_snapshot > 0)
{
int ierr = save_orbital_snapshot(
ct.md_print_filename + "_mdstep" + std::to_string(mdstep), **orbitals);

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

printWithTimeStamp("dumped restart file...", std::cout);
}

md_iterations_tm.stop();

} // md loop
Expand Down
2 changes: 2 additions & 0 deletions src/read_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ void setupROMConfigOption(po::options_description &rom_cfg)
"File name for libROM snapshot/POD matrices.")
("ROM.offline.save_librom_snapshot", po::value<bool>()->default_value(false),
"Save libROM snapshot file at FOM simulation.")
("ROM.offline.librom_snapshot_freq", po::value<int>()->default_value(-1),
"Frequency of saving libROM snapshot file at FOM simulation.")
("ROM.offline.variable", po::value<std::string>()->default_value(""),
"FOM variable to perform POD: either orbitals or potential.")
("ROM.basis.number_of_potential_basis", po::value<int>()->default_value(-1),
Expand Down
1 change: 1 addition & 0 deletions src/rom_Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct ROMPrivateOptions

/* save librom snapshot matrix at FOM simulation. */
bool save_librom_snapshot = false;
int librom_snapshot_freq = -1;

/* options for ROM building */
int num_potbasis = -1;
Expand Down
Loading