Skip to content

Commit

Permalink
refactor UsageError -> UserError
Browse files Browse the repository at this point in the history
  • Loading branch information
wolearyc committed Sep 20, 2024
1 parent 685d444 commit 369f5bb
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions ramannoodle/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SymmetryException(Exception):
"""Symmetry operation failed."""


class UsageError(Exception):
class UserError(Exception):
"""The user has done something they shouldn't.
This exception is used sparingly, as (ideally) the structure of the API should
Expand Down Expand Up @@ -135,7 +135,7 @@ def verify_positions(name: str, array: NDArray) -> None:
raise ValueError(f"{name} has coordinates that are not between 0 and 1")


def get_torch_missing_error() -> UsageError:
def get_torch_missing_error() -> UserError:
"""Get error indicating that torch is not installed."""
required_modules = "'torch', 'torch-scatter', and 'torch-sparse' modules"
return UsageError(f"torch functionality requires {required_modules}")
return UserError(f"torch functionality requires {required_modules}")
4 changes: 2 additions & 2 deletions ramannoodle/io/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
from ramannoodle.dynamics.phonon import Phonons
from ramannoodle.dynamics.trajectory import Trajectory
from ramannoodle.structure.reference import ReferenceStructure
from ramannoodle.exceptions import UsageError, get_torch_missing_error
from ramannoodle.exceptions import UserError, get_torch_missing_error
import ramannoodle.io.vasp as vasp_io

TORCH_PRESENT = True
try:
from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset
except UsageError:
except UserError:
TORCH_PRESENT = False

# These map between file formats and appropriate IO functions.
Expand Down
4 changes: 2 additions & 2 deletions ramannoodle/io/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
verify_list_len,
IncompatibleStructureException,
get_torch_missing_error,
UsageError,
UserError,
)
from ramannoodle.globals import ATOM_SYMBOLS

TORCH_PRESENT = True
try:
from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset
except UsageError:
except UserError:
TORCH_PRESENT = False


Expand Down
4 changes: 2 additions & 2 deletions ramannoodle/io/vasp/outcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
)
from ramannoodle.exceptions import InvalidFileException, NoMatchingLineFoundException
from ramannoodle.globals import ATOMIC_WEIGHTS, ATOMIC_NUMBERS
from ramannoodle.exceptions import get_type_error, UsageError
from ramannoodle.exceptions import get_type_error, UserError
from ramannoodle.dynamics.phonon import Phonons
from ramannoodle.dynamics.trajectory import Trajectory
from ramannoodle.structure.reference import ReferenceStructure

try:
from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset
except UsageError:
except UserError:
pass


Expand Down
4 changes: 2 additions & 2 deletions ramannoodle/io/vasp/vasprun.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from numpy.typing import NDArray

from ramannoodle.io.io_utils import pathify, _read_polarizability_dataset
from ramannoodle.exceptions import InvalidFileException, UsageError
from ramannoodle.exceptions import InvalidFileException, UserError
from ramannoodle.globals import ATOMIC_WEIGHTS, ATOMIC_NUMBERS
from ramannoodle.dynamics.phonon import Phonons
from ramannoodle.dynamics.trajectory import Trajectory
from ramannoodle.structure.reference import ReferenceStructure

try:
from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset
except UsageError:
except UserError:
pass


Expand Down
6 changes: 3 additions & 3 deletions ramannoodle/polarizability/art.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
get_shape_error,
verify_ndarray_shape,
InvalidDOFException,
UsageError,
UserError,
)


Expand Down Expand Up @@ -88,7 +88,7 @@ def add_dof( # pylint: disable=too-many-arguments
:meta private:
"""
raise UsageError("add_dof should not be used; use add_art instead")
raise UserError("add_dof should not be used; use add_art instead")

def add_dof_from_files(
self,
Expand All @@ -104,7 +104,7 @@ def add_dof_from_files(
:meta private:
"""
raise UsageError(
raise UserError(
"add_dof_from_files should not be used; use add_art_from_files instead"
)

Expand Down
4 changes: 2 additions & 2 deletions ramannoodle/polarizability/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
get_shape_error,
verify_ndarray_shape,
DOFWarning,
UsageError,
UserError,
)
import ramannoodle.io.generic as generic_io
from ramannoodle.io.io_utils import pathify_as_list
Expand Down Expand Up @@ -237,7 +237,7 @@ def calc_polarizabilities(
)
except ValueError as err:
if self._is_dummy_model:
raise UsageError(
raise UserError(
"dummy model cannot calculate polarizabilities"
) from err
raise err
Expand Down
4 changes: 2 additions & 2 deletions ramannoodle/polarizability/torch/gnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ramannoodle.structure.reference import ReferenceStructure
from ramannoodle.exceptions import (
get_torch_missing_error,
UsageError,
UserError,
verify_ndarray_shape,
)
from ramannoodle.polarizability.abstract import PolarizabilityModel
Expand All @@ -33,7 +33,7 @@
from torch_geometric.nn.models.schnet import ShiftedSoftplus
from torch_geometric.utils import scatter
import ramannoodle.polarizability.torch.utils as rn_torch_utils
except (ModuleNotFoundError, UsageError) as exc:
except (ModuleNotFoundError, UserError) as exc:
raise get_torch_missing_error() from exc

# pylint: disable=not-callable
Expand Down
4 changes: 2 additions & 2 deletions ramannoodle/polarizability/torch/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ramannoodle.exceptions import ( # pylint: disable=ungrouped-imports
get_torch_missing_error,
UsageError,
UserError,
)

try:
Expand All @@ -16,7 +16,7 @@

from ramannoodle.polarizability.torch.gnn import PotGNN
from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset
except (ModuleNotFoundError, UsageError) as exc:
except (ModuleNotFoundError, UserError) as exc:
raise get_torch_missing_error() from exc


Expand Down
8 changes: 4 additions & 4 deletions test/tests/test_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest

from ramannoodle.polarizability.art import ARTModel
from ramannoodle.exceptions import InvalidDOFException, UsageError
from ramannoodle.exceptions import InvalidDOFException, UserError
from ramannoodle.structure.reference import ReferenceStructure

# pylint: disable=protected-access
Expand Down Expand Up @@ -355,15 +355,15 @@ def test_dummy_art(
assert "atomic Raman tensors are masked" in repr(model)
assert len(model.cart_basis_vectors) == known_dof_added
assert np.isclose(np.linalg.norm(model.cart_basis_vectors[0]), 1)
with pytest.raises(UsageError) as err:
with pytest.raises(UserError) as err:
model.add_dof(np.array([]), np.array([]), np.array([]), 1, False)
assert "add_dof should not be used; use add_art instead" in str(err.value)
with pytest.raises(UsageError) as err:
with pytest.raises(UserError) as err:
model.add_dof_from_files(["blah"], "blah", 1)
assert (
"add_dof_from_files should not be used; use add_art_from_files instead"
in str(err.value)
)
with pytest.raises(UsageError) as err:
with pytest.raises(UserError) as err:
model.calc_polarizabilities(np.array([ref_structure.positions]))
assert "dummy model cannot calculate polarizabilities" in str(err.value)

0 comments on commit 369f5bb

Please sign in to comment.