Repository navigation
Move a protocol written as numbers to the card with the simulator - #27
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
_moved(src/torchsim/model/_signal.py), whichSimulator.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 tensoras_torchmakes 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
ModelOperatormoves its acquisition to the maps' device before every evaluation (_on). AMultiEchoSimulator(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'snlop.MultiEchobuilds its simulator that way, which is howapps.mobaon 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).ruff format --checkandruff checkon the changed files: clean.apps.mobaon CUDA now fits the maps the CPU fits (T2 79.98969 vs 79.98967 on a 32² test case).Documentation impact
None beyond the
_moveddocstring.🤖 Generated with Claude Code