Skip to content

Add exact transform parameter replay#1495

Open
fepegar wants to merge 5 commits into
fepegar/lossless-subject-batchesfrom
fepegar/exact-transform-params
Open

Add exact transform parameter replay#1495
fepegar wants to merge 5 commits into
fepegar/lossless-subject-batchesfrom
fepegar/exact-transform-params

Conversation

@fepegar

@fepegar fepegar commented Jul 13, 2026

Copy link
Copy Markdown
Member

[Generated by a coding agent]


Summary

  • add Transform.apply_with_params() for exact parameter application
  • share copy, wrapping, type restoration, annotation safety, and history handling with normal execution
  • validate per-instance _batch_size, _batched_keys, and _keep dimensions
  • bypass probability and sampling while preserving normal history semantics
  • explicitly reject replay for composition, adapters, and lazy-only spatial transforms

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. #1494 — lossless subject batching — next to merge
  3. Add exact transform parameter replay #1495 — exact transform parameter replay (this PR)
  4. #1496 — subject mapping adapters and examples

Copilot AI review requested due to automatic review settings July 13, 2026 15:49
@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/454c2e0c26592v3m3y3v/

Built from 6124888

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 introduces an “exact replay” pathway for TorchIO transforms by adding Transform.apply_with_params(), enabling callers to reapply a transform using a previously recorded parameter dict while preserving the standard execution lifecycle (wrapping/unwrapping, copy semantics, type restoration, and history recording).

Changes:

  • Added Transform.apply_with_params() plus shared internal execution via _execute() to avoid duplicating lifecycle logic.
  • Implemented validation for reserved per-instance batching fields (_batch_size, _batched_keys, _keep) when replaying parameters.
  • Explicitly disabled parameter replay for composition-style transforms and opaque adapter transforms, and added targeted tests covering replay semantics.

Reviewed changes

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

Show a summary per file
File Description
tests/test_transforms_base.py Adds comprehensive tests for exact-parameter replay behavior, history semantics, copying, and batched-param validation.
src/torchio/transforms/transform.py Implements apply_with_params(), refactors execution into _execute(), and validates batched replay metadata.
src/torchio/transforms/monai_adapter.py Marks MonaiAdapter as not supporting apply_with_params() due to lack of a single param kernel.
src/torchio/transforms/cornucopia_adapter.py Marks CornucopiaAdapter as not supporting apply_with_params() for the same reason.
src/torchio/transforms/compose.py Marks Compose/OneOf/SomeOf as not supporting replay and simplifies rebatching error handling to align with current batch-schema validation.

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

@fepegar
fepegar force-pushed the fepegar/exact-transform-params branch from 530c9ed to cf91c4e Compare July 13, 2026 21:33
@fepegar
fepegar force-pushed the fepegar/lossless-subject-batches branch from 4bd8001 to 2ea69be Compare July 13, 2026 21:33
@fepegar
fepegar force-pushed the fepegar/exact-transform-params branch from cf91c4e to 2951b11 Compare July 13, 2026 21:47
@fepegar
fepegar requested a review from Copilot July 13, 2026 21:47

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 5 out of 5 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 force-pushed the fepegar/exact-transform-params branch 2 times, most recently from b2cb211 to 2253d34 Compare July 13, 2026 22:48
@fepegar
fepegar requested a review from Copilot July 13, 2026 22:49

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 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/torchio/transforms/transform.py
Comment thread src/torchio/transforms/transform.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 7 out of 7 changed files in this pull request and generated no new comments.

@fepegar
fepegar force-pushed the fepegar/exact-transform-params branch from 663847d to 22ccd57 Compare July 13, 2026 23:13
@fepegar
fepegar requested a review from Copilot July 13, 2026 23:13

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 1 comment.

Comment thread src/torchio/transforms/transform.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 7 out of 7 changed files in this pull request and generated no new comments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
fepegar added 4 commits July 14, 2026 09:59
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/exact-transform-params branch from 5c0ed59 to 6124888 Compare July 14, 2026 09:01
@fepegar
fepegar requested a review from Copilot July 14, 2026 09:01

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 no new comments.

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