Skip to content

[Bug]: Possible issue with Matplotlib 3.9.1 wheel on Windows only #28551

Closed
howsoai/howso-engine-recipes
#153

Description

@ianthomas23

Bug summary

Since the release of Matplotlib 3.9.1 I have been experiencing CI failures on ContourPy on Windows only that did not occur with Matplotlib 3.9.0. There is some info in my PR contourpy/contourpy#406 that works around it by pinning matplotlib<3.9.1 on Windows. I am not really sure what the problem is, but I now have a simple reproducer.

Code for reproduction

from contourpy import contour_generator
import matplotlib.pyplot as plt

print("START")
cont_gen = contour_generator(z=[[0, 1], [2, 3]])
try:
    cont_gen.filled(2.0, 1.0)
except Exception as e:
    print("EXCEPTION HANDLER", e)
print("END")

Actual outcome

If you run the above code with matplotlib 3.9.1 and contourpy 1.2.1 (the latest releases) it works OK with correct output of

START
EXCEPTION HANDLER upper_level must be larger than lower_level
END

Note the code imports some of matplotlib but does not use it, and the contourpy code here does not use it either.

If you use matplotlib 3.9.1 or nightly wheel and contourpy nightly wheel then it silently crashes for me with just

START

But if you comment out the import matplotlib... line it works OK again. Use of matplotlib 3.9.0 and any contourpy (1.2.1 or nightly wheel) is always OK.

For my installations here I am pip installing into python-only conda environments, i.e.

conda create -n temp python=3.12
conda activate temp
pip install matplotlib contourpy

Expected outcome

See above.

Additional information

There is a relevant post by @BertJorissen on the pybind11 gitter which has some in-depth analysis and leads me to believe that this is not just a ContourPy problem.

Operating system

Windows only

Matplotlib Version

>= 3.9.1

Matplotlib Backend

No response

Python version

I see same results for python 3.8 to 3.12.

Jupyter version

No response

Installation

pip

