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.

Parameters:
  • edge (Edge) – an edge to be checked

  • vertices (Sequence[Vertex]) – Check if the endvertices of the edge are contained in the list vertices. If None, the function considers all vertices of the graph.

Return type:

None

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.

Parameters:
  • edge (Edge) – Edge for which the containment in the graph self is checked.

  • loopfree (bool) – If True, an error is raised if edge is a loop.

Return type:

None

Graph._input_check_edge_format_list(edges)[source]

Apply _input_check_edge_format() to all edges in a list.

Parameters:

edges (Sequence[Edge]) – A list of pairs to be checked.

Return type:

None

Graph._input_check_edge_list(edges, vertices=None)[source]

Apply _input_check_edge() to all edges in a list.

Parameters:
  • edges (Sequence[Edge]) – A list of edges to be checked.

  • vertices (Sequence[Vertex]) – Check if the endvertices of the edges are contained in the list vertices. If None (default), the function considers all vertices of the graph.

Return type:

None

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.

Parameters:
  • edge_order (Sequence[Edge]) – List of edges in the preferred order. If None, then all edges are returned using edge_list().

  • name (str)

Return type:

list[Edge]

Graph._input_check_no_loop()[source]

Check whether a graph has loops and raise an error in case.

Return type:

None

Graph._input_check_vertex_members(to_check, name='')[source]

Check whether the elements of a list are indeed vertices and raise error otherwise.

Parameters:
  • to_check (Union[Iterable[Vertex], Vertex]) – A vertex or Iterable of vertices for which the containment in self is checked.

  • name (str) – A name of the Iterable to_check can be picked.

Return type:

None

Graph._input_check_vertex_order(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.

Parameters:
  • vertex_order (Sequence[Vertex]) – List of vertices in the preferred order. If None, then all vertices are returned using vertex_list().

  • name (str)

Return type:

list[Vertex]

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:

None

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:

None

Framework._input_check_vertex_key(vertex, realization=None)[source]

Check whether a vertex appears as key in a realization and raise an error otherwise.

Return type:

None

Parameters:
  • vertex (:type:`~pyrigi.data_type.Vertex`)

  • realization (dict[TypeAliasForwardRef(':type:`~pyrigi.data_type.Vertex`'), TypeAliasForwardRef(':type:`~pyrigi.data_type.Point`')])

General input check methods

pyrigi._input_check.dimension(dim)[source]

Check whether an input dimension is a positive integer and raise an error otherwise.

Return type:

None

Parameters:

dim (int)

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.

Parameters:
  • dim (int) – Dimension to be checked

  • possible (list) – Values that are allowed

  • algorithm (str) – Name of the algorithm for the error message

Return type:

None

pyrigi._input_check.equal(val1, val2, name1, name2='')[source]

Check whether an input parameter val1 is equal to val2 and raise an error otherwise.

Parameters:
  • val1 (int | float) – Values that shall be equal

  • val2 (int | float) – Values that shall be equal

  • name1 (str) – Name of the parameter val1

  • name2 (str) – Name of the parameter val2

Return type:

None

pyrigi._input_check.greater(val1, val2, name1, name2='')[source]

Check whether an input parameter val1 is greater than or equal to val2 and raise an error otherwise.

Parameters:
  • val1 (int | float) – Value that shall be greater

  • val2 (int | float) – Value that shall be smaller/equal

  • name1 (str) – Name of the parameter val1

  • name2 (str) – Name of the parameter val2

Return type:

None

pyrigi._input_check.greater_equal(val1, val2, name1, name2='')[source]

Check whether an input parameter val1 is greater than or equal to val2 and raise an error otherwise.

Parameters:
  • val1 (int | float) – Value that shall be greater/equal

  • val2 (int | float) – Value that shall be smaller

  • name1 (str) – Name of the parameter val1

  • name2 (str) – Name of the parameter val2

Return type:

None

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.

Parameters:
  • value (int) – Value to be checked

  • name (str) – Name of the parameter

  • min_val (int) – Lower limit for the value

  • max_val (int) – Upper limit for the value

Return type:

None

pyrigi._input_check.pebble_values(K, L)[source]

Check if K and L satisfy the pebble conditions K > 0 and 0 <= L < 2K and raise an error otherwise.

Return type:

None

Parameters:
pyrigi._input_check.smaller_equal(val1, val2, name1, name2='')[source]

Check whether an input parameter val1 is smaller than or equal to val2 and raise an error otherwise.

Parameters:
  • val1 (int | float) – Value that shall be smaller/equal

  • val2 (int | float) – Value that shall be greater

  • name1 (str) – Name of the parameter val1

  • name2 (str) – Name of the parameter val2

Return type:

None