Retworkx API Reference

Graph Classes

retworkx.PyGraph()

A class for creating undirected graphs.

retworkx.PyDiGraph([check_cycle])

A class for creating directed graphs

retworkx.PyDAG([check_cycle])

A class for creating direct acyclic graphs.

Generators

retworkx.generators.cycle_graph([num_nodes, …])

Generate an undirected cycle graph

retworkx.generators.directed_cycle_graph([…])

Generate a cycle graph

retworkx.generators.path_graph([num_nodes, …])

Generate an undirected path graph

retworkx.generators.directed_path_graph([…])

Generate a directed path graph

retworkx.generators.star_graph([num_nodes, …])

Generate an undirected star graph

retworkx.generators.directed_star_graph([…])

Generate a directed star graph

Random Circuit Functions

retworkx.directed_gnp_random_graph(…[, seed])

Return a \(G_{np}\) directed random graph, also known as an Erdős-Rényi graph or a binomial graph.

retworkx.undirected_gnp_random_graph(…[, seed])

Return a \(G_{np}\) random undirected graph, also known as an Erdős-Rényi graph or a binomial graph.

Algorithm Functions

retworkx.bfs_successors(graph, node, /)

Return successors in a breadth-first-search from a source node.

retworkx.dag_longest_path(graph, /)

Find the longest path in a DAG

retworkx.dag_longest_path_length(graph, /)

Find the length of the longest path in a DAG

retworkx.number_weakly_connected_components(…)

Find the number of weakly connected components in a DAG.

retworkx.is_directed_acyclic_graph(graph, /)

Check that the PyDiGraph or PyDAG doesn’t have a cycle

retworkx.is_isomorphic(first, second, /)

Determine if 2 graphs are structurally isomorphic

retworkx.is_isomorphic_node_match(first, …)

Determine if 2 DAGs are isomorphic

retworkx.topological_sort(graph, /)

Return the topological sort of node indexes from the provided graph

retworkx.descendants(graph, node, /)

Return the descendants of a node in a graph.

retworkx.ancestors(graph, node, /)

Return the ancestors of a node in a graph.

retworkx.lexicographical_topological_sort(…)

Get the lexicographical topological sorted nodes from the provided DAG

retworkx.floyd_warshall(dag, /)

Return the shortest path lengths between ever pair of nodes that has a path connecting them

retworkx.graph_floyd_warshall_numpy(graph, …)

Find all-pairs shortest path lengths using Floyd’s algorithm

retworkx.digraph_floyd_warshall_numpy(graph, …)

Find all-pairs shortest path lengths using Floyd’s algorithm

retworkx.layers(dag, first_layer, /)

Return a list of layers

retworkx.digraph_adjacency_matrix(graph, …)

Return the adjacency matrix for a PyDiGraph object

retworkx.graph_adjacency_matrix(graph, …)

Return the adjacency matrix for a PyGraph class

retworkx.graph_all_simple_paths

Return all simple paths between 2 nodes in a PyGraph object

retworkx.digraph_all_simple_paths

Return all simple paths between 2 nodes in a PyDiGraph object

retworkx.graph_astar_shortest_path(graph, …)

Compute the A* shortest path for a PyGraph

retworkx.digraph_astar_shortest_path(graph, …)

Compute the A* shortest path for a PyDiGraph

retworkx.graph_dijkstra_shortest_path_lengths(…)

Compute the lengths of the shortest paths for a PyGraph object using Dijkstra’s algorithm

retworkx.digraph_dijkstra_shortest_path_lengths(…)

Compute the lengths of the shortest paths for a PyDiGraph object using Dijkstra’s algorithm

retworkx.graph_greedy_color(graph, /)

Color a PyGraph using a largest_first strategy greedy graph coloring.

retworkx.cycle_basis(graph, /[, root])

Return a list of cycles which form a basis for cycles of a given PyGraph

retworkx.strongly_connected_components(graph, /)

Compute the strongly connected components for a directed graph