Skip to content

A feature-rich MR simulator supporting massive parallelization on GPU and automatic differentiation.

License

Notifications You must be signed in to change notification settings

INFN-MRI/torchsim

Repository files navigation

TorchSim

TorchSim is a pure Pytorch-based MR simulator, including analytical and EPG model.

Coverage CI/CD License Codefactor Sphinx PyPi Black PythonVersion

Features

TorchSim contains tools to implement parallelized and differentiable MR simulators. Specifically, we provide

  1. Automatic vectorization of across multiple atoms (e.g., voxels).
  2. Automatic generation of forward and jacobian methods (based on forward-mode autodiff) to be used in parameter fitting or model-based reconstructions.
  3. Support for custom manual defined jacobian methods to override auto-generated jacobian.
  4. Support for advanced signal models, including diffusion, flow, magnetization transfer and chemical exchange.
  5. GPU support.

Installation

TorchSim can be installed via pip as:

pip install torchsim

Basic Usage

Using TorchSim, we can quickly implement and run MR simulations. We also provide pre-defined simulators for several applications:

import numpy as np
import torchsim

# generate a flip angle pattern
flip = np.concatenate((np.linspace(5, 60.0, 300), np.linspace(60.0, 2.0, 300), np.ones(280)*2.0))
sig, jac = torchsim.mrf_sim(flip=flip, TR=10.0, T1=1000.0, T2=100.0, diff=("T1","T2"))

This way we obtained the forward pass signal (sig) as well as the jacobian calculated with respect to T1 and T2.

Development

If you are interested in improving this project, install TorchSim in editable mode:

git clone git@github.com:INFN-MRI/torchsim
cd torchsim
pip install -e .[dev,test,doc]

Related projects

This package is inspired by the following excellent projects:

About

A feature-rich MR simulator supporting massive parallelization on GPU and automatic differentiation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages