Skip to content
Pasqal Documentation

qoolqit.graphs.data_graph

module
qoolqit.graphs.data_graph

Classes

  • DataGraph The main graph structure to represent problem data.

class
DataGraph (edges: Iterable = [])

Bases : BaseGraph

The main graph structure to represent problem data.

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.

  • node_weights : dict Return the dictionary of node weights.

  • edge_weights : dict Return the dictionary of edge weights.

  • has_node_weights : bool Check if the graph has node weights.

  • has_edge_weights : bool Check if the graph has edge weights.

Methods

  • line Constructs a line graph, with the respective coordinates.

  • circle Constructs a circle graph, with the respective coordinates.

  • random_er Constructs an Erdős–Rényi random graph.

  • triangular Constructs a triangular lattice graph, with respective coordinates.

  • hexagonal Constructs a hexagonal lattice graph, with respective coordinates.

  • heavy_hexagonal Constructs a heavy-hexagonal lattice graph, with respective coordinates.

  • random_ud Constructs a random unit-disk graph.

  • from_matrix Constructs a graph from a symmetric square matrix.

  • from_pyg Create a graph from a pyg data object.

  • set_ud_edges Reset the set of edges to be equal to the set of unit-disk edges.

classmethod
line (n: int, spacing: float = 1.0) → DataGraph

Constructs a line graph, with the respective coordinates.

Parameters

  • n : int number of nodes.

  • spacing : float distance between each node.

classmethod
circle (n: int, spacing: float = 1.0, center: tuple = (0.0, 0.0)) → DataGraph

Constructs a circle graph, with the respective coordinates.

Parameters

  • n : int number of nodes.

  • spacing : float distance between each node.

  • center : tuple point (x, y) to set as the center of the graph.

classmethod
random_er (n: int, p: float, seed: int | None = None) → DataGraph

Constructs an Erdős–Rényi random graph.

Parameters

  • n : int number of nodes.

  • p : float probability that any two nodes connect.

  • seed : int | None random seed.

classmethod
triangular (m: int, n: int, spacing: float = 1.0) → DataGraph

Constructs a triangular lattice graph, with respective coordinates.

Parameters

  • m : int Number of rows of triangles.

  • n : int Number of columns of triangles.

  • spacing : float The distance between adjacent nodes on the final lattice.

classmethod
hexagonal (m: int, n: int, spacing: float = 1.0) → DataGraph

Constructs a hexagonal lattice graph, with respective coordinates.

Parameters

  • m : int Number of rows of hexagons.

  • n : int Number of columns of hexagons.

  • spacing : float The distance between adjacent nodes on the final lattice.

classmethod
heavy_hexagonal (m: int, n: int, spacing: float = 1.0) → DataGraph

Constructs a heavy-hexagonal lattice graph, with respective coordinates.

Parameters

  • m : int Number of rows of hexagons.

  • n : int Number of columns of hexagons.

  • spacing : float The distance between adjacent nodes on the final lattice.

classmethod
random_ud (n: int, radius: float = 1.0, L: float | None = None) → DataGraph

Constructs a random unit-disk graph.

The nodes are sampled uniformly from a square of size (L x L). If L is not given, it is estimated based on a rough heuristic that of packing N nodes on a square of side L such that the expected minimum distance is R, leading to L ~ (R / 2) * sqrt(π * n).

Parameters

  • n : int number of nodes.

  • radius : float radius to use for defining the unit-disk edges.

  • L : float | None size of the square on which to sample the node coordinates.

classmethod
from_matrix (data: ArrayLike) → DataGraph

Constructs a graph from a symmetric square matrix.

The diagonal values are set as the node weights. For each entry (i, j) where M[i, j] != 0 an edge (i, j) is added to the graph and the value M[i, j] is set as its weight.

Parameters

  • data : ArrayLike symmetric square matrix.

Raises

  • ValueError

classmethod
from_pyg (data) → DataGraph

Create a graph from a pyg data object.

Raises

  • NotImplementedError

property
node_weights : dict

Return the dictionary of node weights.

property
edge_weights : dict

Return the dictionary of edge weights.

property
has_node_weights : bool

Check if the graph has node weights.

Requires all nodes to have a weight.

property
has_edge_weights : bool

Check if the graph has edge weights.

Requires all edges to have a weight.

method
set_ud_edges (radius: float) → None

Reset the set of edges to be equal to the set of unit-disk edges.