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 RoutingState class.

__init__(*, interaction_generator, max_observation_reach, connection_graph, observe_legal_surpasses, observe_connection_graph)[source]

Init of the RoutingState class.

Parameters:
  • interaction_generator (InteractionGenerator) – Interaction generator for generating interaction circuits. This generator is used to generate a new interaction circuit when RoutingState.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 observation

  • 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.

  • observe_legal_surpasses (bool) – If True a 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) – If True, the connection_graph will be incorporated in the observation_space. Reason to set it False is: 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

networkx graph 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:

Dict

Returns:

Observation space in the form of a Dict space containing:

  • MultiDiscrete space representing the interaction gates ahead of current position.

  • MultiDiscrete space 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:

bool

Checks whether a surpass of the current gate ahead is legal.

Parameters:
  • logical_qubit1 (int) – First qubit of the interaction.

  • logical_qubit2 (int) – Second qubit of the logical interaction.

Return type:

bool

Returns:

A boolean value stating whether a connection gate with the two qubits can be executed with the current mapping and connection graph.

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.

property n_connections: int

Number of connections in the connection_graph.

property n_qubits: int

Number of qubits in the connection_graph.

obtain_info()[source]

Obtain additional information of the current state.

Return type:

dict[str, int | deque[tuple[int, int, int]] | ndarray[Any, dtype[int32]] | list[tuple[int]]]

Returns:

Dictionary containing optional debugging info for the current state.

obtain_observation()[source]

Observe the current state.

Return type:

dict[str, ndarray[Any, dtype[int32]]]

Returns:

Observation based on the current state.

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:

RoutingState

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_inserted deque. The value of n_connections correspond to a surpass.

Return type:

RoutingState

Returns:

Self.