qgym.envs.initial_mapping.initial_mapping_state module
This module contains the InitialMappingState
class.
This InitialMapping
represents the State
of
the InitialMapping
environment.
- Usage:
>>> from qgym.envs.initial_mapping.initial_mapping_state import InitialMappingState >>> from qgym.envs.initial_mapping.graph_generation import BasicGraphGenerator >>> import networkx as nx >>> connection_graph = nx.grid_graph((3,3)) >>> graph_generator = BasicGraphGenerator(9, 0.5) >>> state = InitialMappingState(connection_graph, graph_generator)
- class qgym.envs.initial_mapping.initial_mapping_state.InitialMappingState(connection_graph, graph_generator)[source]
Bases:
State
[Dict
[str
,ndarray
[Any
,dtype
[int32
]]],ndarray
[Any
,dtype
[int32
]]]The
InitialMappingState
class.- __init__(connection_graph, graph_generator)[source]
Init of the
InitialMappingState
class.- Parameters:
connection_graph (
Graph
) – networkx Graph representation of the QPU topology. Each node represents a physical qubit and each edge represents a connection in the QPU topology.graph_generator (
GraphGenerator
) – Graph generator for generating interaction graphs. This generator is used to generate a new interaction graph whenInitialMappingState.reset()
is called without an interaction graph.
- create_observation_space()[source]
Create the corresponding observation space.
- Return type:
- Returns:
Observation space in the form of a
Dict
space containing the following values if the connection graph has no fidelity information:MultiDiscrete
space representing the mapping.MultiBinary
representing the interaction matrix.
- graphs
Dictionary containing the graph and matrix representations of the both the interaction graph and connection graph.
- is_done()[source]
Determine if the state is done or not.
- Return type:
- Returns:
Boolean value stating whether we are in a final state.
- is_truncated()[source]
Determine if the episode should be truncated or not.
- Return type:
- Returns:
Boolean value stating whether the episode should be truncated. The episode is truncated if the number of steps in the current episode is more than 10 times the number of nodes in the connection graph.
- mapped_qubits: dict[str, set[int]]
Dictionary with two sets containing mapped physical and logical qubits.
- mapping
Array of which the index represents a physical qubit, and the value a virtual qubit. A value of
n_nodes + 1
represents the case when nothing is mapped to the physical qubit yet.
- mapping_dict: dict[int, int]
Dictionary that maps logical qubits (keys) to physical qubits (values).
- reset(*, seed=None, interaction_graph=None, **_kwargs)[source]
Reset the state and set a new interaction graph.
To be used after an episode is finished.
- Parameters:
seed (
int
|None
) – Seed for the random number generator, should only be provided (optionally) on the first reset call i.e., before any learning is done.interaction_graph (
Graph
|None
) – Interaction graph to be used for the next iteration, ifcreated. (None a random interaction graph will be)
_kwargs (
Any
) – Additional options to configure the reset.
- Return type:
- Returns:
(self) New initial state.
- steps_done: int
Number of steps done since the last reset.