Skip to content

Fit moba on a card, and check pics there through the reference command - #125

Merged
mcencini merged 1 commit into
mainfrom
moba-on-cuda
Oct 6, 2026
Merged

mcencini merged 1 commit into
mainfrom
moba-on-cuda

Conversation

@mcencini

@mcencini mcencini commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • apps.moba (src/bartorch/apps/_moba.py): the starting point and reference (model.initial(...)) and the zero coil coefficients are made on kspace.device.
  • tests/test_apps.py: test_moba_fits_the_decay_behind_known_coils and test_moba_estimates_the_coils_with_the_decay take the device fixture and check that the fitted maps come back on it.
  • scripts/check_device.py: the three pics checks call bartorch._reference.pics (with traj= and toeplitz=False) in place of the removed bartorch.tools.pics.

Why

A fit given CUDA k-space failed on its first Gauss-Newton step: the iterate was on the host and the data on the card. With torchsim's protocol fix (pulserver/blochsim#27) the model follows the maps too, so moba now fits on a card end to end. check_device.py stopped at 6/9 because tools.pics moved to apps.

Validation

On an RTX 4060 Laptop, CUDA 12.8 build (BARTORCH_CUDA=ON, sm_89), torch 2.13+cu130:

  • pytest -k moba tests/test_apps.py tests/test_cli.py: 79 passed (the CUDA legs included; they need torchsim#27).
  • python scripts/check_device.py: 9/9.
  • moba -T -l2, 128², 8 coils, 8 echoes: the app on CUDA returns the CPU app's maps (R2 error against the truth 2.4e-03 median, 1.8e-02 max, on both devices). Under load from other jobs on the machine it took 30–40 s on the card against 371 s on the host; the command with -g took 2.7 s at its default 8 steps, which do not converge on this phantom (about 12 do).
  • ruff format --check and ruff check on the changed files: clean.

Not in this PR

Most of the app's time on a card is TorchSim's model evaluated about six times per conjugate-gradient step: the bundle's members are TorchOperators, which evaluate with gradients tracked so that their own derivatives can be served by autograd, so a Jacobian built once per Gauss-Newton step cannot be used without making the derivative by the point wrong. Reaching the command's speed needs the bundle members as an operator linear in the tangent, with the second-order terms on demand.

Documentation impact

None.

🤖 Generated with Claude Code

apps.moba made its starting point, its reference and its coil
coefficients on the host whatever device the k-space was on, so a fit
given CUDA k-space failed on its first Gauss-Newton step with a device
mismatch. They are now made on the k-space's device. The two moba tests
that fit with and without known coils run on each device.

scripts/check_device.py called bartorch.tools.pics, which the apps
assemble now; its three pics checks run the reference command instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mcencini
mcencini merged commit 4a309a4 into main Oct 6, 2026
20 of 22 checks passed
@mcencini
mcencini deleted the moba-on-cuda branch October 6, 2026 13:39
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