Skip to content

Commit

Permalink
misc: Replace ValueError with InvalidArgument where necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioLuporini committed Dec 17, 2024
1 parent 1291757 commit 89c26a1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from devito.arch import ANYCPU, Device, compiler_registry, platform_registry
from devito.data import default_allocator
from devito.exceptions import CompilationError, ExecutionError
from devito.exceptions import CompilationError, ExecutionError, InvalidArgument
from devito.logger import debug, info, perf, warning, is_log_enabled_for, switch_log_level
from devito.ir.equations import LoweredEq, lower_exprs, concretize_subdims
from devito.ir.clusters import ClusterGroup, clusterize
Expand Down Expand Up @@ -553,7 +553,7 @@ def _prepare_arguments(self, autotune=None, **kwargs):
if not configuration['ignore-unknowns']:
for k, v in kwargs.items():
if k not in self._known_arguments:
raise ValueError("Unrecognized argument %s=%s" % (k, v))
raise InvalidArgument("Unrecognized argument %s=%s" % (k, v))

# Pre-process Dimension overrides. This may help ruling out ambiguities
# when processing the `defaults` arguments. A topological sorting is used
Expand Down Expand Up @@ -583,8 +583,10 @@ def _prepare_arguments(self, autotune=None, **kwargs):
try:
args.reduce_inplace()
except ValueError:
raise ValueError("Override `%s` is incompatible with overrides `%s`" %
(p, [i for i in overrides if i.name in args]))
raise InvalidArgument(
"Override `%s` is incompatible with overrides `%s`" %
(p, [i for i in overrides if i.name in args])
)

# Process data-carrier defaults
for p in defaults:
Expand All @@ -604,10 +606,11 @@ def _prepare_arguments(self, autotune=None, **kwargs):
# `fact` is supplied w/o overriding `usave`; that's legal
pass
elif is_integer(args[k]) and not contains_val(args[k], v):
raise ValueError("Default `%s` is incompatible with other args as "
"`%s=%s`, while `%s=%s` is expected. Perhaps you "
"forgot to override `%s`?" %
(p, k, v, k, args[k], p))
raise InvalidArgument(
"Default `%s` is incompatible with other args as `%s=%s`, "
"while `%s=%s` is expected. Perhaps you forgot to override "
"`%s`?" % (p, k, v, k, args[k], p)
)

args = kwargs['args'] = args.reduce_all()

Expand Down Expand Up @@ -726,7 +729,7 @@ def arguments(self, **kwargs):
# Check all arguments are present
for p in self.parameters:
if args.get(p.name) is None:
raise ValueError("No value found for parameter %s" % p.name)
raise InvalidArgument("No value found for parameter %s" % p.name)
return args

# Code generation and JIT compilation
Expand Down

0 comments on commit 89c26a1

Please sign in to comment.