Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,6 @@ data/
# Model artifacts
*.pth
brain_mask_extraction_model/

# Claude Code review artifacts
.claude/REVIEW.MD/
30 changes: 30 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,33 @@ Every plan MUST include a Constitution Check evaluated before research and after
```

If speckit is not installed, follow the principles above manually.

## Dependency constraint

Do not add external dependencies unless they are already declared in `setup.cfg` or `pyproject.toml`. Current core deps include: torch, monai, nibabel, numpy, click, zarr, fsspec, joblib, scikit-image, psutil. If you think a new dep is justified, flag it explicitly — do not silently add it.

## MONAI-first rule

Before implementing any data loading, transform, loss, metric, or inference utility, check whether MONAI already provides it. Prefer wrapping MONAI over reimplementing. Check `monai.transforms`, `monai.data`, `monai.inferers`, `monai.losses`, `monai.metrics` before writing new code. If MONAI's version is insufficient, document why in a code comment.

## Read before write

Before modifying any existing module:
1. Read the module completely. List its implicit assumptions.
2. Check what MONAI provides that overlaps.
3. Do not guess function signatures — read the source.
4. If the module has existing tests, read those too to understand expected behavior.

## Testing philosophy

Every test should fail if the feature is removed. If a test passes regardless of whether your code exists, it's not testing your code.

## Review process

A reviewer subagent runs automatically (via stop hook) when you finish a task. It executes tests, inspects the diff, and writes a verdict to `.claude/reviews/`. If the reviewer blocks:
1. Read the review file it points to.
2. Fix every CRITICAL finding.
3. Address WARNING findings where reasonable.
4. The hook will re-run on your next stop.

Do not commit until the reviewer passes.
22 changes: 22 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
import torch


def _mps_supports_conv3d() -> bool:
"""Return True if Conv3D works on the MPS backend."""
if not (hasattr(torch.backends, "mps") and torch.backends.mps.is_available()):
return False
try:
m = torch.nn.Conv3d(1, 1, 1).to("mps")
x = torch.randn(1, 1, 2, 2, 2, device="mps")
m(x)
return True
except RuntimeError:
return False


# Disable MPS auto-detection when Conv3D is unsupported (PyTorch < 2.3 on
# Apple Silicon). Without this, ``nobrainer.gpu.get_device()`` returns MPS
# and every 3D convolution raises ``RuntimeError: Conv3D is not supported on
# MPS``.
if hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
if not _mps_supports_conv3d():
torch.backends.mps.is_available = lambda: False # type: ignore[assignment]


def pytest_collection_modifyitems(config, items):
"""Skip tests marked with @pytest.mark.gpu when CUDA is not available."""
if torch.cuda.is_available():
Expand Down
Loading
Loading