Input Checks¶
To unify to a certain extent error messages there are two ways.
Check the input before actual computations¶
For checking input type and values for standard data types,
we collected in pyrigi/_utils/_input_check.py
a set of methods that are often needed,
see the list below.
For instance, pyrigi._utils._input_check.dimension()
checks whether
the parameter dim
is a positive integer and raises an error otherwise.
Checks related to the class Graph
are in graph._utils._input_check
.
For instance, graph._utils._input_check.no_loop()
checks whether
a graph is loop free and raises an error otherwise.
Example:
import pyrigi._utils._input_check as _input_check
import pyrigi.graph._utils._input_check as _graph_input_check
class Graph(nx.Graph):
...
def method(self, dim: int):
_input_check.dimension(dim)
_graph_input_check.no_loop(self)
...
Note that these input checks are in a private module. However, we do test them.
Check the input at the end by exclusion¶
In some cases a method would run a conditional statement
through all possible options of an input parameter.
If the method reaches the end
an error would be raised to tell the user that the option is not supported.
For instance a parameter algorithm
might have several supported values.
Example:
from pyrigi.exception import NotSupportedValueError
def method(self, algorithm: str = "default"):
if algorithm == "alg1":
...
elif algorithm == "alg2":
...
else:
raise NotSupportedValueError(algorithm, "algorithm", self.method)
Input check functions of Graph¶
The following functions can be used for input checks of Graph
.
- pyrigi.graph._utils._input_check.edge_format(graph, edge, loopfree=False)[source]¶
Check if an
edge
is a pair of (distinct) vertices of the graph and raise an error otherwise.
- pyrigi.graph._utils._input_check.edge_format_list(graph, edges)[source]¶
Apply
edge_format()
to all edges in a list.
- pyrigi.graph._utils._input_check.is_edge(graph, edge, vertices=None)[source]¶
Check if the given input is an edge of the graph with endvertices in vertices and raise an error otherwise.
- pyrigi.graph._utils._input_check.is_edge_list(graph, edges, vertices=None)[source]¶
Apply
is_edge()
to all edges in a list.
- pyrigi.graph._utils._input_check.is_edge_order(graph, edge_order, name='')[source]¶
Check whether the provided
edge_order
contains the same elements as the graph edge set and raise an error otherwise.The
edge_order
is also returned.
- pyrigi.graph._utils._input_check.is_vertex_order(graph, vertex_order, name='')[source]¶
Check whether the provided
vertex_order
contains the same elements as the graph vertex set and raise an error otherwise.The
vertex_order
is also returned.
- pyrigi.graph._utils._input_check.no_loop(graph)[source]¶
Check whether the graph has loops and raise an error in case.
Input check functions of Framework¶
See the methods of FrameworkBase
starting with _input_check
.
General input check functions¶
Module for standard input checks.
- pyrigi._utils._input_check.dimension(dim)[source]¶
Check whether an input dimension is a positive integer and raise an error otherwise.
- pyrigi._utils._input_check.dimension_for_algorithm(dim, possible, algorithm='')[source]¶
Check whether an input dimension is a member of list and raise an error otherwise.
- pyrigi._utils._input_check.equal(val1, val2, name1, name2='')[source]¶
Check whether an input parameter
val1
is equal toval2
and raise an error otherwise.
- pyrigi._utils._input_check.greater(val1, val2, name1, name2='')[source]¶
Check whether an input parameter
val1
is greater than or equal toval2
and raise an error otherwise.
- pyrigi._utils._input_check.greater_equal(val1, val2, name1, name2='')[source]¶
Check whether an input parameter
val1
is greater than or equal toval2
and raise an error otherwise.
- pyrigi._utils._input_check.integrality_and_range(value, name, min_val=0, max_val=inf)[source]¶
Check whether an input parameter
value
is an integer in a certain range and raise an error otherwise.
- pyrigi._utils._input_check.pebble_values(K, L)[source]¶
Check if
K
andL
satisfy the pebble conditionsK > 0
and0 <= L < 2K
and raise an error otherwise.