qgym.utils.input_validation module
This module contains generic input validation methods.
- qgym.utils.input_validation.check_adjacency_matrix(adjacency_matrix)[source]
Check if a matrix is an adjacency matrix, i.e., a square matrix.
- Parameters:
adjacency_matrix (
ArrayLike
) – Matrix to check.- Raises:
ValueError – When the provided input is not a square matrix.
- Return type:
- Returns:
Square NDArray representation of
adjacency_matrix
.
- qgym.utils.input_validation.check_bool(x, name, *, safe=False)[source]
Check if the variable x with name ‘name’ is a Boolean value.
Optionally, cast to Boolean value if it is not.
- Parameters:
- Raises:
TypeError – If safe is
True
and x is not a Boolean value.- Return type:
- Returns:
Boolean representation of the input.
- qgym.utils.input_validation.check_graph_is_valid_topology(graph, name)[source]
Check if graph with name ‘name’ is an instance of
networkx.Graph
, check if the graph is valid topology graph and check if the nodes are integers.- Parameters:
- Raises:
TypeError – If graph is not an instance of
networkx.Graph
.ValueError – If graph is not a valid topology graph.
- Return type:
- Returns:
The input graph.
- qgym.utils.input_validation.check_instance(x, name, dtype)[source]
Check if x with name ‘name’ is an instance of dtype.
- qgym.utils.input_validation.check_int(x, name, *, l_bound=None, u_bound=None, l_inclusive=True, u_inclusive=True)[source]
Check if the variable x with name ‘name’ is a real number.
Optionally, lower and upper bounds can also be checked.
- Parameters:
x (
Any
) – Variable to check.name (
str
) – Name of the variable. This name will be displayed in possible error messages.l_inclusive (
bool
) – IfTrue
the lower bound is inclusive, otherwise the lower bound is exclusive.u_inclusive (
bool
) – IfTrue
the upper bound is inclusive, otherwise the upper bound is exclusive.
- Raises:
TypeError – If x is not a real number.
ValueError – If x is outside the give bounds.
- Return type:
- Returns:
Floating point representation of x.
- qgym.utils.input_validation.check_real(x, name, *, l_bound=None, u_bound=None, l_inclusive=True, u_inclusive=True)[source]
Check if the variable x with name ‘name’ is a real number.
Optionally, lower and upper bounds can also be checked.
- Parameters:
x (
Any
) – Variable to check.name (
str
) – Name of the variable. This name will be displayed in possible error messages.l_inclusive (
bool
) – IfTrue
the lower bound is inclusive, otherwise the lower bound is exclusive.u_inclusive (
bool
) – IfTrue
the upper bound is inclusive, otherwise the upper bound is exclusive.
- Raises:
TypeError – If x is not a real number.
ValueError – If x is outside the give bounds.
- Return type:
- Returns:
Floating point representation of x.
- qgym.utils.input_validation.check_string(x, name, *, lower=False, upper=False)[source]
Check if the variable x with name ‘name’ is a string.
Optionally, the string can be converted to all lowercase or all uppercase letters.
- Parameters:
- Raises:
TypeError – If x is not an instance of
str
.- Return type:
- Returns:
Input string. Optionally, in lowercase or uppercase letters.