unibe-cns / NEAT

NEAT (NEural Analysis Toolkit)
Other
12 stars 15 forks source link

Bump to matplotlib 3 #114

Closed pythonjam closed 3 years ago

pythonjam commented 3 years ago

When installing NEAT under Ubuntu Linux 18, by default the newest version of matplotlib (currently 3.3.3) gets installed. However this version is not compatible and needs to be downgraded.

Traceback (most recent call last): File "/home/name/blah/NEAT/examples/models/channels/TestCaseEvaluation.py", line 7, in from examples.models.channels.channels_hay import Na_Ta File "/home/name/blah/NEAT/examples/models/channels/channels_hay.py", line 3, in from neat import IonChannel File "/home/name/blah/NEAT/neat/init.py", line 13, in from .trees.morphtree import MorphTree File "/home/name/blah/NEAT/neat/trees/morphtree.py", line 17, in from mpl_toolkits.axes_grid1 import make_axes_locatable File "/home/name/.local/lib/python3.6/site-packages/mpl_toolkits/axes_grid1/init.py", line 3, in from .axes_grid import Grid, ImageGrid, AxesGrid File "/home/name/.local/lib/python3.6/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line 22, in class CbarAxesBase: File "/home/name/.local/lib/python3.6/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line 29, in CbarAxesBase @cbook._rename_parameter("3.2", "locator", "ticks") AttributeError: module 'matplotlib.cbook' has no attribute '_rename_parameter'

The workaround is to downgrade to 2.2.5 with pip3 install --upgrade matplotlib==2.2.5

In the long term it may be a good idea to upgrade to matplotlib 3

We should probably at least edit the requirements.txt with something like matplotlib>=2.1.2,<=2.2.5

benelot commented 3 years ago

@WillemWybo I think it would be great anyway if our requirements would be bounded and >= alone. This leads to exactly the case we experience here that an fresh install leads to the user pulling all the newest releases, which might be breaking. I think it would be best to encode at least all the highest minor versions into the file based on the current minimum requirement (major.minor.bug on the version list). What is weird is why the build system still works with it as this should occur there.

WillemWybo commented 3 years ago

Strange, I upgraded my matplotlib to version 3.3.3 (Python version 3.7.6) and I can't reproduce the problem. All tests pass for me.

@benelot Don't we run the risk then of ending up with an outdated software tool? At least if the tests uncover problems related to new versions of software on which NEAT depends, we can update NEAT and stay up to date. @pythonjam seems like this is a matplotlib bug? when you just run from mpl_toolkits.axes_grid1 import make_axes_locatable in a python console, do you experience the same problem?

WillemWybo commented 3 years ago

I googled for the error, and while I don't find an exact reproduction, is seems similar errors occur when multiple versions of matplotlib are installed (eg https://github.com/matplotlib/matplotlib/issues/17128 or https://stackoverflow.com/questions/53421905/matplotlib-attributeerror-module-matplotlib-cbook-has-no-attribute-define-a )

benelot commented 3 years ago

@WillemWybo Our software tool ends up outdated if we do not update the tool :) The illusion of always being up to date by allowing the users to install the library with the newest version of the dependencies is very trappy, as you basically let users test your package with dependency versions you probably did not test it with (as they might get incompatible in the future). This can turn into a broken library and even worse into a library with unnoticed, incorrect behaviour. It would be better to be sure with which libraries it works and set those than to optimistically believe it will work forever when it surely does not. I'd rather install a very old version of matplotlib and be fine with it than having a broken library, and our users need to fix it. To stay up to date, we need to test from time to time if NEAT still works with newer versions, if so, bump up the maximal library version defintion, else actively migrate to the newer library or stay with the old definition.

pythonjam commented 3 years ago

I did a binary search to find out at which version the problem starts for me and it's actually after 3.1.0. So the first version that causes errors is 3.1.1 (note this error is different, but similar in nature):

Traceback (most recent call last): File "/home/name/blah/NEAT/examples/models/channels/TestCaseEvaluation.py", line 7, in from examples.models.channels.channels_hay import Na_Ta File "/home/name/blah/NEAT/examples/models/channels/channels_hay.py", line 3, in from neat import IonChannel File "/home/name/blah/NEAT/neat/init.py", line 13, in from .trees.morphtree import MorphTree File "/home/name/blah/NEAT/neat/trees/morphtree.py", line 18, in from mpl_toolkits.mplot3d import Axes3D File "/home/name/.local/lib/python3.6/site-packages/mpl_toolkits/mplot3d/init.py", line 1, in from .axes3d import Axes3D File "/home/name/.local/lib/python3.6/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 34, in from . import axis3d File "/home/name/.local/lib/python3.6/site-packages/mpl_toolkits/mplot3d/axis3d.py", line 457, in class XAxis(Axis): File "/home/name/.local/lib/python3.6/site-packages/mpl_toolkits/mplot3d/axis3d.py", line 458, in XAxis get_view_interval, set_view_interval = maxis._make_getset_interval( AttributeError: module 'matplotlib.axis' has no attribute '_make_getset_interval'

So for now I would suggest matplotlib>=2.1.2,<=3.1.0 At least based on my experience on ubuntu 18

I should also mention that I don't have the python 2 version of matplotlib installed. Only for python 3 version is installed

@WillemWybo no, oddly if I start python3 in terminal with matplotlib version 3.1.1 installed I don't get any error on from mpl_toolkits.axes_grid1 import make_axes_locatable but when I run code to reproduce issue 81 I get the error above. 3.1.0 is the highest version for me where nothing breaks

pythonjam commented 3 years ago

I just tested the multiple installations theory and it may be the actual reason. I executed

sudo apt remove python3-matplotlib python-matplotlib-data

https://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip "Pip currently ignores uninstall commands that try to uninstall something owned by the OS"

Then I installed matplotlib 3.3.3 again. This time it introduces a new conflict with numpy:

RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb Traceback (most recent call last): File "/home/name/blah/NEAT/examples/models/channels/TestCaseEvaluation.py", line 7, in from examples.models.channels.channels_hay import Na_Ta File "/home/name/blah/NEAT/examples/models/channels/channels_hay.py", line 3, in from neat import IonChannel File "/home/name/blah/NEAT/neat/init.py", line 13, in from .trees.morphtree import MorphTree File "/home/name/blah/NEAT/neat/trees/morphtree.py", line 13, in import matplotlib.patheffects as patheffects File "/home/name/.local/lib/python3.6/site-packages/matplotlib/init.py", line 174, in _check_versions() File "/home/name/.local/lib/python3.6/site-packages/matplotlib/init.py", line 159, in _check_versions from . import ft2font ImportError: numpy.core.multiarray failed to import

Which may indicate that I may also need to get rid of OS owned numpy. For all I know this will trigger a whole chain of libraries that were installed by the OS that now need to be uninstalled.

pythonjam commented 3 years ago

Yes, I think it's likely a debian specific pip problem

https://github.com/pypa/pip/issues/4222 https://github.com/pypa/pip/issues/6143

Now I'm thinking about renaming the issue to "pip3 mishandling of OS owned libraries when installing NEAT on debian"? Let me know if I should do that

On the general matter of version bumping, I believe github offers dependabot now. It's a bot that creates PR's for outdated dependecies (Settings -> Security and Analysis -> Dependabot alerts)