qgym.utils.input_parsing module

This module contains function which parse user input.

With parsing we mean that the user input is validated and transformed to a predictable format. In this way, users can give different input formats, but internally we are assured that the data has the same format.

qgym.utils.input_parsing.has_fidelity(graph)[source]

Check if the given graph has fidelity encoded in its edges.

A graph can have fidelity encoded by setting the “weight” attributes of at least one edge to a fidelity value.

Parameters:

graph (Graph) – Networks representation of the graph.

Return type:

bool

Returns:

Boolean value stating wether the graph has fidelity encoded.

qgym.utils.input_parsing.parse_connection_graph(graph)[source]

Parse the user input (given in __init__) to create a connection graph.

Parameters:

graph (Union[Graph, Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]], list[int], tuple[int, ...]]) – A graph representation of a connection graph. Supported input formats are a graph represented as a Graph, an adjacency matrix represented as an ArrayLike or gridsize specification.

Return type:

Graph

Returns:

Connection graph as a Graph.

qgym.utils.input_parsing.parse_rewarder(rewarder, default)[source]

Parse a rewarder given by the user.

Parameters:
  • rewarder (Rewarder | None) – Rewarder to use for the environment. If None, then a new instance of the default rewarder will be returned.

  • default (type[Rewarder]) – Type of the desired default rewarder to used when no rewarder is given.

Return type:

Rewarder

Returns:

A deepcopy of the given rewarder or a new instance of type default if rewarder is None.

qgym.utils.input_parsing.parse_seed(seed)[source]

Parse a give seed to produce a numpy.random.Generator.

Parameters:

seed (Generator | SupportsInt | None) – Seed to parse.

Return type:

Generator

Returns:

A generator created from the given seed.

Raises:

TypeError – If seed is not a Generator, SupportsInt or None.

qgym.utils.input_parsing.parse_visualiser(render_mode, vis_type, args)[source]

Parse a Visualiser by the render mode.

Parameters:
  • render_mode (str | None) – If None return None. Otherwise return a Visualiser of type vis_type with optional arguments given in args.

  • vis_type (type[Visualiser]) – Type of Visualiser to make if render_mode is not None.

  • args (list[Any]) – Additional argument to give to the init of the Visualiser if vis_type is not None.

Return type:

None | Visualiser

Returns:

If render_mode is None return None. Otherwise return a Visualiser of type vis_type with optional arguments given in args.