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

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

Built distributions (wheels)

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

Download URL torchsim-0.0.4.tar.gz
Size 20.5 MB
Tags Source
SHA-256 checksum
How to use checksums
739656945ba6664b3fa3248772bdd51641fe38326fae0d092374b82119766ec4
BLAKE2b-256 checksum
How to use checksums
f057019e2a1ce857c9b4206763ea4b3740238c6fa459cb28e4c387b1005c4d0a
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.4-cp310-abi3-win_amd64.whl

Download URL torchsim-0.0.4-cp310-abi3-win_amd64.whl
Size 901.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
265d6672331df97b51749b0f34ed537c4402ac3c94fcb1bcc6ee206ef02f3fa1
BLAKE2b-256 checksum
How to use checksums
d96f889391a638cab628c8816915c3f2c0e3e61a760fbafe8b6eaeb22a06bd8f
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.4-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL torchsim-0.0.4-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
71946079f58a1e6d55591d941e01c34c6a2e8128a24bb2b254221ebd58c532a4
BLAKE2b-256 checksum
How to use checksums
9783befad83d3d937b15c727d773cf316ee472df34d4869065bc3ef6e710b02f
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.4-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL torchsim-0.0.4-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
eeed5586893ae672afe16fc0fedf84dc5633a9562eab64ea0fc8a5579aff8c8c
BLAKE2b-256 checksum
How to use checksums
3e2ed12bcb210040428683565fcce27dd772d814317293307d965bcfaeeec39f
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.4-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL torchsim-0.0.4-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
49bf1c1c92801de55c33a38ebb052574a89d69fd4ba2abaaabefd6245e9198b7
BLAKE2b-256 checksum
How to use checksums
7c5b99bfc542b5b6ebeec56abfad9bc2ebf471307abb24d2cd9d71d5d8294ace
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.4-cp310-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL torchsim-0.0.4-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
2618e863aa1d7a256b1df4112a065b9756d888d26ebb71f5b3d9d783ef3435e6
BLAKE2b-256 checksum
How to use checksums
dd52a3e04e20ff241818fddfa58a59ec8bdcd08d8fce52613d6c5253d9a22949
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.4-cp310-abi3-macosx_11_0_arm64.whl

Download URL torchsim-0.0.4-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
0300d54d76fb60ca51a7304b243d85a5cbeea29fbd9c33f2ec6d5fa92feff1fb
BLAKE2b-256 checksum
How to use checksums
c3b3b85db4e2c5f02e9bcbd03a82e764aa03f320e289108674a207976878ab11
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.4-cp310-abi3-macosx_10_9_x86_64.whl

Download URL torchsim-0.0.4-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
b219ac5ee99791059613eb053e187b4342f381ce280ab1a63c681ce29a502779
BLAKE2b-256 checksum
How to use checksums
367c65ab0aa9f3a8cf003c78815b74ba274440db7257bc4c40c825741471c5b7
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

0.0.5

8 release files

This release

0.0.4 This release

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