Activity

  1. ianthomas23 commented on Jul 12, 2024

    @ianthomas23
    MemberAuthor

    I suppose the first stage here is to confirm if any other Matplotlib devs can reproduce this on Windows.

  2. BertJorissen commented on Jul 14, 2024

    @BertJorissen

    Hi Ian
    my problem originated from using inheritance on an Pybind11-class, which has a function that throws some error.
    I see that your function above calls SerialContourGenerator, which is a child class from the Pybind11-ContourGenerator, which will throw a std::invalid_argument-exception. It thus seems to be the same issue indeed.
    The error comes from matplotlib, as both my test program and contourpy work happily next to each other, but they crash when matplotlib has been loaded (but not necessarily used).
    From comparing the releases 3.9.0 and 3.9.1, there does not seem to be any problem that I can point out immediately.
    I see however that the wheels are also repaired on windows. I'm not sure if this is necessary. When I turned this repairing on before, my package seemed to behave weirdly.
    Best
    Bert

  3. story645 commented on Jul 14, 2024

    @story645
    Member

    I can't reproduce b.c I keep getting this error when trying to install nightly:

    ERROR: Could not find a version that satisfies the requirement numpy>=1.23 (from contourpy) (from versions: 2.1.0.dev0)
    ERROR: No matching distribution found for numpy>=1.23
  4. ianthomas23 commented on Jul 15, 2024

    @ianthomas23
    MemberAuthor

    @story645 I use something like this:

    python -m pip install "matplotlib==3.9.1"
    python -m pip install --only-binary=:all: --pre --upgrade --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple contourpy

    to give matplotlib 3.9.1, numpy 2.0.0 and contourpy 1.3.0.dev1

  5. story645 commented on Jul 17, 2024

    @story645
    Member

    Thanks @ianthomas23 and ran your code and can reproduce:

    • w/ matplotlib: crashes after START
    • w/o matplotlib: no crash
  6. ianthomas23 commented on Jul 24, 2024

    @ianthomas23
    MemberAuthor

    I've created a repo to demonstrate this at https://github.com/ianthomas23/mpl-test. If you look at the github action run https://github.com/ianthomas23/mpl-test/actions/runs/10079751371 you'll see that it uses the reproducer code from above both with and without the matplotlib import for various combinations of mpl and contourpy versions. The interesting addition is a run that builds mpl 3.9.1 from source using MSVC and this passes the tests, compared to the official wheel (built using the cibuildwheel machinery in the mpl repo) which fails the tests.

  7. nquetschlich commented on Jul 24, 2024

    @nquetschlich

    I am very happy that I stumbled over this issue because since two weeks, also the CI pipeline for one of our open-source projects fails on windows without any (useful) error message (see, e.g., https://github.com/cda-tum/mqt-predictor/actions/runs/9824223458/job/27126370262).
    Unfortunately I do not have the time to create a minimal working example, but downgrading Matplotlib to <v3.9.1 solved the issue (see munich-quantum-toolkit/predictor#258).

    I just wanted to mention it, seems like we ran into the same issue as you did.

  8. added
    Release critical
    on Aug 1, 2024
  9. ianthomas23 commented on Aug 1, 2024

    @ianthomas23
    MemberAuthor

    I have labelled this "release critical" as there is evidence of 3 downstream libraries suffering crashes on Windows using Matplotlib 3.9.1, so it is not specific to ContourPy. I need help with this.

  10. added this to the v3.9.2 milestone on Aug 1, 2024
  11. tacaswell commented on Aug 1, 2024

    @tacaswell
    Member

    So to summerize:

    • 3.9.0 wheels work
    • 3.9.1 + nightly wheels do not work
    • locally built wheels work

    Given that locally built wheels work I suspect that this is not a problem in Matplotlib source, but is something is the build process. My two suspicions are:

    • a delvewheel bug
    • a pybind11 bug

    It looks like delvewheel had releases on April 17 (1.6.0), Jun 20 (1.7.0) and July 3 (1.7.1). We did 3.9.1 on July 4 and 3.9.0 on May 15 so that means we likely got delvewheel 1.6.0 for mpl3.9.0 and 1.7.1 for mpl3.9.1.

    It looks like pybinb11 had release on Mar 27 (2.12.0), Jun 25 (2.13.0) and Jun 26 (2.13.1) which means we likely got 2.12.0 for mpl3.9.0 and 2.13.1 for mpl3.9.1. However, given that locally built wheels work (and CI has kept working), I am a bit skeptical that it is pybind11 alone. However, I do have some concern that there could be some interaction between c-extensions using pybind11 with different versions of pybind11 conflicting with each other. I have never seen any discussion of this being a concern and I trust the pybind11 devs that if this were a known issue they would make it well known, but I do not actually understand how pybind11 works well enough to to explain why it is not a possible problem so would like my assumption checked.

    Open technical question:

    • do we see this problem with 3.9.1 from conda-forge?
    • if a working locally built wheel is run through delvewheel does it then break? If so, can you try multiple versions to see if that affects it.
    • does changing the version of pybind11 used locally have any affect?
    • if we put the minimal example in our test suite, do our windows builds start failing? I suspect not, but we should check (I'll do that right after I post this comment)

    Open policy question:

    • should we remove the windows 3.9.1 wheels from pypi?

    I'm going to put this on our meeting agenda for the call today.

  12. 72 remaining items

  13. added a commit that references this issue on Sep 11, 2024
  14. jfuruness commented on Sep 12, 2024

    @jfuruness

    On github actions, on windows, using pypy3 and matplotlib 3.9.2, I get what seems to be the same error. Oddly though, I only get the error on certain repos of mine that use matplotlib, and not others:

      .tox\pypy3\lib\site-packages\matplotlib\__init__.py:159: in <module>
          from . import _api, _version, cbook, _docstring, rcsetup
      .tox\pypy3\lib\site-packages\matplotlib\cbook.py:32: in <module>
          from matplotlib import _api, _c_internal_utils
      E   ImportError: The specified module could not be found
    
  15. tacaswell commented on Sep 12, 2024

    @tacaswell
    Member

    @jfuruness I suspect your issues is that you are using pypy310 which we do not provide wheels for (yet) and something is going wrong with your local build. Please see the install docs on building from source on windows.

  16. jfuruness commented on Sep 13, 2024

    @jfuruness

    @tacaswell Ah I didn't realize, thank you for the explanation. Looking at a few of the past prior releases I don't see wheels for pypy310, is there a plan to add these in the future (and perhaps a gh issue I could follow)?

  17. QuLogic commented on Sep 13, 2024

    @QuLogic
    Member

    We were waiting for NumPy wheels numpy/numpy#24728; it looks like those are out, but they didn't close the issue, so I wasn't notified.

  18. jfuruness commented on Sep 13, 2024

    @jfuruness

    @QuLogic Ah makes sense, sounds good! Thank you both for you support of matplotlib!

  19. added a commit that references this issue on Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Release criticalstatus: confirmed bugthird-party integration: contourpy

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions