Skip to main content

Introduction

demo-nocap.png

sfparticles is a simulation toolkit for particle tracking. Unklike particle-in-cell simulations, sfparticles does not solve field equations but instead tracks individual particles in pre-defined fields, without considering the inter-particle interactions. This allows for fast 3D simulations of large numbers of particles when plamsa denisty is low.

Features

  • Numba Acceleration: sfparticles leverages Numba to accelerate simulations by compiling Python code to machine code.
  • Cascade Simulation: Optimized for exponentially growing number of particles.
  • Flexible Field Configuration: sfparticles allows you to define complex electromagnetic fields using python functions.
  • Particle Tracking: Track the trajectories of particles. see example.

Installation

from github:

git clone https://github.com/xsgeng/sfparticles.git
cd sfparticles
pip install --user -e .

from pypi:

pip install sfparticles

Usage

Basic Simulation

To run a basic simulation, you can refer to the example scripts provided in the examples directory. For instance, to simulate a particle cascade, you can use the cascade.py script:

python examples/cascade.py
# set number of threads
NUMBA_NUM_THREADS=64 python examples/cascade.py

For trajectory simulations, you can use the trajectory.py script:

python examples/trajectory.py

Advanced Settings

You can set environment variables to configure the simulation. For example, to use an optical depth radiation model, set the SFPARTICLES_OPTICAL_DEPTH environment variable:

SFPARTICLES_OPTICAL_DEPTH=1 python examples/cascade.py

GPU Acceleration

For even faster simulations, sfparticles supports GPU acceleration. To enable this feature, you need to install CUDA and set SFPARTICLES_USE_GPU=1 environment variable.

Note: GPU is slow for small number of particles.

Installing CUDA

conda install -c conda-forge cupy cudatoolkit=11.2

Enabling GPU Acceleration

SFPARTICLES_USE_GPU=1 python examples/cascade.py

For Slurm job schedulers, you can use the following command:

SFPARTICLES_USE_GPU=1 srun -p gpu -G 1 -u python examples/cascade.py

Metadata

Release files for sfparticles 0.5.0

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

Source distribution (sdist)

Source distribution for sfparticles 0.5.0
File Size Uploaded
sfparticles-0.5.0.tar.gz 2.6 MB Details

Built distribution (wheel)

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

Total release size: 5.2 MB

Release files / sfparticles-0.5.0.tar.gz

Download URL sfparticles-0.5.0.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
517a7b6ba4791ee577880a7333cae527b405858a53b18adf38320fdaf517f554
BLAKE2b-256 checksum
How to use checksums
4a7cf29276ef20b456e1d8ac3d792aa045bea0380e0756c8deb1c18b95963ff1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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 Apr 28, 2026.

Transparency log

Release files / sfparticles-0.5.0-py3-none-any.whl

Download URL sfparticles-0.5.0-py3-none-any.whl
Size 2.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
00c32ce769154ca6c04f0d7ea14c56f744fb130c3ca1259a631b95775e87a019
BLAKE2b-256 checksum
How to use checksums
73e48f42d213d7f2bbb90e4322c13c10a2fb4e2560c56ff092375a61843de464
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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 Apr 28, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.11

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