You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose to remove the C++ quad contouring code that is in Matplotlib, which I originally wrote in 2014, and replace it with use of a new external dependency ContourPy.
ContourPy is a new Python/C++ project that contains the original (2005) and current (2014) Matplotlib contouring algorithms as well as a new one that includes more features and is faster is many situations. The project primarily exists to allow other Python libraries to have access to contouring without having to have Matplotlib as a dependency, but I am happy to do the work required for it to be used by Matplotlib as well.
The new algorithm is a complete rewrite, taking the good features of the previous two algorithms and replacing the bad features with better ones. There are new features which may be of interest eventually, such as the quad_as_tri option which divides each full quad into 4 triangles for contouring purposes, and support for multithreading (high risk at the moment). The major difference is that it supports a number of different return types so that, for example, you can request Matplotlib Path kind codes or not.
I recommend a conservative approach, which is to use the new algorithm but without any of the new features and using exactly the same return types that Matplotlib is used to. Later on we can look at those two areas which will give improved functionality and performance.
The changes for this can be done in a single PR (which I have waiting in the wings) as follows:
Delete the three src/_contour* files and remove the contour section from setupext.py.
Add the new dependency contour>=1 to setup.py, environment.yml and possibly other places in the CI config files.
In contour.py change the import statement and creation of a ContourGenerator object. This changes only ~6 lines of code.
Removing the tests of the internal contour API in test_contour.py.
Baseline image changes.
The latter all occur because the new contouring algorithm returns exactly the same lines/polygons but not necessarily starting with the same point. The Agg backend renders polygons with 4+ points exactly the same regardless of starting point, but it renders triangles differently. This is a feature/bug of Agg which has been around for years.
Your concerns should be ones of packaging and maintenance.
Packaging
ContourPy is written in C++11 and wrapped using pybind11. I don't use any C++ language features invented in the last 10+ years. Pybind11 is actively maintained and builds on all hardware/OS/Python version combinations. I have PyPI wheels available for all the hardware/OS/Python version combinations that Matplotlib supports plus a few others, all via cibuildwheel. There are conda-forge packages too.
The only runtime dependency is numpy.
Maintenance
I am the only maintainer of ContourPy and I expect it will stay that way although obviously I would welcome contributions from others. My job (https://makepath.com/) is in the areas of visualisation and spatial algorithms and ContourPy sits firmly in both camps, and I have a remit to use, develop and support Open Source projects, so the short to medium term future of ContourPy is assured. I suppose the other comment here is that I am already the de facto maintainer of the Matplotlib C++ contouring and tricontouring algorithms that I wrote, but I can only recall fixing one bug in each over the last 8 and 12 years respectively, both just after initial release, so you should not have any particular concerns about the quality of my C++.
If you don't want to go ahead with this change and would prefer to keep the existing C++ code in Matplotlib then I am fine with this. I am also OK with the idea of using ContourPy but via the existing mpl2014 algorithm (as I call it) which involves a PR with all the changes above except for the baseline image changes.
The text was updated successfully, but these errors were encountered:
I propose to remove the C++ quad contouring code that is in Matplotlib, which I originally wrote in 2014, and replace it with use of a new external dependency ContourPy.
ContourPy is a new Python/C++ project that contains the original (2005) and current (2014) Matplotlib contouring algorithms as well as a new one that includes more features and is faster is many situations. The project primarily exists to allow other Python libraries to have access to contouring without having to have Matplotlib as a dependency, but I am happy to do the work required for it to be used by Matplotlib as well.
The new algorithm is a complete rewrite, taking the good features of the previous two algorithms and replacing the bad features with better ones. There are new features which may be of interest eventually, such as the
quad_as_tri
option which divides each full quad into 4 triangles for contouring purposes, and support for multithreading (high risk at the moment). The major difference is that it supports a number of different return types so that, for example, you can request MatplotlibPath
kind codes or not.I recommend a conservative approach, which is to use the new algorithm but without any of the new features and using exactly the same return types that Matplotlib is used to. Later on we can look at those two areas which will give improved functionality and performance.
The changes for this can be done in a single PR (which I have waiting in the wings) as follows:
src/_contour*
files and remove thecontour
section fromsetupext.py
.contour>=1
tosetup.py
,environment.yml
and possibly other places in the CI config files.contour.py
change the import statement and creation of aContourGenerator
object. This changes only ~6 lines of code.test_contour.py
.The latter all occur because the new contouring algorithm returns exactly the same lines/polygons but not necessarily starting with the same point. The Agg backend renders polygons with 4+ points exactly the same regardless of starting point, but it renders triangles differently. This is a feature/bug of Agg which has been around for years.
Your concerns should be ones of packaging and maintenance.
Packaging
ContourPy is written in C++11 and wrapped using pybind11. I don't use any C++ language features invented in the last 10+ years. Pybind11 is actively maintained and builds on all hardware/OS/Python version combinations. I have PyPI wheels available for all the hardware/OS/Python version combinations that Matplotlib supports plus a few others, all via
cibuildwheel
. There are conda-forge packages too.The only runtime dependency is
numpy
.Maintenance
I am the only maintainer of ContourPy and I expect it will stay that way although obviously I would welcome contributions from others. My job (https://makepath.com/) is in the areas of visualisation and spatial algorithms and ContourPy sits firmly in both camps, and I have a remit to use, develop and support Open Source projects, so the short to medium term future of ContourPy is assured. I suppose the other comment here is that I am already the de facto maintainer of the Matplotlib C++ contouring and tricontouring algorithms that I wrote, but I can only recall fixing one bug in each over the last 8 and 12 years respectively, both just after initial release, so you should not have any particular concerns about the quality of my C++.
If you don't want to go ahead with this change and would prefer to keep the existing C++ code in Matplotlib then I am fine with this. I am also OK with the idea of using ContourPy but via the existing
mpl2014
algorithm (as I call it) which involves a PR with all the changes above except for the baseline image changes.The text was updated successfully, but these errors were encountered: