Skip to content

Commit

Permalink
add time argument to apply_diag_coulomb_evolution function
Browse files Browse the repository at this point in the history
  • Loading branch information
bartandrews committed Nov 22, 2024
1 parent df7bab5 commit 697bbc7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
6 changes: 4 additions & 2 deletions python/ffsim/tenpy/gates/diag_coulomb.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
def apply_diag_coulomb_evolution(
eng: TEBDEngine,
mat: np.ndarray,
time: float,
*,
norm_tol: float = 1e-5,
) -> None:
Expand All @@ -33,6 +34,7 @@ def apply_diag_coulomb_evolution(
Args:
eng: The TEBD engine.
mat: The diagonal Coulomb matrices of dimension `(2, norb, norb)`.
time: The evolution time.
norm_tol: The norm error above which we recanonicalize the MPS. In general, the
application of a two-site gate to an MPS with truncation may degrade its
canonical form. To mitigate this, we explicitly bring the MPS back into
Expand All @@ -54,11 +56,11 @@ def apply_diag_coulomb_evolution(
if mat_aa[i, j]:
apply_two_site(
eng,
num_num_interaction(-mat_aa[i, j]),
num_num_interaction(-time * mat_aa[i, j]),
(i, j),
norm_tol=norm_tol,
)

# apply alpha-beta gates
for i in range(norb):
apply_single_site(eng, on_site_interaction(-mat_ab[i, i]), i)
apply_single_site(eng, on_site_interaction(-time * mat_ab[i, i]), i)
2 changes: 1 addition & 1 deletion python/ffsim/tenpy/gates/ucj.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def apply_ucj_op_spin_balanced(
orb_rot.conjugate().T @ current_basis,
norm_tol=norm_tol,
)
apply_diag_coulomb_evolution(eng, diag_mats, norm_tol=norm_tol)
apply_diag_coulomb_evolution(eng, diag_mats, 1, norm_tol=norm_tol)
current_basis = orb_rot
if ucj_op.final_orbital_rotation is None:
apply_orbital_rotation(
Expand Down
12 changes: 4 additions & 8 deletions tests/python/tenpy/gates/basic_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def test_givens_rotation(norb: int, nelec: tuple[int, int], spin: Spin):
)

# apply random orbital rotation to MPS
options = {"trunc_params": {"chi_max": 16, "svd_min": 1e-6}}
eng = TEBDEngine(mps, None, options)
eng = TEBDEngine(mps, None, {})
ffsim.tenpy.apply_two_site(eng, givens_rotation(theta, spin, phi=phi), (p, p + 1))

# test expectation is preserved
Expand Down Expand Up @@ -130,8 +129,7 @@ def test_num_interaction(norb: int, nelec: tuple[int, int], spin: Spin):
vec = ffsim.apply_num_interaction(original_vec, theta, p, norb, nelec, spin)

# apply random number interaction to MPS
options = {"trunc_params": {"chi_max": 16, "svd_min": 1e-6}}
eng = TEBDEngine(mps, None, options)
eng = TEBDEngine(mps, None, {})
ffsim.tenpy.apply_single_site(eng, num_interaction(theta, spin), p)

# test expectation is preserved
Expand Down Expand Up @@ -180,8 +178,7 @@ def test_on_site_interaction(
vec = ffsim.apply_on_site_interaction(original_vec, theta, p, norb, nelec)

# apply random on-site interaction to MPS
options = {"trunc_params": {"chi_max": 16, "svd_min": 1e-6}}
eng = TEBDEngine(mps, None, options)
eng = TEBDEngine(mps, None, {})
ffsim.tenpy.apply_single_site(eng, on_site_interaction(theta), p)

# test expectation is preserved
Expand Down Expand Up @@ -237,8 +234,7 @@ def test_num_num_interaction(norb: int, nelec: tuple[int, int], spin: Spin):
)

# apply random number-number interaction to MPS
options = {"trunc_params": {"chi_max": 16, "svd_min": 1e-6}}
eng = TEBDEngine(mps, None, options)
eng = TEBDEngine(mps, None, {})
ffsim.tenpy.apply_two_site(eng, num_num_interaction(theta, spin), (p, p + 1))

# test expectation is preserved
Expand Down
13 changes: 5 additions & 8 deletions tests/python/tenpy/gates/diag_coulomb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
(4, (0, 0)),
],
)
def test_apply_diag_coulomb_evolution(
norb: int,
nelec: tuple[int, int],
):
def test_apply_diag_coulomb_evolution(norb: int, nelec: tuple[int, int]):
"""Test applying a diagonal Coulomb evolution gate to an MPS."""
rng = np.random.default_rng()

Expand All @@ -57,16 +54,16 @@ def test_apply_diag_coulomb_evolution(
mat_aa += mat_aa.T
mat_ab = np.diag(rng.standard_normal(norb))
diag_coulomb_mats = np.array([mat_aa, mat_ab, mat_aa])
time = rng.random()

# apply random diagonal Coulomb evolution to state vector
vec = ffsim.apply_diag_coulomb_evolution(
original_vec, diag_coulomb_mats, 1, norb, nelec
original_vec, diag_coulomb_mats, time, norb, nelec
)

# apply random diagonal Coulomb evolution to MPS
options = {"trunc_params": {"chi_max": 16, "svd_min": 1e-6}}
eng = TEBDEngine(mps, None, options)
ffsim.tenpy.apply_diag_coulomb_evolution(eng, diag_coulomb_mats[:2])
eng = TEBDEngine(mps, None, {})
ffsim.tenpy.apply_diag_coulomb_evolution(eng, diag_coulomb_mats[:2], time)

# test expectation is preserved
original_expectation = np.vdot(original_vec, vec)
Expand Down
3 changes: 1 addition & 2 deletions tests/python/tenpy/gates/orbital_rotation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def test_apply_orbital_rotation(
vec = ffsim.apply_orbital_rotation(original_vec, mat, norb, nelec)

# apply random orbital rotation to MPS
options = {"trunc_params": {"chi_max": 16, "svd_min": 1e-6}}
eng = TEBDEngine(mps, None, options)
eng = TEBDEngine(mps, None, {})
ffsim.tenpy.apply_orbital_rotation(eng, mat)

# test expectation is preserved
Expand Down

0 comments on commit 697bbc7

Please sign in to comment.