Skip to content

MAINT: Make nibabel a required dependency #11564

Closed

Description

@larsoner

To me there are a few criteria for adding a new core dep. Ideally (but not always) it would at least:

  1. Have an established history/structure
  2. Be well maintained (with an expectation of future maintenance)
  3. Demonstrate low maintenance burden, ideally as MNE-Python as an optional dep (but could be elsewhere)
  4. Be used in a lot of places or at least a few important places in our codebase
  5. Be pure-python (to ensure installability everywhere and help ensure that things don't break often)
  6. Have a slow change/deprecation/change policy
  7. 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!

Activity

  1. cbrnr commented on Mar 16, 2023

    @cbrnr
    Contributor

    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.

  2. larsoner commented on Mar 16, 2023

    @larsoner
    MemberAuthor

    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.

  3. cbrnr commented on Mar 16, 2023

    @cbrnr
    Contributor

    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).

  4. larsoner commented on Mar 16, 2023

    @larsoner
    MemberAuthor

    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.

  5. added this to the 1.4 milestone on Mar 16, 2023
  6. cbrnr commented on Mar 16, 2023

    @cbrnr
    Contributor

    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.

  7. drammock commented on Mar 16, 2023

    @drammock
    Member

    absolutely mandatory dependencies

    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).

  8. cbrnr commented on Mar 16, 2023

    @cbrnr
    Contributor

    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).

  9. drammock commented on Mar 16, 2023

    @drammock
    Member

    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.

  10. larsoner commented on Mar 16, 2023

    @larsoner
    MemberAuthor

    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.

  11. agramfort commented on Mar 16, 2023

    @agramfort
    SponsorMember
  12. larsoner commented on Mar 16, 2023

    @larsoner
    MemberAuthor

    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.

    But why? What's the cost (to end users) of adding nibabel as a required dependency? I think in practice it shouldn't cause any issues for people...

  13. cbrnr commented on Mar 17, 2023

    @cbrnr
    Contributor

    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).

  14. larsoner commented on Mar 17, 2023

    @larsoner
    MemberAuthor

    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):

    1. pooch -- for mne.datasets
    2. jinja2 -- for mne.report.Report (also for some _repr_html_ but there it's more just convenience, a .format would suffice)
    3. tqdm and decorator -- mne.utils and therefore a bunch of other places
    4. 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

    1. (4) is less "core" to the package than 1, 2, and 3 (I don't think it is for 1 and 2 at least?)
    2. nibabel is a more complex dependency to install/resolve than the others (I don't think it is), or
    3. 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.

  15. cbrnr commented on Mar 17, 2023

    @cbrnr
    Contributor

    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).

  16. cbrnr commented on Mar 17, 2023

    @cbrnr
    Contributor

    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...

  17. larsoner commented on Mar 17, 2023

    @larsoner
    MemberAuthor

    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.

  18. cbrnr commented on Mar 17, 2023

    @cbrnr
    Contributor

    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.

  19. larsoner commented on Mar 17, 2023

    @larsoner
    MemberAuthor

    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.

  20. cbrnr commented on Mar 17, 2023

    @cbrnr
    Contributor

    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!

  21. larsoner commented on Mar 25, 2023

    @larsoner
    MemberAuthor

    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

  22. larsoner commented on Jul 6, 2023

    @larsoner
    MemberAuthor

    @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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions