From 8c9cafdb8f5f1dbfd395ade86d030e421a0df0f3 Mon Sep 17 00:00:00 2001 From: Caleb Johnson Date: Mon, 28 Oct 2024 13:15:04 -0500 Subject: [PATCH] Add SCIState class --- docs/apidocs/qiskit_addon_sqd.fermion.rst | 1 + qiskit_addon_sqd/fermion.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/apidocs/qiskit_addon_sqd.fermion.rst b/docs/apidocs/qiskit_addon_sqd.fermion.rst index 27c7c9e..977423d 100644 --- a/docs/apidocs/qiskit_addon_sqd.fermion.rst +++ b/docs/apidocs/qiskit_addon_sqd.fermion.rst @@ -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 diff --git a/qiskit_addon_sqd/fermion.py b/qiskit_addon_sqd/fermion.py index c90794d..afae405 100644 --- a/qiskit_addon_sqd/fermion.py +++ b/qiskit_addon_sqd/fermion.py @@ -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 " @@ -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.""" @@ -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