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

Proposal for auto import extensions module. #2571

Merged
merged 10 commits into from
Mar 19, 2024

Conversation

samuelgarcia
Copy link
Member

@samuelgarcia samuelgarcia commented Mar 13, 2024

Hi @zm711 @alejoe91.
This is proposal to auto load extensions : when extension is builin and not registered because not impotred yet : then we have an auto load mechanism. This should help the end user.
Tell me what you think.

This is hard to be tested in core tests because it auload submodules which will fail on core testing because of dependencies.
So I made local tests and it works.

This should fix partially #2560.

if extension_name in _builtin_extensions:
module = _builtin_extensions[extension_name]
if autoload:
print(f"module '{module}' is imported automatically for extension '{extension_name}'")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print(f"module '{module}' is imported automatically for extension '{extension_name}'")

should we remove the print?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is good to have a message for auto loading no ?
Maybe a warning

Copy link
Member

Choose a reason for hiding this comment

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

not sure

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm torn here... If someone requests this functionality they should expect us to import what is needed to do the operation right? I guess the concern would be some sort of namespace clash? Like if we run an extractor the user expects a read operation from a file, we don't explicitly say we are creating a memmap which may lead to RAM exhaustion. On the other hand people complain about things failing silently for the job_kwargs.

Copy link
Member

Choose a reason for hiding this comment

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

The extractors example is a very good point. If someone saves a JSON file with dump_to_json, all the modules from extractors, preprocessing, etc. will be loaded.
In that case, we store the path to the class so imports are minimal.

Maybe we could do the same here? e.g.

_builtin_extensions = {
    "spike_amplitudes": "spikeinterface.postprocessing.spike_amplitudes.SpikeAmplitudeExtension",
    ...
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be removed. What is the user supposed to do with this information?

This sounds more like logging and when it is output by default the convention is to print to standard error as far as I am aware. So a warning. But I personally think that warnings should be actionable so not even sure about that one.

@alejoe91 alejoe91 added enhancement New feature or request core Changes to core module labels Mar 13, 2024
Copy link
Collaborator

@zm711 zm711 left a comment

Choose a reason for hiding this comment

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

As long as you're okay with autoload then this seems good to me. I can also test locally this afternoon. Otherwise, I think just the additional error messaging is much improved.

if extension_name in _builtin_extensions:
module = _builtin_extensions[extension_name]
if autoload:
print(f"module '{module}' is imported automatically for extension '{extension_name}'")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm torn here... If someone requests this functionality they should expect us to import what is needed to do the operation right? I guess the concern would be some sort of namespace clash? Like if we run an extractor the user expects a read operation from a file, we don't explicitly say we are creating a memmap which may lead to RAM exhaustion. On the other hand people complain about things failing silently for the job_kwargs.

src/spikeinterface/core/sortinganalyzer.py Outdated Show resolved Hide resolved
@zm711
Copy link
Collaborator

zm711 commented Mar 13, 2024

So testing this isn't quite working locally for me. I have a binary_folder with following extensions.
image
upon loading I get:
image
and if I try to grab an extension I get
image

I believe there are a few issues:

get_extension makes a call to has_extension which I believe is failing.
And during loading we also make all call to get_saved_extension_names which relies on _possible_extensions which I believe is not being populated.

What else do you want me to try locally Sam? Were you using zarr backend for this or did you get this to work with binary?

@zm711
Copy link
Collaborator

zm711 commented Mar 13, 2024

Also I never get to the print statement we were discussing above (L1082).

@samuelgarcia
Copy link
Member Author

Oups. My bad I tested the compute() let me finish this correctly.

@zm711
Copy link
Collaborator

zm711 commented Mar 13, 2024

Happy to test compute() tomorrow (that was actually the one thing I didn't test-haha). But yeah for me I think load is a nicer target since I always import everything when I'm doing computations, but when I'm reloading sometimes I just do core to check things so it might miss some of the extensions.

@zm711
Copy link
Collaborator

zm711 commented Mar 14, 2024

Tested both compute and load_sorting_analyzer and both worked for me locally.

@samuelgarcia samuelgarcia changed the title Proposal for auto load extensions. Proposal for auto import extensions module. Mar 18, 2024
Co-authored-by: Zach McKenzie <[email protected]>
Co-authored-by: Alessio Buccino <[email protected]>
@alejoe91 alejoe91 merged commit 52617ee into SpikeInterface:main Mar 19, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Changes to core module enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants