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 a set of methods that are often needed in _input_check.py
,
see the list below.
For instance pyrigi._input_check.dimension()
checks whether
the parameter dim
is a positive integer and raises an error otherwise.
Checks which need properties of the calling object
are in the respective class of the object and
have a name starting with _input_check_
.
For instance Graph._input_check_no_loop()
checks whether
a graph is loop free and raises an error otherwise.
Example:
import pyrigi._input_check as _input_check
class Graph(nx.Graph):
...
def method(self, dim: int):
_input_check.dimension(dim)
self._input_check_no_loop()
...
Note that these input checks are considered private methods. 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:
def method(algorithm: str = test):
if algorithm == "alg1":
...
elif algorithm == "alg2":
...
else:
raise NotSupportedValueError(algorithm, "algorithm", self.method)
Input check functions¶
Input check methods of Graph¶
- Graph._input_check_edge(edge, vertices=None)[source]¶
Check if the given input is an edge of the graph with endvertices in vertices and raise an error otherwise.
- Graph._input_check_edge_format(edge, loopfree=False)[source]¶
Check if an
edge
is a pair of (distinct) vertices of the graph and raise an error otherwise.
- Graph._input_check_edge_format_list(edges)[source]¶
Apply
_input_check_edge_format()
to all edges in a list.
- Graph._input_check_edge_list(edges, vertices=None)[source]¶
Apply
_input_check_edge()
to all edges in a list.
- Graph._input_check_edge_order(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.
- Graph._input_check_no_loop()[source]¶
Check whether a graph has loops and raise an error in case.
- Return type:
- Graph._input_check_vertex_members(to_check, name='')[source]¶
Check whether the elements of a list are indeed vertices and raise error otherwise.
Input check methods of Framework¶
- Framework._input_check_point_dimension(point)[source]¶
Check whether a point has the right dimension and raise an error otherwise.
- Return type:
- Parameters:
point (:type:`~pyrigi.data_type.Point`)
- Framework._input_check_underlying_graphs(other_framework)[source]¶
Check whether the underlying graphs of two frameworks are the same and raise an error otherwise.
- Return type:
General input check methods¶
- pyrigi._input_check.dimension(dim)[source]¶
Check whether an input dimension is a positive integer and raise an error otherwise.
- pyrigi._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._input_check.equal(val1, val2, name1, name2='')[source]¶
Check whether an input parameter
val1
is equal toval2
and raise an error otherwise.
- pyrigi._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._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._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._input_check.pebble_values(K, L)[source]¶
Check if
K
andL
satisfy the pebble conditionsK > 0
and0 <= L < 2K
and raise an error otherwise.