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
To me there are a few criteria for adding a new core dep. Ideally (but not always) it would at least:
Have an established history/structure
Be well maintained (with an expectation of future maintenance)
Demonstrate low maintenance burden, ideally as MNE-Python as an optional dep (but could be elsewhere)
Be used in a lot of places or at least a few important places in our codebase
Be pure-python (to ensure installability everywhere and help ensure that things don't break often)
Have a slow change/deprecation/change policy
Have limited installation requirements itself
To me nibabel has all of these features. Adding it as a core dependency would simplify a lot of our codebase/shims (no more _import_nibabel, etc.) and reduce Python ecosystem code duplication (really FreeSurfer surface reading should be implemented one place!). So overall I think we should add it as a core dependency.
Any thoughts on this?
FWIW this is spurred by the recent change I made to remove our (duplicated with nibabel) FreeSurfer surface reading code in #11557. It didn't trigger CI failure there for some reason, but now it causes 117 test failures because we read a lot of surfaces!
All of your points make sense. However, would it also solve these problems when we add it as an extra dependency? We could create a new extra group in setup.py if it doesn't fit into an existing group.
However, would it also solve these problems when we add it as an extra dependency?
We could do this but I don't see much advantage given the low maintenance burden for us. I do see having to do the extra bit of pip install mne[something] for every user who wants to read surfaces as a big disadvantage, though. It complicates our install instructions, gives them more to know/understand/get wrong, etc.
I always appreciated that pip install mne pulls in only absolutely mandatory dependencies. Sure you can argue that nibabel is small, pure Python, etc. etc., but it still misses the point that it is only needed for specific use cases. Many EEG users will never work with surfaces.
That said, if it makes our life easier I'm fine with adding it even though it doesn't really fit into my mental model of MNE 😄 (maybe my model is wrong).
I always appreciated that pip install mne pulls in only absolutely mandatory dependencies.
Currently it pulls in jinja2, which I don't think fits this absolute mandatory mental model. We could make this optional, it would just require more shims and "junk" in our codebase, user knowledge for install, etc. To me what/where we use nibabel is more important/prolific than where we use jinja2, but I think it would be a step backward for us to remove jinja2 as a required dep. So as far as the mental model goes, I think you're assigning more weight to the absolute-mandatory aspects (and what qualifies as this) than me at least.
To me the biggest weight (by far) is burden on maintainers and and users as a whole -- if adding a new required dependency is expected to make our life as maintainers and users lives easier on the whole, we should do it.
Sure, I just wanted to extrapolate and caution that we don't want to end up in a situation where we suddenly have 100 required dependencies, because they make our life (as both users and maintainers) easier. This can surely be argued, but the downside is of course that every dependency introduces a huge maintenance burden. I know that this is why you have listed these criteria for a package to qualify, and I already said I'm OK either way.
BTW, jinja2 is already a required core dependency.
Similar to my comment in #11544 (comment) about defining "MNE should work", here we have the same issue of defining what is "absolutely mandatory". For anyone whose work involves working with Freesurfer surfaces (which is a lot of MNE users) being able to read Freesurfer surfaces is mandatory.
Right now lots of things are optional only because we chose to arrange our imports that way and the motivation that @agramfort usually points to is that minimal install should be lightweight for running MNE on servers where no interactive stuff happens. To me, that's a good concern to keep in mind but it's not the only concern (@larsoner's hit the major ones for me: simplifying / removing our import shims, and simplifying our install instructions and the install process for lots of users).
Exactly @drammock! I think of PsychoPy, which has always had the opposite problem – they basically make every package mandatory, which means dozens of dependencies. It will work for every use case, but it requires to maintain a huge dependency chain (hell).
it sounds like the three of us are on the same page(ish), or at least OK with adding nibabel as a core dep. Let's give it some time to see if anyone else wants to weigh in.
it sounds like the three of us are on the same page(ish), or at least OK with adding nibabel as a core dep. Let's give it some time to see if anyone else wants to weigh in.
Sounds good to me!
BTW, jinja2 is already a required core dependency.
Yes this is sort of my point -- we already require jinja2, and I think nibabel fits the top-comment inclusion criteria better than jinja2.
minimal install should be lightweight for running MNE on servers
Before @agramfort can complain about this 🙂 -- the pure Python part in the criteria above should help us a bit here. The nibabel Linux wheel is 3.3 MB. For context, SciPy is 34 MB and NumPy is 16.7 MB. So overall I think it's an acceptable size nowadays.
I see many usage of mne that only requires raw data processing hence only
numpy and scipy (and matplotlib) if you want plotting. But not even qt...
If you don't work with anatomical data which many EEG people do, nibabel is
not necessary.
So I am really not convinced here. To me mne should work fine for all the
sensor level data without any extra dependency
that assumes you have MRIs.
To me it's more a philosophical issue. Maybe we have differing opinions on what core MNE is, but I agree with @agramfort that it is "standard" EEG/MEG processing with sensor data.
Another option to go forward is to "soft-require" a package when it is not necessary for core functionality. For example, I assume nibabel is only used in specific sub-modules. What if we just import it normally there (and make sure that import mne is not affected)? Then we can get rid of all import shims etc. and still have a minimum set of core dependencies. If we want to go this route, I suggest to re-evaluate some of our recently added dependencies. In particular, jinja2 could be handled exactly like I'm suggesting – we don't need it as a core dependency, but people who want to generate reports will need to install it.
BTW, a regular ModuleNotFoundError is informative, so we don't need to do any extra handling (the error clearly states which package is missing).
Finally, people who use our standalone installers will always have everything available. So this is really a problem that affects "non-standard" users (e.g. people who have reasons why they do not use the standalone installers).
Maybe we have differing opinions on what core MNE is, but I agree with @agramfort that it is "standard" EEG/MEG processing with sensor data
To avoid these philosophical aspects, can we say something is likely a "core" part of MNE the more we have dedicated root classes and/or public submodules to it? If so, it's easy to justify why we already added some required deps in the last few years (plus a proposed number 4):
pooch -- for mne.datasets
jinja2 -- for mne.report.Report (also for some _repr_html_ but there it's more just convenience, a .format would suffice)
tqdm and decorator -- mne.utils and therefore a bunch of other places
nibabel -- mne.forward, mne.beamformer, mne.inverse_sparse, mne.minimum_norm (MNE namesake!), mne.viz.Brain, and probably others implicitly or explicitly
To stay consistent and say nibabel in (4) doesn't make sense to add @agramfort@cbrnr I think you'd need to say that either
(4) is less "core" to the package than 1, 2, and 3 (I don't think it is for 1 and 2 at least?)
nibabel is a more complex dependency to install/resolve than the others (I don't think it is), or
we should revert the dependency requirement for some or all of 1-3 and soft import those, too (seems like a step backward for maintainability)
And this brings me back to the question I posed that I think is really more important than the philosophical one anyway:
What's the cost (to end users) of adding nibabel as a required dependency?
I think we have good evidence in practice the last few years of requiring pooch, jinja2, tqdm, and decorator that the cost to end-users (and us as maintainers) is negligible. I haven't seen any users complain about pip install mne pulling them in or causing conflicts, etc. but maybe it's silent or I've missed it (?). In the meantime, our code is simpler for not having to soft import any of them (as it is in #11565 for nibabel).
Another option to go forward is to "soft-require" a package when it is not necessary for core functionality
This is what we already do and what I'm trying to avoid / remove in #11565.
This is what we already do and what I'm trying to avoid / remove in #11565.
No, by soft-import I mean import at the (sub-)module level and only avoid exposing it in mne. That way, it is not necessary to nest the import in a function, and we can write the (sub-)module as if the package was available (if not, users will get a ModuleNotFoundError telling them to install the missing package).
So if something is already in mne, like nibabel, it's probably time to include the package as a required dependency. However, pooch and jinja2 could be removed (without changing almost anything in our code). Edit: I misread that, nibabel is not in the root mne module...
However, pooch and jinja2 could be removed (without changing almost anything in our code)
Yes they could, but I think going this path will undoubtedly have bad consequences for end users. Some people will continue to pip install mne as they always have (or even conda install mne-base) and all of a sudden their mne.report.Report and mne.datasets.sample.data_path() are broken with ModuleNotFoundError until they pip install pooch jinja2 as well. So again I think we need to think about the practical effect on end users of this change. I don't think the additional burden/annoyance/change in behavior caused by making pooch and jinja2 would be worth what we gain by making them optional -- which in this case I think is just avoiding installing two packages for the other people who won't use these parts of our code.
It's not just these two packages, pooch requires appdirs, packaging, and request, which in turn requires four more packages, so these are 7 packages. jinja2 only need one additional package. Now we're at 10 packages for these two dependencies.
Again, I am fine with including a package that we think is absolutely required for core MNE. The problems you are mentioning relate to backward compatibility, because we would remove something what was previously present.
But the issue here is whether or not to add nibabel. Again, if the majority here thinks it is necessary, I'm fine with including it. But I would still consider the other option, namely isolating the relevant sub-modules so that mne does not import that package (and we don't have to make it a required dependency). Technically, this might even amount to the same thing for us maintainers, because we will need to make sure that nibabel works, no matter if it's required or optional. I guess then it comes down to keeping MNE lean vs. adding packages that we think should be in core MNE.
It's not just these two packages, pooch requires appdirs, packaging, and request
To be fair, some of these are probably already required by NumPy, SciPy, and/or matplotilb or their deps. Just looking at matplotlib for example, it directly requires importlib-resources and packaging (and would end up in any sane Python installation nowadays anyway) so I don't think these should count against the new required deps.
Again, I am fine with including a package that we think is absolutely required for core MNE. The problems you are mentioning relate to backward compatibility,
I don't think they only relate to backward compat, though (even though it would be a break). It's not just old users who would run into the "oh crap mne.report.Report doesn't work without more/different pip calls". It's new ones, too. I think it's important we stay consistent with our thinking/practices here independent of how, yes, it is would be worse from a backward compat sense if we removed it now.
But the issue here is whether or not to add nibabel
@cbrnr again I want to ask a third time now (I think?) what I think is the core question, still not directly addressed: "What's the cost (to end users) of adding nibabel as a required dependency?" The way you and @agramfort talk about it, it seems like you are worried that it will be (or risks being) a burden to end-users if we add this extra dependency. I understand there is some non-zero risk/overhead to users, but in practice I just haven't seen a problem with jinja2, tqdm, decorator, or pooch even if they did need 10 new total reqs in the last couple of years.
FWIW nibabel only needs packaging, and importlib_resources. These are needed by matplotlib already, so in practice I think we are talking about one new, pure python, well supported, slow changing dependency.
But I would still consider the other option,
I think we should concentrate in this issue on our required dependency policy. Yes we can think about ways of mitigating the situation with optional deps in different ways. What we have is already okay so I'd rather discuss that separately.
again I want to ask a third time now (I think?) what I think is the core question, still not directly addressed: "What's the cost (to end users) of adding nibabel as a required dependency?
This cost is that they have additional packages in their (v)env. The more packages there are, the more likely some sort of conflict will be. But again, you argue that nibabel has very few dependecies, is well maintained and mature, etc., so the cost is very low. And I don't disagree!
Closing, see #11565 (comment) . TL;DR is that the is real pain/overhead in managed environments so we should only add in the future if it really helps us in some way
@agramfort we should be able to safely vendor a dependency though, right? In theory it should be the same as adapting BSD-compatible code which we do all the time...
Activity
cbrnr commentedon Mar 16, 2023
All of your points make sense. However, would it also solve these problems when we add it as an extra dependency? We could create a new extra group in
setup.pyif it doesn't fit into an existing group.larsoner commentedon Mar 16, 2023
We could do this but I don't see much advantage given the low maintenance burden for us. I do see having to do the extra bit of
pip install mne[something]for every user who wants to read surfaces as a big disadvantage, though. It complicates our install instructions, gives them more to know/understand/get wrong, etc.cbrnr commentedon Mar 16, 2023
I always appreciated that
pip install mnepulls in only absolutely mandatory dependencies. Sure you can argue thatnibabelis small, pure Python, etc. etc., but it still misses the point that it is only needed for specific use cases. Many EEG users will never work with surfaces.That said, if it makes our life easier I'm fine with adding it even though it doesn't really fit into my mental model of MNE 😄 (maybe my model is wrong).
larsoner commentedon Mar 16, 2023
Currently it pulls in jinja2, which I don't think fits this absolute mandatory mental model. We could make this optional, it would just require more shims and "junk" in our codebase, user knowledge for install, etc. To me what/where we use
nibabelis more important/prolific than where we use jinja2, but I think it would be a step backward for us to removejinja2as a required dep. So as far as the mental model goes, I think you're assigning more weight to the absolute-mandatory aspects (and what qualifies as this) than me at least.To me the biggest weight (by far) is burden on maintainers and and users as a whole -- if adding a new required dependency is expected to make our life as maintainers and users lives easier on the whole, we should do it.
cbrnr commentedon Mar 16, 2023
Sure, I just wanted to extrapolate and caution that we don't want to end up in a situation where we suddenly have 100 required dependencies, because they make our life (as both users and maintainers) easier. This can surely be argued, but the downside is of course that every dependency introduces a huge maintenance burden. I know that this is why you have listed these criteria for a package to qualify, and I already said I'm OK either way.
BTW,
jinja2is already a required core dependency.drammock commentedon Mar 16, 2023
Similar to my comment in #11544 (comment) about defining "MNE should work", here we have the same issue of defining what is "absolutely mandatory". For anyone whose work involves working with Freesurfer surfaces (which is a lot of MNE users) being able to read Freesurfer surfaces is mandatory.
Right now lots of things are optional only because we chose to arrange our imports that way and the motivation that @agramfort usually points to is that minimal install should be lightweight for running MNE on servers where no interactive stuff happens. To me, that's a good concern to keep in mind but it's not the only concern (@larsoner's hit the major ones for me: simplifying / removing our import shims, and simplifying our install instructions and the install process for lots of users).
cbrnr commentedon Mar 16, 2023
Exactly @drammock! I think of PsychoPy, which has always had the opposite problem – they basically make every package mandatory, which means dozens of dependencies. It will work for every use case, but it requires to maintain a huge dependency chain (hell).
drammock commentedon Mar 16, 2023
it sounds like the three of us are on the same page(ish), or at least OK with adding nibabel as a core dep. Let's give it some time to see if anyone else wants to weigh in.
larsoner commentedon Mar 16, 2023
Sounds good to me!
Yes this is sort of my point -- we already require
jinja2, and I thinknibabelfits the top-comment inclusion criteria better thanjinja2.Before @agramfort can complain about this 🙂 -- the pure Python part in the criteria above should help us a bit here. The nibabel Linux wheel is 3.3 MB. For context, SciPy is 34 MB and NumPy is 16.7 MB. So overall I think it's an acceptable size nowadays.
agramfort commentedon Mar 16, 2023
larsoner commentedon Mar 16, 2023
But why? What's the cost (to end users) of adding
nibabelas a required dependency? I think in practice it shouldn't cause any issues for people...cbrnr commentedon Mar 17, 2023
To me it's more a philosophical issue. Maybe we have differing opinions on what core MNE is, but I agree with @agramfort that it is "standard" EEG/MEG processing with sensor data.
Another option to go forward is to "soft-require" a package when it is not necessary for core functionality. For example, I assume
nibabelis only used in specific sub-modules. What if we just import it normally there (and make sure thatimport mneis not affected)? Then we can get rid of all import shims etc. and still have a minimum set of core dependencies. If we want to go this route, I suggest to re-evaluate some of our recently added dependencies. In particular,jinja2could be handled exactly like I'm suggesting – we don't need it as a core dependency, but people who want to generate reports will need to install it.BTW, a regular
ModuleNotFoundErroris informative, so we don't need to do any extra handling (the error clearly states which package is missing).Finally, people who use our standalone installers will always have everything available. So this is really a problem that affects "non-standard" users (e.g. people who have reasons why they do not use the standalone installers).
larsoner commentedon Mar 17, 2023
To avoid these philosophical aspects, can we say something is likely a "core" part of MNE the more we have dedicated root classes and/or public submodules to it? If so, it's easy to justify why we already added some required deps in the last few years (plus a proposed number 4):
pooch-- formne.datasetsjinja2-- formne.report.Report(also for some_repr_html_but there it's more just convenience, a.formatwould suffice)tqdmanddecorator--mne.utilsand therefore a bunch of other placesnibabel--mne.forward,mne.beamformer,mne.inverse_sparse,mne.minimum_norm(MNE namesake!),mne.viz.Brain, and probably others implicitly or explicitlyTo stay consistent and say
nibabelin (4) doesn't make sense to add @agramfort @cbrnr I think you'd need to say that eithernibabelis a more complex dependency to install/resolve than the others (I don't think it is), orAnd this brings me back to the question I posed that I think is really more important than the philosophical one anyway:
I think we have good evidence in practice the last few years of requiring
pooch,jinja2,tqdm, anddecoratorthat the cost to end-users (and us as maintainers) is negligible. I haven't seen any users complain aboutpip install mnepulling them in or causing conflicts, etc. but maybe it's silent or I've missed it (?). In the meantime, our code is simpler for not having to soft import any of them (as it is in #11565 fornibabel).This is what we already do and what I'm trying to avoid / remove in #11565.
cbrnr commentedon Mar 17, 2023
No, by soft-import I mean import at the (sub-)module level and only avoid exposing it in
mne. That way, it is not necessary to nest the import in a function, and we can write the (sub-)module as if the package was available (if not, users will get aModuleNotFoundErrortelling them to install the missing package).cbrnr commentedon Mar 17, 2023
So if something is already in
mne, likenibabel, it's probably time to include the package as a required dependency. However,poochandjinja2could be removed (without changing almost anything in our code). Edit: I misread that,nibabelis not in the rootmnemodule...larsoner commentedon Mar 17, 2023
Yes they could, but I think going this path will undoubtedly have bad consequences for end users. Some people will continue to
pip install mneas they always have (or evenconda install mne-base) and all of a sudden theirmne.report.Reportandmne.datasets.sample.data_path()are broken withModuleNotFoundErroruntil theypip install pooch jinja2as well. So again I think we need to think about the practical effect on end users of this change. I don't think the additional burden/annoyance/change in behavior caused by makingpoochandjinja2would be worth what we gain by making them optional -- which in this case I think is just avoiding installing two packages for the other people who won't use these parts of our code.cbrnr commentedon Mar 17, 2023
It's not just these two packages,
poochrequiresappdirs,packaging, andrequest, which in turn requires four more packages, so these are 7 packages.jinja2only need one additional package. Now we're at 10 packages for these two dependencies.Again, I am fine with including a package that we think is absolutely required for core MNE. The problems you are mentioning relate to backward compatibility, because we would remove something what was previously present.
But the issue here is whether or not to add
nibabel. Again, if the majority here thinks it is necessary, I'm fine with including it. But I would still consider the other option, namely isolating the relevant sub-modules so thatmnedoes not import that package (and we don't have to make it a required dependency). Technically, this might even amount to the same thing for us maintainers, because we will need to make sure thatnibabelworks, no matter if it's required or optional. I guess then it comes down to keeping MNE lean vs. adding packages that we think should be in core MNE.larsoner commentedon Mar 17, 2023
To be fair, some of these are probably already required by NumPy, SciPy, and/or matplotilb or their deps. Just looking at
matplotlibfor example, it directly requiresimportlib-resourcesandpackaging(and would end up in any sane Python installation nowadays anyway) so I don't think these should count against the new required deps.I don't think they only relate to backward compat, though (even though it would be a break). It's not just old users who would run into the "oh crap
mne.report.Reportdoesn't work without more/differentpipcalls". It's new ones, too. I think it's important we stay consistent with our thinking/practices here independent of how, yes, it is would be worse from a backward compat sense if we removed it now.@cbrnr again I want to ask a third time now (I think?) what I think is the core question, still not directly addressed: "What's the cost (to end users) of adding nibabel as a required dependency?" The way you and @agramfort talk about it, it seems like you are worried that it will be (or risks being) a burden to end-users if we add this extra dependency. I understand there is some non-zero risk/overhead to users, but in practice I just haven't seen a problem with jinja2, tqdm, decorator, or
poocheven if they did need 10 new total reqs in the last couple of years.FWIW
nibabelonly needspackaging, andimportlib_resources. These are needed bymatplotlibalready, so in practice I think we are talking about one new, pure python, well supported, slow changing dependency.I think we should concentrate in this issue on our required dependency policy. Yes we can think about ways of mitigating the situation with optional deps in different ways. What we have is already okay so I'd rather discuss that separately.
cbrnr commentedon Mar 17, 2023
This cost is that they have additional packages in their (v)env. The more packages there are, the more likely some sort of conflict will be. But again, you argue that
nibabelhas very few dependecies, is well maintained and mature, etc., so the cost is very low. And I don't disagree!larsoner commentedon Mar 25, 2023
Closing, see #11565 (comment) . TL;DR is that the is real pain/overhead in managed environments so we should only add in the future if it really helps us in some way
larsoner commentedon Jul 6, 2023
@agramfort we should be able to safely vendor a dependency though, right? In theory it should be the same as adapting BSD-compatible code which we do all the time...