Skip to content

Move a protocol written as numbers to the card with the simulator - #27

Merged
mcencini merged 1 commit into
mainfrom
device-moves-protocol-lists
Oct 6, 2026
Merged

mcencini merged 1 commit into
mainfrom
device-moves-protocol-lists

Conversation

@mcencini

@mcencini mcencini commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

What changed

  • _moved (src/torchsim/model/_signal.py), which Simulator.to(device) and _SignalModel.to(device) use, now moves a protocol entry given as a list or tuple of numbers to the target device as the tensor as_torch makes of it. Tensors move as before; scalars and non-numeric entries stay as given; on the host nothing is converted, so the caller's library is kept.
  • tests/recon/test_operator.py: test_maps_on_a_card_meet_echo_times_written_as_numbers_there, parametrized over a list and a tuple of echo times.

Why

ModelOperator moves its acquisition to the maps' device before every evaluation (_on). A MultiEchoSimulator(TE=[...]) kept its echo times on the host through that move, and the closed form failed on a CUDA/CPU device mismatch, so no model with a protocol written as plain numbers could run on a card. bartorch's nlop.MultiEcho builds its simulator that way, which is how apps.moba on CUDA found it. A NumPy protocol was unaffected: it is already a tensor by construction.

Validation

On an RTX 4060 (CUDA 13.0, torch 2.13):

  • pytest tests/recon/test_operator.py tests/model: 88 passed (the new test fails on main with the device mismatch).
  • Every test file mentioning CUDA: 829 passed, 1 skipped.
  • ruff format --check and ruff check on the changed files: clean.
  • bartorch apps.moba on CUDA now fits the maps the CPU fits (T2 79.98969 vs 79.98967 on a 32² test case).

Documentation impact

None beyond the _moved docstring.

🤖 Generated with Claude Code

Simulator.to(device) moved only the protocol entries that were already
tensors. Echo times given as a list or tuple stayed on the host, and a
closed form then multiplied them against maps on the card, which fails on
a device mismatch. ModelOperator moves its acquisition to the maps' device
before every evaluation, so any model whose protocol was written as plain
numbers could not be evaluated on CUDA; bartorch's nlop.MultiEcho is one.

Off the host, a list or tuple of numbers now arrives as the tensor
as_torch makes of it. On the host it stays as the caller wrote it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mcencini
mcencini merged commit e0987ba into main Oct 6, 2026
22 checks passed
@mcencini
mcencini deleted the device-moves-protocol-lists branch October 6, 2026 13:25
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