Skip to content

Commit

Permalink
rename apply_on_site_num_num_interaction to apply_on_site_interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Apr 3, 2024
1 parent 5f674d9 commit a3f6f78
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies = [
"pyscf>=2.3.0",
"qiskit >= 1.0.0",
"scipy",
"typing-extensions",
]

[project.urls]
Expand Down
2 changes: 2 additions & 0 deletions python/ffsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
apply_num_num_interaction,
apply_num_op_prod_interaction,
apply_num_op_sum_evolution,
apply_on_site_interaction,
apply_on_site_num_num_interaction,
apply_orbital_rotation,
apply_tunneling_interaction,
Expand Down Expand Up @@ -103,6 +104,7 @@
"apply_num_num_interaction",
"apply_num_op_prod_interaction",
"apply_num_op_sum_evolution",
"apply_on_site_interaction",
"apply_on_site_num_num_interaction",
"apply_orbital_rotation",
"apply_tunneling_interaction",
Expand Down
2 changes: 2 additions & 0 deletions python/ffsim/gates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
apply_num_interaction,
apply_num_num_interaction,
apply_num_op_prod_interaction,
apply_on_site_interaction,
apply_on_site_num_num_interaction,
apply_tunneling_interaction,
)
Expand All @@ -33,6 +34,7 @@
"apply_num_num_interaction",
"apply_num_op_prod_interaction",
"apply_num_op_sum_evolution",
"apply_on_site_interaction",
"apply_on_site_num_num_interaction",
"apply_orbital_rotation",
"apply_tunneling_interaction",
Expand Down
24 changes: 22 additions & 2 deletions python/ffsim/gates/basic_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from collections.abc import Sequence

import numpy as np
from typing_extensions import deprecated

from ffsim.gates.orbital_rotation import _one_subspace_indices, apply_orbital_rotation
from ffsim.spin import Spin
Expand Down Expand Up @@ -311,6 +312,7 @@ def apply_num_num_interaction(
return vec


@deprecated("Use apply_on_site_interaction instead.")
def apply_on_site_num_num_interaction(
vec: np.ndarray,
theta: float,
Expand All @@ -320,9 +322,27 @@ def apply_on_site_num_num_interaction(
*,
copy: bool = True,
):
r"""Apply an on-site number-number interaction gate.
r"""Apply an on-site interaction gate.
The on-site number-number interaction gate is
This function is deprecated. Use :func:`ffsim.apply_on_site_interaction` instead.
"""
return apply_on_site_interaction(
vec=vec, theta=theta, target_orb=target_orb, norb=norb, nelec=nelec, copy=copy
)


def apply_on_site_interaction(
vec: np.ndarray,
theta: float,
target_orb: int,
norb: int,
nelec: tuple[int, int],
*,
copy: bool = True,
):
r"""Apply an on-site interaction gate.
The on-site interaction gate is
.. math::
Expand Down
15 changes: 11 additions & 4 deletions tests/python/gates/basic_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,14 @@ def test_apply_num_num_interaction_eigenvalues(norb: int, nelec: tuple[int, int]


@pytest.mark.parametrize("norb, nelec", ffsim.testing.generate_norb_nelec(range(4)))
def test_apply_on_site_num_num_interaction(norb: int, nelec: tuple[int, int]):
def test_apply_on_site_interaction(norb: int, nelec: tuple[int, int]):
"""Test applying on-site number-number interaction."""
dim = ffsim.dim(norb, nelec)
rng = np.random.default_rng()
vec = np.array(ffsim.random.random_statevector(dim, seed=rng))
theta = rng.uniform(-10, 10)
for i in range(norb):
result = ffsim.apply_on_site_num_num_interaction(
vec, theta, i, norb=norb, nelec=nelec
)
result = ffsim.apply_on_site_interaction(vec, theta, i, norb=norb, nelec=nelec)
generator = ffsim.FermionOperator(
{
(
Expand Down Expand Up @@ -351,3 +349,12 @@ def mat(theta: float) -> np.ndarray:
norb=norb,
spin=spin,
)


def test_deprecations():
"""Test deprecation warnings are raised properly."""
norb = 2
nelec = (1, 1)
vec = ffsim.hartree_fock_state(norb, nelec)
with pytest.warns(DeprecationWarning):
_ = ffsim.apply_on_site_num_num_interaction(vec, 0.1, 0, norb=norb, nelec=nelec)

0 comments on commit a3f6f78

Please sign in to comment.