Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Comment thread
krishnendurajesh marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All graph classes and top-level functions are accessible with a single import.
To illustrate this, the following example calculates the shortest path
between two nodes `A` and `C` in an undirected graph.


```python3
import rustworkx

Expand All @@ -40,8 +41,13 @@ graph.add_edges_from([(a, b, 1.5), (a, c, 5.0), (b, c, 2.5)])

# Returns the path A -> B -> C
rustworkx.dijkstra_shortest_paths(graph, a, c, weight_fn=float)

```

NOTE:The library supports standard Python type annotations (e.g., `PyGraph[NodeData, EdgeData]`) for specifying expected data types.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be more cleanly expressed as an Alert

> [!NOTE]
> The library supports standard Python type annotations (e.g., `PyGraph[NodeData, EdgeData]`) for specifying expected data types.




## Installing rustworkx

rustworkx is published on [PyPI](https://pypi.org/project/rustworkx/) so on x86\_64, i686, ppc64le, s390x, and
Expand Down
25 changes: 25 additions & 0 deletions src/digraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,31 @@ use super::dag_algo::is_directed_acyclic_graph;
/// :math:`2^{32} - 1` (4,294,967,294) each. Attempting to add more nodes or
/// edges than this will result in an exception being raised.
///
/// Type Annotations:
///
/// You may use standard Python typing for specifying expected data types for node and edge parameters.
/// The generic parameters for ``PyDiGraph`` are ordered like this: ``PyDiGraph[NodeData, EdgeData]``.
///
/// .. code-block:: python
///
/// import rustworkx as rx
///
/// graph: rx.PyDiGraph[str, int] = rx.PyDiGraph()
/// node_a = graph.add_node("qubit0")
/// node_b = graph.add_node("qubit1")
/// graph.add_edge(node_a, node_b, 10)
///
/// If you use methods that create edges without data (that is ,connecting 2 nodes with an edge with no value), such as
/// :meth:`~rustworkx.PyDiGraph.add_edges_from_no_data`, you must include
/// ``None`` in your edge (``_T``) type annotation (using ``| None``).
///
/// .. code-block:: python
///
/// # Type hinting a graph where edges can be created without a value
/// graph: rx.PyDiGraph[str, int | None] = rx.PyDiGraph()
/// graph.add_nodes_from(["qubit0", "qubit1"])
/// graph.add_edges_from_no_data([(0, 1)]) # parent=0, child=1
///
/// :param bool check_cycle: When this is set to ``True`` the created
/// ``PyDiGraph`` has runtime cycle detection enabled.
/// :param bool multigraph: When this is set to ``False`` the created
Expand Down
25 changes: 25 additions & 0 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,31 @@ use petgraph::visit::{
/// :math:`2^{32} - 1` (4,294,967,294) each. Attempting to add more nodes or
/// edges than this will result in an exception being raised.
///
/// Type Annotations:
Comment thread
krishnendurajesh marked this conversation as resolved.
///
/// You can use standard Python typing for specifying expected data types for both node and edge parameters.
/// The generic parameters for ``PyGraph`` are ordered as ``PyGraph[NodeData, EdgeData]``.
///
/// .. code-block:: python
///
/// import rustworkx as rx
///
/// graph: rx.PyGraph[str, int] = rx.PyGraph()
/// node_a = graph.add_node("qubit0")
/// node_b = graph.add_node("qubit1")
/// graph.add_edge(node_a, node_b, 10)
///
/// If you plan to use methods that create edges without data (connecting 2 nodes with an edge with no value), such as
/// :meth:`~rustworkx.PyGraph.add_edges_from_no_data`, you must include
/// ``None`` in your edge (_T) type annotation (using ``| None``).
///
/// .. code-block:: python
///
/// # Type hinting a graph where edges can be created without a value
/// graph: rx.PyGraph[str, int | None] = rx.PyGraph()
/// graph.add_nodes_from(["qubit0", "qubit1"])
/// graph.add_edges_from_no_data([(0, 1)])
///
/// :param bool multigraph: When this is set to ``False`` the created PyGraph
/// object will not be a multigraph. When ``False`` if a method call is
/// made that would add parallel edges the weight/weight from that
Expand Down
Loading