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

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

Built distributions (wheels)

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

Download URL torchsim-0.0.6.tar.gz
Size 20.5 MB
Tags Source
SHA-256 checksum
How to use checksums
c099defe761e98e0a537118e931fba77e9660f2df623ce44a369580fbdfd90ea
BLAKE2b-256 checksum
How to use checksums
1f64b8b475b0a0ad8708487792b02edc96791703d288b47c626b0f4a7d78812d
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 17, 2026.

Transparency log

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

Download URL torchsim-0.0.6-cp310-abi3-win_amd64.whl
Size 901.6 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8f9ddc631086d7dc6a37b144da50939be90472bd744169fc53f3a246c6cf780b
BLAKE2b-256 checksum
How to use checksums
61d62fbc5bb52d6826aa43af4488fa1a5afc1c7b2caed6f48221570db428e3a9
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 17, 2026.

Transparency log

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

Download URL torchsim-0.0.6-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
d76f846cf19a88c99c155e3a2979e58d670f182214d6f812955b16f882c7be13
BLAKE2b-256 checksum
How to use checksums
8e72f240173c14b78f166ad12f845d09a3aef9265676b50651da2e3a75ef9534
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 17, 2026.

Transparency log

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

Download URL torchsim-0.0.6-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
a455ca8fa49a8c70c6007deebcd6929bb0a3a900e39b70ea4bb4d3cc2c108fa8
BLAKE2b-256 checksum
How to use checksums
418b9ea35bfd457bf9c94e378c2d29fedc31b21d10c6db43c0b52d8caedf28be
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 17, 2026.

Transparency log

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

Download URL torchsim-0.0.6-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
1cf3007d9634aee1734880e18324c54e24679266b02495f285c9c1386a78a7ac
BLAKE2b-256 checksum
How to use checksums
99a834f32604830b963dac8df90b812859719a5980552542607dba40e9075932
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 17, 2026.

Transparency log

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

Download URL torchsim-0.0.6-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
8b31ef9dabcf610064d581fbe3e2c48d369ddee4ab050550e329b72a8257a9e9
BLAKE2b-256 checksum
How to use checksums
cf8c225bdfdb65c4183fec51708dcd90aa75191ba67e028ab8a574a650993691
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 17, 2026.

Transparency log

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

Download URL torchsim-0.0.6-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
fcacf7985f388f0e420ded3090f48e7d1cccff326ced3fe79a99f0e73da1964c
BLAKE2b-256 checksum
How to use checksums
91a1350723ac8ef6869f9b4ae4bd94851678d519dfd04299f3f87d3096179906
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 17, 2026.

Transparency log

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

Download URL torchsim-0.0.6-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
a6a0a2dcdf687785e162cf3dbdcf4c645baefd1961f8a0dd048cda502170f502
BLAKE2b-256 checksum
How to use checksums
b254f1370fe75b01cb4631c691ddda5f314f5308b6e227dcdee92a03db5109d3
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 17, 2026.

Transparency log

Release history Release notifications | RSS feed

0.0.8

8 release files

0.0.7

8 release files

This release

0.0.6 This release

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