Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinfriede committed Jan 8, 2025
1 parent 57f9bd2 commit 7b7ef5b
Show file tree
Hide file tree
Showing 21 changed files with 193 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/dxtb/_src/basis/indexhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ def allowed_dtypes(self) -> tuple[torch.dtype, ...]:
"""
return (torch.int16, torch.int32, torch.int64, torch.long)

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
return (
f"IndexHelper(\n"
f" unique_angular={self.unique_angular},\n"
Expand All @@ -1187,7 +1187,7 @@ def __str__(self) -> str:
")"
)

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)


Expand Down
4 changes: 2 additions & 2 deletions src/dxtb/_src/calculators/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,10 @@ def serialize(value):

return json_string

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
info = self.info()["SCF Options"]
info_str = ", ".join(f"{key}={value}" for key, value in info.items())
return f"{self.__class__.__name__}({info_str})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)
8 changes: 4 additions & 4 deletions src/dxtb/_src/calculators/config/scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def info(self) -> dict[str, Any]:
}
}

def __str__(self):
def __str__(self): # pragma: no cover
config_str = [
f"Configuration for SCF:",
f" Guess Method: {self.guess}",
Expand All @@ -332,7 +332,7 @@ def __str__(self):
]
return "\n".join(config_str)

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)


Expand Down Expand Up @@ -462,10 +462,10 @@ def info(self) -> dict[str, dict[str, None | float | int | str]]:
}
}

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
info = self.info()["Fermi Smearing"]
info_str = ", ".join(f"{key}={value}" for key, value in info.items())
return f"{self.__class__.__name__}({info_str})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)
4 changes: 2 additions & 2 deletions src/dxtb/_src/calculators/properties/vibration/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def __getitem__(self, key: str) -> Tensor:
f"Invalid key: '{key}'. Possible keys are '{', '.join(s)}'."
)

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
text = ""
for s in get_all_slots(self):
attr = getattr(self, s)
Expand All @@ -200,5 +200,5 @@ def __str__(self) -> str:
text = text[:-2]
return f"{self.__class__.__name__}({text})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)
4 changes: 2 additions & 2 deletions src/dxtb/_src/calculators/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def __init__(
self.cenergies = {}
self.iter = 0

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
"""Custom print representation showing all available slots."""
return f"{self.__class__.__name__}({self.__slots__})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
"""Custom print representation showing all available slots."""
return str(self)

Expand Down
4 changes: 2 additions & 2 deletions src/dxtb/_src/calculators/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ def to(self, device: torch.device) -> Self:

return self

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
"""
Return a string representation of the instance.
"""
Expand All @@ -953,6 +953,6 @@ def __str__(self) -> str:
f")"
)

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
"""Return a representation of the instance."""
return str(self)
6 changes: 5 additions & 1 deletion src/dxtb/_src/cli/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ def singlepoint(self) -> Result | Tensor:

raise RuntimeError("No calculation was performed.")

def __repr__(self) -> str: # pragma: no cover
def __str__(self) -> str: # pragma: no cover
"""Custom print representation of class."""
return f"{self.__class__.__name__}({self.args})"

def __repr__(self) -> str: # pragma: no cover
"""Custom print representation of class."""
return str(self)
11 changes: 8 additions & 3 deletions src/dxtb/_src/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ def __init__(
):
super().__init__(device, dtype)

def __str__(self) -> str:
def __len__(self) -> int:
slots = get_all_slots(self)
return len([s for s in slots if not s.startswith("_")])

def __str__(self) -> str: # pragma: no cover
slots = get_all_slots(self)
s = ", ".join(s for s in slots if not s.startswith("_"))
return f"{self.__class__.__name__}({s})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)


Expand Down Expand Up @@ -140,7 +144,8 @@ def update(self, **kwargs: Any) -> None:
else:
raise AttributeError(
f"Cannot update '{key}' of the '{self.__class__.__name__}' "
"interaction. Invalid attribute."
"interaction. Invalid attribute.\nPossible attributes are: "
f"{', '.join(self.__slots__)}."
)

self.cache_invalidate()
Expand Down
10 changes: 8 additions & 2 deletions src/dxtb/_src/components/interactions/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def __iadd__(self, other: Container) -> Self:

return self

def __repr__(self):
def __str__(self): # pragma: no cover
return (
f"{self.__class__.__name__}("
f"label={self.label!r}, "
Expand All @@ -302,6 +302,9 @@ def __repr__(self):
f"batch_mode={self.batch_mode!r})"
)

def __repr__(self): # pragma: no cover
return str(self)


class Charges(Container):
"""
Expand All @@ -318,7 +321,7 @@ def mono(self) -> Tensor:
def mono(self, mono: Tensor) -> None:
self._mono = mono

def __repr__(self):
def __str__(self): # pragma: no cover
dp_shape = self.dipole.shape if self.dipole is not None else None
qp_shape = self.quad.shape if self.quad is not None else None
return (
Expand All @@ -329,6 +332,9 @@ def __repr__(self):
f"batch_mode={self.batch_mode!r})"
)

def __repr__(self): # pragma: no cover
return str(self)


class Potential(Container):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/dxtb/_src/components/interactions/dispersion/d4sc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@

from ..base import Interaction, InteractionCache

__all__ = ["DispersionD4SC", "LABEL_DispersionD4SC", "new_d4sc"]
__all__ = ["DispersionD4SC", "LABEL_DISPERSIOND4SC", "new_d4sc"]


LABEL_DispersionD4SC = "DispersionD4SC"
LABEL_DISPERSIOND4SC = "DispersionD4SC"
"""Label for the :class:`.DispersionD4SC` interaction, coinciding with the class name."""


