Skip to content

Fix QuantumCircuit.draw without matplotlib installed#8737

Merged
mergify[bot] merged 2 commits intoQiskit:mainfrom
jakelishman:fix-draw-with-no-matplotlib
Sep 13, 2022
Merged

Fix QuantumCircuit.draw without matplotlib installed#8737
mergify[bot] merged 2 commits intoQiskit:mainfrom
jakelishman:fix-draw-with-no-matplotlib

Conversation

@jakelishman
Copy link
Copy Markdown
Member

Summary

A recent change to the structure of the visualisation module in #8306 caused matplotlib to be eagerly imported when qiskit.visualization was imported, since the internal bloch module was imported in the __init__. This means that QuantumCircuit.draw() in text mode had ceased working without the visualisation extra installed.

This module doesn't really need to be eagerly imported, and it's faffy to refactor it all to use lazy imports.

Details and comments

I've seen a couple of CI failures in the QPY backwards-compatibility tests seemingly caused by this. It's odd they didn't prevent the initial merge, but maybe some internal dependencies re-organised themselves around the same time.

A recent change to the structure of the visualisation module in Qiskit#8306
caused `matplotlib` to be eagerly imported when `qiskit.visualization`
was imported, since the internal `bloch` module was imported in the
`__init__`.  This means that `QuantumCircuit.draw()` in text mode had
ceased working without the visualisation extra installed.

This module doesn't really need to be eagerly imported, and it's faffy
to refactor it all to use lazy imports.
@jakelishman jakelishman added type: qa Issues and PRs that relate to testing and code quality Changelog: None Do not include in the GitHub Release changelog. labels Sep 13, 2022
@qiskit-bot
Copy link
Copy Markdown
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:

@mtreinish
Copy link
Copy Markdown
Member

Yeah, those shouldn't have been in the top level both because of potentially dragging mpl in to the import too early without an optional check, but also we don't want to re-xport those as part of the interface

@coveralls
Copy link
Copy Markdown

coveralls commented Sep 13, 2022

Pull Request Test Coverage Report for Build 3047539200

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.0002%) to 84.319%

Totals Coverage Status
Change from base Build 3047057501: -0.0002%
Covered Lines: 57878
Relevant Lines: 68642

💛 - Coveralls

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 the GitHub Release changelog. type: qa Issues and PRs that relate to testing and code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants