Skip to content

Commit

Permalink
Add SCIState class
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-johnson committed Oct 28, 2024
1 parent ca05d8b commit 8c9cafd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/apidocs/qiskit_addon_sqd.fermion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Fermion (:mod:`qiskit_addon_sqd.fermion`)

.. currentmodule:: qiskit_addon_sqd.fermion

.. autoclass:: SCIState
.. autofunction:: bitstring_matrix_to_ci_strs
.. autofunction:: enlarge_batch_from_transitions
.. autofunction:: flip_orbital_occupancies
Expand Down
14 changes: 8 additions & 6 deletions qiskit_addon_sqd/fermion.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@

class SCIState(fci.selected_ci.SCIVector):
"""An immutable, lightweight wrapper for the ``pyscf.fci.selected_ci.SCIVector`` class."""

def __init__(self, *args, **kwargs):
"""Instantiate an SCIState object."""
super().__init__(*args, **kwargs)

# Light check on `_strs` structure once during initialization
if not (isinstance(self._strs, Sequence) and len(self._strs) == 2) or not all(isinstance(strs, np.ndarray) for strs in self._strs):
raise ValueError(
"Cannot instantiate SCIState with input _strs field: {self._strs}."
)
if not (isinstance(self._strs, Sequence) and len(self._strs) == 2) or not all(
isinstance(strs, np.ndarray) for strs in self._strs
):
raise ValueError("Cannot instantiate SCIState with input _strs field: {self._strs}.")
if self.shape != (len(self._strs[0]), len(self._strs[1])):
raise ValueError(
"Cannot instantiate SCIState with array shape ({self.shape}) and CI "
Expand All @@ -52,6 +54,7 @@ def __init__(self, *args, **kwargs):
def ci_strs_a(self):
"""The alpha determinants."""
return self._strs[0]

@property
def ci_strs_b(self):
"""The beta determinants."""
Expand All @@ -69,8 +72,7 @@ def solve_fermion(
max_davidson: int = 100,
verbose: int | None = None,
) -> tuple[float, SCIState, list[np.ndarray], float]:
"""
Approximate the ground state given molecular integrals and a set of electronic configurations.
"""Approximate the ground state given molecular integrals and a set of electronic configurations.
Args:
bitstring_matrix: A set of configurations defining the subspace onto which the Hamiltonian
Expand Down

0 comments on commit 8c9cafd

Please sign in to comment.