Skip to content

Fix string parsing bug for chunk_size in magicgui LineEdit#59

Open
HashemW wants to merge 1 commit into
volume-em:mainfrom
HashemW:fix-chunk-size-parsing
Open

Fix string parsing bug for chunk_size in magicgui LineEdit#59
HashemW wants to merge 1 commit into
volume-em:mainfrom
HashemW:fix-chunk-size-parsing

Conversation

@HashemW

@HashemW HashemW commented Apr 2, 2026

Copy link
Copy Markdown

Description of the Issue

When running the 3D Inference module via the Napari GUI, the chunk_size parameter is passed from the magicgui LineEdit widget as a raw string (e.g., "256").

Because the backend VolumeInferenceWidget relies on a len() 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_size parsing logic in to robustly handle both GUI and API inputs, ensuring the int | list[int] type hint is respected while safely parsing string outputs.

  • GUI Support (Strings): Added parsing for comma-separated strings (e.g., "64, 256, 256") to maintain support for anisotropic chunking, as well as handling for single-number strings (e.g., "256").
  • Validation: Implemented strict .isdigit() and type checking so invalid text inputs (e.g., "apple") throw clean assertions rather than failing silently.
  • API Backwards Compatibility: Preserved direct int and list[int] handling for users executing the plugin headlessly or via custom Python scripts.

Testing Performed

  • Verified via local editable install (pip install -e .).
  • Tested single string inputs ("256") from the GUI -> successfully parsed to (256, 256, 256).
  • Tested comma-separated string inputs ("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.

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.

1 participant