Skip to content

Commit

Permalink
rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Sep 6, 2023
1 parent f2b3ae4 commit e595ca8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions python/ffsim/variational/lucj.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,20 @@ def to_parameters(

@staticmethod
def from_t_amplitudes(
t2: np.ndarray,
t2_amplitudes: np.ndarray,
*,
t1_amplitudes: np.ndarray | None = None,
n_reps: int | None = None,
t1: np.ndarray | None = None,
tol: float = 1e-8,
) -> "UCJOperator":
"""Initialize the UCJ operator from t2 (and optionally t1) amplitudes."""
# TODO maybe allow specifying alpha-alpha and alpha-beta indices
nocc, _, nvrt, _ = t2.shape
nocc, _, nvrt, _ = t2_amplitudes.shape
norb = nocc + nvrt

diag_coulomb_mats, orbital_rotations = double_factorized_t2(t2, tol=tol)
diag_coulomb_mats, orbital_rotations = double_factorized_t2(
t2_amplitudes, tol=tol
)
n_vecs, norb, _ = diag_coulomb_mats.shape
expanded_diag_coulomb_mats = np.zeros((2 * n_vecs, norb, norb))
expanded_orbital_rotations = np.zeros((2 * n_vecs, norb, norb), dtype=complex)
Expand All @@ -261,10 +263,10 @@ def from_t_amplitudes(
diag_coulomb_mats_alpha_beta = expanded_diag_coulomb_mats.copy()

final_orbital_rotation = None
if t1 is not None:
if t1_amplitudes is not None:
final_orbital_rotation_generator = np.zeros((norb, norb), dtype=complex)
final_orbital_rotation_generator[:nocc, nocc:] = t1
final_orbital_rotation_generator[nocc:, :nocc] = -t1.T
final_orbital_rotation_generator[:nocc, nocc:] = t1_amplitudes
final_orbital_rotation_generator[nocc:, :nocc] = -t1_amplitudes.T
final_orbital_rotation = scipy.linalg.expm(final_orbital_rotation_generator)

return UCJOperator(
Expand Down
2 changes: 1 addition & 1 deletion tests/variational/lucj_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_t_amplitudes_roundtrip():
t2 = ffsim.random.random_t2_amplitudes(norb, nocc)
t1 = rng.standard_normal((nocc, norb - nocc))

operator = ffsim.UCJOperator.from_t_amplitudes(t2, t1=t1)
operator = ffsim.UCJOperator.from_t_amplitudes(t2, t1_amplitudes=t1)
t2_roundtripped, t1_roundtripped = operator.to_t_amplitudes(nocc=nocc)

np.testing.assert_allclose(
Expand Down

0 comments on commit e595ca8

Please sign in to comment.