Fix string parsing bug for chunk_size in magicgui LineEdit#59
Open
HashemW wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the Issue
When running the 3D Inference module via the Napari GUI, the
chunk_sizeparameter is passed from themagicguiLineEditwidget as a raw string (e.g.,"256").Because the backend
VolumeInferenceWidgetrelies on alen()check intended for lists/tuples, strings of length 3 bypass the assertion (len("256") == 3). This causes the string to be iterated over, silently setting the chunk size to microscopic dimensions(2, 5, 6). When Zarr processes large volumes it generates millions of tiny chunk files and severely capping GPU utilization.Proposed Changes
This PR updates the
chunk_sizeparsing logic in to robustly handle both GUI and API inputs, ensuring theint | list[int]type hint is respected while safely parsing string outputs."64, 256, 256") to maintain support for anisotropic chunking, as well as handling for single-number strings (e.g.,"256")..isdigit()andtypechecking so invalid text inputs (e.g.,"apple") throw clean assertions rather than failing silently.intandlist[int]handling for users executing the plugin headlessly or via custom Python scripts.Testing Performed
pip install -e .)."256") from the GUI -> successfully parsed to(256, 256, 256)."64, 256, 256") from the GUI -> successfully parsed to(64, 256, 256).Note: Discussed this issue over email with Dr. Kedar Narayan, submitting this PR per his request.