Skip to content

Commit b039eea

Browse files
authored
revert t2 indexing convention in documentation (#466)
1 parent 68a8e2c commit b039eea

File tree

2 files changed

+49
-23
lines changed

2 files changed

+49
-23
lines changed

docs/explanations/lucj.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@
113113
"$$\n",
114114
"t_{ijab} = i \\sum_{k=0}^{L - 1} \\sum_{pq}\n",
115115
" Z^{(k)}_{pq}\n",
116-
" U^{(k)}_{(\\eta + a)p} U^{(k)*}_{ip} U^{(k)}_{(\\eta + b)q} U^{(k)*}_{jq}\n",
116+
" U^{(k)}_{ap} U^{(k)*}_{ip} U^{(k)}_{bq} U^{(k)*}_{jq}.\n",
117117
"$$\n",
118-
"Here, each $Z^{(k)}$ is a real symmetric matrix representing a diagonal Coulomb operator, each $U^{(k)}$ is a unitary matrix representing an orbital rotation, and the shape of the t2 amplitudes tensor is $(\\eta, \\eta, N - \\eta, N - \\eta)$, where $N$ is the number of orbitals and $\\eta$ is the number of orbitals that are occupied. If the number of terms in the sum is truncated, or if some diagonal Coulomb interactions are dropped (by zeroing out the corresponding entries of the $Z^{(k)}$ matrices), then the equality no longer holds. However, given any two tensors $\\bar{U}^{(k)}_{ij}$ and $\\bar{Z}^{(k)}_{ij}$, we can plug them into the expression to obtain some $t_2$-amplitudes $\\bar{t}_{ijab}$. The compressed double factorization attempts to find tensors that minimize the least-squares objective function\n",
118+
"Here, each $Z^{(k)}$ is a real symmetric matrix representing a diagonal Coulomb operator, each $U^{(k)}$ is a unitary matrix representing an orbital rotation, $i$ and $j$ run over occupied orbitals, and $a$ and $b$ run over virtual orbitals. If the number of terms in the sum is truncated, or if some diagonal Coulomb interactions are dropped (by zeroing out the corresponding entries of the $Z^{(k)}$ matrices), then the equality no longer holds. However, given any two tensors $\\bar{U}^{(k)}_{ij}$ and $\\bar{Z}^{(k)}_{ij}$, we can plug them into the expression to obtain some $t_2$-amplitudes $\\bar{t}_{ijab}$. The compressed double factorization attempts to find tensors that minimize the least-squares objective function\n",
119119
"$$\n",
120120
"\\frac12 \\sum_{ijab} \\lvert \\bar{t}_{ijab} - t_{ijab} \\rvert ^2.\n",
121121
"$$\n",

python/ffsim/linalg/double_factorized_decomposition.py

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -505,21 +505,21 @@ def double_factorized_t2(
505505
tuple[np.ndarray, np.ndarray]
506506
| tuple[np.ndarray, np.ndarray, scipy.optimize.OptimizeResult]
507507
):
508-
r"""Double-factorized decomposition of t2 amplitudes.
508+
r"""Double-factorized decomposition of :math:`t_2` amplitudes.
509509
510-
The double-factorized decomposition of a t2 amplitudes tensor :math:`t_{ijab}` is
510+
The double-factorized decomposition of a :math:`t_2` amplitudes tensor
511+
:math:`t_{ijab}` is
511512
512513
.. math::
513514
514515
t_{ijab} = i \sum_{k=0}^{L - 1} \sum_{pq}
515516
Z^{(k)}_{pq}
516-
U^{(k)}_{(\eta + a)p} U^{(k)*}_{ip} U^{(k)}_{(\eta + b)q} U^{(k)*}_{jq}
517+
U^{(k)}_{ap} U^{(k)*}_{ip} U^{(k)}_{bq} U^{(k)*}_{jq},
517518
518-
Here each :math:`Z^{(k)}` is a real symmetric matrix, referred to as a
519-
"diagonal Coulomb matrix," each :math:`U^{(k)}` is a unitary matrix,
520-
referred to as an "orbital rotation," and the shape of the t2 amplitudes tensor is
521-
:math:`(\eta, \eta, N - \eta, N - \eta)`, where :math:`N` is the number of orbitals
522-
and :math:`\eta` is the number of orbitals that are occupied.
519+
where each :math:`Z^{(k)}` is a real symmetric matrix representing a diagonal
520+
Coulomb operator, each :math:`U^{(k)}` is a unitary matrix representing an orbital
521+
rotation, :math:`i` and :math:`j` run over occupied orbitals, and :math:`a` and
522+
:math:`b` run over virtual orbitals.
523523
524524
The number of terms :math:`L` in the decomposition depends on the allowed
525525
error threshold. A larger error threshold may yield a smaller number of terms.
@@ -529,7 +529,7 @@ def double_factorized_t2(
529529
error threshold.
530530
531531
The default behavior of this routine is to perform a straightforward
532-
"exact" factorization of the t2 amplitudes tensor based on a nested
532+
"exact" factorization of the :math:`t_2` amplitudes tensor based on a nested
533533
eigenvalue decomposition, and then truncate the terms based on the values of `tol`
534534
and `max_terms`.
535535
If `optimize` is set to ``True``, then the entries of the resulting tensors
@@ -552,16 +552,38 @@ def double_factorized_t2(
552552
automatically: `multi_stage_start` defaults to the total number of terms returned by
553553
the exact factorization, and `multi_stage_step` defaults to 1.
554554
555-
Note: Currently, only real-valued t2 amplitudes are supported.
555+
The original :math:`t_2` amplitudes tensor can be reconstructed, up to the error
556+
tolerance, using the following function:
557+
558+
.. code::
559+
560+
def reconstruct_t2(
561+
diag_coulomb_mats: np.ndarray, orbital_rotations: np.ndarray, nocc: int
562+
) -> np.ndarray:
563+
return (
564+
1j
565+
* np.einsum(
566+
"kpq,kap,kip,kbq,kjq->ijab",
567+
diag_coulomb_mats,
568+
orbital_rotations,
569+
orbital_rotations.conj(),
570+
orbital_rotations,
571+
orbital_rotations.conj(),
572+
)[:nocc, :nocc, nocc:, nocc:]
573+
)
574+
575+
Note: Currently, only real-valued :math:`t_2` amplitudes are supported.
556576
557577
Args:
558-
t2_amplitudes: The t2 amplitudes tensor.
578+
t2_amplitudes: The doubles amplitudes tensor of shape
579+
``(nocc, nocc, nvrt, nvrt)``, where ``nocc`` is the number of occupied
580+
orbitals and ``nvrt`` is the number of virtual orbitals.
559581
tol: Tolerance for error in the decomposition.
560582
The error is defined as the maximum absolute difference between
561583
an element of the original tensor and the corresponding element of
562584
the reconstructed tensor.
563585
max_terms: An optional limit on the number of terms to keep in the decomposition
564-
of the t2 amplitudes tensor. This argument overrides `tol`.
586+
of the :math:`t_2` amplitudes tensor. This argument overrides `tol`.
565587
optimize: Whether to optimize the tensors returned by the decomposition to
566588
to minimize the error in the factorization.
567589
method: The optimization method. See the documentation of
@@ -743,10 +765,10 @@ def fun(x: np.ndarray):
743765
def double_factorized_t2_alpha_beta(
744766
t2_amplitudes: np.ndarray, *, tol: float = 1e-8, max_terms: int | None = None
745767
) -> tuple[np.ndarray, np.ndarray]:
746-
r"""Double-factorized decomposition of alpha-beta t2 amplitudes.
768+
r"""Double-factorized decomposition of alpha-beta :math:`t_2` amplitudes.
747769
748-
Decompose alpha-beta t2 amplitudes into diagonal Coulomb matrices with orbital
749-
rotations. This function returns two arrays:
770+
Decompose alpha-beta :math:`t_2` amplitudes into diagonal Coulomb matrices with
771+
orbital rotations. This function returns two arrays:
750772
751773
- `diagonal_coulomb_mats`, with shape `(n_terms, 3, norb, norb)`.
752774
- `orbital_rotations`, with shape `(n_terms, 2, norb, norb)`.
@@ -755,8 +777,8 @@ def double_factorized_t2_alpha_beta(
755777
tolerance might yield a smaller value for `n_terms`. You can also set an optional
756778
upper bound on `n_terms` using the `max_terms` argument.
757779
758-
The original t2 amplitudes tensor can be reconstructed, up to the error tolerance,
759-
using the following function:
780+
The original :math:`t_2` amplitudes tensor can be reconstructed, up to the error
781+
tolerance, using the following function:
760782
761783
.. code::
762784
@@ -783,7 +805,7 @@ def reconstruct_t2_alpha_beta(
783805
)
784806
return (
785807
2j
786-
* contract(
808+
* np.einsum(
787809
"kpq,kap,kip,kbq,kjq->ijab",
788810
expanded_diag_coulomb_mats,
789811
expanded_orbital_rotations,
@@ -793,16 +815,20 @@ def reconstruct_t2_alpha_beta(
793815
)[:nocc_a, norb : norb + nocc_b, nocc_a:norb, norb + nocc_b :]
794816
)
795817
796-
Note: Currently, only real-valued t2 amplitudes are supported.
818+
Note: Currently, only real-valued :math:`t_2` amplitudes are supported.
797819
798820
Args:
799-
t2_amplitudes: The t2 amplitudes tensor.
821+
t2_amplitudes: The doubles amplitudes tensor of shape
822+
``(nocc_a, nocc_b, nvrt_a, nvrt_b)``, where ``nocc_a`` is the number of
823+
occupied spin-alpha orbitals, ``nvrt_a`` is the number of virtual spin-alpha
824+
orbitals, ``nocc_b`` is the number of occupied spin-beta orbitals, and
825+
``nvrt_b`` is the number of virtual spin-beta orbitals.
800826
tol: Tolerance for error in the decomposition.
801827
The error is defined as the maximum absolute difference between
802828
an element of the original tensor and the corresponding element of
803829
the reconstructed tensor.
804830
max_terms: An optional limit on the number of terms to keep in the decomposition
805-
of the t2 amplitudes tensor. This argument overrides `tol`.
831+
of the :math:`t_2` amplitudes tensor. This argument overrides `tol`.
806832
807833
808834
Returns:

0 commit comments

Comments
 (0)