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 calculations of Pinned H2O with 3 DOF #289

Open
wants to merge 59 commits into
base: ROMFPMD
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
1ad1292
Fix EnergyAndForces tests (#277)
jeanlucf22 Sep 26, 2024
8ac6cd6
Move factor 4pi out og linear solvers (#278)
jeanlucf22 Sep 30, 2024
a2ece1a
Move some code into PoissonSolverFactory (#279)
jeanlucf22 Sep 30, 2024
8b577ea
Clean up class Potentials (#280)
jeanlucf22 Oct 3, 2024
7ac691c
Clean up class Ions, add test for it (#281)
jeanlucf22 Oct 12, 2024
fa36d2f
set up offline procedure
siuwuncheung Nov 14, 2024
1526974
Parametric file
siuwuncheung Nov 14, 2024
65939c5
Add basis script
siuwuncheung Nov 14, 2024
03e59eb
Add postprocessing scripts
siuwuncheung Nov 14, 2024
318325c
Add files via upload
siuwuncheung Nov 15, 2024
b616e8e
Add restore check. Make H1 shorter than H2 in original system for ver…
siuwuncheung Nov 19, 2024
ffd2a8b
Merge branch 'ROM-PinnedH2O-3DOF' of https://github.com/LLNL/mgmol in…
siuwuncheung Nov 19, 2024
38a0511
Minor change
siuwuncheung Nov 19, 2024
2f79fdb
Add C++ translation
siuwuncheung Nov 19, 2024
8f61523
Add restoring test
siuwuncheung Nov 19, 2024
c05ba7f
Add test MD_MVP (#290)
jeanlucf22 Nov 25, 2024
bb8051d
Clean up code related to DM restart data (#292)
jeanlucf22 Dec 2, 2024
a227c04
Write dm (#291)
jeanlucf22 Dec 2, 2024
a09ca14
Set up test
siuwuncheung Dec 3, 2024
47e6335
Update cfg
siuwuncheung Dec 3, 2024
cdf38c8
Fix conversions
siuwuncheung Dec 6, 2024
15555f4
Add new script
siuwuncheung Dec 6, 2024
f2c963c
Add CMake
siuwuncheung Dec 6, 2024
b09a20f
Restore
siuwuncheung Dec 12, 2024
cac12ac
Updates
siuwuncheung Dec 13, 2024
9acca3f
Changes
siuwuncheung Dec 19, 2024
98ef8f2
Relocate set
siuwuncheung Dec 19, 2024
b2bc316
Refactor
siuwuncheung Dec 19, 2024
b263532
Remove unused function in Control (#294)
jeanlucf22 Dec 23, 2024
3eb52d6
Change symlink to restart in tests (#295)
jeanlucf22 Jan 3, 2025
c1d46bc
Extract number empty orbitals from restart file (#296)
jeanlucf22 Jan 7, 2025
6feca4f
Merge release to ROMFPMD
siuwuncheung Jan 16, 2025
c9b4a15
Merge branch 'merge-release-20250113' into ROM-PinnedH2O-3DOF
siuwuncheung Jan 16, 2025
e2656f8
Merge branch 'ROMFPMD' into ROM-PinnedH2O-3DOF
siuwuncheung Jan 16, 2025
0bb043d
updates
siuwuncheung Jan 16, 2025
15a0e37
Updates
siuwuncheung Jan 17, 2025
88f2535
Fixes
siuwuncheung Jan 17, 2025
eaa93ea
Add computeGramAndInvS
siuwuncheung Jan 17, 2025
0777a95
Add
siuwuncheung Jan 17, 2025
7fa2b79
Debug
siuwuncheung Jan 21, 2025
f33a8d9
Clean up
siuwuncheung Jan 21, 2025
4a1c0ef
Turn on MVP solver for nempty > 0 case
siuwuncheung Jan 22, 2025
3f18631
Add getForces for evaluateDMandEnergyAndForces
siuwuncheung Jan 23, 2025
1340d30
Merge branch 'DM_driver_print_force' into ROM-PinnedH2O-3DOF
siuwuncheung Jan 23, 2025
c25c614
Add new tests
siuwuncheung Jan 23, 2025
1b5ed09
Remove redundant line
siuwuncheung Jan 23, 2025
2b62d76
Fix filename
siuwuncheung Jan 23, 2025
6e0113b
Add quench and MVP comparison for main executable
siuwuncheung Jan 24, 2025
e699f4d
minor changes
siuwuncheung Jan 24, 2025
9943a23
Changes in setting of Quench and MVP comparison
siuwuncheung Jan 24, 2025
13b59b3
Add number of quench iterations for convergence
siuwuncheung Jan 24, 2025
18650d5
Update job scripts
siuwuncheung Jan 27, 2025
fb2c72d
Update config files
siuwuncheung Jan 27, 2025
8036917
Update toy example
siuwuncheung Jan 27, 2025
a80300d
Remove redundant script
siuwuncheung Jan 28, 2025
f0eaa2a
Updates
siuwuncheung Jan 28, 2025
0822805
Update scripts
siuwuncheung Jan 28, 2025
c0bc938
Add functional script
siuwuncheung Jan 30, 2025
dd076eb
Templatize scripts
siuwuncheung Jan 31, 2025
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
63 changes: 0 additions & 63 deletions examples/PinnedH2O/generate_coord.py

This file was deleted.

28 changes: 28 additions & 0 deletions examples/PinnedH2O/get_ROM_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import subprocess
import re

pattern = r"For energy fraction: \d+\.\d+, take first (\d+) of \d+ basis vectors"

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")

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}")
3 changes: 3 additions & 0 deletions src/ExtendedGridOrbitals.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ class ExtendedGridOrbitals : public Orbitals
const pb::Grid& mygrid = mymesh->grid();
return mygrid.maxDomainSize();
}
#ifdef MGMOL_HAS_LIBROM
void set(std::string file_path, int rdim);
#endif
};

#endif
4 changes: 2 additions & 2 deletions src/MGmol.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ class MGmol : public MGmolInterface
}

#ifdef MGMOL_HAS_LIBROM
int save_orbital_snapshot(std::string snapshot_dir, OrbitalsType& orbitals);
void project_orbital(std::string snapshot_dir, int rdim, OrbitalsType& orbitals);
int save_orbital_snapshot(std::string file_path, OrbitalsType& orbitals);
void project_orbital(std::string file_path, int rdim, OrbitalsType& orbitals);
#endif
};
// Instantiate static variables here to avoid clang warnings
Expand Down
1 change: 0 additions & 1 deletion src/md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ void MGmol<OrbitalsType>::md(OrbitalsType** orbitals, Ions& ions)
force(**orbitals, ions);

#ifdef MGMOL_HAS_LIBROM
// TODO: cleanup
if (ct.getROMOptions().num_orbbasis > 0)
{
if (onpe0)
Expand Down
20 changes: 20 additions & 0 deletions src/rom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#ifdef MGMOL_HAS_LIBROM

#include "LocGridOrbitals.h"
#include "ExtendedGridOrbitals.h"
#include "MGmol.h"

#include "librom.h"
Expand Down Expand Up @@ -91,6 +92,25 @@ void MGmol<OrbitalsType>::project_orbital(std::string file_path, int rdim, Orbit
}
}

void ExtendedGridOrbitals::set(std::string file_path, int rdim)
{
const int dim = getLocNumpt();

CAROM::BasisReader reader(file_path);
CAROM::Matrix* orbital_basis = reader.getSpatialBasis(rdim);

Control& ct = *(Control::instance());
Mesh* mymesh = Mesh::instance();
pb::GridFunc<ORBDTYPE> gf_psi(mymesh->grid(), ct.bcWF[0], ct.bcWF[1], ct.bcWF[2]);
CAROM::Vector psi;
for (int i = 0; i < rdim; ++i)
{
orbital_basis->getColumn(i, psi);
gf_psi.assign(psi.getData());
setPsi(gf_psi, i);
}
}

template class MGmol<LocGridOrbitals>;
template class MGmol<ExtendedGridOrbitals>;

Expand Down
11 changes: 11 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ add_executable(testDMandEnergyAndForces
${CMAKE_SOURCE_DIR}/tests/DMandEnergyAndForces/testDMandEnergyAndForces.cc)
add_executable(testRestartEnergyAndForces
${CMAKE_SOURCE_DIR}/tests/RestartEnergyAndForces/testRestartEnergyAndForces.cc)
add_executable(testPinnedH2O_3DOF
${CMAKE_SOURCE_DIR}/tests/PinnedH2O_3DOF/testPinnedH2O_3DOF.cc)

if(${MAGMA_FOUND})
add_executable(testOpenmpOffload
Expand Down Expand Up @@ -382,6 +384,14 @@ add_test(NAME testRestartEnergyAndForces
${CMAKE_CURRENT_SOURCE_DIR}/RestartEnergyAndForces/restart.cfg
${CMAKE_CURRENT_SOURCE_DIR}/RestartEnergyAndForces/h2o.xyz
${CMAKE_CURRENT_SOURCE_DIR}/../potentials)
add_test(NAME testPinnedH2O_3DOF
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PinnedH2O_3DOF/test.py
${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS}
${CMAKE_CURRENT_BINARY_DIR}/testPinnedH2O_3DOF
${CMAKE_CURRENT_SOURCE_DIR}/PinnedH2O_3DOF/mgmol.cfg
${CMAKE_CURRENT_SOURCE_DIR}/PinnedH2O_3DOF/coords.in
${CMAKE_CURRENT_SOURCE_DIR}/PinnedH2O_3DOF/lrs.in
${CMAKE_CURRENT_SOURCE_DIR}/../potentials)

if(${MAGMA_FOUND})
add_test(NAME testOpenmpOffload
Expand Down Expand Up @@ -579,6 +589,7 @@ target_link_libraries(testEnergyAndForces PRIVATE mgmol_src)
target_link_libraries(testWFEnergyAndForces PRIVATE mgmol_src)
target_link_libraries(testDMandEnergyAndForces PRIVATE mgmol_src)
target_link_libraries(testRestartEnergyAndForces PRIVATE mgmol_src)
target_link_libraries(testPinnedH2O_3DOF PRIVATE mgmol_src)
target_link_libraries(testIons PRIVATE mgmol_src)
target_link_libraries(testDensityMatrix PRIVATE ${HDF5_LIBRARIES})

Expand Down
1 change: 1 addition & 0 deletions tests/PinnedH2O_3DOF/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 test.py srun -p debug -n 64 ../../build_quartz/tests/testPinnedH2O_3DOF mgmol_online.cfg coords_1.00_1.00_0.0.in ../../potentials
Binary file added tests/PinnedH2O_3DOF/aux/PinnedH2O_3DOF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions tests/PinnedH2O_3DOF/aux/get_ROM_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import subprocess
import re

bondlength_num_increments = (2, 5, 10)
bondangle_num_increments = (2, 5, 10)

pattern = r"For energy fraction: \d+\.\d+, take first (\d+) of \d+ basis vectors"

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

for _, N_L in enumerate(bondlength_num_increments):
for _, N_theta in enumerate(bondangle_num_increments):
snapshots = 2*(N_L+1)*(N_L+2)*(N_theta+1)
grep_command = f"grep 'take first' basis_{N_L}_{N_theta}_PinnedH2O_3DOF.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"{N_L} & {N_theta} & {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}")
69 changes: 69 additions & 0 deletions tests/PinnedH2O_3DOF/aux/plot_PinnedH2O_3DOF.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

ref_bondlength = 1.83
ref_bondangle = 104.5

# factors and increments for bond lengths and bond angle
bondlength_factor = np.linspace(0.95, 1.05, 3)
bondangle_increment = np.linspace(-5, 5, 3)

fig, ax = plt.subplots()

for d_bondangle in bondangle_increment:
bondangle = ref_bondangle + d_bondangle
x = ref_bondlength * np.cos(np.radians(bondangle / 2))
y = ref_bondlength * np.sin(np.radians(bondangle / 2))
for i, f_bondlength1 in enumerate(bondlength_factor):
H1_x = f_bondlength1*x
H1_y = f_bondlength1*y
ax.plot(H1_x, H1_y, 'ro', markersize=8, alpha=0.1)
for f_bondlength2 in bondlength_factor[:(i+1)]:
H2_x = f_bondlength2*x
H2_y = -f_bondlength2*y
ax.plot(H2_x, H2_y, 'bo', markersize=8, alpha=0.1)

ref_bondangle = np.radians(ref_bondangle)
x = ref_bondlength * np.cos(ref_bondangle / 2)
y = ref_bondlength * np.sin(ref_bondangle / 2)

ax.plot([0, x], [0, y], 'r-', lw=2)
ax.plot([0, x], [0, -y], 'b-', lw=2)
ax.plot(0, 0, 'ko', markersize=8)
ax.plot(x, y, 'ro', markersize=8)
ax.plot(x, -y, 'bo', markersize=8)

arc1 = matplotlib.patches.Arc(xy=(0, 0),
width=0.5,
height=0.5,
angle=0,
theta1=0,
theta2=ref_bondangle/2,
color='red',
linewidth=2)
ax.add_patch(arc1)
ax.text(0.4, 0.25, r"$\frac{\theta}{2}$", ha='center', va='center', fontsize=12, color='red')

arc2 = matplotlib.patches.Arc(xy=(0, 0),
width=0.5,
height=0.5,
angle=0,
theta1=-ref_bondangle/2,
theta2=0,
color='blue',
linewidth=2)
ax.add_patch(arc2)
ax.text(0.4, -0.25, r"$\frac{\theta}{2}$", ha='center', va='center', fontsize=12, color='blue')

ax.text(x / 2 - 0.1, y / 2, r"$L_1$", ha='right', color='red')
ax.text(x / 2 - 0.1, -y / 2, r"$L_2$", ha='right', color='blue')

ax.plot([-2, 2], [0, 0], 'k--', lw=1)
ax.set_xlim(-2.0, 2.0)
ax.set_ylim(-2.0, 2.0)
ax.set_aspect('equal')
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.grid(True)
plt.savefig("PinnedH2O_3DOF.png")
Loading
Loading