Add insert_node_on_in_edges and insert_node_on_out_edges methods#181
Conversation
This commit adds 2 new methods to the PyDiGraph class, insert_node_between() and insert_node_between_multiple. These methods are for inserting edges between a node and another node that has edges. You specify a node and which node to insert it between and it will loop over either the incoming or outgoing edges and add edges between the existing edges.
|
Marking as on hold because I need to add more unittests to improve the coverage, and also add more than the simple cases. |
This commit migrates the inner loop for apply_operation_back and apply_operation_front to leverage retworkx's insert_node_between_multiple PyDiGraph method. This retworkx method performs essentially the same loop internally but executes faster. Depends on Qiskit/rustworkx#181 being included in a release.
Pull Request Test Coverage Report for Build 355266041
💛 - Coveralls |
Yeah that's a good idea. I'll update it shortly to split the functions |
This commit splits the new methods into separate and better named ones per @itoko's excellent suggestion. The insert_node_between method becomes insert_node_on_in_edges and insert_node_on_out_edges, and insert_node_between_multiple becomes insert_node_on_in_edges_multiple and insert_node_on_out_edges_multiple. The direction kwarg is also removed from the Python API.
|
@mtreinish Thank you. I have one more comment on docstrings. I think we can describe the spec more clearly without parent/child notation: (I like the term BTW, I personally prefer |
|
@itoko thank you for the suggestions. I was actually hoping you'd leave a comment like that. I thought the names were awkward in this function, but couldn't come up with anything better so just left it as is. I'll update it now per your suggestions. |
Co-authored-by: Toshinari Itoko <itoko@jp.ibm.com>
* Leverage retworkx for apply_operation* inner loop This commit migrates the inner loop for apply_operation_back and apply_operation_front to leverage retworkx's insert_node_between_multiple PyDiGraph method. This retworkx method performs essentially the same loop internally but executes faster. Depends on Qiskit/rustworkx#181 being included in a release. * DNM: Test with retworkx branch * Update for retworkx 0.6.0 release * Remove stray kwarg from earlier revision Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit adds 2 new methods to the PyDiGraph class,
insert_node_between() and insert_node_between_multiple. These methods
are for inserting edges between a node and another node that has edges.
You specify a node and which node to insert it between and it will loop
over either the incoming or outgoing edges and add edges between the
existing edges.