Skip to content

Commit

Permalink
remove deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Nov 2, 2024
1 parent 3c10618 commit 43cfce3
Show file tree
Hide file tree
Showing 15 changed files with 2 additions and 1,014 deletions.
10 changes: 0 additions & 10 deletions python/ffsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,14 @@
expectation_one_body_power,
expectation_one_body_product,
hartree_fock_state,
indices_to_strings,
one_hot,
rdm,
rdms,
sample_slater_determinant,
sample_state_vector,
slater_determinant,
slater_determinant_amplitudes,
slater_determinant_rdm,
slater_determinant_rdms,
spin_square,
strings_to_addresses,
strings_to_indices,
)
from ffsim.trotter import (
simulate_qdrift_double_factorized,
Expand Down Expand Up @@ -158,18 +153,15 @@
"fermi_hubbard_2d",
"fermion_operator",
"hartree_fock_state",
"indices_to_strings",
"init_cache",
"linalg",
"linear_operator",
"multireference_state",
"multireference_state_prod",
"number_operator",
"one_hot",
"optimize",
"qiskit",
"random",
"rdm",
"rdms",
"sample_slater_determinant",
"sample_state_vector",
Expand All @@ -178,11 +170,9 @@
"simulate_trotter_double_factorized",
"slater_determinant",
"slater_determinant_amplitudes",
"slater_determinant_rdm",
"slater_determinant_rdms",
"spin_square",
"strings_to_addresses",
"strings_to_indices",
"testing",
"trace",
]
27 changes: 0 additions & 27 deletions python/ffsim/hamiltonians/molecular_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@

import dataclasses
import itertools
import os

import numpy as np
import pyscf.ao2mo
import pyscf.tools
from opt_einsum import contract
from pyscf.fci.direct_nosym import absorb_h1e, contract_2e, make_hdiag
from scipy.sparse.linalg import LinearOperator
from typing_extensions import deprecated

from ffsim.cistring import gen_linkstr_index
from ffsim.operators import FermionOperator, cre_a, cre_b, des_a, des_b
Expand Down Expand Up @@ -53,29 +49,6 @@ class MolecularHamiltonian:
two_body_tensor: np.ndarray
constant: float = 0.0

@staticmethod
@deprecated(
"The MolecularHamiltonian.from_fcidump method is deprecated. "
"Instead, use MolecularData.from_fcidump and then access the `hamiltonian` "
"attribute of the returned MolecularData."
)
def from_fcidump(file: str | bytes | os.PathLike) -> MolecularHamiltonian:
"""Initialize a MolecularHamiltonian from an FCIDUMP file.
.. warning::
This function is deprecated. Instead, use MolecularData.from_fcidump and
then access the `hamiltonian` attribute of the returned MolecularData.
Args:
file: The FCIDUMP file path.
"""
data = pyscf.tools.fcidump.read(file, verbose=False)
return MolecularHamiltonian(
one_body_tensor=data["H1"],
two_body_tensor=pyscf.ao2mo.restore(1, data["H2"], data["NORB"]),
constant=data["ECORE"],
)

@property
def norb(self) -> int:
"""The number of spatial orbitals."""
Expand Down
26 changes: 0 additions & 26 deletions python/ffsim/molecular_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import pyscf.mp
import pyscf.symm
import pyscf.tools
from typing_extensions import deprecated

from ffsim.hamiltonians import MolecularHamiltonian

Expand Down Expand Up @@ -194,31 +193,6 @@ def from_scf(
hf_energy=hf_energy,
)

@staticmethod
@deprecated(
"The from_mole method is deprecated. Instead, pass an SCF object directly to "
"from_scf."
)
def from_mole(
molecule: pyscf.gto.Mole,
active_space: Iterable[int] | None = None,
scf_func=pyscf.scf.RHF,
) -> "MolecularData":
"""Initialize a MolecularData object from a PySCF molecule.
.. warning::
This method is deprecated. Instead, pass an SCF object directly to
:func:`from_scf`.
Args:
molecule: The molecule.
active_space: An optional list of orbitals to use for the active space.
scf_func: The PySCF SCF function to use for the Hartree-Fock calculation.
"""
hartree_fock = scf_func(molecule)
hartree_fock.run()
return MolecularData.from_scf(hartree_fock, active_space=active_space)

def run_cisd(self, *, store_cisd_vec: bool = False) -> None:
"""Run CISD and store results."""
cisd = pyscf.ci.CISD(self.scf.run())
Expand Down
2 changes: 0 additions & 2 deletions python/ffsim/random/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
random_real_symmetric_matrix,
random_special_orthogonal,
random_state_vector,
random_statevector,
random_t2_amplitudes,
random_two_body_tensor,
random_uccsd_restricted,
Expand All @@ -43,7 +42,6 @@
"random_orthogonal",
"random_real_symmetric_matrix",
"random_special_orthogonal",
"random_statevector",
"random_state_vector",
"random_t2_amplitudes",
"random_two_body_tensor",
Expand Down
29 changes: 0 additions & 29 deletions python/ffsim/random/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,11 @@
from collections import defaultdict

import numpy as np
from typing_extensions import deprecated

from ffsim import hamiltonians, operators, variational
from ffsim.variational.util import validate_interaction_pairs


@deprecated(
"ffsim.random.random_statevector is deprecated. "
"Instead, use ffsim.random.random_state_vector."
)
def random_statevector(dim: int, *, seed=None, dtype=complex) -> np.ndarray:
"""Return a random state vector sampled from the uniform distribution.
.. warning::
This function is deprecated. Use :func:`ffsim.random.random_state_vector`
instead.
Args:
dim: The dimension of the state vector.
seed: A seed to initialize the pseudorandom number generator.
Should be a valid input to ``np.random.default_rng``.
dtype: The data type to use for the result.
Returns:
The sampled state vector.
"""
rng = np.random.default_rng(seed)
vec = rng.standard_normal(dim).astype(dtype, copy=False)
if np.issubdtype(dtype, np.complexfloating):
vec += 1j * rng.standard_normal(dim).astype(dtype, copy=False)
vec /= np.linalg.norm(vec)
return vec


