Skip to content

Conversation

maxwell04-wq
Copy link
Contributor

Fixes #774.
Updates:

  • draw_edges(): set rad=0.25 for looped nodes.
  • draw_edge_labels(): Modify label offsets for looped nodes.

@coveralls
Copy link

coveralls commented May 31, 2024

Pull Request Test Coverage Report for Build 9448236772

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.04%) to 95.837%

Files with Coverage Reduction New Missed Lines %
rustworkx-core/src/generators/random_graph.rs 2 85.04%
src/shortest_path/all_pairs_bellman_ford.rs 6 95.53%
Totals Coverage Status
Change from base Build 9447555728: -0.04%
Covered Lines: 17380
Relevant Lines: 18135

💛 - Coveralls

@maxwell04-wq
Copy link
Contributor Author

@mtreinish one major hiccup in the implementation is that the position of the edges is calculated on the plot in the draw_edges() function and the position of the labels can only be evaluated relative to the position of the nodes and not the edges in the draw_edge_labels() function. While the current parameters for the curved edges of multigraphs work for plotting the labels, maybe there's a better way to evaluate the position of the labels.

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

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

I think we need to work on the loop condition. You'll also need to add a release note (https://github.com/Qiskit/rustworkx/blob/main/CONTRIBUTING.md#release-notes)


reverse_edge = np.concatenate(([dst], [src]))
for edge in edge_pos: # the loop can be optimized
if bool(np.sum(np.all(np.equal(edge, reverse_edge)))):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there are easier and simpler ways to write this. I don't quite understand why we are using NumPy for this check either

@maxwell04-wq
Copy link
Contributor Author

@IvanIsCoding I have not tried to align the labels vertically as, following the logic of rad in connectionstyle=arc3, simply offsetting the y coordinates of labels to rad generates a figure wherein the labels are perfectly placed on the edges.
test_fig
Would you suggest that I work on aligning the edge labels?

# radius of edges
reverse_edge = [dst, src]
if (
len(np.where(np.all(edge_pos == reverse_edge, axis=(1, 2)))[0]) != 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this scales quadratically on the number of edges. O(E^2) is not ideal, if we plot a dense graph this is going to be a problem. You need to rewrite this condition using a set or something similar instead of naively looking through all the edges

Comment on lines 7 to 10
other:
- |
The radius of the edges of self-loops in multigraphs is set to `0.25`.
The edge labels are offset accordingly.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need the other section

- |
Fixes the plots of multigraphs using the `mpl_draw()` function. Refer to
`#12345 <https://github.com/Qiskit/rustworkx/issues/774>` for more
details.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The release notes would be better if you actually drew a multigraph with mpl_draw as an example. You can use

as an example, it becomes this: https://www.rustworkx.org/release_notes.html#new-features

@maxwell04-wq maxwell04-wq requested a review from IvanIsCoding June 8, 2024 22:52
@IvanIsCoding
Copy link
Collaborator

release_notes_2_0
It seems to be working, I will merge the PR

@IvanIsCoding IvanIsCoding added the automerge Queue a approved PR for merging label Jun 10, 2024
@IvanIsCoding IvanIsCoding merged commit 646057a into Qiskit:main Jun 10, 2024
SILIZ4 pushed a commit to SILIZ4/rustworkx that referenced this pull request Jul 4, 2025
* Update Qiskit#1: Fixing  mpl_draw() for multigraphs

* Update matplotlib.py for formatting

* Update rustworkx/visualization/matplotlib.py

Co-authored-by: Ivan Carvalho <[email protected]>

* Update matplotlib.py to remove the loop

* Add releasenotes

* Reformat connectionstyle string in rustworkx/visualization/matplotlib.py

Co-authored-by: Ivan Carvalho <[email protected]>

* Fixes Qiskit#774

* Optimize edge search by using sets

---------

Co-authored-by: Ivan Carvalho <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Queue a approved PR for merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mpl_draw() does not work for multigraphs

3 participants