qgym.envs.routing.routing_state module
This module contains the RoutingState class.
This RoutingState represents the State of the
Routing environment.
- Usage:
 >>> from qgym.envs.routing.routingstate import RoutingState >>> from qgym.generators import BasicInteractionGenerator >>> import networkx as nx >>> connection_graph = nx.grid_graph((3,3)) >>> state = RoutingState( >>> interaction_generator = BasicInteractionGenerator(9, 100), >>> max_observation_reach = 20, >>> connection_graph = connection_graph, >>> observe_legal_surpasses = True, >>> observe_connection_graph = False, >>> )
- class qgym.envs.routing.routing_state.RoutingState(*, interaction_generator, max_observation_reach, connection_graph, observe_legal_surpasses, observe_connection_graph)[source]
 Bases:
State[Dict[str,ndarray[Any,dtype[int32]]],int]The
RoutingStateclass.- __init__(*, interaction_generator, max_observation_reach, connection_graph, observe_legal_surpasses, observe_connection_graph)[source]
 Init of the
RoutingStateclass.- Parameters:
 interaction_generator (
InteractionGenerator) – Interaction generator for generating interaction circuits. This generator is used to generate a new interaction circuit whenRoutingState.reset()is called without an interaction circuit.max_observation_reach (
int) – Sets a cap on the maximum amount of gates the agent can see ahead when making an observation. When bigger than max_interaction_gates the agent will always see all gates ahead in an observationconnection_graph (
Graph) –networkxgraph representation of the QPU topology. Each node represents a physical qubit and each edge represents a connection in the QPU topology.observe_legal_surpasses (
bool) – IfTruea boolean array of length max_observation_reach indicating whether the gates ahead can be executed, will be added to the observation_space.observe_connection_graph (
bool) – IfTrue, the connection_graph will be incorporated in the observation_space. Reason to set itFalseis: QPU-topology doesn’t change, hence an agent could infer the topology from the training data without needing to explicitly add it to the observations. This reduced the size observation_space.
- connection_graph
 networkxgraph representation of the QPU topology. Each node represents a physical qubit and each edge represents a connection in the QPU topology.
- create_observation_space()[source]
 Create the corresponding observation space.
- Return type:
 - Returns:
 Observation space in the form of a
Dictspace containing:MultiDiscretespace representing the interaction gates ahead of current position.MultiDiscretespace representing the current mapping of logical onto physical qubits
- edges
 List of all the edges, used to decode given actions.
- interaction_circuit
 An array of 2-tuples of integers, where every tuple represents a, not specified, gate acting on the two qubits labeled by the integers in the tuples.
- interaction_generator
 Sets the maximum amount of gates in the interaction_circuit, when a new interaction_circuit is generated.
- is_done()[source]
 Checks if the current state is in a final state.
Returs: Boolean value stating whether we are in a final state.
- Return type:
 
- is_legal_surpass(logical_qubit1, logical_qubit2)[source]
 Checks whether a surpass of the current gate ahead is legal.
- mapping
 Array of which each index represents a logical qubit and each value represents a physical qubit.
- max_observation_reach
 An integer that sets a cap on the maximum amount of gates the agent can see ahead when making an observation. When bigger than max_interaction_gates the agent will always see all gates ahead in an observation.
- position: int
 An integer representing before which gate in the interaction_circuit the agent currently is.
- reset(*, seed=None, interaction_circuit=None, **_kwargs)[source]
 Reset the state (in place) and load a new (random) initial state.
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.circuit – Optional list of tuples of ints that the interaction gates via the qubits the gates are acting on.
_kwargs (
Any) – Additional options to configure the reset.
- Return type:
 - Returns:
 Self.
- steps_done: int
 Number of steps done since the last reset.
- swap_gates_inserted: deque[tuple[int, int, int]]
 A deque of 3-tuples of integers, to register which gates to insert and where. Every tuple (g, q1, q2) represents the insertion of a SWAP-gate acting on logical qubits q1 and q2 before gate g in the interaction_circuit.
- update_state(action)[source]
 Update the state (in place) of this environment using the given action.
- Parameters:
 action (
int) – Integer value in [0, n_connections]. Each value of 0 to n_connections-1 corresponds to placing a SWAP and this SWAP gate will be appended to the swap_gates_inserteddeque. The value of n_connections correspond to a surpass.- Return type:
 - Returns:
 Self.