def random_state_vector(dim: int, *, seed=None, dtype=complex) -> np.ndarray:
"""Return a random state vector sampled from the uniform distribution.
Expand Down
11 changes: 1 addition & 10 deletions python/ffsim/states/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,21 @@
from ffsim.states.bitstring import (
BitstringType,
addresses_to_strings,
indices_to_strings,
strings_to_addresses,
strings_to_indices,
)
from ffsim.states.product_state_sum import ProductStateSum
from ffsim.states.rdm import rdm, rdms
from ffsim.states.rdm import rdms
from ffsim.states.sample_slater import sample_slater_determinant
from ffsim.states.slater import (
hartree_fock_state,
slater_determinant,
slater_determinant_amplitudes,
slater_determinant_rdm,
slater_determinant_rdms,
)
from ffsim.states.states import (
StateVector,
dim,
dims,
one_hot,
sample_state_vector,
spin_square,
)
Expand All @@ -47,17 +43,12 @@
"expectation_one_body_power",
"expectation_one_body_product",
"hartree_fock_state",
"indices_to_strings",
"one_hot",
"rdm",
"rdms",
"sample_slater_determinant",
"sample_state_vector",
"slater_determinant",
"slater_determinant_amplitudes",
"slater_determinant_rdm",
"slater_determinant_rdms",
"spin_square",
"strings_to_addresses",
"strings_to_indices",
]
138 changes: 0 additions & 138 deletions python/ffsim/states/bitstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import numpy as np
from pyscf.fci import cistring
from typing_extensions import deprecated


class BitstringType(Enum):
Expand All @@ -46,90 +45,6 @@ class BitstringType(Enum):
"""Bit array."""


@deprecated(
"ffsim.indices_to_strings is deprecated. "
"Instead, use ffsim.addresses_to_strings."
)
def indices_to_strings(
indices: Sequence[int] | np.ndarray,
norb: int,
nelec: int | tuple[int, int],
concatenate: bool = True,
bitstring_type: BitstringType = BitstringType.STRING,
):
"""Convert state vector indices to bitstrings.
.. warning::
This function is deprecated. Use :class:`ffsim.addresses_to_strings` instead.
Example:
.. code::
import ffsim
norb = 3
nelec = (2, 1)
dim = ffsim.dim(norb, nelec)
ffsim.indices_to_strings(range(dim), norb, nelec)
# output:
# ['001011',
# '010011',
# '100011',
# '001101',
# '010101',
# '100101',
# '001110',
# '010110',
# '100110']
Args:
indices: The state vector indices to convert to bitstrings.
norb: The number of spatial orbitals.
nelec: Either a single integer representing the number of fermions for a
spinless system, or a pair of integers storing the numbers of spin alpha
and spin beta fermions.
bitstring_type: The desired type of bitstring output.
concatenate: Whether to concatenate the spin-alpha and spin-beta parts of the
bitstrings. If True, then a single list of concatenated bitstrings is
returned. The strings are concatenated in the order :math:`s_b s_a`,
that is, the alpha string appears on the right.
If False, then two lists are returned, ``(strings_a, strings_b)``. Note that
the list of alpha strings appears first, that is, on the left.
In the spinless case (when `nelec` is an integer), this argument is ignored.
"""
if isinstance(nelec, int):
# Spinless case
return convert_bitstring_type(
list(cistring.addrs2str(norb=norb, nelec=nelec, addrs=indices)),
input_type=BitstringType.INT,
output_type=bitstring_type,
length=norb,
)

# Spinful case
n_alpha, n_beta = nelec
dim_b = math.comb(norb, n_beta)
indices_a, indices_b = np.divmod(indices, dim_b)
strings_a = convert_bitstring_type(
list(cistring.addrs2str(norb=norb, nelec=n_alpha, addrs=indices_a)),
input_type=BitstringType.INT,
output_type=bitstring_type,
length=norb,
)
strings_b = convert_bitstring_type(
list(cistring.addrs2str(norb=norb, nelec=n_beta, addrs=indices_b)),
input_type=BitstringType.INT,
output_type=bitstring_type,
length=norb,
)
if concatenate:
return concatenate_bitstrings(
strings_a, strings_b, bitstring_type=bitstring_type, length=norb
)
return strings_a, strings_b


def convert_bitstring_type(
strings: Sequence[str] | Sequence[int] | np.ndarray,
input_type: BitstringType,
Expand Down Expand Up @@ -244,59 +159,6 @@ def concatenate_bitstrings(
return np.concatenate([strings_b, strings_a], axis=1)


@deprecated(
"ffsim.strings_to_indices is deprecated. "
"Instead, use ffsim.strings_to_addresses."
)
def strings_to_indices(
strings: Sequence[str], norb: int, nelec: int | tuple[int, int]
) -> np.ndarray:
"""Convert bitstrings to state vector indices.
.. warning::
This function is deprecated. Use :class:`ffsim.strings_to_addresses` instead.
Example:
.. code::
import ffsim
norb = 3
nelec = (2, 1)
dim = ffsim.dim(norb, nelec)
ffsim.strings_to_indices(
[
"001011",
"010011",
"100011",
"001101",
"010101",
"100101",
"001110",
"010110",
"100110",
],
norb,
nelec,
)
# output:
# array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int32)
"""
if isinstance(nelec, int):
return cistring.strs2addr(
norb=norb, nelec=nelec, strings=[int(s, base=2) for s in strings]
)

n_alpha, n_beta = nelec
strings_a = [int(s[norb:], base=2) for s in strings]
strings_b = [int(s[:norb], base=2) for s in strings]
addrs_a = cistring.strs2addr(norb=norb, nelec=n_alpha, strings=strings_a)
addrs_b = cistring.strs2addr(norb=norb, nelec=n_beta, strings=strings_b)
dim_b = math.comb(norb, n_beta)
return addrs_a * dim_b + addrs_b


def addresses_to_strings(
addresses: Sequence[int] | np.ndarray,
norb: int,
Expand Down
Loading

0 comments on commit 43cfce3

Please sign in to comment.