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

Fix Matplotlib renderer.M deprecation #6728

Closed
wants to merge 2 commits into from
Closed

Fix Matplotlib renderer.M deprecation #6728

wants to merge 2 commits into from

Conversation

splch
Copy link
Contributor

@splch splch commented Jul 13, 2021

Summary

When plotting a bloch sphere using Matplotlib version 3.4.2, the following deprecation warning is given:

/opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69: MatplotlibDeprecationWarning: 
The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use self.axes.M instead.
  x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)

By changing x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) to x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M), the warning is fixed.

Details and comments

Version information:

Qiskit Software Version
Qiskit 0.27.0
Terra 0.17.4
Aer 0.8.2
Ignis 0.6.0
Aqua 0.9.2
Matplotlib 3.4.2

By changing ```x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)``` to ```x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M)```, the following warning is fixed:
```
/opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69: MatplotlibDeprecationWarning: 
The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use self.axes.M instead.
  x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
```
@splch splch requested review from nkanazawa1989, nonhermitian and a team as code owners July 13, 2021 03:02
@jakelishman
Copy link
Member

We made the same change in qutip/qutip#1556. Given that this is the same file (give or take), there's another change about deprecated automatic adding of axes to figures (see qutip/qutip#1503) that might be necessary as well?

@mtreinish
Copy link
Member

I looked at this problem back when matplotlib 3.4 was first released here: #6087 the issue we hit is that there doesn't seem to be a way to thread the needle on our current minimum supported matplotlib version and fixing the deprecation warnings. The only way we can fix this is deciding to bump our minimum matplotlib version

@jakelishman
Copy link
Member

In QuTiP we parsed the matplotlib version from matplotlib.__version__, and then just branched on the version:
https://github.com/qutip/qutip/blob/833cea2be5a0ac503e4fc925a0a0313718f76e85/qutip/bloch.py#L23-L29

It's not the most elegant, but I was of the same opinion as you about maintaining a good period of compatibility. For reference, mpl 2.1 is January 2018, and 3.0 is September 2018. If 0.19 is planned for late (late late) September, then bumping to mpl 3.0 will keep a 3-year compatibility window, and ease a couple of the branching requirements.

@mtreinish
Copy link
Member

Since this was opened we've had to make a bunch of changes to the bloch sphere visualization to fix compatibility with newer matplotlibs (v3.5.0 kind of forced our hands because it broke compatibility with other things). This was incorporated into the those changes which were released as part of the 0.19.0 release. So, this PR no longer applies to the repo, so I'm going to close this now. Thanks for tackling this earlier even if didn't end up merging in this form and please feel free to re-open this if I'm missing something or there is more to discuss on this.

@mtreinish mtreinish closed this Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants