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

[ENH, MRG] Add object-oriented widget abstraction #10913

Merged
merged 29 commits into from
Aug 4, 2022

Conversation

alexrockhill
Copy link
Contributor

@alexrockhill alexrockhill commented Jul 8, 2022

Fixes #10779
Superceeds #10803

Follows @larsoner 's advice to split the abstraction up into a first PR and per conversation @drammock and @hoechenberger 's adds onto existing backend without replacing for now.

@alexrockhill
Copy link
Contributor Author

Huh odd, it seems like maybe a new pyvista release is causing things to fail. I undid all the changes to names (just named the new abstraction different names) and it doesn't fail any of the new tests, only the brain scraper which uses the old abstraction. I think this is good to go, I've tested it locally and things look good.

@alexrockhill
Copy link
Contributor Author

Except I think 3D rendering is broken in notebook with the latest versions of 3D rendering packages, I tried with a fresh install because I thought it was just installing the development version of ipywidgets which broke other things... I think there are some stability issues with notebook...

@alexrockhill
Copy link
Contributor Author

Ah I had to pip install pyvista[all] and then it worked great. Having used notebook a lot more for this PR, I still do stand by that you really don't know what you're going to get when you launch it; sometimes widgets don't render in the classic notebook sometimes they don't render in jupyter lab, sometimes you can't focus on the widgets to do the keypresses and you just restart the kernel, relaunch the notebook, uninstall reinstall etc. until things work. With a fresh install I have things working on my machine great now, this is ready for review.

The one thing I still haven't figured out is simulating keypresses in notebook, I might still give that a few minutes try.

@alexrockhill
Copy link
Contributor Author

alexrockhill commented Jul 12, 2022

This is ready for review besides the test failures which I am at a loss to explain; the code that they are executing is untouched, the new code is added on top in a way that should be completely compatible. Then there are some unrelated failures to load the headless display backend that also fail on main. I can't replicate the test failures locally either...

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure is indeed weird, let me try making a PR to PyVista to work around this issue...

mne/viz/backends/renderer.py Show resolved Hide resolved
@alexrockhill
Copy link
Contributor Author

alexrockhill commented Jul 13, 2022

I have a PR to pyvista currently to fix the mesh point error.

It merged also so that should be fixed.

@larsoner
Copy link
Member

Okay the failures look real/relevant now @alexrockhill

@alexrockhill
Copy link
Contributor Author

Okay the failures look real/relevant now @alexrockhill

Hmm, it passes locally for me. Maybe that shouldn't be tested on Windows? The code that gets the renderer and the renderer itself is completely untouched as far as I can tell so this is where I'm very confused about where the failure is coming from.

@larsoner
Copy link
Member

Maybe that shouldn't be tested on Windows?

It works on the existing backend so it should work on the new / refactored one

The code that gets the renderer and the renderer itself is completely untouched as far as I can tell so this is where I'm very confused about where the failure is coming from.

I would try adding some logger.debug statements and running the scraper code with 'debug' log level and see where it fails

@larsoner
Copy link
Member

... or maybe better, get a Windows VM or boot running and test there, but that is some work though they are available:

https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/

Maybe this plus our latest windows installer would make this not too painful?

@alexrockhill
Copy link
Contributor Author

alexrockhill commented Jul 18, 2022

I have access to a Windows machine and I tried to pip install and got an error with vtk that it couldn't find an OpenGL version so I switched to the standalone executable installer which has been going for half an hour with no signs of progress after Preparing transaction: ... working... done. cc @hoechenberger

EDIT: Actually it did finish after about half an hour. But then I have mne version 0.24.0 in ipython and no version found with just python. I'm quite confused on where my python installation is supposed to be.

So it's been pretty painful so far...

I'll try just pushing an empty commit again. Maybe something has changed in the last couple days because again I only added new classes, I changed it so that I didn't touch any of the old backend abstraction.

I guess the thing I don't really understand is why this would be failing on Windows but not the other operating systems even if there were changes to the backend code...

@alexrockhill
Copy link
Contributor Author

Ah well it looks like there's all new unrelated test failures this time around

@larsoner
Copy link
Member

Let's see how #10933 does

@larsoner
Copy link
Member

Feel free to rebase or merge with main and push

@alexrockhill
Copy link
Contributor Author

Ok I finally got it running locally on Windows and it fails but with an error past the current failure.

Normally, I would 100% agree with you @larsoner that because the CI passed before I did anything and then failed when I changed the code that it's something in the code but the results are all over the place with this backend stuff so I really don't know what's going on or how to fix it.

Screen Shot 2022-07-18 at 3 22 42 PM

requirements.txt Outdated Show resolved Hide resolved
@larsoner
Copy link
Member

Agreed in #10935 (comment)

@alexrockhill
Copy link
Contributor Author

@larsoner, I think the failures are from the pyvista bump to dev. I'm not exactly sure how to solve that, do you have any ideas?

@alexrockhill
Copy link
Contributor Author

Huh okay so it looks like ipympl maybe causes some major issues on Windows. It's odd that these didn't fail before... If it's not installed, matplotlib just plain doesn't work in notebook which is the case in main right now, there just isn't a time-series plot for source estimates. Not sure where to go from here...

@alexrockhill
Copy link
Contributor Author

Hmm okay patched everything but clicks don't work for some reason in pip installed Windows, I'll have to see what dependencies are different

@alexrockhill
Copy link
Contributor Author

So the difference that is causing the failed tests is that pympl was not installed by conda. Without it, the plots don't actually show up in notebook so I think it should be added as a dependency we should figure out how to get all the failed tests on Windows to pass. It appears to have to do with things not having the focus and therefore not receiving clicks. I might have some time to work on this, but if anyone else wants, especially who wrote those parts, please do jump in. Here are the failed tests: https://dev.azure.com/mne-tools/mne-python/_build/results?buildId=20791&view=logs&j=dded70eb-633c-5c42-e995-a7f8d1f99d91&t=8394206f-a00b-5cb7-44ca-464c9d5f9e25, they're mostly in plot_3d.py and indirectly through things like topomaps.

@larsoner
Copy link
Member

So the difference that is causing the failed tests is that pympl was not installed by conda. Without it, the plots don't actually show up in notebook so I think it should be added as a dependency we should figure out how to get all the failed tests on Windows to pass.

So this is a problem in main we just haven't noticed up to this point, right? If so, let's just add conditional skips in this PR, and follow up with a fix to the newly created #10961 in another PR. That way you can start actually using this infrastructure and tackle CI/testing infrastructure issues when you or someone else is motivated later.

Comment on lines 399 to 401
# see https://github.com/mne-tools/mne-python/issues/10961
@pytest.mark.skipif(
sys.platform.startswith('win'), reason='Needs fix on Windows')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, it's all of these? I thought it was just notebook stuff that was broken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it was 22 failed tests, I think about 12 were unique to parameterization. I have no idea why they are failing, I raised the issue in ipympl above because it seemed so odd. They work on Linux/MacOS so it seems like there is an underlying ipympl settings issue that causes odd things to happen. I can get on a Windows computer and have a look in 3 hours (in use right now).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I assumed the ipympl stuff just meant that we would skip a couple of isolated notebook tests, but these are core viz tests. If ipympl installation breaks this many tests on Windows, we might be better off uninstalling ipympl from windows for now so we don't have to skip these tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, okay, then notebook won't render matplotlib plots on Windows I think. I'll take a quick look at ipympl CIs and see if they test this kind of thing or what.

Copy link
Contributor Author

@alexrockhill alexrockhill Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that was quick, they don't have any CIs that run on Windows so I think that would be the issue. That really creates a headache for notebook support... as in, probably a bad idea to support the notebook backend on Windows when ipympl doesn't. I think beyond just uninstalling ipympl on Windows, there should be some documentation about this lack of support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the tests will pass without ipympl on Windows for this PR but I'm pretty sure the GUIs won't render properly. If we just do that in the CIs then the GUIs will work if someone installs via the requirements.txt file but these core viz tests fill fail and there could be more trouble. If we remove it from the requirements.txt, then maybe we should officially remove support for GUIs on Windows so that people know that it's not supposed to work. It's really bad that if someone just installs ipympl on Windows, the basic functionality of their MNE installation might break... That might be worth mentioning somewhere as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the tests will pass without ipympl on Windows for this PR

Good!

but I'm pretty sure the GUIs won't render properly...

This is all the case on main, correct?

Let me iterate again -- if it's the case on main, then please let's deal with it in different PR where we figure out how to fix things properly. Adopting the new abstraction framework -- which this PR moves us toward -- is separable from how things work on windows, at least to the extent that things on windows are in the same state/probably broken with our current framework on main as well.

If we try to tackle these two problems simultaneously, then it creates a review nightmare, and prevents any new progress with a new framework (that you advocated for so strongly!). We could tackle the ipympl-and-testing-on-windows first and then come back to this PR if you really want, but then this PR is stuck and you can't use your new framework.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this should all be broken on main, it's just coming up because to get things to work properly for the abstraction, you need ipympl. I just pushed a commit that hopefully should pass, is that what you were thinking?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's more or less the idea, but don't forget to remove all the skipifs since we don't need them now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're all gone in the diff.

I left the one on brain scraper because it seems like it's actually a separate issue; here's the CI where it alone failed (https://dev.azure.com/mne-tools/mne-python/_build/results?buildId=20714&view=logs&j=dded70eb-633c-5c42-e995-a7f8d1f99d91&t=8394206f-a00b-5cb7-44ca-464c9d5f9e25).

@alexrockhill
Copy link
Contributor Author

Ok, it took an extra 2 minutes and 45 seconds to uninstall ipympl in conda but looks like all the tests pass now ipympl is only installed for Linux/MacOS https://dev.azure.com/mne-tools/mne-python/_build/results?buildId=20896&view=logs&j=2bd7b19d-6351-5e7f-8417-63f327ab45bc&t=ad0e667f-a008-5b85-3355-13ec37736b34. The downside is that you can't specify operating system-dependent packages in the environment.yml file the way you can in a requirements.txt file so it was done on the CI side for conda. Other than that, good to go I think.

requirements.txt Outdated Show resolved Hide resolved
@alexrockhill
Copy link
Contributor Author

Do you want to wait to merge this until after the release? Otherwise, I think this is okay now

@alexrockhill
Copy link
Contributor Author

Do you want to wait to merge this until after the release? Otherwise, I think this is okay now

Any thoughts on a plan for this @larsoner? No need to rush merging just wanted to get your thoughts.

@larsoner
Copy link
Member

larsoner commented Aug 2, 2022

We should release 1.1 in the next day or two so let's merge after that, then you can make use of this framework!

@alexrockhill
Copy link
Contributor Author

Sounds good, okay to merge?

@larsoner larsoner merged commit 4c219c2 into mne-tools:main Aug 4, 2022
@larsoner
Copy link
Member

larsoner commented Aug 4, 2022

Yes, thanks @alexrockhill !

Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't pretend to have carefully reviewed / assessed the implementation, but the changes look reasonable and the code is pretty clear. Aside from a couple fairly minor comments/questions LGTM. I'll let @larsoner push the green button

Comment on lines +43 to +46
try: # remove when pyvista 0.35.2 patch is released
_close_all()
except AttributeError:
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyvista 0.36.1 is latest release, do we still need this?

mne/viz/backends/_notebook.py Show resolved Hide resolved
_AbstractCanvas.__init__(
self, width=width, height=height, dpi=dpi)
self.fig = Figure(figsize=(width, height), dpi=dpi)
self.ax = self.fig.add_subplot(111, position=[0.15, 0.15, 0.75, 0.75])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious where these position values come from, are they arbitrary? tailored to a specific kind of inset plot (i.e. the traces from clicked verts in a Brain GUI)? Wondering if we'll regret hard-coding this later, if some other plot type gets inserted here (e.g., I can easily imagine a time-freq image plot making sense in a Brain GUI, but potentially any others?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just to give more room on the edges so things don't get cut off. Tight layout doesn't play nicely with all the Qt stuff... Otherwise all the coordinate transforms should be handled by the axis and should be unaffected.

@drammock
Copy link
Member

drammock commented Aug 4, 2022

Haha, looks like @larsoner merged while I was reviewing. NBD, my comments were pretty minor anyway.

@larsoner
Copy link
Member

larsoner commented Aug 4, 2022

@alexrockhill at least the PyVista thing is still relevant and I missed it, can you make a follow-up PR?

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.

[MAINT] Remove redundancy in Abtract Qt Classes
3 participants