Skip to content

Fix: compute extension children on-the-fly to catch optional dependencies - #4913

Open
alejoe91 wants to merge 10 commits into
SpikeInterface:mainfrom
alejoe91:get-extension-children-runtime
Open

alejoe91 wants to merge 10 commits into
SpikeInterface:mainfrom
alejoe91:get-extension-children-runtime

Conversation

@alejoe91

@alejoe91 alejoe91 commented Nov 5, 2026

Copy link
Copy Markdown
Member

Fixes #4912

@alejoe91 alejoe91 added the core Changes to core module label Nov 5, 2026
@alejoe91 alejoe91 changed the title ix: compute extension children on-the-fly to catch optional dependencies Fix: compute extension children on-the-fly to catch optional dependencies Nov 5, 2026
Comment on lines +2934 to +2935
extensions : dict
Mapping of computed extension name -> params.

@chrishalcrow chrishalcrow Nov 6, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I found this name and param docstring very confusing.

What would a more descriptive name of extensions be? It's something like computed_extensions_and_extensions_to_compute Maybe if the doc was more informative it'd be fine.

other_extensions
computed_extensions
??

Comment on lines +2913 to +2928
@@ -2923,15 +2922,29 @@ def _get_children_dependencies(extension_name):
For instance, recomputing the "waveforms" needs to delete the "templates", since the latter depends on the former.
For this particular example, if we change the "ms_before" parameter of the "waveforms", also the "templates" will
require recomputation as this parameter is inherited.

Dependencies are resolved with the params of each extension, so optional dependencies (e.g. "quality_metrics"
on "spike_amplitudes") are included. Every alternative of a "a|b" dependency counts as a parent, since which
one was used is not recorded.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the docstring is a bit of out date now. Here's my attempt at a new one:

Extension classes have a depend_on attribute to declare which class they depend on. For instance "templates" depends on "waveforms"; "waveforms" depends on "random_spikes". This function is going the opposite way: it finds all children, grandchildren etc that depend on a particular extension.

Depending on their parameters, certain extensions depend on different combinations of extensions. E.g. if you're computing snrs, then noise_levels has quality_metrics as a child. But if you're just computing firing_rate, then it does not. Hence the dependency graph depends on what other extensions are being computed, or are saved in the analyzer. We account for these through the other_extensions argument.

@chrishalcrow

Copy link
Copy Markdown
Member

If I do this:

import spikeinterface.full as si
rec, sort = si.generate_ground_truth_recording()
analyzer = si.create_sorting_analyzer(sort, rec, format='binary_folder', folder='test_analyzer')
analyzer.compute({'noise_levels': {}, 'waveforms': {'ms_before':10}, 'templates': {}, 'quality_metrics': {'metric_names': ['snr', 'firing_rate', 'firing_range']}})
analyzer.compute({'noise_levels': {}})

Then all quality metrics are deleted when noise_levels are re-computed. I don't think this should happen.

@alejoe91

Copy link
Copy Markdown
Member Author

If I do this:

import spikeinterface.full as si
rec, sort = si.generate_ground_truth_recording()
analyzer = si.create_sorting_analyzer(sort, rec, format='binary_folder', folder='test_analyzer')
analyzer.compute({'noise_levels': {}, 'waveforms': {'ms_before':10}, 'templates': {}, 'quality_metrics': {'metric_names': ['snr', 'firing_rate', 'firing_range']}})
analyzer.compute({'noise_levels': {}})

Then all quality metrics are deleted when noise_levels are re-computed. I don't think this should happen.

This is done in the last commit. Basically, the delete function now takes the deleted_parents, which are ignored by default. The BaseMetricExtension though overrides the function and only deletes metric depending on deleted parents. Added a test :)

Comment on lines 2911 to +2931
@@ -2908,15 +2920,34 @@ def _get_children_dependencies(extension_name):
For instance, recomputing the "waveforms" needs to delete the "templates", since the latter depends on the former.
For this particular example, if we change the "ms_before" parameter of the "waveforms", also the "templates" will
require recomputation as this parameter is inherited.

Extension classes have a `depend_on` attribute to declare which class they depend on. For instance "templates"
depends on "waveforms"; "waveforms" depends on "random_spikes". This function is going the opposite way: it finds
all children, grandchildren etc that depend on a particular extension.

Depending on their parameters, certain extensions depend on different combinations of extensions. E.g. if you're
computing snrs, then noise_levels has quality_metrics as a child. But if you're just computing firing_rate,
then it does not. Hence the dependency graph depends on what other extensions are being computed, or are saved
in the analyzer. We account for these through the `all_extension_params` argument.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This docstring repeats itself

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done in 6d81f1e

self.data.get("runtime_s", {}).pop(m, None)
if self.format != "memory" and not self.sorting_analyzer.is_read_only():
self.save()
warnings.warn(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This warning is great! We should maybe add a warning when we delete any parent extension (e.g. if you do a .compute('noise_levels') we should report which extensions we're deleting.

zarr.consolidate_metadata(zarr_root.store)

def delete(self):
def delete(self, deleted_parents=None) -> bool:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is more specific than the name suggests. If you're really just deleting an extension, I think you should use delete_extension or _delete_extension_folder? Maybe we should update delete_extension to accept deleted_parents, or have a hyper specific name?

Suggested change
def delete(self, deleted_parents=None) -> bool:
def delete_dependent_part_of_extension(self, deleted_parents=None) -> bool:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking at this more. We now have:

  • SortingAnalyzer.delete_extension
  • SortingAnalyzer._delete_extension_storage
  • AnalyzerExtension.delete
  • AnalyzerExtension._delete_extension_folder

delete_extension calls delete and _delete_extension_storage.
delete calls _delete_extension_folder

Sure it's all logical and to do with folder vs memory, but feels like a bit of a mess. I think renaming delete would clarify a little bit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed in bfda106

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

Labels

core Changes to core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional dependencies don't participate in extension invalidation

2 participants