Skip to main content

Tests PyPI Docs: stable PyTorch License: MIT

bartorch

bartorch puts BART, the Berkeley Advanced Reconstruction Toolbox, inside your Python process. You hand it PyTorch tensors, on the CPU or on a CUDA device, and BART works on them where they are: no .cfl files, no bart executable, no subprocess. What comes back is a tensor, so a BART reconstruction can sit inside any PyTorch code, including the training loop of an unrolled network.

You use BART in one of three ways, from the most ready-made to the most flexible:

  • Tools. Every BART command is a Python function: bt.ecalib(kspace), bt.phantom(128), bt.traj(...). If you know BART's command line, you already know them.
  • Apps. BART's reconstructions (pics, moba, mobafit, POCSENSE) are functions that take k-space and return an image.
  • Operators and solvers. You write the encoding yourself, A = P F S or anything else, compose it with @ and +, and solve it with one of BART's iterations. This is where a reconstruction BART has no command for lives, and it is differentiable.

The three are the same library underneath: apps.pics is an encoding operator and a solver, built for you.

bartorch architecture

How it works

  1. You pass a tensor. A C-order tensor of shape (coils, z, y, x) holds the same bytes as a BART array of dimensions [x, y, z, coils], so bartorch reverses the shape and hands BART the tensor's memory. Nothing is copied.
  2. BART runs in the same process, compiled into the package. When BART reports an error, you get a Python exception (bartorch.BartError) with BART's message, and your interpreter keeps running.
  3. A few parts of BART are swapped for faster ones: every non-uniform FFT is FINUFFT (cuFINUFFT on a card), and the FFT, BLAS and LAPACK come from MKL, PyTorch's own library or SciPy. The numbers are BART's everywhere else.
  4. A CUDA tensor stays on its card. The operators and solvers run there directly, and a tool runs on the card when that has been checked to be safe; otherwise its result is copied back to the card for you.
  5. An operator applied to a tensor that requires a gradient is recorded by autograd, and its backward pass is its adjoint. You can train through a reconstruction.

Tools: BART's commands

import bartorch.tools as bt

kspace = bt.phantom(128, coils=8, kspace=True)  # (coils, z, y, x)
compressed = bt.cc(kspace, p=4)
maps = bt.ecalib(compressed, maps=1)
  • Options are keyword arguments, under BART's long name or its one-letter flag.
  • Where BART takes a bitmask of dimensions, you pass tensor axes: bartorch.fft(x, axes=(-2, -1)).
  • Every command BART has is here, as a function or, for the few with a reason not to be, listed as such in the documentation.

Apps: BART's reconstructions

from bartorch import apps, priors

image = apps.pics(compressed, maps, regularizers=priors.Wavelet((-1, -2), 0.005))
  • A regularization term is an object from bartorch.priors, not a -R string; its axes are tensor axes.
  • apps.pics gives the same bits as BART's pics command, and the documentation's tests hold it to that.

Operators and solvers: custom reconstruction

import torch

from bartorch import linop, optim, priors

A = linop.CartesianSense(maps, (128, 128), pattern)  # A = P F S
image = optim.FISTA(priors.Wavelet((-1, -2), 0.005), maxiter=100)(kspace, A)

B = A @ linop.Diagonal(phase)  # one more factor, still one BART operator
loss = (B(x) - kspace).abs().pow(2).sum()
loss.backward()  # x.grad is 2 B^H (B x - y)
  • A(x) applies the operator, A.H(y) its adjoint, and A.H @ A its normal. A composition is handed to BART as one operator, so a solver iterating on it never comes back to Python.
  • A.plan tells you how BART will run what you composed: which transform, which factors were fused, and whether it fell back to a slower path.
  • An operator you write in Python (a forward and an adjoint) joins a composition like any other.

Command line

The bartorch command takes the same arguments as bart, so a script written for BART runs with the name changed and no BART installation:

bartorch phantom -k -s 8 kspace
bartorch ecalib -m 1 kspace maps
bartorch pics -R W:3:0:0.005 kspace maps image

Installation

pip install bartorch
pip install "bartorch[cu12]"  # with CUDA 12; use cu13 for CUDA 13

Wheels are built for Linux x86-64, macOS arm64 and Windows x86-64; the CUDA build is Linux x86-64 only. The other extras are listed under Optional dependencies, GPU builds under Installation, and source builds in the developer guide.

Learn more

  • Course: from k-space to an image, then parallel imaging, regularization, non-Cartesian and model-based reconstruction, and learned regularization. Every lesson opens in Colab.
  • Documentation, for every function, operator and option.

How to cite

bartorch has no publication of its own. Please cite BART (Uecker et al., doi:10.5281/zenodo.592960) and the papers behind the methods you used (ESPIRiT, compressed sensing, nonlinear inversion, ...), and report the bartorch version. Contributors and citation lists the references.

License

MIT. The embedded BART (BSD-3-Clause), FINUFFT (Apache-2.0) and the other bundled code keep their own licenses; see License and third-party notices. bartorch is an independent project, not affiliated with or endorsed by the BART developers, the PyTorch Foundation or The Linux Foundation. The logo combines BART's mark with the PyTorch logo's flame; PyTorch, the PyTorch logo and any related marks are trademarks of The Linux Foundation.

Metadata

Release files for bartorch 0.0.24

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bartorch 0.0.24
File Size Uploaded Provenance Actions
bartorch-0.0.24.tar.gz 7.4 MB With provenance Details for bartorch-0.0.24.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for bartorch 0.0.24
File Interpreter ABI Platform Actions
bartorch-0.0.24-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for bartorch-0.0.24-py3-none-win_amd64.whl
bartorch-0.0.24-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for bartorch-0.0.24-py3-none-manylinux_2_28_x86_64.whl
bartorch-0.0.24-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for bartorch-0.0.24-py3-none-macosx_11_0_arm64.whl

Total release size: 31.3 MB

Release files / bartorch-0.0.24.tar.gz

Download URL bartorch-0.0.24.tar.gz
Size 7.4 MB
Tags Source
SHA-256 checksum
How to use checksums
9c1c2428aed1b546276ee7dc54eeaa39b33b1d9a9e97621948bf336b92d86180
BLAKE2b-256 checksum
How to use checksums
3b88c7131cd61a3e240f3d7c22576a3102cd32506925000dcc2ca491760aa523
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 13, 2026.

Transparency log

Release files / bartorch-0.0.24-py3-none-win_amd64.whl

Download URL bartorch-0.0.24-py3-none-win_amd64.whl
Size 7.7 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
55aec9a262a3701bfc5a49fc6cee9e8967e345552e2bc35acec62024342c0af2
BLAKE2b-256 checksum
How to use checksums
693e043f76d9dbb5d2b48c2e74f61efde627dd62194d1ca071e3d29c0918c1bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 13, 2026.

Transparency log

Release files / bartorch-0.0.24-py3-none-manylinux_2_28_x86_64.whl

Download URL bartorch-0.0.24-py3-none-manylinux_2_28_x86_64.whl
Size 13.2 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
1ec8c02da0cc258b34b7deb7da5dbbe4c810c059911ec3c32d5a71abf3199c32
BLAKE2b-256 checksum
How to use checksums
c5eb9fdd2a386664b03ba6c03de4dbd493a741f5ca61f6642a37bd46db63e011
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 13, 2026.

Transparency log

Release files / bartorch-0.0.24-py3-none-macosx_11_0_arm64.whl

Download URL bartorch-0.0.24-py3-none-macosx_11_0_arm64.whl
Size 3.0 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
94d865a2684689d6117e1ee06a940ff1cd3440a5265c350718ed6cc5cf17e8e1
BLAKE2b-256 checksum
How to use checksums
331e17e165da8912b558460192edc2401fd9a5038a5a9bd60f889cc3edba17fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 13, 2026.

Transparency log

Security for bartorch 0.0.24

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.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for bartorch-0.0.24.tar.gz

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 Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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