Expand Down
4 changes: 2 additions & 2 deletions src/dxtb/_src/components/interactions/field/efield.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ def get_dipole_potential(
"""
return -cache.vdp

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
return f"{self.__class__.__name__}(field={self.field})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)


Expand Down
4 changes: 2 additions & 2 deletions src/dxtb/_src/components/interactions/field/efieldgrad.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def get_quadrupole_energy(
# equivalent: torch.sum(-cache.vqp * charges, dim=-1)
return 0.5 * einsum("...x,...ix->...i", cache.efg, charges)

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
return f"{self.__class__.__name__}(field_grad={self.field_grad})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)


Expand Down
6 changes: 3 additions & 3 deletions src/dxtb/_src/components/interactions/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from .container import Charges, Potential
from .coulomb.secondorder import ES2, LABEL_ES2
from .coulomb.thirdorder import ES3, LABEL_ES3
from .dispersion.d4sc import DispersionD4SC, LABEL_DispersionD4SC
from .dispersion.d4sc import LABEL_DISPERSIOND4SC, DispersionD4SC
from .field.efield import LABEL_EFIELD, ElectricField
from .field.efieldgrad import LABEL_EFIELD_GRAD, ElectricFieldGrad

Expand Down Expand Up @@ -302,7 +302,7 @@ def get_interaction(self, name: str) -> Interaction:
@_docstring_reset
def reset_d4sc(self) -> Interaction:
"""Reset tensor attributes to a detached clone of the current state."""
return self.reset(LABEL_DispersionD4SC)
return self.reset(LABEL_DISPERSIOND4SC)

@_docstring_reset
def reset_efield(self) -> Interaction:
Expand All @@ -328,7 +328,7 @@ def reset_es3(self) -> Interaction:

@_docstring_update
def update_d4sc(self, **kwargs: Any) -> Interaction:
return self.update(LABEL_DispersionD4SC, **kwargs)
return self.update(LABEL_DISPERSIOND4SC, **kwargs)

@_docstring_update
def update_efield(
Expand Down
10 changes: 8 additions & 2 deletions src/dxtb/_src/exlibs/xitorch/_core/linop.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def __init__(
stacklevel=2,
)

def __repr__(self) -> str:
def __str__(self) -> str: # pragma: no cover
return (
"LinearOperator ({}) with shape {}, dtype = {}, device = {}".format(
self.__class__.__name__,
Expand All @@ -184,6 +184,9 @@ def __repr__(self) -> str:
)
)

def __repr__(self) -> str: # pragma: no cover
return str(self)

@abstractmethod
def _getparamnames(self, prefix: str = "") -> list[str]:
"""
Expand Down Expand Up @@ -655,12 +658,15 @@ def __init__(self, obj: LinearOperator):
)
self.obj = obj

def __repr__(self):
def __str__(self): # pragma: no cover
return "AdjointLinearOperator with shape {} of:\n - {}".format(
_shape2str(self.shape),
_indent(self.obj.__repr__(), 3),
)

def __repr__(self): # pragma: no cover
return str(self)

def _mv(self, x: torch.Tensor) -> torch.Tensor:
if not self.obj.is_rmv_implemented:
raise RuntimeError(
Expand Down
4 changes: 2 additions & 2 deletions src/dxtb/_src/integral/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def gradient(self) -> Tensor:
def gradient(self, mat: Tensor) -> None:
self._gradient = mat

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
d = self.__dict__.copy()
if self._matrix is not None:
d["_matrix"] = self._matrix.shape
Expand All @@ -285,5 +285,5 @@ def __str__(self) -> str:

return f"{self.__class__.__name__}({d})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)
8 changes: 4 additions & 4 deletions src/dxtb/_src/integral/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def __len__(self) -> int:

# pretty print

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
attributes = ["hcore", "overlap", "dipole", "quadrupole"]
details = []

Expand All @@ -512,7 +512,7 @@ def __str__(self) -> str:

return f"Integrals({', '.join(details)}\n)"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)


Expand Down Expand Up @@ -690,7 +690,7 @@ def checks(self) -> None:
f"{defaults.QP_SHAPE}. Got {tensor.shape[-3]}."
)

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
attributes = ["hcore", "overlap", "dipole", "quadrupole"]
details = []

Expand All @@ -701,5 +701,5 @@ def __str__(self) -> str:

return f"Integrals({', '.join(details)}\n)"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)
4 changes: 2 additions & 2 deletions src/dxtb/_src/integral/driver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ def setup(self, positions: Tensor, **kwargs) -> None:
Cartesian coordinates of all atoms (shape: ``(..., nat, 3)``).
"""

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
return (
f"{self.__class__.__name__}("
f"Family: {self.family}, "
f"Number of Atoms: {self.numbers.shape[-1]}, "
f"Setup?: {self.is_setup()})"
)

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)
4 changes: 2 additions & 2 deletions src/dxtb/_src/loader/lazy/lazy_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __getattr__(self, item: Any) -> Any:

return getattr(self._loaded, item)

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
"""
Custom string representation of the `LazyLoaderParam` object.
Expand All @@ -115,7 +115,7 @@ def __str__(self) -> str:
"""
return f"LazyLoaderParam({str(self.filepath)})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
"""
Custom representation of the `LazyLoaderParam` object.
Expand Down
4 changes: 2 additions & 2 deletions src/dxtb/_src/scf/mixer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def __init__(
# explicitly set this information
self._batch_mode = batch_mode

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
"""Returns representative string."""
return f"{self.__class__.__name__}({self.iter_step}, {self.options})"

def __repr__(self) -> str:
def __repr__(self) -> str: # pragma: no cover
return str(self)

@abstractmethod
Expand Down
Loading

0 comments on commit 7b7ef5b

Please sign in to comment.