Conversation
…ect-MONAI#9040) Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
9af7cce to
5d3d1ac
Compare
📝 WalkthroughWalkthroughThe inverse collation tests now check NIfTI availability and load reusable 2D and 3D datasets during class initialization. Each test reseeds deterministic behavior and receives shallow copies of the required datasets. Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
tests/transforms/test_inverse_collation.py (2)
93-94: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd Google-style docstrings to both setup hooks.
Line 94 defines
setUpClasswithout a docstring. Line 105 definessetUpwithout a docstring. Document the shared and per-test fixture attributes. Addunittest.SkipTestto theRaisessection forsetUpClass.As per path instructions, docstrings must be present for all definitions and use Google-style sections.
Also applies to: 105-105
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/transforms/test_inverse_collation.py` around lines 93 - 94, Add Google-style docstrings to the setUpClass and setUp methods in the test fixture, documenting the shared and per-test attributes they initialize. Include a Raises section in setUpClass documenting unittest.SkipTest, and ensure both docstrings use the required Google-style sections.Source: Path instructions
107-108: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winProtect the shallow-copy fixture contract.
Lines 107-108 copy only the outer dictionaries. All entries share the same loaded tensor and metadata objects.
CacheDatasetpasses source items directly to its deterministic cache stage, so an in-place transform or metadata update could contaminate later entries or tests. (raw.githubusercontent.com)Add an isolation regression check for the base fixtures, or deep-copy values when a transform requires it. Verify this contract for every transform in
TESTS_2DandTESTS_3D.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/transforms/test_inverse_collation.py` around lines 107 - 108, Update the fixture setup around data_3d and data_2d so each generated entry has isolated tensor and metadata values rather than sharing nested objects from base_3d/base_2d. Add regression coverage that checks this isolation for every transform listed in TESTS_2D and TESTS_3D, preserving the existing fixture counts and transform behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/transforms/test_inverse_collation.py`:
- Around line 100-103: Update the fixture setup around make_nifti_image and the
class initialization to retain all generated NIfTI paths in a shared temporary
directory and register class-level cleanup before creating the fixtures. Ensure
cleanup covers both files and directories, including partial failures during
base_3d or base_2d setup, while preserving the existing load_ims inputs.
---
Nitpick comments:
In `@tests/transforms/test_inverse_collation.py`:
- Around line 93-94: Add Google-style docstrings to the setUpClass and setUp
methods in the test fixture, documenting the shared and per-test attributes they
initialize. Include a Raises section in setUpClass documenting
unittest.SkipTest, and ensure both docstrings use the required Google-style
sections.
- Around line 107-108: Update the fixture setup around data_3d and data_2d so
each generated entry has isolated tensor and metadata values rather than sharing
nested objects from base_3d/base_2d. Add regression coverage that checks this
isolation for every transform listed in TESTS_2D and TESTS_3D, preserving the
existing fixture counts and transform behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 59e45b6f-f18a-4024-b487-13f60181ad2b
📒 Files selected for processing (1)
tests/transforms/test_inverse_collation.py
ericspod
left a comment
There was a problem hiding this comment.
Hi @aymuos15 I feel this file needs more work to overcome issues it already had. I don't see the value of the nifti loading here, but in general the way the test cases are made isn't great and the testing of collation isn't really that robust. If we're going to update this file it should be more thorough beyond just the change you wanted to make.
| if not has_nib: | ||
| self.skipTest("nibabel required for test_inverse") | ||
|
|
||
| raise unittest.SkipTest("nibabel required for test_inverse") |
There was a problem hiding this comment.
Using SkipIfNoModule on the class itself should have the same effect.
|
|
||
| def setUp(self): | ||
| set_determinism(seed=0) | ||
| self.data_3d = [dict(self.base_3d) for _ in range(11)] |
There was a problem hiding this comment.
Is there any real point in loading data from nifti files? I think we can just get away with creating MetaTensors here and populate their meta dictionaries with some dummy data to ensure it gets collated, but otherwise the whole nifti process seems unnecessary.
| TESTS_3D = [ | ||
| (t.__class__.__name__ + (" pad_list_data_collate" if collate_fn else " default_collate"), t, collate_fn, 3) | ||
| for collate_fn in [None, pad_list_data_collate] | ||
| for t in [ | ||
| Flipd(KEYS, spatial_axis=1), | ||
| RandFlipd(keys=KEYS, prob=0.5, spatial_axis=[1, 2]), | ||
| RandAxisFlipd(keys=KEYS, prob=0.5), | ||
| Compose([RandRotate90d(keys=KEYS, spatial_axes=(1, 2))]), | ||
| RandZoomd(keys=KEYS, prob=0.5, min_zoom=0.5, max_zoom=1.1, keep_size=True), | ||
| Rotated(keys=KEYS, angle=np.pi, dtype=np.float64), | ||
| RandRotated(keys=KEYS, prob=0.5, range_x=np.pi, dtype=np.float64), | ||
| RandAffined( | ||
| keys=KEYS, prob=0.5, rotate_range=np.pi, device=torch.device("cuda" if torch.cuda.is_available() else "cpu") | ||
| ), | ||
| ] | ||
| ] | ||
|
|
||
| TESTS_2D = [ | ||
| (t.__class__.__name__ + (" pad_list_data_collate" if collate_fn else " default_collate"), t, collate_fn, 2) | ||
| for collate_fn in [None, pad_list_data_collate] | ||
| for t in [ | ||
| Flipd(KEYS, spatial_axis=1), | ||
| RandFlipd(keys=KEYS, prob=0.5, spatial_axis=[1]), | ||
| RandAxisFlipd(keys=KEYS, prob=0.5), | ||
| Compose([RandRotate90d(keys=KEYS, prob=0.5, spatial_axes=(0, 1))]), | ||
| RandZoomd(keys=KEYS, prob=0.5, min_zoom=0.5, max_zoom=1.1, keep_size=True), | ||
| Rotated(keys=KEYS, angle=np.pi / 2, dtype=np.float64), | ||
| RandRotated(keys=KEYS, prob=0.5, range_x=np.pi, dtype=np.float64), | ||
| RandAffined( | ||
| keys=KEYS, prob=0.5, rotate_range=np.pi, device=torch.device("cuda" if torch.cuda.is_available() else "cpu") | ||
| ), | ||
| ] | ||
| ] |
There was a problem hiding this comment.
This outside the scope of this PR but these are prime candidates to be converted to using dict_product.
Description
Fixtures for the inverse-collation tests were rebuilt in
setUpon every test, re-generating the synthetic NIfTI volumes 32 times per run. The build now happens once insetUpClass, with each test taking a shallow copy of the loaded dicts. The transforms never mutate their inputs and every case re-seeds determinism, so behaviour is unchanged.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.