Skip to content

Commit

Permalink
refactor cholesky module usage, remove force_tilesize option and upda…
Browse files Browse the repository at this point in the history
…te docs
  • Loading branch information
ajaypanyala committed Nov 6, 2024
1 parent b995da4 commit ad11e69
Show file tree
Hide file tree
Showing 115 changed files with 1,002 additions and 1,010 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Release/
cmake-build-debug/
cmake-build-release/
build/
ebuild/
debug*
build*
.xlsx
Expand Down
1 change: 0 additions & 1 deletion ci/reference_output/ch4.def2-tzvp.ccsd_t.json
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@
"convd": 1e-06,
"diis_hist": 20,
"AO_tilesize": 30,
"force_tilesize": "false",
"scf_type": "unrestricted",
"multiplicity": 3,
"lambdas": [],
Expand Down
2 changes: 0 additions & 2 deletions ci/reference_output/co.cc-pvdz.gfccsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@
"convd": 1e-11,
"diis_hist": 10,
"AO_tilesize": 30,
"force_tilesize": "false",
"damp": 100,
"debug": "false",
"restart": "false",
Expand Down Expand Up @@ -535,7 +534,6 @@
"CCSD": {
"threshold": 1e-06,
"tilesize": 40,
"force_tilesize": "false",
"lshift": 0.0,
"ndiis": 5,
"readt": "false",
Expand Down
1 change: 0 additions & 1 deletion ci/reference_output/cr2.def2-svp.scf.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@
"convd": 1e-07,
"diis_hist": 10,
"AO_tilesize": 30,
"force_tilesize": "false",
"damp": 100,
"debug": "false",
"restart": "false",
Expand Down
1 change: 0 additions & 1 deletion ci/reference_output/h2o_ducc.cc-pvdz.ducc.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@
"convd": 1e-08,
"diis_hist": 10,
"AO_tilesize": 30,
"force_tilesize": "false",
"scf_type": "restricted",
"multiplicity": 1,
"lambdas": [],
Expand Down
1 change: 0 additions & 1 deletion ci/reference_output/h2o_eom.cc-pvdz.eomccsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@
"convd": 1e-08,
"diis_hist": 10,
"AO_tilesize": 30,
"force_tilesize": "false",
"scf_type": "restricted",
"multiplicity": 1,
"lambdas": [],
Expand Down
1 change: 0 additions & 1 deletion ci/reference_output/ozone.sto-3g.rt-eomccsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
"convd": 0.1,
"diis_hist": 10,
"AO_tilesize": 30,
"force_tilesize": "false",
"scf_type": "unrestricted",
"multiplicity": 2
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@
"convd": 1e-07,
"diis_hist": 12,
"AO_tilesize": 30,
"force_tilesize": "false",
"scf_type": "restricted",
"multiplicity": 1,
"lambdas": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@
"convd": 1e-07,
"diis_hist": 12,
"AO_tilesize": 37,
"force_tilesize": "false",
"scf_type": "restricted",
"multiplicity": 1,
"lambdas": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@
"convd": 1e-09,
"diis_hist": 12,
"AO_tilesize": 30,
"force_tilesize": "false",
"scf_type": "restricted",
"multiplicity": 1
},
Expand Down
1 change: 0 additions & 1 deletion ci/reference_output/uracil.cc-pvdz.ccsd_t.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@
"convd": 1e-7,
"diis_hist": 10,
"AO_tilesize": 30,
"force_tilesize": "false",
"scf_type": "restricted",
"multiplicity": 1
},
Expand Down
6 changes: 0 additions & 6 deletions docs/schema/input_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
"diis_hist": {
"type": "number"
},
"force_tilesize": {
"type": "boolean"
},
"tilesize": {
"type": "number"
},
Expand Down Expand Up @@ -287,9 +284,6 @@
"threshold": {
"type": "number"
},
"force_tilesize": {
"type": "boolean"
},
"tilesize": {
"type": "number"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/basic_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Some common options supported are as follows:
:file_prefix: A string indicating the prefix for the name of the workspace folder where the results of a run are stored.
It also forms the prefix for the files written to the workspace folder. The *default prefix* is the name of the input file without the *.json* extension.

:output_dir: A string indicating the path to the directory where the where the results of a run are stored. If not provided, the default is the current working directory.
:output_dir: A string indicating the path to an existing directory where the where the results of a run are stored. If not provided, the default is the current working directory.

.. _Basis:

Expand Down
8 changes: 5 additions & 3 deletions docs/user_guide/coupledcluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ The following CCSD options are supported. The remaining CC methods (CC2, Lambda,
"CC": {
"threshold": 1e-6,
"force_tilesize": false,
"tilesize": 50,
"lshift": 0,
"ndiis": 5,
Expand All @@ -45,11 +44,14 @@ The following CCSD options are supported. The remaining CC methods (CC2, Lambda,
}
}
:threshold: ``[default=1e-6]`` Specifies the convergence threshold of iterative solutions of amplitude equations. The threshold refers to the norm of residual, namely, the deviation from the amplitude equations.

:force_tilesize: ``[default=false]``
:tilesize: ``[default=40]`` The tilesize for the MO or MSO space. An integer value that is automatically set unless specified explicitly by the user. It is recommended to let the CC module determine this value automatically.

.. warning::

:tilesize: ``[default=40]`` The tilesize for the MO or MSO space. An integer value that is automatically set. If **force_tilesize=true**, the value specified by the user is respected. It is recommended to let the CC module automatically determine this value.
The automatically determined tilesize may vary depending on node count and the number of processes per node. When restarting a calculation with different node counts, the user is expected to explicitly set the tilesize to match the value used in the initial run.

:lshift: ``[default=0]`` The level shift option that increases small orbital energy differences used in calculating the updates for cluster amplitudes. When calculating ground states with multi-configurational character or if convergence is slow, one may need to specify a typical values for lshift between 0.3 and 0.5.

Expand Down
7 changes: 2 additions & 5 deletions docs/user_guide/scf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ The values listed below are the defaults where few options are automatically adj
"conve": 1e-8,
"convd": 1e-7,
"diis_hist": 10,
"force_tilesize": false,
"tilesize": 30,
"damp": 100,
"nnodes": 1,
Expand Down Expand Up @@ -97,10 +96,8 @@ The values listed below are the defaults where few options are automatically adj

:diis_hist: ``[default=10]`` Specifies the number of DIIS history entries to store for the fock and error matrices.

:force_tilesize: ``[default=false]``

:tilesize: The tilesize for the AO dimension. An integer value that is automatically set to ``ceil(Nbf * 0.05)``. If **force_tilesize=true**,
the value specified by the user is respected. It is recommended to let the SCF module automatically determine this value.
:tilesize: The tilesize for the AO dimension. An integer value that is automatically set to ``ceil(Nbf * 0.05)``
if the user has not explicitly set it. It is recommended to let the SCF module automatically determine this value.

:damp: damping (mixing) factor for the density matrix where :math:`0 \leq \alpha \leq 100`. Specifies the percentage of the current iterations density mixed with the previous iterations density. ``default=100`` indicates no damping.

Expand Down
18 changes: 9 additions & 9 deletions exachem/cc/cc2/cc2_canonical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ cc2_v2_driver(ChemEnv& chem_env, ExecutionContext& ec, const TiledIndexSpace& MO
}

chem_env.cc_context.cc2_correlation_energy = energy;
chem_env.cc_context.cc2_total_energy = chem_env.hf_energy + energy;
chem_env.cc_context.cc2_total_energy = chem_env.scf_context.hf_energy + energy;

if(ec.pg().rank() == 0) {
sys_data.results["output"]["CC2"]["n_iterations"] = niter + 1;
Expand All @@ -304,15 +304,15 @@ void cc2_canonical_driver(ExecutionContext& ec, ChemEnv& chem_env) {

scf(ec, chem_env);

double hf_energy = chem_env.hf_energy;
double hf_energy = chem_env.scf_context.hf_energy;
libint2::BasisSet shells = chem_env.shells;
Tensor<T> C_AO = chem_env.C_AO;
Tensor<T> C_beta_AO = chem_env.C_beta_AO;
Tensor<T> F_AO = chem_env.F_AO;
Tensor<T> F_beta_AO = chem_env.F_beta_AO;
TiledIndexSpace AO_opt = chem_env.AO_opt;
std::vector<size_t> shell_tile_map = chem_env.shell_tile_map;
bool scf_conv = chem_env.no_scf;
Tensor<T> C_AO = chem_env.scf_context.C_AO;
Tensor<T> C_beta_AO = chem_env.scf_context.C_beta_AO;
Tensor<T> F_AO = chem_env.scf_context.F_AO;
Tensor<T> F_beta_AO = chem_env.scf_context.F_beta_AO;
TiledIndexSpace AO_opt = chem_env.is_context.AO_opt;
std::vector<size_t> shell_tile_map = chem_env.scf_context.shell_tile_map;
bool scf_conv = chem_env.scf_context.no_scf;

SystemData& sys_data = chem_env.sys_data;
CCSDOptions& ccsd_options = chem_env.ioptions.ccsd_options;
Expand Down
85 changes: 23 additions & 62 deletions exachem/cc/cc2/cd_cc2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,37 @@ namespace fs = std::filesystem;

namespace exachem::cc2 {
void cd_cc2_driver(ExecutionContext& ec, ChemEnv& chem_env) {
using T = double;

using T = double;
auto rank = ec.pg().rank();

scf::scf_driver(ec, chem_env);

double hf_energy = chem_env.hf_energy;
libint2::BasisSet shells = chem_env.shells;
Tensor<T> C_AO = chem_env.C_AO;
Tensor<T> C_beta_AO = chem_env.C_beta_AO;
Tensor<T> F_AO = chem_env.F_AO;
Tensor<T> F_beta_AO = chem_env.F_beta_AO;
TiledIndexSpace AO_opt = chem_env.AO_opt;
TiledIndexSpace AO_tis = chem_env.AO_tis;
std::vector<size_t> shell_tile_map = chem_env.shell_tile_map;
bool scf_conv = chem_env.no_scf;

SystemData sys_data = chem_env.sys_data;
CCSDOptions& ccsd_options = chem_env.ioptions.ccsd_options;
auto debug = ccsd_options.debug;
if(rank == 0) ccsd_options.print();
cholesky_2e::cholesky_2e_driver(ec, chem_env);

if(rank == 0)
cout << endl << "#occupied, #virtual = " << sys_data.nocc << ", " << sys_data.nvir << endl;
const bool is_rhf = chem_env.sys_data.is_restricted;

auto [MO, total_orbitals] = cholesky_2e::setupMOIS(ec, chem_env);
std::string files_prefix = chem_env.get_files_prefix();

std::string out_fp = chem_env.workspace_dir;
std::string files_dir = out_fp + chem_env.ioptions.scf_options.scf_type + "/cc2";
std::string files_prefix = /*out_fp;*/ files_dir + "/" + sys_data.output_file_prefix;
std::string f1file = files_prefix + ".f1_mo";
std::string t1file = files_prefix + ".t1amp";
std::string t2file = files_prefix + ".t2amp";
std::string v2file = files_prefix + ".cholv2";
std::string cholfile = files_prefix + ".cholcount";
std::string ccsdstatus = files_prefix + ".ccsdstatus";

const bool is_rhf = sys_data.is_restricted;
CDContext& cd_context = chem_env.cd_context;
CCContext& cc_context = chem_env.cc_context;
cc_context.init_filenames(files_prefix);
CCSDOptions& ccsd_options = chem_env.ioptions.ccsd_options;

bool ccsd_restart = ccsd_options.readt || ((fs::exists(t1file) && fs::exists(t2file) &&
fs::exists(f1file) && fs::exists(v2file)));
auto debug = ccsd_options.debug;
bool scf_conv = chem_env.scf_context.no_scf;
std::string t1file = cc_context.t1file;
std::string t2file = cc_context.t2file;
const std::string ccsdstatus = cc_context.ccsdstatus;

// deallocates F_AO, C_AO
auto [cholVpr, d_f1, lcao, chol_count, max_cvecs, CI] =
exachem::cholesky_2e::cholesky_2e_driver<T>(chem_env, ec, MO, AO_opt, C_AO, F_AO, C_beta_AO,
F_beta_AO, shells, shell_tile_map, ccsd_restart,
cholfile);
free_tensors(lcao);
bool ccsd_restart = ccsd_options.readt ||
((fs::exists(t1file) && fs::exists(t2file) && fs::exists(cd_context.f1file) &&
fs::exists(cd_context.v2file)));

if(ccsd_options.writev) ccsd_options.writet = true;

TiledIndexSpace N = MO("all");
TiledIndexSpace& MO = chem_env.is_context.MSO;
TiledIndexSpace& CI = chem_env.is_context.CI;
TiledIndexSpace N = MO("all");
Tensor<T> d_f1 = chem_env.cd_context.d_f1;
Tensor<T> cholVpr = chem_env.cd_context.cholV2;

std::vector<T> p_evl_sorted;
Tensor<T> d_r1, d_r2, d_t1, d_t2;
Expand All @@ -78,31 +57,13 @@ void cd_cc2_driver(ExecutionContext& ec, ChemEnv& chem_env) {
ec, MO, d_f1, ccsd_options.ndiis, ccsd_restart && fs::exists(ccsdstatus) && scf_conv);

if(ccsd_restart) {
read_from_disk(d_f1, f1file);
if(fs::exists(t1file) && fs::exists(t2file)) {
read_from_disk(d_t1, t1file);
read_from_disk(d_t2, t2file);
}
read_from_disk(cholVpr, v2file);
ec.pg().barrier();
p_evl_sorted = tamm::diagonal(d_f1);
}

else if(ccsd_options.writet) {
// fs::remove_all(files_dir);
if(!fs::exists(files_dir)) fs::create_directories(files_dir);

write_to_disk(d_f1, f1file);
write_to_disk(cholVpr, v2file);

if(rank == 0) {
std::ofstream out(cholfile, std::ios::out);
if(!out) cerr << "Error opening file " << cholfile << endl;
out << chol_count << std::endl;
out.close();
}
}

if(rank == 0 && debug) {
print_vector(p_evl_sorted, files_prefix + ".eigen_values.txt");
cout << "Eigen values written to file: " << files_prefix + ".eigen_values.txt" << endl << endl;
Expand All @@ -114,7 +75,7 @@ void cd_cc2_driver(ExecutionContext& ec, ChemEnv& chem_env) {

ccsd_restart = ccsd_restart && fs::exists(ccsdstatus) && scf_conv;

std::string fullV2file = files_prefix + ".fullV2";
std::string fullV2file = cd_context.fullV2file;
t1file = files_prefix + ".fullT1amp";
t2file = files_prefix + ".fullT2amp";

Expand Down Expand Up @@ -145,7 +106,7 @@ void cd_cc2_driver(ExecutionContext& ec, ChemEnv& chem_env) {
}
}

ccsd_stats(ec, hf_energy, residual, corr_energy, ccsd_options.threshold);
ccsd_stats(ec, chem_env.scf_context.hf_energy, residual, corr_energy, ccsd_options.threshold);

if(ccsd_options.writet && !fs::exists(ccsdstatus)) {
// write_to_disk(d_t1,t1file);
Expand Down
2 changes: 1 addition & 1 deletion exachem/cc/cc2/cd_cc2_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ std::tuple<double, double> cc2_cs::cd_cc2_cs_driver(
}

chem_env.cc_context.cc2_correlation_energy = energy;
chem_env.cc_context.cc2_total_energy = chem_env.hf_energy + energy;
chem_env.cc_context.cc2_total_energy = chem_env.scf_context.hf_energy + energy;

if(ec.pg().rank() == 0) {
sys_data.results["output"]["CC2"]["n_iterations"] = niter + 1;
Expand Down
2 changes: 1 addition & 1 deletion exachem/cc/cc2/cd_cc2_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ std::tuple<double, double> cc2_os::cd_cc2_os_driver(
}

chem_env.cc_context.cc2_correlation_energy = energy;
chem_env.cc_context.cc2_total_energy = chem_env.hf_energy + energy;
chem_env.cc_context.cc2_total_energy = chem_env.scf_context.hf_energy + energy;

if(ec.pg().rank() == 0) {
sys_data.results["output"]["CC2"]["n_iterations"] = niter + 1;
Expand Down
Loading

0 comments on commit ad11e69

Please sign in to comment.