Skip to content

Make subject batching lossless - #1494

Closed
fepegar wants to merge 12 commits into
mainfrom
fepegar/lossless-subject-batches
Closed

Make subject batching lossless#1494
fepegar wants to merge 12 commits into
mainfrom
fepegar/lossless-subject-batches

Conversation

@fepegar

@fepegar fepegar commented Jul 13, 2026

Copy link
Copy Markdown
Member

[Generated by a coding agent]


Summary

  • validate complete Subject and Image schemas before stacking
  • preserve metadata, annotations, image subclasses, and shared/per-element histories
  • support metadata-only and annotation-only batches
  • add SubjectsBatch.map_subjects() for safe subject-wise processing
  • reject spatial transforms on annotations until coordinate updates are supported

Validation

  • full test suite and cross-platform GitHub Actions
  • Ruff lint and formatting
  • ty type checking
  • documentation tests and Zensical build
  • pre-commit.ci, including Xenon complexity checks

Stack (merge bottom-up)

  1. #1493 — documentation corrections — merged
  2. Make subject batching lossless #1494 — lossless subject batching (this PR; next to merge)
  3. #1495 — exact transform parameter replay
  4. #1496 — subject mapping adapters and examples

Copilot AI review requested due to automatic review settings July 13, 2026 15:46
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

📖 Docs Preview

Preview of the documentation for this PR:

🔗 https://smokeshow.helpmanual.io/113u4m4m4d1y4e2f4a0t/

Built from 8fa6c2e

Copilot AI 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.

Pull request overview

This PR makes batching/unbatching of Subject/Image data lossless by validating schemas before stacking and preserving per-element payload (metadata, annotations, subclasses) and transform histories. It also introduces safer subject-wise processing via SubjectsBatch.map_subjects() and explicitly rejects spatial transforms when annotations are present (until coordinate updates are supported).

Changes:

  • Add full schema validation for subjects/images before stacking, and preserve nested metadata/annotations + image subclass identity across batch round-trips.
  • Track and round-trip both shared and per-element transform histories for ImagesBatch and SubjectsBatch, including during wrapping/unwrapping in Transform.
  • Add SubjectsBatch.map_subjects() and enforce annotation restrictions for spatial transforms (including lazy spatial forwards).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_transforms_base.py Adjust tests to use a subject containing multiple images + metadata.
tests/test_batch.py Add coverage for payload/history round-trips, schema validation, metadata/annotation-only batching, and map_subjects().
src/torchio/transforms/transform.py Preserve histories when wrapping/unwrapping batches and reject spatial transforms with annotations.
src/torchio/transforms/spatial/ensure_shape_multiple.py Apply spatial-annotation rejection in the lazy forward path.
src/torchio/transforms/spatial/crop_or_pad.py Apply spatial-annotation rejection in the lazy forward path.
src/torchio/data/batch.py Implement lossless batching for images/subjects: schema validation, payload templates, annotation stores, and history helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/torchio/data/batch.py
@fepegar
fepegar force-pushed the fepegar/lossless-subject-batches branch from 4bd8001 to 2ea69be Compare July 13, 2026 21:33
Base automatically changed from fepegar/v2-transform-docs to main July 13, 2026 21:34
@fepegar
fepegar requested a review from Copilot July 13, 2026 21:35

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/torchio/transforms/transform.py Outdated
Comment thread docs/get-started/migration.md Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@fepegar
fepegar force-pushed the fepegar/lossless-subject-batches branch from 4be07a8 to a13d20a Compare July 13, 2026 22:15
@fepegar
fepegar requested a review from Copilot July 13, 2026 22:15

Copilot AI 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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread src/torchio/data/batch.py Outdated
Comment thread src/torchio/transforms/spatial/crop_or_pad.py Outdated
Comment thread src/torchio/transforms/spatial/ensure_shape_multiple.py Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/torchio/data/batch.py

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/torchio/data/image.py

Copilot AI 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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/torchio/data/batch.py Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Copilot AI 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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Copilot AI 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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

fepegar added 12 commits July 20, 2026 21:17
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
@fepegar
fepegar force-pushed the fepegar/lossless-subject-batches branch from f239e5b to 8fa6c2e Compare July 20, 2026 20:20
@fepegar
fepegar marked this pull request as draft July 20, 2026 20:21
@fepegar

fepegar commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

[Generated by a coding agent]


Superseded by the simpler replacement stack:

The replacement keeps the same features while removing optional template state, shared/per-element history duality, and persisted private batching keys.

@fepegar fepegar closed this Jul 20, 2026
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