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.
- 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 aGraph
, an adjacency matrix represented as anArrayLike
or gridsize specification.- Return type:
- Returns:
Connection graph as a
Graph
.
- qgym.utils.input_parsing.parse_rewarder(rewarder, default)[source]
Parse a rewarder given by the user.
- Parameters:
- Return type:
- 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:
- Returns:
A generator created from the given seed.
- Raises:
TypeError – If seed is not a
Generator
,SupportsInt
orNone
.
- qgym.utils.input_parsing.parse_visualiser(render_mode, vis_type, args)[source]
Parse a Visualiser by the render mode.
- Parameters:
render_mode (
str
|None
) – IfNone
returnNone
. Otherwise return aVisualiser
of type vis_type with optional arguments given in args.vis_type (
type
[Visualiser
]) – Type ofVisualiser
to make if render_mode is notNone
.args (
list
[Any
]) – Additional argument to give to the init of theVisualiser
if vis_type is notNone
.
- Return type:
- Returns:
If render_mode is
None
returnNone
. Otherwise return aVisualiser
of type vis_type with optional arguments given in args.