Skip to main content

TorchSim

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

codecov Tests Lint License Codefactor Documentation PyPi Ruff 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:FiRMLAB-Pisa/torchsim
cd torchsim
pip install -e ".[dev]"
pre-commit install

The install compiles the two C++ kernels, so it needs a C++17 compiler; CMake and Ninja arrive as build-time wheels. pre-commit runs the formatter and the linter -- both ruff -- on every commit, which is exactly what CI checks.

Related projects

This package is inspired by the following excellent projects:

Metadata

Release files for torchsim 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torchsim 0.0.5
File Size Uploaded
torchsim-0.0.5.tar.gz 20.5 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for torchsim 0.0.5
File
torchsim-0.0.5-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
torchsim-0.0.5-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
torchsim-0.0.5-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
torchsim-0.0.5-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
torchsim-0.0.5-cp310-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 Details
torchsim-0.0.5-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
torchsim-0.0.5-cp310-abi3-macosx_10_9_x86_64.whl CPython 3.10 abi3 macOS 10.9+ x86-64 Details

Total release size: 31.7 MB

Release files / torchsim-0.0.5.tar.gz

Download URL torchsim-0.0.5.tar.gz
Size 20.5 MB
Tags Source
SHA-256 checksum
How to use checksums
823827c68829640034391af594cc0647e49db7543aca4f357a4a1abe91588fc9
BLAKE2b-256 checksum
How to use checksums
3aa5ce39b511914050d67ec057c5b04de3e0171fd3efc9dff00b986c846b8cc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / torchsim-0.0.5-cp310-abi3-win_amd64.whl

Download URL torchsim-0.0.5-cp310-abi3-win_amd64.whl
Size 901.3 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
73981890181763779de0fef2c6a22c98661e771cceecc4fc63530bb324914d20
BLAKE2b-256 checksum
How to use checksums
1d7f7a30020c8dba9957934965cf00e5b79d96dca710b0654b0bfd4db6cd2ddc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / torchsim-0.0.5-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL torchsim-0.0.5-cp310-abi3-musllinux_1_2_x86_64.whl
Size 2.6 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7d4e3bfc1ad731f0d674e13fadeadb96257aeaed87d0a939b715a1b0ea9b48c6
BLAKE2b-256 checksum
How to use checksums
e9868ffdc1d78a840cb2fd1e6617f9e3bce5a400299e4d3adbea69e904c87697
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / torchsim-0.0.5-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL torchsim-0.0.5-cp310-abi3-musllinux_1_2_aarch64.whl
Size 2.4 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
f000d97a10b621f7f93e3552ff892961f178240a6e6b03533c36b788a9706b03
BLAKE2b-256 checksum
How to use checksums
683344982d3209f1bbdec4faf4cd3fdac8c0fe0ffb5f9ca26c7e26a251d69ef4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / torchsim-0.0.5-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL torchsim-0.0.5-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
d09adac409a2cf82e8a2574f45e3fc6096656b65d9d8a5eb0768176479607c0d
BLAKE2b-256 checksum
How to use checksums
d02ee7075f35cadbba714ebe59f094be5e0597367e34cffa850cfae8f6f9e5ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / torchsim-0.0.5-cp310-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL torchsim-0.0.5-cp310-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 1.4 MB
Tags CPython 3.10 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
afea7d8beea0ff3af21fcdbe533e16df1f4f6ac6a275ef62b23b642a09198865
BLAKE2b-256 checksum
How to use checksums
b78bd5be41a3f93f6a6156a69e3afda57bb00f7c1d50c5eeb73e7a52507391dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / torchsim-0.0.5-cp310-abi3-macosx_11_0_arm64.whl

Download URL torchsim-0.0.5-cp310-abi3-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
43c9aa894aeffd46070cb7b61e1e13992f6749f7e76d64c25d8078c28fda0756
BLAKE2b-256 checksum
How to use checksums
fe5ed248fae0ef43a8c11b0da4c05222c6b92306a626576559302ba2252070ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / torchsim-0.0.5-cp310-abi3-macosx_10_9_x86_64.whl

Download URL torchsim-0.0.5-cp310-abi3-macosx_10_9_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
c330281d97abd5f1e91d3d9b41a05f70e8f09f3897350857c5622c004ec4d86a
BLAKE2b-256 checksum
How to use checksums
4fced0b80623c8064329249871328f21b8eeda45bf67bacfdf6235aa83eef3ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release history Release notifications | RSS feed

0.0.8

8 release files

0.0.7

8 release files

0.0.6

8 release files

This release

0.0.5 This release

8 release files

0.0.4

8 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page