Skip to content
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

Prequel to if/else changes to mpl circuit drawer #10096

Merged
merged 26 commits into from
Jun 20, 2023

Conversation

enavarro51
Copy link
Contributor

Summary

Needed changes to base mpl drawer before implementing if/else display.

Details and comments

This PR changes some of the structure of the mpl circuit drawer as a prelude to providing a full display of the interior of if/else gates. About 200 lines of code are changed and most are repetitive variable name changes. The changes are

  • Remove the Anchor class from the drawer. This class was mostly redundant and just added complexity. The plot_coords method and the x_index attribute were retained and are now part of the MatplotlibDrawer class.
  • In order to handle nested ControlFlowOps, it's most efficient to call the drawer class recursively. But only a few of the drawer methods are needed. Therefore for simplicity is was necessary to remove some attributes, such as _data and _wire_map and initiate these variables in the draw method and pass them to subsequent methods. The majority of the changes are these variable changes.
  • Layer widths are now stored on a per-node basis instead of a layer number basis. This is necessary for the nodes in the recursive calls as the layer numbering is reset at each recursion.

These changes have been tested with all the existing ipynb image tests and the functionality of the drawer should be unchanged from the current main mpl drawer.

@enavarro51 enavarro51 requested review from a team and nonhermitian as code owners May 10, 2023 14:46
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label May 10, 2023
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

@coveralls
Copy link

coveralls commented May 10, 2023

Pull Request Test Coverage Report for Build 5137779293

  • 127 of 206 (61.65%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 85.933%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/visualization/circuit/matplotlib.py 127 206 61.65%
Totals Coverage Status
Change from base Build 5127277220: 0.02%
Covered Lines: 71292
Relevant Lines: 82962

💛 - Coveralls

@jakelishman jakelishman self-assigned this May 16, 2023
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

If I understand correctly, most of this is about removing some of the global state from MatplotlibDrawer, and passing it a little more explicitly around in the (to be added) recursive calls? I'm totally on board with that.

Removing the Anchor class also seems fine to me, and it's super promising that the tests didn't need any modifications with this. Thanks Edwin!

@jakelishman jakelishman added the Changelog: None Do not include in changelog label Jun 15, 2023
@jakelishman jakelishman added this pull request to the merge queue Jun 15, 2023
@jakelishman jakelishman removed this pull request from the merge queue due to a manual request Jun 15, 2023
@jakelishman
Copy link
Member

Wait sorry, I just realised that the MPL tests don't run in the standard format (at least without #9961) - I'll probably merge this in a sec, I'll just check the outputs locally first.

@jakelishman
Copy link
Member

I've verified locally that this PR introduces no changes to the visual test suite compared to main.

@jakelishman jakelishman added this pull request to the merge queue Jun 20, 2023
Merged via the queue into Qiskit:main with commit 57cd30f Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: visualization qiskit.visualization
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants