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.

This package is inspired by the following excellent projects:

Metadata

Release files for torchsim 0.0.8

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.8
File Size Uploaded
torchsim-0.0.8.tar.gz 20.6 MB Details

Built distributions (wheels)

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

Total release size: 33.1 MB

Release files / torchsim-0.0.8.tar.gz

Download URL torchsim-0.0.8.tar.gz
Size 20.6 MB
Tags Source
SHA-256 checksum
How to use checksums
6626025983aa0fe3c9d385d861f7b210a9a6d111ec58d439cfe150021d036baf
BLAKE2b-256 checksum
How to use checksums
0f236ee7d5f39ff2182a2a6e00632ba3bfc707ea4151adc6e3c88e5f0291490e
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 Oct 1, 2026.

Transparency log

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

Download URL torchsim-0.0.8-cp310-abi3-win_amd64.whl
Size 1.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1ee8a9673e4d4d31f9b0a7f95b99dd3e7e7cc1c6b6acf586abd217b73e8664a3
BLAKE2b-256 checksum
How to use checksums
4aada2ff53f7fd2896019a083a852afe9c1109f69a2e43af923a3b19fadcd64a
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 Oct 1, 2026.

Transparency log

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

Download URL torchsim-0.0.8-cp310-abi3-musllinux_1_2_x86_64.whl
Size 2.8 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
3cec4abb46304b26d92401261d9425fabb7995c4976d04b88b005a826f4620b1
BLAKE2b-256 checksum
How to use checksums
646935f1cd9b3c3b0f49521758c3735aa0a9bf6a5ad700d2ff058302da7c3a81
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 Oct 1, 2026.

Transparency log

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

Download URL torchsim-0.0.8-cp310-abi3-musllinux_1_2_aarch64.whl
Size 2.6 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
150fa08eb52bfdcfae5cb56f2d0cc00a523307867a0c414e2898a6146a3ea849
BLAKE2b-256 checksum
How to use checksums
bae25916ba30a0e89cac77791c36c2f28895be3c0e2bc51807045350b6fad157
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 Oct 1, 2026.

Transparency log

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

Download URL torchsim-0.0.8-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.0 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
5b2e06db2266216183cc2c3850f10d62b1c639e373b184677d99fc72992331d3
BLAKE2b-256 checksum
How to use checksums
0e90e1b8f983a3bb076c49f1dbedb5d1c02a94378c26fa2f141d45caf6b4e0fe
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 Oct 1, 2026.

Transparency log

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

Download URL torchsim-0.0.8-cp310-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 1.6 MB
Tags CPython 3.10 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
57183f84fcda93c4889f939d12c6f2bec01988884162d0f8ac10cb9bb105130c
BLAKE2b-256 checksum
How to use checksums
b490f4290163012a354eea368a749e7fc1bbef55f519d0c5d8f6139f1e550126
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 Oct 1, 2026.

Transparency log

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

Download URL torchsim-0.0.8-cp310-abi3-macosx_11_0_arm64.whl
Size 1.2 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5089d1f2bd8091decd9b735e2ab32cf11122a9e234d9e6f3e53d282991d25791
BLAKE2b-256 checksum
How to use checksums
0eae4baccaf966f54401489b9392bca2d49807cc3d0a41732522bde6a9298e05
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 Oct 1, 2026.

Transparency log

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

Download URL torchsim-0.0.8-cp310-abi3-macosx_10_9_x86_64.whl
Size 1.3 MB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
6729bc488c38fa58c3a2474217b7f5f4d8ccf3424e9d07ddd1d0b147f316e3ea
BLAKE2b-256 checksum
How to use checksums
3b2a2c70a2da3f9f82e3d44e33eab2d1fd6a5fab03c6f6219829df8e1b6d26e7
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 Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.8 This release

8 release files

0.0.7

8 release files

0.0.6

8 release files

0.0.5

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