Skip to main content

MRI Bloch Simulation

GigaBlochs is a flexible Bloch simulation framework enabling large parameter space investigations in Magnetic Resonance Imaging (MRI). The Bloch equations describe the time-evolution of magnetization in a magnetic field resulting from radiofrequency (RF) pulses, gradients waveforms, off-resonance effects, and motion of hydrogen nuclei (or "spins") through these fields, as in the case of pulsatile blood flow in arteries.

The capability to handle arbitrary, multi-dimensional spin properties which evolve at every timestep, combined with tools for flow modelling, allows for realistic simulations of complex sequences, such as Arterial Spin Labelling (ASL). ASL is a technique that uses the magnetization of blood as an endogenous contrast agent for quantification of perfusion.

Features

  • Simulate the full time-evolution of the magnetization following an arbitrary pulse sequence
  • Avoids the hard pulse approximation, constructing all B-field components from RF and gradient waveforms along with off-resonance effects
  • Uses numpy-style broadcasting to effectively run up to millions of Bloch simulations in parallel
  • Sophisticated blood flow modelling tools to incorportate friction and pulsatile flow effects when relevant
  • GPU acceleration using CuPy, with CPU fallback, for seamless and fully device-agnostic simulation code
  • Visualise the effect on magnetization of whole parameter grids using Bokeh
  • Animations of the magnetization dynamics in 3D on the Bloch Sphere using Manim

ASL Features

  • Simulate PASL sequences or background suppression using adiabatic pulses
  • Simulate CASL with constant concurrent RF and gradients
  • Simulate PCASL with a train of RF sinc pulses and gradients
  • Use arbitrary flow trajectories to simulate the effect of pulsatile blood flow
  • Use the rigid tube model to simulate viscosity and vessel wall friction across arteries

Example

Pulsed ASL (PASL) uses an adiabatic pulse to label a slab of blood in one go. Here's an animation on the Bloch sphere of an adiabatic inversion pulse in a reference frame rotating at the instantaneous frequency of the pulse (which only coincides with the Larmor frequency when passing through the transverse plane):

.. video:: _static/BlochScene_PASL.mp4 :width: 800 ➿

.. code-block:: python

from gigablochs import animation
animation.bloch_sphere(downsampled_magnetization, downsampled_b_field, time_interval)

See examples/Adiabatic Inversion Animation.ipynb <https://github.com/nathanielatom/gigablochs/blob/main/examples/Adiabatic%20Inversion%20Animation.ipynb>__ for the full simulation code.

.. .. toctree:: :maxdepth: 2 :caption: Examples :hidden:

    adiabatic_pulse_demo

.. pcasl_demo flow_demo background_suppression_demo

Installation

To install GigaBlochs, simply run:

.. code-block:: bash

pip install git+https://github.com/nathanielatom/gigablochs

Advanced Installation

For GPU acceleration using cupy, ensure you have a compatible NVIDIA GPU and CUDA toolkit <https://docs.cupy.dev/en/stable/install.html#requirements>__, then install GigaBlochs with the gpu extra:

.. code-block:: bash

pip install git+https://github.com/nathanielatom/gigablochs[gpu]

For 3D animations on the Bloch sphere using manim, install dependencies <https://docs.manim.community/en/stable/installation.html>__ as shown below and include the animation extra:

.. tab-set::

.. tab-item:: Ubuntu / Debian / Windows Subsystem for Linux (WSL)

    .. code-block:: bash

        sudo apt update
        sudo apt install build-essential pkg-config libcairo2-dev libpango1.0-dev
        pip install git+https://github.com/nathanielatom/gigablochs[animation]

.. tab-item:: macOS

    .. code-block:: bash

        # install brew package manager if not already installed
        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
        brew install cairo pkg-config
        pip install git+https://github.com/nathanielatom/gigablochs[animation]

Both extras can be installed at once with gigablochs[animation,gpu].

See dependencies in the pyproject.toml file for required and optional packages. To install the very latest commit from github run:

.. code-block:: bash

pip install git+https://github.com/nathanielatom/gigablochs

Metadata

Release files for gigablochs 0.2.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 gigablochs 0.2.4
File Size Uploaded
gigablochs-0.2.4.tar.gz 34.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gigablochs 0.2.4
File Interpreter ABI Platform
gigablochs-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 69.7 kB

Release files / gigablochs-0.2.4.tar.gz

Download URL gigablochs-0.2.4.tar.gz
Size 34.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1b22fce48afce098f7036bdf44a3534c7e1fc1aad3363e70879f9c6ef600e672
BLAKE2b-256 checksum
How to use checksums
8ee2997515a317faa8c305ca2ec8481a09f20841c2267a8d94954ffa408adfbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 2, 2026.

Transparency log

Release files / gigablochs-0.2.4-py3-none-any.whl

Download URL gigablochs-0.2.4-py3-none-any.whl
Size 34.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9bf43821f48afe5cc280dfcee285d97afe391d3d78c21afd355d272f06bf23d
BLAKE2b-256 checksum
How to use checksums
2ad51ac2e21fb46a70046b4958735c692a305895fcdaff3109be9115a784d5cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.4 This release

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