Skip to content

Commit

Permalink
refactor: use only public API in PropertyTest
Browse files Browse the repository at this point in the history
  • Loading branch information
mrossinek committed Feb 10, 2022
1 parent fcf140a commit ed23adf
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ def __init__(
self._absolute_tolerance = absolute_tolerance
self._relative_tolerance = relative_tolerance

@property
def num_spin_orbitals(self) -> int:
"""Returns the number of spin orbitals."""
return self._num_spin_orbitals

@num_spin_orbitals.setter
def num_spin_orbitals(self, num_spin_orbitals: int) -> None:
"""Sets the number of spin orbitals."""
self._num_spin_orbitals = num_spin_orbitals

@property
def spin(self) -> Optional[float]:
"""Returns the expected spin."""
Expand All @@ -77,6 +87,26 @@ def spin(self, spin: Optional[float]) -> None:
"""Sets the expected spin."""
self._spin = spin

@property
def absolute_tolerance(self) -> float:
"""Returns the absolute tolerance."""
return self._absolute_tolerance

@absolute_tolerance.setter
def absolute_tolerance(self, absolute_tolerance: float) -> None:
"""Sets the absolute tolerance."""
self._absolute_tolerance = absolute_tolerance

@property
def relative_tolerance(self) -> float:
"""Returns the relative tolerance."""
return self._relative_tolerance

@relative_tolerance.setter
def relative_tolerance(self, relative_tolerance: float) -> None:
"""Sets the relative tolerance."""
self._relative_tolerance = relative_tolerance

def __str__(self) -> str:
string = [super().__str__() + ":"]
string += [f"\t{self._num_spin_orbitals} SOs"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ def __init__(
name = self.__class__.__name__ + axis.upper()
super().__init__(name, electronic_integrals, shift=shift)

@property
def axis(self) -> str:
"""Returns the axis."""
return self._axis

@axis.setter
def axis(self, axis: str) -> None:
"""Sets the axis."""
self._axis = axis

def to_hdf5(self, parent: h5py.Group) -> None:
"""Stores this instance in an HDF5 group inside of the provided parent group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import itertools
from abc import ABC, abstractmethod
from copy import deepcopy
from typing import List, Optional, Tuple, Union
from typing import Generator, List, Optional, Tuple, Union

import h5py
import numpy as np
Expand Down Expand Up @@ -99,6 +99,36 @@ def __init__(
if basis != ElectronicBasis.SO:
self._fill_matrices()

@property
def basis(self) -> ElectronicBasis:
"""Returns the basis."""
return self._basis

@basis.setter
def basis(self, basis: ElectronicBasis) -> None:
"""Sets the basis."""
self._basis = basis

@property
def num_body_terms(self) -> int:
"""Returns the num_body_terms."""
return self._num_body_terms

@num_body_terms.setter
def num_body_terms(self, num_body_terms: int) -> None:
"""Sets the num_body_terms."""
self._num_body_terms = num_body_terms

@property
def threshold(self) -> float:
"""Returns the threshold."""
return self._threshold

@threshold.setter
def threshold(self, threshold: float) -> None:
"""Sets the threshold."""
self._threshold = threshold

def to_hdf5(self, parent: h5py.Group) -> None:
"""Stores this instance in an HDF5 group inside of the provided parent group.
Expand Down Expand Up @@ -180,6 +210,14 @@ def _render_matrix_as_sparse_list(matrix) -> List[str]:
count += 1
return string

def __iter__(self) -> Generator[np.ndarray, None, None]:
"""An iterator over the internal matrices."""
if isinstance(self._matrices, np.ndarray):
yield self._matrices
else:
for mat in self._matrices:
yield mat

@staticmethod
def set_truncation(max_num_entries: int) -> None:
"""Set the maximum number of integral values to display before truncation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def __init__(self, num_spin_orbitals: int) -> None:
super().__init__(self.__class__.__name__)
self._num_spin_orbitals = num_spin_orbitals

@property
def num_spin_orbitals(self) -> int:
"""Returns the number of spin orbitals."""
return self._num_spin_orbitals

@num_spin_orbitals.setter
def num_spin_orbitals(self, num_spin_orbitals: int) -> None:
"""Sets the number of spin orbitals."""
self._num_spin_orbitals = num_spin_orbitals

def __str__(self) -> str:
string = [super().__str__() + ":"]
string += [f"\t{self._num_spin_orbitals} SOs"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def __init__(
else:
self._num_alpha, self._num_beta = num_particles

self._occupation_alpha: Union[np.ndarray, list[float]]
self._occupation_beta: Union[np.ndarray, list[float]]
if occupation is None:
self._occupation_alpha = [1.0 for _ in range(self._num_alpha)]
self._occupation_alpha += [0.0] * (num_spin_orbitals // 2 - len(self._occupation_alpha))
Expand All @@ -84,8 +86,8 @@ def __init__(
self._occupation_alpha = [np.ceil(o / 2) for o in occupation]
self._occupation_beta = [np.floor(o / 2) for o in occupation]
else:
self._occupation_alpha = occupation # type: ignore
self._occupation_beta = occupation_beta # type: ignore
self._occupation_alpha = occupation
self._occupation_beta = occupation_beta

self._absolute_tolerance = absolute_tolerance
self._relative_tolerance = relative_tolerance
Expand All @@ -95,16 +97,31 @@ def num_spin_orbitals(self) -> int:
"""Returns the num_spin_orbitals."""
return self._num_spin_orbitals

@num_spin_orbitals.setter
def num_spin_orbitals(self, num_spin_orbitals: int) -> None:
"""Sets the number of spin orbitals."""
self._num_spin_orbitals = num_spin_orbitals

@property
def num_alpha(self) -> int:
"""Returns the number of alpha electrons."""
return self._num_alpha

@num_alpha.setter
def num_alpha(self, num_alpha: int) -> None:
"""Sets the number of alpha electrons."""
self._num_alpha = num_alpha

@property
def num_beta(self) -> int:
"""Returns the number of beta electrons."""
return self._num_beta

@num_beta.setter
def num_beta(self, num_beta: int) -> None:
"""Sets the number of beta electrons."""
self._num_beta = num_beta

@property
def num_particles(self) -> Tuple[int, int]:
"""Returns the number of electrons."""
Expand All @@ -119,6 +136,11 @@ def occupation_alpha(self) -> np.ndarray:
"""
return np.asarray(self._occupation_alpha)

@occupation_alpha.setter
def occupation_alpha(self, occ_alpha: Union[np.ndarray, List[float]]) -> None:
"""Sets the occupation numbers of the alpha-spin orbitals."""
self._occupation_alpha = occ_alpha

@property
def occupation_beta(self) -> np.ndarray:
"""Returns the occupation numbers of the beta-spin orbitals.
Expand All @@ -128,6 +150,31 @@ def occupation_beta(self) -> np.ndarray:
"""
return np.asarray(self._occupation_beta)

@occupation_beta.setter
def occupation_beta(self, occ_beta: Union[np.ndarray, List[float]]) -> None:
"""Sets the occupation numbers of the beta-spin orbitals."""
self._occupation_beta = occ_beta

@property
def absolute_tolerance(self) -> float:
"""Returns the absolute tolerance."""
return self._absolute_tolerance

@absolute_tolerance.setter
def absolute_tolerance(self, absolute_tolerance: float) -> None:
"""Sets the absolute tolerance."""
self._absolute_tolerance = absolute_tolerance

@property
def relative_tolerance(self) -> float:
"""Returns the relative tolerance."""
return self._relative_tolerance

@relative_tolerance.setter
def relative_tolerance(self, relative_tolerance: float) -> None:
"""Sets the relative tolerance."""
self._relative_tolerance = relative_tolerance

def __str__(self) -> str:
string = [super().__str__() + ":"]
string += [f"\t{self._num_spin_orbitals} SOs"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def basis(self, basis: VibrationalBasis) -> None:
"""Sets the basis."""
self._basis = basis

@property
def num_body_terms(self) -> int:
"""Returns the num_body_terms."""
return self._num_body_terms

@num_body_terms.setter
def num_body_terms(self, num_body_terms: int) -> None:
"""Sets the num_body_terms."""
self._num_body_terms = num_body_terms

@property
def integrals(self) -> List[Tuple[float, Tuple[int, ...]]]:
"""Returns the integrals."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from __future__ import annotations

from typing import cast, Dict, List, Optional, Tuple
from typing import cast, Dict, Generator, List, Optional, Tuple

import h5py

Expand Down Expand Up @@ -141,6 +141,18 @@ def from_legacy_driver_result(cls, result: LegacyDriverResult) -> VibrationalEne
[VibrationalIntegrals(num_body, ints) for num_body, ints in sorted_integrals.items()]
)

def __iter__(self) -> Generator[VibrationalIntegrals, None, None]:
"""Returns the generator-iterator method."""
return self._generator()

def _generator(self) -> Generator[VibrationalIntegrals, None, None]:
"""A generator-iterator method [1] iterating over all internal ``VibrationalIntegrals``.
[1]: https://docs.python.org/3/reference/expressions.html#generator-iterator-methods
"""
for ints in self._vibrational_integrals.values():
yield ints

def add_vibrational_integral(self, integral: VibrationalIntegrals) -> None:
# pylint: disable=line-too-long
"""Adds a
Expand Down
Loading

0 comments on commit ed23adf

Please sign in to comment.