Skip to content

Register NumPy functions wrapped with Wrap1to1Func in plugins - #416

Merged
PierreRaybaut merged 3 commits into
developfrom
fix/415-register-wrapped-functions
Oct 21, 2026
Merged

PierreRaybaut merged 3 commits into
developfrom
fix/415-register-wrapped-functions

Conversation

@PierreRaybaut

Copy link
Copy Markdown
Contributor

Fixes #415.

Problem

The documented processing plugin example plugins/examples/datalab_custom_func.py, used by the Custom function tutorial and the plugin guide, no longer loaded on develop: registering sipi.Wrap1to1Func(weighted_average_denoise) with register_1_to_1 raised ValueError: 'weighted_average_denoise' is not a valid computation function, so the plugin added no menu. ComputingFeature only accepted functions decorated with Sigima's @computation_function(), and ccb81ef had moved the example from compute_1_to_1, which does not check the function, to register_1_to_1, which does. No test loaded the shipped examples in DataLab.

The regression only exists on develop: no released version is affected.

Fix

  • ComputingFeature validates its function with _check_feature_function: a decorated Sigima computation function, or, for a 1-to-1 feature, a Wrap1to1Func instance of sigima.proc.signal or sigima.proc.image. Such a wrapper is picklable (as the process pool requires), named after the wrapped function and returns the expected object; Sigima documents it as usable in DataLab, and DataLab already detects the plugin origin of such wrappers.
  • Other callables remain refused at registration, with a message naming both accepted forms; a wrapper registered for another pattern is refused too, since it produces one object from one object.
  • The example, the tutorial and the migration guide are unchanged.

Behaviour change

  • 1-to-1 features accept Wrap1to1Func wrappers, which were refused.
  • The error message for other functions now names the accepted forms. It still starts with '<name>' is not a valid computation function.

Tests

  • New test_shipped_plugin_examples_load_in_datalab (plugins_app_test.py): loads every plugin of plugins/examples in DataLab from a plugin directory, checks their stable IDs, the menu of the custom function example and the result of its processing on an image, then again after Reload plugins. It also fails if an example is added without being listed. It fails on develop with the error above.
  • processor_registry_unit_test.py: wrapped NumPy functions registered as signal and image 1-to-1 features (name, implicit feature ID, lookup by function); refusal for the four other patterns; refusal of plain functions with the accepted forms.
  • Regression: datalab/tests/backbone/plugins, datalab/tests/features/plugins, processor registry, feature identity and contract consistency tests, 243 passed.
  • Ruff format and check; Pylint reports no new message on the changed modules (three existing messages in datalab/gui/processor/base.py).

Documentation and translations

  • doc/features/advanced/plugins.rst: the functions processing plugins may register, with a link to the processing plugin example (new plugin_example_processing label).
  • French translation of this entry only; the French documentation builds with -W.
  • No release notes: the regression was never released.

Out of scope

Since plugins register their processing with `register_1_to_1`, a NumPy
function wrapped with Sigima's `Wrap1to1Func` was refused as "not a valid
computation function", so the documented example
`plugins/examples/datalab_custom_func.py` no longer loaded. Such a wrapper
is a valid feature function: it is picklable, named after the wrapped
function and returns the expected object, as Sigima documents it.

1-to-1 features now accept the `Wrap1to1Func` instances of
`sigima.proc.signal` and `sigima.proc.image`, besides decorated computation
functions. Other callables are still refused at registration, with a
message naming the accepted forms, and so is a wrapper registered for
another pattern.

Assisted-by: Claude Opus 5.5
Examples were only imported, so registering their processing could fail
unnoticed. A new application test loads every plugin of `plugins/examples`
in DataLab from a plugin directory, checks their stable IDs and the menu of
the custom function example, and runs its processing on an image, also
after reloading the plugins. It fails without the fix.

Unit tests cover wrapped NumPy functions registered as signal and image
1-to-1 features, and their refusal for other patterns, as well as the
refusal of plain functions.

Assisted-by: Claude Opus 5.5
…415)

A Sigima computation function, or, for a 1-to-1 feature without parameters,
a NumPy function wrapped with `Wrap1to1Func`, as in the processing plugin
example. With its French translation.

Assisted-by: Claude Opus 5.5
@PierreRaybaut PierreRaybaut added the bug Something isn't working label Oct 21, 2026
@PierreRaybaut
PierreRaybaut merged commit 65f00cc into develop Oct 21, 2026
6 checks passed
PierreRaybaut added a commit that referenced this pull request Oct 21, 2026
Since #416 (#415), 1-to-1 features accept a NumPy function wrapped with
Sigima's `Wrap1to1Func`. Generated single-file plugins now register
`Wrap1to1Func(sample_processing)` directly, without the decorated
`compute_sample_processing` function and the imports it needed: the
generated file is shorter, and its only function is the one to edit.

Assisted-by: Claude Opus 5.5
@PierreRaybaut
PierreRaybaut deleted the fix/415-register-wrapped-functions branch October 23, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant