-
BaseGraph — The BaseGraph in QoolQit, directly inheriting from the NetworkX Graph.
qoolqit.graphs.base_graph
module
qoolqit.graphs.base_graph
Classes
class
BaseGraph
(edges: Iterable = [])
Bases : nx.Graph
The BaseGraph in QoolQit, directly inheriting from the NetworkX Graph.
Defines basic functionalities for graphs within the Rydberg Analog, such as instantiating from a set of node coordinates, directly accessing node distances, and checking if the graph is unit-disk.
Default constructor for the BaseGraph.
Parameters
-
edges : Iterable — set of edge tuples (i, j)
Attributes
-
adj — Graph adjacency object holding the neighbors of each node.
-
name — String identifier of the graph.
-
nodes — A NodeView of the Graph as G.nodes or G.nodes().
-
edges — An EdgeView of the Graph as G.edges or G.edges().
-
degree — A DegreeView for the Graph as G.degree or G.degree().
-
sorted_edges : set — Returns the set of edges (u, v) such that (u < v).
-
all_node_pairs : set — Return a list of all possible node pairs in the graph.
-
has_coords : bool — Check if the graph has coordinates.
-
has_edges : bool — Check if the graph has edges.
-
coords : dict — Return the dictionary of node coordinates.
Methods
-
from_nodes — Construct a base graph from a set of nodes.
-
from_coordinates — Construct a base graph from a set of coordinates.
-
from_nx — Convert a NetworkX Graph object into a QoolQit graph instance.
-
from_pyg — Convert a PyTorch Geometric Data object into a QoolQit graph instance.
-
distances — Returns a dictionary of distances for a given set of edges.
-
interactions — Rydberg model interaction 1/r^6 between pair of nodes.
-
min_distance — Returns the minimum distance in the graph.
-
max_distance — Returns the maximum distance in the graph.
-
ud_radius_range — Return the range (R_min, R_max) where the graph is unit-disk.
-
is_ud_graph — Check if the graph is unit-disk.
-
ud_edges — Returns the set of edges given by the intersection of circles of a given radius.
-
rescale_coords — Rescales the node coordinates by a factor.
-
set_ud_edges — Reset the set of edges to be equal to the set of unit-disk edges.
-
draw — Draw the graph.
classmethod
from_nodes
(nodes: Iterable) → BaseGraph
Construct a base graph from a set of nodes.
Parameters
-
nodes : Iterable — set of nodes.
classmethod
from_coordinates
(coords: list | dict) → BaseGraph
Construct a base graph from a set of coordinates.
Parameters
-
coords : list | dict — list or dictionary of coordinate pairs.
classmethod
from_nx
(g: nx.Graph) → BaseGraph
Convert a NetworkX Graph object into a QoolQit graph instance.
The input networkx.Graph graph must be defined only with the following allowed
Node attributes
pos (tuple): represents the node 2D position. Must be a list/tuple of real numbers.weight: represents the node weight. Must be a real number.Edge attributes: weight: represents the edge weight. Must be a real number.
Returns an instance of the class with following attributes
- _node_weights : dict[node, float or None]
- _edge_weights : dict[(u,v), float or None]
- _coords : dict[node, (float,float) or None]
Raises
-
TypeError
-
ValueError
classmethod
from_pyg
(g: torch_geometric.data.Data) → BaseGraph
Convert a PyTorch Geometric Data object into a QoolQit graph instance.
This method requires installing the torch_geometric package.
The input torch_geometric.data.Data object must be defined only with the following
allowed attributes:
x (torch.Tensor): node weights as a matrix with shape (num_nodes, 1).
edge_index (torch.Tensor): graph connectivity as a matrix with shape (2, num_edges).
num_nodes (int): minimum number of nodes. The total number of nodes will be inferred
from this number and from the edges of the graph.
pos (torch.Tensor): node 2D positions as a matrix with shape (num_nodes, 2)
edge_attr (torch.Tensor): edge weights as a matrix with shape (num_edges, 1).
If the graph is defined only through the edge_index attribute, num_nodes is required.
The input graph will be converted to a unidirectional graph.
Raises
-
TypeError
-
AttributeError
-
ImportError
-
ValueError
property
sorted_edges
: set
Returns the set of edges (u, v) such that (u < v).
property
all_node_pairs
: set
Return a list of all possible node pairs in the graph.
property
has_coords
: bool
Check if the graph has coordinates.
Requires all nodes to have coordinates.
property
has_edges
: bool
Check if the graph has edges.
property
coords
: dict
Return the dictionary of node coordinates.
method
distances
(edge_list: Iterable | None = None) → dict
Returns a dictionary of distances for a given set of edges.
Distances are calculated directly from the coordinates. Raises an error if there are no coordinates on the graph.
Parameters
-
edge_list : Iterable | None — set of edges.
Raises
-
AttributeError
-
ValueError
method
interactions
() → dict
Rydberg model interaction 1/r^6 between pair of nodes.
method
min_distance
(connected: bool | None = None) → float
Returns the minimum distance in the graph.
Parameters
-
connected : bool | None — if True/False, computes only over connected/disconnected nodes.
method
max_distance
(connected: bool | None = None) → float
Returns the maximum distance in the graph.
Parameters
-
connected : bool | None — if True/False, computes only over connected/disconnected nodes.
method
ud_radius_range
() → tuple
Return the range (R_min, R_max) where the graph is unit-disk.
The graph is unit-disk if the maximum distance between all connected nodes is smaller than the minimum distance between disconnected nodes. This means that for any value R in that interval, the following condition is true:
graph.ud_edges(radius = R) == graph.sorted edges
Raises
-
AttributeError
-
ValueError
method
is_ud_graph
() → bool
Check if the graph is unit-disk.
method
ud_edges
(radius: float) → set
Returns the set of edges given by the intersection of circles of a given radius.
Parameters
-
radius : float — the value
Raises
-
AttributeError
method
rescale_coords
(*args: Any, scaling: float | None = None, spacing: float | None = None) → None
Rescales the node coordinates by a factor.
Accepts either a scaling or a spacing factor.
Parameters
-
scaling : float | None — value to scale by.
-
spacing : float | None — value to set as the minimum distance in the graph.
Raises
-
AttributeError
-
TypeError
method
set_ud_edges
(radius: float) → None
Reset the set of edges to be equal to the set of unit-disk edges.
Parameters
-
radius : float — the radius to use in determining the set of unit-disk edges.
method
draw
(return_fig: bool = False, *args: Any, **kwargs: Any) → Figure | None
Draw the graph.
Uses the draw_networkx function from NetworkX.
Parameters
-
*args : Any — arguments to pass to draw_networkx.
-
**kwargs : Any — keyword-arguments to pass to draw_networkx.