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.7

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.7
File Size Uploaded
torchsim-0.0.7.tar.gz 20.5 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for torchsim 0.0.7
File
torchsim-0.0.7-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
torchsim-0.0.7-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
torchsim-0.0.7-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
torchsim-0.0.7-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.7-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.7-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
torchsim-0.0.7-cp310-abi3-macosx_10_9_x86_64.whl CPython 3.10 abi3 macOS 10.9+ x86-64 Details

Total release size: 31.8 MB

Release files / torchsim-0.0.7.tar.gz

Download URL torchsim-0.0.7.tar.gz
Size 20.5 MB
Tags Source
SHA-256 checksum
How to use checksums
152019817cf6084553785475b025ad88c22b559b0b91531c35e254b275149cfa
BLAKE2b-256 checksum
How to use checksums
3c9444b6e309803809213a04042cd8b344ba30efbe4966f866e8cfc6a7331f24
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 30, 2026.

Transparency log

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

Download URL torchsim-0.0.7-cp310-abi3-win_amd64.whl
Size 916.8 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
92f90749f298e3ceec13426dd4b641917ea20299c01d15b27fb46153c680ae7f
BLAKE2b-256 checksum
How to use checksums
0f6c7ba00fcf0d166f027c886a47deab75b3f63151683cda80a78517f2037c55
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 30, 2026.

Transparency log

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

Download URL torchsim-0.0.7-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
34a7c844d1531ef217fad370c7de1bd00e7996948e5cefc1164a15404aa859d7
BLAKE2b-256 checksum
How to use checksums
0f83507bab2fb7f5cde6f98646ba71df448cfacbc8e3199e9b3eb7d9a2164e00
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 30, 2026.

Transparency log

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

Download URL torchsim-0.0.7-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
b31dc7e5f89b3a07425795d892c57908bc0fc64c9ea6f61085a5267f392df6d5
BLAKE2b-256 checksum
How to use checksums
2aeaca62678d2dc507903e0a3d4e30f0f10591f1efb91f4f43198c47092a5a9c
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 30, 2026.

Transparency log

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

Download URL torchsim-0.0.7-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.8 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
0afc3522673383322e19648429dfbdde6746b20e8b76ee93e9a0ecd9ec522806
BLAKE2b-256 checksum
How to use checksums
5fcdbf59269fd63fc17ab04b200550eb20e9b858c6f9daddc785f698e43e7422
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 30, 2026.

Transparency log

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

Download URL torchsim-0.0.7-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
c7a2f470d1131816292ebe131371b8284afb8fdabdd5ea0f9de39d422a3a01c3
BLAKE2b-256 checksum
How to use checksums
edad948841e9ff9011de8992916d28fce5474b78005cef12905338a9574fd655
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 30, 2026.

Transparency log

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

Download URL torchsim-0.0.7-cp310-abi3-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b8e8a748ae71dbba6562f8253f8d794e348c056dcacbf8ca3e140997c7a7a644
BLAKE2b-256 checksum
How to use checksums
d3421348d2105a415c1a7b215f455bcb6cebbcc5ac8e1de449d72b4724f54d05
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 30, 2026.

Transparency log

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

Download URL torchsim-0.0.7-cp310-abi3-macosx_10_9_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
bed0999621a8766b094fd6cd9d25f005e85086b9b2025de998cb64aec5a5f2ed
BLAKE2b-256 checksum
How to use checksums
e66d1d6a21ec44cfa633a1bebdefd77042b650d574ae84489ec85f1bd568046d
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 30, 2026.

Transparency log

Release history Release notifications | RSS feed

0.0.8

8 release files

This release

0.0.7 This release

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