-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make API uniform #215
Comments
I think that using python would be the easier path forward here. I've tried to do this on the rust side several ways and the issue I have is that python binding macros def dfs_edges(self, graph, source=None):
"""Get edge list in depth first order
:param (PyGraph|PyDiGraph|PyDAG) graph: The graph to get the DFS edge list from
:param int source: An optional node index to use as the starting node
for the depth-first search. The edge list will only return edges in
the components reachable from this index. If this is not specified
then a source will be chosen arbitrarly and repeated until all
components of the graph are searched.
:returns: A list of edges as a tuple of the form ``(source, target)`` in
depth-first order
:rtype: EdgeList
"""
if isinstance(graph, PyGraph):
graph_dfs_edges(graph, source)
else:
digraph_dfs_edges(graph, source) in the main package |
In the rust generated Python API we need to have fixed class inpurts to satisfy the traits used by the pyo3 macro generated FFI functions. This results in duplicate methods like digraph_dfs_edges and graph_dfs_edges with the same implementation just differing input types. To simplify the API for users this commit adds universal functions to the python side of the retworkx package to take in any retworkx graph object and dispatch to the proper function in the rust generated api that relies on strict input types. Fixes Qiskit#215
* Add universal methods In the rust generated Python API we need to have fixed class inpurts to satisfy the traits used by the pyo3 macro generated FFI functions. This results in duplicate methods like digraph_dfs_edges and graph_dfs_edges with the same implementation just differing input types. To simplify the API for users this commit adds universal functions to the python side of the retworkx package to take in any retworkx graph object and dispatch to the proper function in the rust generated api that relies on strict input types. Fixes #215 * Add release notes * Cleanup docs for new functions * Add as_undirected flag to distance_matrix()
What is the expected enhancement?
Currently, many methods require prefixing the name with the type of the graph (i.e.
digraph_
). Would it be possible to dispatch the right method based on the type of the graph automatically? This arose in a discussion on a prior PR (Qiskit/qiskit#5471 (comment)).One pythonic way to implement this would be to switch on the type, if implementing this in Rust is a problem. Then the right Rust method may be called by the Python code.
The text was updated successfully, but these errors were encountered: