# Retworkx API Reference¶

## Graph Classes¶

 retworkx.PyGraph([multigraph]) A class for creating undirected graphs retworkx.PyDiGraph([check_cycle, multigraph]) A class for creating directed graphs retworkx.PyDAG([check_cycle, multigraph]) A class for creating direct acyclic graphs.

## Generators¶

 retworkx.generators.cycle_graph([num_nodes, …]) Generate an undirected cycle graph Generate a cycle graph retworkx.generators.path_graph([num_nodes, …]) Generate an undirected path graph Generate a directed path graph retworkx.generators.star_graph([num_nodes, …]) Generate an undirected star graph Generate a directed star graph retworkx.generators.mesh_graph([num_nodes, …]) Generate an undirected mesh graph where every node is connected to every other Generate a directed mesh graph where every node is connected to every other retworkx.generators.grid_graph([rows, cols, …]) Generate an undirected grid graph. Generate a directed grid graph. The edges propagate towards right and

## 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. Return a $$G_{np}$$ random undirected graph, also known as an Erdős-Rényi graph or a binomial graph. retworkx.directed_gnm_random_graph(…[, seed]) Return a $$G_{nm}$$ of a directed graph Return a $$G_{nm}$$ of an undirected graph

## Algorithm Functions¶

### Specific Graph Type Methods¶

 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 Find the length of the longest path in a DAG Find the number of weakly connected components in a DAG. Find the weakly connected components in a directed graph retworkx.is_weakly_connected(graph, /) Check if the graph is weakly connected Check that the PyDiGraph or PyDAG doesn’t have a cycle retworkx.digraph_is_isomorphic(first, second) Determine if 2 directed graphs are isomorphic retworkx.graph_is_isomorphic(first, second) Determine if 2 undirected graphs 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. Get the lexicographical topological sorted nodes from the provided DAG retworkx.graph_distance_matrix(graph, /[, …]) Get the distance matrix for an undirected graph retworkx.digraph_distance_matrix(graph, /[, …]) Get the distance matrix for a directed graph Return the shortest path lengths between ever pair of nodes that has a path connecting them Find all-pairs shortest path lengths using Floyd’s algorithm retworkx.digraph_floyd_warshall_numpy Find all-pairs shortest path lengths using Floyd’s algorithm retworkx.collect_runs(graph, filter) Collect runs that match a filter function retworkx.layers(dag, first_layer, /) Return a list of layers 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 Compute the A* shortest path for a PyGraph Compute the A* shortest path for a PyDiGraph retworkx.graph_dijkstra_shortest_paths Find the shortest path from a node retworkx.digraph_dijkstra_shortest_paths Find the shortest path from a node Compute the lengths of the shortest paths for a PyGraph object using Dijkstra’s algorithm Compute the lengths of the shortest paths for a PyDiGraph object using Dijkstra’s algorithm Compute the length of the kth shortest path Compute the length of the kth shortest path 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 Compute the strongly connected components for a directed graph retworkx.graph_dfs_edges(graph, /[, source]) Get edge list in depth first order retworkx.digraph_dfs_edges(graph, /[, source]) Get edge list in depth first order retworkx.digraph_find_cycle(graph, /[, source]) Return the first cycle encountered during DFS of a given PyDiGraph, empty list is returned if no cycle is found retworkx.digraph_union(first, second, …) Return a new PyDiGraph by forming a union from two input PyDiGraph objects retworkx.is_matching(graph, matching, /) Check if matching is valid for graph retworkx.is_maximal_matching(graph, matching, /) Check if a matching is a maximal (not maximum) matching for a graph retworkx.max_weight_matching(graph, /[, …]) Compute a maximum-weighted matching for a PyGraph retworkx.minimum_spanning_edges(graph[, …]) Find the edges in the minimum spanning tree or forest of a graph using Kruskal’s algorithm. retworkx.minimum_spanning_tree(graph[, …]) Find the minimum spanning tree or forest of a graph using Kruskal’s algorithm. retworkx.graph_transitivity(graph, /) Compute the transitivity of an undirected graph. retworkx.digraph_transitivity(graph, /) Compute the transitivity of a directed graph. retworkx.graph_core_number(graph, /) Return the core number for each node in the graph. retworkx.digraph_core_number(graph, /) Return the core number for each node in the directed graph. retworkx.graph_complement(graph, /) Compute the complement of a graph. retworkx.digraph_complement(graph, /) Compute the complement of a graph.

### Universal Functions¶

These functions are algorithm functions that wrap per graph object type functions in the algorithms API but can be run with a PyGraph, PyDiGraph, or PyDAG object.

 Compute the complement of a graph. Get the distance matrix for a graph Find all-pairs shortest path lengths using Floyd’s algorithm Return the adjacency matrix for a graph object Return all simple paths between 2 nodes in a PyGraph object Compute the A* shortest path for a graph Find the shortest path from a node Compute the lengths of the shortest paths for a graph object using Dijkstra’s algorithm. Compute the length of the kth shortest path Get edge list in depth first order Determine if 2 graphs are isomorphic Determine if 2 graphs are isomorphic Compute the transitivity of a graph. Return the core number for each node in the graph.

## Return Iterator Types¶

 retworkx.BFSSuccessors A custom class for the return from retworkx.bfs_successors() retworkx.NodeIndices A custom class for the return of node indices retworkx.EdgeList A custom class for the return of edge lists retworkx.WeightedEdgeList A custom class for the return of edge lists with weights