Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 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
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
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
eb53963
Clean up MD_IonicStepper restart data write (#297)
jeanlucf22 Jan 16, 2025
857673f
Clean up code based on compiler warnings (#299)
jeanlucf22 Jan 17, 2025
f294d3c
Add getForces for evaluateDMandEnergyAndForces (#300)
siuwuncheung Jan 23, 2025
98a79de
Add check for compatibility MVP/Mehrstellen (#301)
jeanlucf22 Jan 24, 2025
8eda83e
Add support for Br atom (#302)
jeanlucf22 Feb 3, 2025
f298d43
Clean up some HDFrestart functions (#303)
jeanlucf22 Feb 11, 2025
c690bc5
Fix and test restart single hdf5 file (#305)
jeanlucf22 Feb 17, 2025
9f1fc20
Save Hartree potential for write in restart file (#306)
jeanlucf22 Feb 17, 2025
8a1cf05
Speed-up recently added tests (#309)
jeanlucf22 Feb 19, 2025
8a26879
Encapsulate some functions in Potentials (#310)
jeanlucf22 Feb 20, 2025
59b79e7
Remove confusing 0 in naming restart files (#308)
jeanlucf22 Feb 20, 2025
16a818a
Add functionalities for extra info in restart file (#312)
jeanlucf22 Feb 20, 2025
77bd87e
MPI abort (#313)
jeanlucf22 Feb 21, 2025
8b84de4
Rho and VH restart (#311)
jeanlucf22 Feb 24, 2025
8003d70
Strenghten testIons (#315)
jeanlucf22 Mar 4, 2025
4efb34c
More clean up in class Potentials (#316)
jeanlucf22 Mar 4, 2025
2f511b7
Misc code fixes (#317)
jeanlucf22 Mar 14, 2025
45a2c80
Use unique restart filenames in test HDF5single (#318)
jeanlucf22 Mar 14, 2025
b6cf162
Swap ions in existing test (#319)
jeanlucf22 Mar 15, 2025
7fbfe13
Code clean up (#320)
jeanlucf22 Mar 17, 2025
14eb43f
Added functionalities to set local forces (#321)
jeanlucf22 Mar 21, 2025
c61b48d
Update mixed precision code (#322)
jeanlucf22 Mar 24, 2025
e37983b
Clean up and fixes Ions (#326)
jeanlucf22 Mar 26, 2025
89630b3
Fixes for build without HDF5P (#324)
jeanlucf22 Mar 26, 2025
e80193b
Fix testRhoVhRestart (#325)
jeanlucf22 Mar 26, 2025
bcad112
Fix a few more issues with class Ions (#328)
jeanlucf22 Mar 26, 2025
a78e260
Introduce new constructor for class Ions (#330)
jeanlucf22 Mar 27, 2025
c4817b8
Add cleanup and MGmolInterface (#331)
siuwuncheung Mar 27, 2025
a5f6f3a
Add function to set local forces (#333)
jeanlucf22 Mar 28, 2025
4e82239
Fix setLocalForces (#335)
siuwuncheung Mar 30, 2025
f715dd9
Fix test WFEnergyAndForces (#336)
jeanlucf22 Apr 4, 2025
89d502e
Add mixing option in MVP (#337)
jeanlucf22 Apr 4, 2025
33d9ddb
Merge branch 'release' into ROM_MVP_timer
siuwuncheung Apr 9, 2025
71ab082
Timer
siuwuncheung Apr 9, 2025
f198397
Update MVP with mixing (#339)
jeanlucf22 Apr 9, 2025
ecf9e98
Merge branch 'release' into ROM_MVP_timer
siuwuncheung Apr 9, 2025
cb3b877
Updates
siuwuncheung Apr 10, 2025
8f03101
use setupPotentials
siuwuncheung Apr 22, 2025
a8ec88b
Setup potentials again
siuwuncheung May 8, 2025
7dae033
setupRhoc is done within setupPotentials
siuwuncheung May 8, 2025
a2421cd
Avoid setPositions
siuwuncheung May 8, 2025
81c98df
Rescaling ROM ion density
siuwuncheung May 8, 2025
8257638
Relax threshold
siuwuncheung May 14, 2025
77d02df
Increase tolerance for testROMIonDensity
siuwuncheung May 14, 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
2 changes: 1 addition & 1 deletion examples/PinnedH2O/job.basis_1_50
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setenv OMP_NUM_THREADS 1

set ncpus = 8

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/PinnedH2O/job.offline
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setenv OMP_NUM_THREADS 1

set ncpus = 8

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/PinnedH2O/job.ref
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ setenv OMP_NUM_THREADS 1
set ncpus = 8
set case = 2

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/PinnedH2O/job.rom
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setenv OMP_NUM_THREADS 1

set ncpus = 8

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/PinnedH2O/job.rom_3DOF
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ setenv OMP_NUM_THREADS 1
set ncpus = 8
set case = 2

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

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

Expand Down
6 changes: 4 additions & 2 deletions examples/PinnedH2O/mgmol_rom_3DOF_test1.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
verbosity=1
verbosity=2
xcFunctional=PBE
FDtype=4th
[Mesh]
Expand Down Expand Up @@ -34,7 +34,9 @@ initial_width=2.
nempty=30
[DensityMatrix]
solver=MVP
nb_inner_it=100
nb_inner_it=20
mixing=0.8
tol=1.e-8
[Restart]
output_level=4
[ROM]
Expand Down
6 changes: 4 additions & 2 deletions examples/PinnedH2O/mgmol_rom_3DOF_test2.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
verbosity=1
verbosity=2
xcFunctional=PBE
FDtype=4th
[Mesh]
Expand Down Expand Up @@ -30,7 +30,9 @@ initial_width=2.
nempty=30
[DensityMatrix]
solver=MVP
nb_inner_it=100
nb_inner_it=20
mixing=0.8
tol=1.e-8
[Restart]
output_level=4
[ROM]
Expand Down
12 changes: 7 additions & 5 deletions src/Control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ void Control::print(std::ostream& os)
<< conv_tol << std::endl;
os << std::fixed;
os << " Density matrix mixing = " << dm_mix << std::endl;
os << std::setprecision(4) << std::scientific << " Density matrix tol = " << dm_tol << std::endl;
if (DMEigensolver() == DMEigensolverType::Eigensolver)
{
os << " Density matrix computation algorithm = "
Expand Down Expand Up @@ -439,7 +440,7 @@ void Control::sync(void)
memset(&int_buffer[0], 0, size_int_buffer * sizeof(int));
}

const short size_float_buffer = 43;
const short size_float_buffer = 44;
float* float_buffer = new float[size_float_buffer];
if (mype_ == 0)
{
Expand Down Expand Up @@ -485,6 +486,7 @@ void Control::sync(void)
float_buffer[40] = threshold_eigenvalue_gram_quench_;
float_buffer[41] = pair_mlwf_distance_threshold_;
float_buffer[42] = e0_;
float_buffer[43] = dm_tol;
}
else
{
Expand Down Expand Up @@ -680,6 +682,7 @@ void Control::sync(void)
threshold_eigenvalue_gram_quench_ = float_buffer[40];
pair_mlwf_distance_threshold_ = float_buffer[41];
e0_ = float_buffer[42];
dm_tol = float_buffer[43];
max_electronic_steps_loose_ = max_electronic_steps;

delete[] short_buffer;
Expand All @@ -699,8 +702,8 @@ void Control::setDefaultValues()

void Control::adjust()
{
// change dm_mix default to 1. if not using Davidson
if (it_algo_type_ != 2 && dm_mix < 0.) dm_mix = 1.;
// change dm_mix default to 1. if not using Davidson or MVP
if ((it_algo_type_ != 2 && DM_solver_ != 1) && dm_mix < 0.) dm_mix = 1.;

if (nel_ - 2 * numst == 0)
{
Expand Down Expand Up @@ -1720,6 +1723,7 @@ void Control::setOptions(const boost::program_options::variables_map& vm)
lrs_extrapolation = 10;

dm_mix = vm["DensityMatrix.mixing"].as<float>();
dm_tol = vm["DensityMatrix.tol"].as<float>();
dm_inner_steps = vm["DensityMatrix.nb_inner_it"].as<short>();
dm_use_old_ = vm["DensityMatrix.use_old"].as<bool>() ? 1 : 0;
str = vm["DensityMatrix.algo"].as<std::string>();
Expand All @@ -1739,8 +1743,6 @@ void Control::setOptions(const boost::program_options::variables_map& vm)
else
dm_algo_ = 2;

dm_tol = vm["DensityMatrix.tol"].as<float>();

str = vm["DensityMatrix.solver"].as<std::string>();
if (str.compare("Mixing") == 0) DM_solver_ = 0;
if (str.compare("MVP") == 0) DM_solver_ = 1;
Expand Down
19 changes: 0 additions & 19 deletions src/Ions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1315,22 +1315,6 @@ void Ions::setLocalForces(
{
if (ion->compareName(*s))
{
//std::cout << "Ion found: " << ion->name() << std::endl;
//std::cout << "Ion force: (" << *it << ", " << *(it + 1) << ", " << *(it + 2) << ")" << std::endl;
//std::cout << "names: ";
//for (int i = 0; i < names.size(); i++)
//{
// std::cout << names[i];
// if (i == forces.size() - 1) std::cout << std::endl;
// else std::cout << ", ";
//}
//std::cout << "forces: ";
//for (int i = 0; i < forces.size(); i++)
//{
// std::cout << forces[i];
// if (i == forces.size() - 1) std::cout << ")" << std::endl;
// else std::cout << ", ";
//}
ion->set_force(0, *it);
ion->set_force(1, *(it + 1));
ion->set_force(2, *(it + 2));
Expand Down Expand Up @@ -1364,9 +1348,6 @@ void Ions::setLocalForces(
double d = std::sqrt(d2);
if (d < tol)
{
std::cout << "Ion found: " << ion->name() << std::endl;
std::cout << "Ion position:( " << *cit << ", " << *(cit + 1) << ", " << *(cit + 2) << ")" << std::endl;
std::cout << "Ion force: (" << *fit << ", " << *(fit + 1) << ", " << *(fit + 2) << ")" << std::endl;
ion->set_force(0, *fit);
ion->set_force(1, *(fit + 1));
ion->set_force(2, *(fit + 2));
Expand Down
2 changes: 2 additions & 0 deletions src/MGmol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ extern Timer md_moveVnuc_tm;
extern Timer md_updateMasks_tm;
extern Timer md_extrapolateOrbitals_tm;
extern Timer md_updateRhoAndPot_tm;
extern Timer md_updateDMandEnergy_tm;
extern Timer quench_tm;
extern Timer ions_setupInteractingIons_tm;
extern Timer ions_setup_tm;
Expand Down Expand Up @@ -928,6 +929,7 @@ void MGmol<OrbitalsType>::printTimers()
init_nuc_tm_.print(os_);
md_updateMasks_tm.print(os_);
md_extrapolateOrbitals_tm.print(os_);
md_updateDMandEnergy_tm.print(os_);
quench_tm.print(os_);
evnl_tm_.print(os_);
ions_setupInteractingIons_tm.print(os_);
Expand Down
115 changes: 67 additions & 48 deletions src/MVPSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ MVPSolver<OrbitalsType, MatrixType>::MVPSolver(MPI_Comm comm, std::ostream& os,
Electrostatic* electrostat, MGmol<OrbitalsType>* mgmol_strategy,
const int numst, const double kbT,
const std::vector<std::vector<int>>& global_indexes,
const short n_inner_steps, const bool use_old_dm)
const short n_inner_steps, const double mixing, const double tol_de0,
const bool use_old_dm)
: comm_(comm),
os_(os),
n_inner_steps_(n_inner_steps),
use_old_dm_(use_old_dm),
ions_(ions),
numst_(numst)
numst_(numst),
mixing_(mixing),
tol_de0_(tol_de0)
{
Control& ct = *(Control::instance());
if (onpe0 && ct.verbose > 0)
Expand Down Expand Up @@ -207,7 +210,6 @@ int MVPSolver<OrbitalsType, MatrixType>::solve(OrbitalsType& orbitals)

kbpsi.computeHvnlMatrix(&kbpsi, ions_, h11_nl);

const double tol_de0 = 1.e-12;
for (int inner_it = 0; inner_it < n_inner_steps_; inner_it++)
{
if (onpe0 && ct.verbose > 1)
Expand Down Expand Up @@ -270,62 +272,79 @@ int MVPSolver<OrbitalsType, MatrixType>::solve(OrbitalsType& orbitals)

double de0 = evaluateDerivative(dmInit, delta_dm, ts0);

if (std::abs(de0) < tol_de0 && inner_it > 0)
// check for convergence
if (std::abs(de0) < tol_de0_ && inner_it > 0)
{
if (onpe0 && ct.verbose > 0)
std::cout << "MVP: de0 = " << de0
<< ", convergence achieved" << std::endl;
break;
}

//
// evaluate free energy at beta=1
//
if (onpe0 && ct.verbose > 2)
std::cout << "MVP --- Target energy..." << std::endl;
proj_mat_work_->setDM(target, orbitals.getIterativeIndex());
proj_mat_work_->computeOccupationsFromDM();
if (ct.verbose > 2) proj_mat_work_->printOccupations(os_);
const double nel = proj_mat_work_->getNel();
if (onpe0 && ct.verbose > 1)
os_ << "MVP --- Number of electrons at beta=1 : " << nel
<< std::endl;

rho_->computeRho(orbitals, target);

mgmol_strategy_->update_pot(vh_init, ions_);

energy_->saveVofRho();

// update h11
double beta = 0.;
if (mixing_ > 0.)
{
h11 = h11_nl;
mgmol_strategy_->addHlocal2matrix(orbitals, orbitals, h11);
beta = mixing_;
if (onpe0 && ct.verbose > 0)
{
if (ct.verbose > 1)
os_ << "MVP with beta = " << beta << std::endl;
os_ << std::setprecision(12);
os_ << std::fixed << "MVP inner iteration " << inner_it
<< ", E0=" << e0 << std::endl;
}
}

proj_mat_work_->assignH(h11);
proj_mat_work_->setHB2H();

const double ts1
= evalEntropyMVP(proj_mat_work_, (ct.verbose > 2), os_);
const double e1 = energy_->evaluateTotal(
ts1, proj_mat_work_, ions_, orbitals, ct.verbose - 1, os_);

// line minimization
const double beta
= minQuadPolynomial(e0, e1, de0, (ct.verbose > 2), os_);
assert(!std::isnan(beta));

if (onpe0 && ct.verbose > 0)
else
{
os_ << std::setprecision(12);
os_ << std::fixed << "MVP inner iteration " << inner_it
<< ", E0=" << e0 << ", E1=" << e1;
os_ << std::scientific << ", E0'=" << de0
<< " -> beta=" << beta;
os_ << std::endl;
}
//
// evaluate free energy at beta=1
//
if (onpe0 && ct.verbose > 2)
std::cout << "MVP --- Target energy..." << std::endl;
proj_mat_work_->setDM(target, orbitals.getIterativeIndex());
proj_mat_work_->computeOccupationsFromDM();
if (ct.verbose > 2) proj_mat_work_->printOccupations(os_);
const double nel = proj_mat_work_->getNel();
if (onpe0 && ct.verbose > 1)
os_ << "MVP --- Number of electrons at beta=1 : " << nel
<< std::endl;

rho_->computeRho(orbitals, target);

mgmol_strategy_->update_pot(vh_init, ions_);

energy_->saveVofRho();

// update h11
{
h11 = h11_nl;
mgmol_strategy_->addHlocal2matrix(
orbitals, orbitals, h11);
}

proj_mat_work_->assignH(h11);
proj_mat_work_->setHB2H();

const double ts1
= evalEntropyMVP(proj_mat_work_, (ct.verbose > 2), os_);
const double e1 = energy_->evaluateTotal(ts1,
proj_mat_work_, ions_, orbitals, ct.verbose - 1, os_);

// line minimization
beta
= minQuadPolynomial(e0, e1, de0, (ct.verbose > 2), os_);
assert(!std::isnan(beta));

if (onpe0 && ct.verbose > 0)
{
os_ << std::setprecision(12);
os_ << std::fixed << "MVP inner iteration " << inner_it
<< ", E0=" << e0 << ", E1=" << e1;
os_ << std::scientific << ", E0'=" << de0
<< " -> beta=" << beta;
os_ << std::endl;
}
}
// update DM
*work_ = dmInit;
work_->axpy(beta, delta_dm);
Expand Down
9 changes: 8 additions & 1 deletion src/MVPSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class MVPSolver
Ions& ions_;

int numst_;
double mixing_;

/*!
* tolerance on energy slope in inner iterations
*/
double tol_de0_;

Rho<OrbitalsType>* rho_;
Energy<OrbitalsType>* energy_;
Expand All @@ -56,7 +62,8 @@ class MVPSolver
Electrostatic* electrostat, MGmol<OrbitalsType>* mgmol_strategy,
const int numst, const double kbT,
const std::vector<std::vector<int>>& global_indexes,
const short n_inner_steps, const bool use_old_dm);
const short n_inner_steps, const double mixing, const double tol_de0,
const bool use_old_dm);
~MVPSolver();

int solve(OrbitalsType& orbitals);
Expand Down
2 changes: 1 addition & 1 deletion src/MVP_DMStrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int MVP_DMStrategy<OrbitalsType, MatrixType>::update(OrbitalsType& orbitals)

MVPSolver<OrbitalsType, MatrixType> solver(comm_, os_, ions_, rho_, energy_,
electrostat_, mgmol_strategy_, ct.numst, ct.occ_width, global_indexes_,
ct.dm_inner_steps, use_old_dm_);
ct.dm_inner_steps, ct.dm_mix, ct.dm_tol, use_old_dm_);

return solver.solve(orbitals);
}
Expand Down
3 changes: 3 additions & 0 deletions src/md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Timer md_tau_tm("md_tau");
Timer md_moveVnuc_tm("md_moveVnuc");
Timer md_updateMasks_tm("md_updateMasks");
Timer md_extrapolateOrbitals_tm("md_extrapolateOrbitals");
Timer md_updateDMandEnergy_tm("md_updateDMandEnergy");

#define DUMP_MAX_NUM_TRY 5

Expand Down Expand Up @@ -485,7 +486,9 @@ void MGmol<OrbitalsType>::md(OrbitalsType** orbitals, Ions& ions)

if (ROM_MVP)
{
md_updateDMandEnergy_tm.start();
updateDMandEnergy(**orbitals, *ROM_ions, eks);
md_updateDMandEnergy_tm.stop();
}
else
{
Expand Down
Loading