Skip to content

Fix cache deserialization for ops using OpBlockedArrayCache - #3119

Merged
k-dominik merged 3 commits into
ilastik:mainfrom
k-dominik:fix-cache-loading
Dec 22, 2025
Merged

k-dominik merged 3 commits into
ilastik:mainfrom
k-dominik:fix-cache-loading

Conversation

@k-dominik

@k-dominik k-dominik commented Dec 18, 2025 •

Copy link
Copy Markdown
Contributor

.setInSlot should not be called from outside of slot. Deserialization should always go via Slot.__setitem__ which handles setItem of the operators.

I made .setInSlot private now so that invoking it directly is clearly discouraged.

Workflows that were affected by this (check mark indicates confirmed fix):

  • Object classification from Predictions
  • Object classification from Segmentation
  • All tracking workflows
    • Tracking from preds
    • Animal tracking from preds
    • Tracking from seg
    • Animal tracking from seg
    • Tracking w learning from preds
    • Tracking w learning from segs
  • Carving no OpBlockedArrayCache serialization here.
  • Multicut this one was actually working

Some timings to show benefit ;)

project timinig1 main [s] timinig1 here [s]
large 2d oc from pred 16 6
large 3d oc from seg 31 7

Checklist

  • Format code and imports.
  • Add tests.
  • Reference relevant issues and other pull requests.
  • Rebase commits into a logical sequence.

Footnotes

  1. timing measured from start loading to 0 requests - make sure to save in Object Classification or object feature selection applet (binary image needs to be shown) to measure this. ↩ ↩2

@codecov

codecov Bot commented Dec 18, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.25000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.37%. Comparing base (2a43619) to head (db924f1).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
ilastik/applets/cropping/opCropping.py 0.00% 2 Missing ⚠️
...tik/applets/objectExtraction/opObjectExtraction.py 50.00% 2 Missing ⚠️
...conservation/opRelabeledMergerFeatureExtraction.py 66.66% 2 Missing ⚠️
ilastik/applets/cropping/opCropSelection.py 0.00% 1 Missing ⚠️
lazyflow/operator.py 75.00% 1 Missing ⚠️
lazyflow/operators/oldVigraOperators.py 75.00% 1 Missing ⚠️
lazyflow/operators/opCompressedCache.py 66.66% 1 Missing ⚠️
lazyflow/operators/opCompressedUserLabelArray.py 50.00% 1 Missing ⚠️
lazyflow/operators/opLazyConnectedComponents.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3119      +/-   ##
==========================================
- Coverage   63.38%   63.37%   -0.02%     
==========================================
  Files         534      534              
  Lines       64852    64835      -17     
==========================================
- Hits        41105    41086      -19     
- Misses      23747    23749       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

direct invocation of setInSlot will not work for this OpBlockedArrayCache,
but has to go via connected slots __setitem__ to reach setInSlot of the cache.
@k-dominik k-dominik changed the title Fix cache deserialization for OpBlockedArrayCache Fix cache deserialization for ops using OpBlockedArrayCache Dec 19, 2025
prevent accidental usage of direct setInSlot invocations which led to hard
to locate bugs. _setInSlot is only intended to be invoked by Slot class.
@k-dominik
k-dominik marked this pull request as ready for review December 19, 2025 14:58
@k-dominik
k-dominik requested a review from btbest December 19, 2025 15:00

@btbest btbest left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tried to experience the speedup but didn't manage... just for documentation it would be nice if you can describe in what situation there is a speedup 😅 but lgtm

I did find a small problem (easy fix):

oc-from-segmentation: While trying to reproduce, I was putting mitocheck (txyc) into raw data, and an apparently misordered segmentation (zxyc) as secondary data.

Problem: Instead of the "fix this dataset" dialog to adjust axis order, on this PR I just get a "here's an error" dialog, with no option. It's because OpRegionFeatures.setupOutputs raises Exception, not DatasetConstraintError

opObjectExtraction.py", line 531, in setupOutputs
    raise Exception(
Exception: shapes do not match. label volume shape: (1, 1344, 1024, 53, 1). raw data shape: (53, 1344, 1024, 1, 1)

I guess OpRegionFeatures is now higher up in the chain, or previously wasn't ready this early..? If this doesn't immediately make sense to you, maybe worth checking - otherwise it's a quick fix of just replacing the Exception.

Comment on lines +267 to 270
# "Invalid slot for _setInSlot(): {}".format( slot.name )
# Nothing to do here.
# Our Input slots are directly fed into the cache,
# so all calls to __setitem__ are forwarded automatically

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
# "Invalid slot for _setInSlot(): {}".format( slot.name )
# Nothing to do here.
# Our Input slots are directly fed into the cache,
# so all calls to __setitem__ are forwarded automatically

seems obsolete now :)

@k-dominik k-dominik Dec 22, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any operator with a cache deep inside needs to implement _setInSlot(...): pass...

Currently, any op where SomeSlot[slicing] = value is called needs to implement _setInSlot(...): pass) in order for the forwarding to a (possibly) nested cache op can be done - which - idk, I find a bit too much noise (as well as these comments throughout the code base that you highlight). I was still debating though how to safely do so that one could not forget to implement it in the ops that actually need it (like caches)... So for this PR I'm gonna leave it in, but will open an issue.

@k-dominik

k-dominik commented Dec 22, 2025 •

Copy link
Copy Markdown
Contributor Author

I tried to experience the speedup but didn't manage... just for documentation it would be nice if you can describe in what situation there is a speedup 😅 but lgtm

The speedup is observed when opening any applet that would show the binary image (e.g. classification one). Saving the project with this applet enabled will give you the speedup on load. Also note that the data needs to be large for the speedup to be relevant. Mitocheck has very small images that take no time to do thresholding on. I was testing with a project that had 10k x 14k input images

@k-dominik

Copy link
Copy Markdown
Contributor Author

I did find a small problem (easy fix):

oc-from-segmentation: While trying to reproduce, I was putting mitocheck (txyc) into raw data, and an apparently misordered segmentation (zxyc) as secondary data.

Problem: Instead of the "fix this dataset" dialog to adjust axis order, on this PR I just get a "here's an error" dialog, with no option. It's because OpRegionFeatures.setupOutputs raises Exception, not DatasetConstraintError

opObjectExtraction.py", line 531, in setupOutputs
    raise Exception(
Exception: shapes do not match. label volume shape: (1, 1344, 1024, 53, 1). raw data shape: (53, 1344, 1024, 1, 1)

Nice find 😅 . I can reproduce this - but also on main. So it's not related to this PR. Will raise the DatasetConstraintError as you suggest!

Raising a blank exception does not give users a chance to correct, whereas
this exception is treated differently, and the user gets the dialog for re-
ordering.

Co-authored-by: Benedikt Best <[email protected]>
@k-dominik
k-dominik merged commit 5dc26e7 into ilastik:main Dec 22, 2025
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants