Giter VIP home page Giter VIP logo

Comments (11)

joshuacwnewton avatar joshuacwnewton commented on June 28, 2024 1

Thank you for the detailed investigation! Taking a look now. :)

from spinalcordtoolbox.

jcohenadad avatar jcohenadad commented on June 28, 2024

I tried to checkout an older version of SCT (I wanted to specifically checkout 6.3, but ran into #4524, so I ended up randomly picking 8f2b0e0, which was before the introduction of LazyImport):

I still observe an error, so in the end this issue is likely not related to the LazyImports:

Terminal output
👉 PROCESSING: sub-MGH
Traceback (most recent call last):
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_label_utils.py", line 24, in <module>
    from spinalcordtoolbox.reports.qc import generate_qc
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/reports/qc.py", line 22, in <module>
    from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 1270, in <module>
    rcParams['backend'] = os.environ.get('MPLBACKEND')
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 738, in __setitem__
    raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key backend: 'module://matplotlib_inline.backend_inline' is not a valid value for backend; supported values are ['gtk3agg', 'gtk3cairo', 'gtk4agg', 'gtk4cairo', 'macosx', 'nbagg', 'notebook', 'qtagg', 'qtcairo', 'qt5agg', 'qt5cairo', 'tkagg', 'tkcairo', 'webagg', 'wx', 'wxagg', 'wxcairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
Traceback (most recent call last):
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_register_multimodal.py", line 34, in <module>
    from spinalcordtoolbox.reports import qc2
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/reports/qc2.py", line 20, in <module>
    from matplotlib.axes import Axes
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 1270, in <module>
    rcParams['backend'] = os.environ.get('MPLBACKEND')
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 738, in __setitem__
    raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key backend: 'module://matplotlib_inline.backend_inline' is not a valid value for backend; supported values are ['gtk3agg', 'gtk3cairo', 'gtk4agg', 'gtk4cairo', 'macosx', 'nbagg', 'notebook', 'qtagg', 'qtcairo', 'qt5agg', 'qt5cairo', 'tkagg', 'tkcairo', 'webagg', 'wx', 'wxagg', 'wxcairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']

Next suspicion: the declaration of %matplotlib inline in the notebook.

from spinalcordtoolbox.

jcohenadad avatar jcohenadad commented on June 28, 2024

I removed the declaration %matplotlib inline, but I still get the same error.

Googling around:

I manually set: %matplotlib notebook (as suggested in MPL doc), but I still get the same error. My suspicion is that inside SCT's sct_register_multimodal, we re-set MPL's backend.

from spinalcordtoolbox.

jcohenadad avatar jcohenadad commented on June 28, 2024

When I comment out this line, the notebook runs without error:

from spinalcordtoolbox.reports import qc2

Which suggests that one solution (probably not the best...) would consist in not running this line if QC report is not asked for.

from spinalcordtoolbox.

jcohenadad avatar jcohenadad commented on June 28, 2024

What I find strange, however, is how come we're only seeing this issue now... we've been using notebooks in other projects lately, and it included sct_register_multimodal, example here

from spinalcordtoolbox.

jcohenadad avatar jcohenadad commented on June 28, 2024

Hum, it's getting weirder-- if I run another sct_register_multimodal syntax (with other data and parameters), there is no crash:

image

from spinalcordtoolbox.

jcohenadad avatar jcohenadad commented on June 28, 2024

Ah! Interesting! When commenting out the SCT's call that comes before the call to sct_register_multimodal, there is no crash either:

image

OK, so... maybe running sct_label_utils somehow changes something about the state of MPL backend???

Nevermind... now it works even if I put back the sct_label_utils line...

from spinalcordtoolbox.

jcohenadad avatar jcohenadad commented on June 28, 2024

re-starting the notebook, re-running the cells, now it works without crash... i don't understand.

AH! ok, nevermind.. I had forgotten that I commented out the problematic import in sct_register_multimodal... ok starting the experiments again...

from spinalcordtoolbox.

jcohenadad avatar jcohenadad commented on June 28, 2024

ok, crash is consistent:

image

from spinalcordtoolbox.

jcohenadad avatar jcohenadad commented on June 28, 2024

also consistent when running it in ANOTHER notebook (the rf-shimming one):

image

from spinalcordtoolbox.

joshuacwnewton avatar joshuacwnewton commented on June 28, 2024

Briefly looking at issues in other repos, I see a few things:

  • module://matplotlib_inline.backend_inline should be a valid backend.
  • However, 2 other people are reporting this same error (1, 2), and their reports are relatively recent (18-19 days ago). This seems to suggest that this error may be due a recent change in matplotlib/jupyter/etc. Maybe the issue was always present, but matplotlib only started throwing the error in recent versions?

I was able to reproduce the issue depending on the state of the SCT repo:

  • If matplotlib-inline is installed in SCT's environment, there is no error.
  • If matplotlib-inline is uninstalled, then the error is thrown:
Traceback (most recent call last):
  File "/home/joshua/repos/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_register_multimodal.py", line 34, in <module>
    from spinalcordtoolbox.reports import qc2
  File "/home/joshua/repos/spinalcordtoolbox/spinalcordtoolbox/reports/qc2.py", line 30, in <module>
    import matplotlib
  File "/home/joshua/repos/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 1270, in <module>
    rcParams['backend'] = os.environ.get('MPLBACKEND')
  File "/home/joshua/repos/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 738, in __setitem__
    raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key backend: 'module://matplotlib_inline.backend_inline' is not a valid value for backend; supported values are ['gtk3agg', 'gtk3cairo', 'gtk4agg', 'gtk4cairo', 'macosx', 'nbagg', 'notebook', 'qtagg', 'qtcairo', 'qt5agg', 'qt5cairo', 'tkagg', 'tkcairo', 'webagg', 'wx', 'wxagg', 'wxcairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']

I'm not 100% sure why you only encountered this error sporadically. Perhaps the "sporadic" part was due to the LazyLoading? But, nonetheless, we should be able to fix this by adding matplotlib-inline to SCT's requirements.txt.

from spinalcordtoolbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.