From 688a5b58ccb9fe0e0078daae9a6670a4588f39fa Mon Sep 17 00:00:00 2001 From: "Kevin J. Sung" Date: Tue, 7 Nov 2023 08:26:30 -0500 Subject: [PATCH] docs --- .../double_factorized_hamiltonian.py | 22 +++++++++---------- .../linalg/double_factorized_decomposition.py | 2 +- .../double_factorized_decomposition_test.py | 6 ++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/python/ffsim/hamiltonians/double_factorized_hamiltonian.py b/python/ffsim/hamiltonians/double_factorized_hamiltonian.py index c8247a45c..847e6b7f4 100644 --- a/python/ffsim/hamiltonians/double_factorized_hamiltonian.py +++ b/python/ffsim/hamiltonians/double_factorized_hamiltonian.py @@ -24,7 +24,7 @@ @dataclasses.dataclass(frozen=True) class DoubleFactorizedHamiltonian: - r"""A Hamiltonian in the double-factorized form of the low rank decomposition. + r"""A Hamiltonian in the double-factorized representation. The double-factorized form of the molecular Hamiltonian is @@ -70,6 +70,10 @@ class DoubleFactorizedHamiltonian: where the asterisk denotes summation over indices :math:`\sigma\tau, ij` where :math:`\sigma \neq \tau` or :math:`i \neq j`. + References: + - `Low rank representations for quantum simulation of electronic structure`_ + - `Quantum Filter Diagonalization with Double-Factorized Hamiltonians`_ + Attributes: one_body_tensor (np.ndarray): The one-body tensor :math:`\kappa`. diag_coulomb_mats (np.ndarray): The diagonal Coulomb matrices. @@ -77,6 +81,10 @@ class DoubleFactorizedHamiltonian: constant (float): The constant. z_representation (bool): Whether the Hamiltonian is in the "Z" representation rather than the "number" representation. + + .. _Low rank representations for quantum simulation of electronic structure: https://arxiv.org/abs/1808.02625 + .. _Quantum Filter Diagonalization with Double-Factorized Hamiltonians: https://arxiv.org/abs/2104.08957 + .. _scipy.optimize.minimize: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html """ one_body_tensor: np.ndarray @@ -155,7 +163,7 @@ def from_molecular_hamiltonian( coefficients stored in the tensor to achieve a "compressed" factorization. This option is enabled by setting the `optimize` parameter to `True`. The optimization attempts to minimize a least-squares objective function - quantifying the error in the low rank decomposition. + quantifying the error in the decomposition. It uses `scipy.optimize.minimize`_, passing both the objective function and its gradient. The diagonal coulomb matrices returned by the optimization can be optionally constrained to have only certain elements allowed to be @@ -171,7 +179,7 @@ def from_molecular_hamiltonian( hamiltonian: The Hamiltonian whose double-factorized representation to compute. z_representation: Whether to use the "Z" representation of the - low rank decomposition. + decomposition. tol: Tolerance for error in the decomposition. The error is defined as the maximum absolute difference between an element of the original tensor and the corresponding element of @@ -197,14 +205,6 @@ def from_molecular_hamiltonian( Returns: The double-factorized Hamiltonian. - - References: - - `arXiv:1808.02625`_ - - `arXiv:2104.08957`_ - - .. _arXiv:1808.02625: https://arxiv.org/abs/1808.02625 - .. _arXiv:2104.08957: https://arxiv.org/abs/2104.08957 - .. _scipy.optimize.minimize: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html """ one_body_tensor = hamiltonian.one_body_tensor - 0.5 * np.einsum( "prqr", hamiltonian.two_body_tensor diff --git a/python/ffsim/linalg/double_factorized_decomposition.py b/python/ffsim/linalg/double_factorized_decomposition.py index 2c6ceafdf..9e0dadaed 100644 --- a/python/ffsim/linalg/double_factorized_decomposition.py +++ b/python/ffsim/linalg/double_factorized_decomposition.py @@ -117,7 +117,7 @@ def double_factorized( coefficients stored in the tensor to achieve a "compressed" factorization. This option is enabled by setting the `optimize` parameter to `True`. The optimization attempts to minimize a least-squares objective function - quantifying the error in the low rank decomposition. + quantifying the error in the decomposition. It uses `scipy.optimize.minimize`, passing both the objective function and its gradient. The core tensors returned by the optimization can be optionally constrained to have only certain elements allowed to be nonzero. This is achieved by diff --git a/tests/linalg/double_factorized_decomposition_test.py b/tests/linalg/double_factorized_decomposition_test.py index b85557611..ead34a65b 100644 --- a/tests/linalg/double_factorized_decomposition_test.py +++ b/tests/linalg/double_factorized_decomposition_test.py @@ -69,7 +69,7 @@ def test_modified_cholesky(dim: int): "dim, cholesky", [(4, True), (4, False), (5, True), (5, False)] ) def test_double_factorized_random(dim: int, cholesky: bool): - """Test low rank two-body decomposition on a random tensor.""" + """Test double-factorized decomposition on a random tensor.""" two_body_tensor = random_two_body_tensor_real(dim, seed=9825) diag_coulomb_mats, orbital_rotations = double_factorized( two_body_tensor, cholesky=cholesky @@ -87,7 +87,7 @@ def test_double_factorized_random(dim: int, cholesky: bool): @pytest.mark.parametrize("cholesky", [True, False]) def test_double_factorized_tol_max_vecs(cholesky: bool): - """Test low rank decomposition error threshold and max vecs.""" + """Test double-factorized decomposition error threshold and max vecs.""" mol = gto.Mole() mol.build( verbose=0, @@ -282,7 +282,7 @@ def test_double_factorized_t2_amplitudes_random(norb: int, nocc: int): def test_double_factorized_t2_tol_max_vecs(): - """Test low rank decomposition error threshold and max vecs.""" + """Test double-factorized decomposition error threshold and max vecs.""" mol = gto.Mole() mol.build( verbose=0,