Skip to content

Commit 572c329

Browse files
kylebystromsunqm
authored andcommitted
update docs for revised SGX algorithm
1 parent 6b473f4 commit 572c329

2 files changed

Lines changed: 45 additions & 24 deletions

File tree

source/user/ref.bib

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,16 @@ @article{Neese2009
840840
pages = {98},
841841
year = {2009}
842842
}
843+
@article{Helmich2021,
844+
title = {An Improved Chain of Spheres for Exchange Algorithm},
845+
author = {{Helmich-Paris}, Benjamin and {de Souza}, Bernardo and Neese, Frank and Izs{\'a}k, R{\'o}bert},
846+
year = 2021,
847+
journal = {J. Chem. Phys.},
848+
volume = {155},
849+
number = {10},
850+
pages = {104109},
851+
doi = {10.1063/5.0058766},
852+
}
843853
@article{Cances2013,
844854
author = {Cances, Eric and Maday, Yvon and Stamm, Benjamin },
845855
title = {Domain decomposition for implicit solvation models},

source/user/sgx.rst

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,70 @@ Seminumerical exchange (SGX)
55

66
*Modules*: :py:mod:`pyscf.sgx`
77

8-
The SGX module implements seminumerical computation of the exchange matrix.
8+
The SGX module implements seminumerical computation of the exchange matrix (and also the Coulomb matrix).
99

1010
Introduction
1111
============
1212

1313
Direct computation of the Hartree-Fock exchange matrix in the atomic orbital basis scales poorly with system size.
1414
To achieve better scaling, one three-dimensional integral in the 6-dimensional two-electron integrals can be computed analytically, while the other can be evaluated on a real-space grid, as proposed by Friesner :cite:`Friesner1985`.
15-
The PySCF implementation resembles the chain-of-spheres (COSX) algorithm of Neese et al. :cite:`Neese2009`, but uses more conservative grids and a slightly different P-junction screening function.
15+
The PySCF implementation resembles the chain-of-spheres (COSX) algorithm of Neese et al. :cite:`Neese2009`, but uses slightly different default grids and a modified P-junction screening algorithm.
1616
Overlap fitting is used to reduce aliasing errors :cite:`Izsak2011`.
17-
SGX scales as :math:`O(N^2)` with system size, as opposed to the :math:`O(N^4)` scaling of analytical exchange :cite:`Neese2009`.
17+
Before screening of negligible integrals, SGX scales as :math:`O(N^3)` with system size, as opposed to the :math:`O(N^4)` scaling of analytical exchange :cite:`Neese2009`. This makes its performance favorable for large basis sets and large systems.
18+
In principle, both SGX and analytical exchange scale asymptotically as :math:`O(N^2)` if negligible integrals are screened out, and as :math:`O(N)` if the system has a gap and negligible density matrix components are screened.
19+
However, the linear scaling is difficult to achieve in practice and only seen for some very large systems.
1820

1921
Usage and Example
2022
=================
2123

22-
Any :attr:`scf.hf.SCF` object :attr:`mf` can be converted to an equivalent object that computes the Coulomb and exchange matrices with SGX instead of analytical integration by calling :code:`sgx.sgx_fit(mf)`.
24+
Any :mod:`scf.hf.SCF` object :code:`mf` can be converted to an equivalent object that computes the Coulomb and exchange matrices with SGX instead of analytical integration by calling :code:`sgx.sgx_fit(mf)`.
2325

2426
* :source:`examples/sgx/00-simple_sgx.py`
2527

2628
.. literalinclude:: ../../examples/sgx/00-simple_sgx.py
2729

28-
In this case, the error of DFJ+SGX compared to analytical exchange is about 0.03 mEh. The line
30+
In this case, the error of DF-J+SGX-K compared to analytical exchange is about 0.03 mEh. The line
2931

3032
.. code::
3133
3234
mf.with_df.dfj = True
3335
3436
specifies to compute the Coulomb matrix using density fitting (DF-J) while using SGX for the exchange matrix.
3537

36-
The :attr:`pjs` option turns on P-junction screening, which means that the three-center integrals are screened by the density matrix.
37-
If a three-center integral gets contracted only with negligibly small density matrix elements, it is not computed.
38-
This feature can only be used with :attr:`dfj=True`.
39-
If :attr:`dfj=False` and :attr:`pjs=True`, :attr:`dfj` is set to :attr:`True`, and a warning is issued.
40-
The P-junction screening threshold is determined by :attr:`mf.direct_scf_tol`.
38+
Passing :code:`pjs=True` to :code:`sgx_fit` sets :code:`dfj=True` and also turns on P-junction screening (:code:`optk=True`), which means that the three-center integrals are screened by the density matrix.
39+
If a three-center integral gets contracted only with negligibly small density matrix elements, it is not computed. Because the J-matrix cannot be screened in this manner, :code:`optk=True` only activates P-junction screening when used with :code:`dfj=True`.
40+
If :code:`dfj=False`, :code:`optk` is ignored.
4141

42-
Direct evaluation of the J matrix can be used by setting :attr:`mf.with_df.direct_j = True`, but this is much slower than SGX-J or DF-J and only intended for testing purposes.
42+
When :code:`optk=True`, the P-junction screening threshold is determined by two parameters: :code:`mf.with_df.sgx_tol_energy` and :code:`mf.with_df.sgx_tol_potential`.
43+
These parameters correspond to approximate upper bounds on the error of the exchange energy and K-matrix due to P-junction screening, respectively.
44+
By default, :code:`sgx_tol_energy=sgx_tol_potential="auto"`, in which case :code:`sgx_tol_energy` is set to :code:`mf.direct_scf_tol` and :code:`sgx_tol_potential=sgx_tol_energy**0.5`.
45+
For more aggressive screening that is still numerically stable and sufficiently precise for most cases, we recommend :code:`sgx_tol_energy=mf.conv_tol` or :code:`0.1*mf.conv_tol` and :code:`sgx_tol_potential="auto"`.
46+
The first thing to try if you have numerical issues is setting :code:`mf.rebuild_nsteps=1`.
47+
This turns off incremental building of the K-matrix, which is faster but can accumulate errors between SCF steps.
48+
49+
Direct evaluation of the J matrix can be used by setting :code:`mf.with_df.direct_j = True`, but this is much slower than SGX-J or DF-J and only intended for testing purposes.
4350

4451
Adjustable Parameters
4552
=====================
4653

47-
Calling the :attr:`sgx_fit` function on an :attr:`scf.hf.SCF` object returns an equivalent :attr:`SGXHF` object with a :attr:`with_df` attribute that handles SGX integration. To use a non-default auxiliary basis (for :attr:`dfj=True`), :attr:`auxbasis` can be specified in the call to :attr:`sgx_fit`. In addition, there are various adjustable parameters for SGX:
54+
Calling the :code:`sgx_fit` function on an :mod:`scf.hf.SCF` object returns an equivalent :code:`SGXHF` object with a :code:`with_df` attribute that handles SGX integration. To use a non-default auxiliary basis (for :code:`dfj=True`), :code:`auxbasis` can be specified in the call to :code:`sgx_fit`. The other input option to :code:`sgx_fit` is :code:`pjs`. If :code:`pjs=False` (default), :code:`dfj=optk=False`, otherwise :code:`dfj=optk=True`. In addition, there are various adjustable parameters for SGX that can be set after initialization.
55+
56+
:code:`with_df` attributes:
4857

49-
:attr:`with_df` attributes:
58+
* :code:`grids_level_i`: The grid level to use for initial SCF iterations.
59+
* :code:`grids_level_f`: The grid level to use for final SCF iterations.
60+
* :code:`dfj`: If :code:`True`, density fitting is used for the J-matrix. If :code:`False`, SGX is used.
61+
* :code:`optk`: If :code:`True`, P-junction screening is used. Threshold determined by :code:`sgx_tol_energy` and :code:`sgx_tol_potential`. Only applies if :code:`dfj=True`.
62+
* :code:`sgx_tol_energy` and :code:`sgx_tol_potential`: Sets the approximate upper bound on the energy and K-matrix errors due to density matrix screening. Ignored if :code:`optk=False` or :code:`dfj=False`. See the Usage and Example section above for instructions on how to set these, as well as the docstrings for more details.
63+
* :code:`use_opt_grids`: Whether to use optimized grids for SGX based on COSX in ORCA :cite:`Helmich2021`. Default is True.
64+
* :code:`fit_ovlp`: Whether to numerically fit the overlap matrix to improve numerical precision. Default is True.
65+
* :code:`grids_thrd`: When the values of all atomic orbitals, multiplied by the qudrature weight, are less than this threshold for a given grid point, it is removed from the SGX numerical grid.
66+
* :code:`grids_switch_thrd`: The threshold for the magnitude of the change in the density matrix that triggers the switch from the initial grid specified by :code:`grids_level_i` to the final grid specified by :code:`grids_level_f`.
67+
* :code:`bound_aglo`: Determines how to estimate the maximum value of the three-center SGX integrals. Options are :code:`"ovlp"`, :code:`"sample"`, and :code:`"sample_pos"` (default). :code:`"ovlp"` assumes the maximum value of each integral is roughly equal to the maximum overlap between orbitals in a shell (with a value of 1 for shells on the same atom to account for orthogonality). :code:`"sample"` constructs a coarse grid for each atom pair and computes the maximum value of the integrals over these grids. :code:`"sample_pos"` does the same but also contructs an approximate estimate for the integral inside each grid block (position-dependent estimate), which can produce a small speedup for global exchange and a larger speedup for short-range exchange. Usually the default value :code:`"sample_pos"` should be fine.
68+
* :code:`direct_j`: If :code:`True`, direct evaluation of the J-matrix is used (slow, for testing only).
5069

51-
* :attr:`grids_level_i`: The grid level to use for initial SCF iterations.
52-
* :attr:`grids_level_f`: The grid level to use for final SCF iterations.
53-
* :attr:`grids_thrd`: The grid points where no atomic orbital is significant (has a value greater than this threshold) are removed from consideration.
54-
* :attr:`grids_switch_thrd`: The threshold for the magnitude of the change in the density matrix that triggers the switch from the initial grid specified by :attr:`grids_level_i` to the final grid specified by :attr:`grids_level_f`.
55-
* :attr:`blockdim`: The maximum number of grid points to loop over at once. The number of grid points per batch is the minimum of :attr:`blockdim` and the maximum number of points allowed by the memory available for the calculation. The maximum memory can be adjusted by setting the :attr:`max_memory` attribute, which is initially set to :attr:`mol.max_memory`, the max memory setting for the Mole object.
56-
* :attr:`dfj`: If :attr:`True`, density fitting is used for the J-matrix. If :attr:`False`, SGX is used.
57-
* :attr:`direct_j`: If :attr:`True`, direct evaluation of the J-matrix is used (slow, for testing only).
58-
* :attr:`pjs`: If :attr:`True`, P-junction screening is used. Threshold determined by :attr:`direct_scf_tol`.
5970

60-
:attr:`SGXHF` attribute:
71+
:code:`SGXHF` attributes:
6172

62-
* :attr:`direct_scf_sgx`: Whether to use direct SCF within the SGX module, meaning that the J and K matrices are evaluated from the difference in the density matrix from the previous iteration.
63-
* :attr:`rebuild_nsteps`: Rebuild the SGX JK matrix from scratch every :attr:`rebuild_nsteps` steps (default 5). Set to 0 to turn off rebuilding the JK matrix (Warning: This can cause creeping numerical error).
73+
* :code:`auxbasis`: The auxiliary basis for J-matrix density fitting. Used if :code:`dfj=True`.
74+
* :code:`rebuild_nsteps`: By default, when :code:`mf.direct_scf=True`, the K-matrix is constructed incrementally from the change in the density matrix between SCF steps (as is the case for other exchange algorithms in PySCF). The SGX J and K matrices are then rebuilt from scratch every :code:`rebuild_nsteps` steps (default 5). Set to 1 to rebuild from scratch at every step, and set to greater than the max number of cycles to turn off rebuilding the JK matrix (Warning: This can cause creeping numerical error). The SGX matrix is built from scratch when the numerical grid changes, regardless of the value of :code:`rebuild_nsteps`, because the same density matrix will have different energies for different grid sizes.

0 commit comments

Comments
 (0)