FBPIC installation tutorial: CPU and GPU setup with Conda
Updated · Scientifically reviewed by Dinkar Mishra, PhD on
Short answer
FBPIC is a Python package: create a Conda environment with Python, NumPy, SciPy, Numba and h5py, then pip install fbpic. For NVIDIA GPU runs also install a CuPy build matching your CUDA version (for example cupy-cuda12x); for multi-GPU runs add mpi4py. Verify by running an official example script with use_cuda=True and checking that the process appears in nvidia-smi.
Who this is for
Researchers and students in laser–plasma and accelerator physics who want to run FBPIC on a workstation or cluster.
Software
FBPIC latest release on PyPIPython 3.x supported by the release (see docs)CUDA 12.x with matching CuPy (GPU runs)
Prerequisites
- Linux (or WSL2 on Windows). macOS works for CPU-only runs.
- Miniforge or Anaconda for Conda environments.
- For GPU runs: an NVIDIA GPU with a working driver. Check with
nvidia-smiand note the “CUDA Version” it reports. If the GPU is not visible, fix that first using our GPU not detected guide.
Step 1: create a clean environment
conda create -n fbpic -c conda-forge python numpy scipy numba h5py
conda activate fbpic
Using conda-forge for the numerical stack avoids mixing incompatible binary packages.
Step 2: install FBPIC
python -m pip install fbpic
Step 3 (GPU): install CuPy for your CUDA version
python -m pip install cupy-cuda12x # for CUDA 12.x drivers; use cupy-cuda11x for CUDA 11.x
python -c "import cupy; print(cupy.cuda.runtime.getDeviceCount(), 'GPU(s) visible')"
The CuPy package must match the CUDA major version that your driver supports. See the CuPy installation guide for other options, including Conda packages.
Step 4 (optional): MPI for multi-GPU runs
On a workstation:
conda install -c conda-forge mpi4py openmpi
On a cluster, build mpi4py against the system MPI instead, so it works with the high-speed interconnect and Slurm:
module load openmpi
env MPICC="$(which mpicc)" python -m pip install --no-binary=mpi4py mpi4py
Step 5 (optional): run on a Slurm cluster
On a cluster, install FBPIC in your own Conda environment (in your home or project directory), then submit GPU jobs through Slurm with one MPI rank per GPU:
#!/bin/bash
#SBATCH --job-name=fbpic-lwfa
#SBATCH --partition=gpu
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=4
#SBATCH --gpus-per-node=4
#SBATCH --time=06:00:00
#SBATCH --output=logs/%x-%j.out
set -euo pipefail
source "$HOME/miniforge3/etc/profile.d/conda.sh"
conda activate fbpic
srun python lwfa_script.py
Make sure each rank sees its own GPU. Many sites handle this automatically through Slurm’s GPU binding; otherwise follow your centre’s guidance on CUDA_VISIBLE_DEVICES. Our Slurm job submission guide explains the directives.
Verify
-
Import test
python -c "import fbpic; print('FBPIC', fbpic.__version__)" -
Run an official example. Download the laser-wakefield example script from the FBPIC documentation (“Running a simulation” section). Set
use_cuda = Truefor GPU runs, then run it:python lwfa_script.py -
Confirm the GPU is used. While it runs, open another terminal. Your Python process should appear with memory allocated:
nvidia-smi -
Check the output. FBPIC writes openPMD files in
diags/hdf5. Open them with openPMD-viewer (python -m pip install openpmd-viewer) to plot fields and particles.
Troubleshooting
ImportErrormentioning CuPy or CUDA libraries: the CuPy build does not match your CUDA driver version. Uninstall it and install the matchingcupy-cuda11xorcupy-cuda12x.- Numba errors at start-up, for example about unsupported NumPy versions: Numba supports a specific range of NumPy versions. Recreate the environment from conda-forge so that compatible versions are chosen together.
- The run is very slow and the GPU is idle:
use_cudaisFalse, or CuPy failed to import and FBPIC fell back to the CPU. Check the start-up messages and step 3. - MPI runs hang at start-up: mpi4py is linked against a different MPI from the one launching the job. Rebuild mpi4py against the system MPI as in step 4.
Assumptions and limitations
- Package names (
cupy-cuda12x) and supported Python, Numba and NumPy versions change over time. The FBPIC and CuPy documentation are authoritative for the release you install. - FBPIC targets NVIDIA GPUs. AMD and Intel GPUs are not supported by its GPU path.
- Installation success is not physics validation. Check resolution and convergence for your problem; see PIC convergence testing.
Frequently asked questions
Do I need a GPU to run FBPIC?+
No. FBPIC runs on CPUs through Numba, which is fine for learning and small 2D-like (few-mode) runs. Production wakefield simulations are usually run on NVIDIA GPUs, where FBPIC is much faster.
Does FBPIC support AMD GPUs?+
FBPIC's GPU path is written for CUDA (via Numba and CuPy), so it targets NVIDIA GPUs. For AMD or Intel GPUs, WarpX supports HIP and SYCL backends.
What geometry does FBPIC simulate?+
FBPIC uses a quasi-cylindrical (r–z) grid with a small number of azimuthal Fourier modes and a spectral field solver. This captures nearly cylindrically symmetric problems such as laser wakefields at a fraction of the cost of full 3D, but it is not suitable for strongly asymmetric 3D physics.
How do I run FBPIC on several GPUs?+
Install mpi4py against your cluster's MPI and launch with mpirun or srun, one MPI rank per GPU. FBPIC decomposes the domain along the propagation axis.
References
- FBPIC documentation · FBPIC developers
- FBPIC source code · GitHub
- Lehe et al., A spectral, quasi-cylindrical and dispersion-free particle-in-cell algorithm, Comput. Phys. Commun. 203, 66 (2016) · Peer-reviewed article
- CuPy installation guide · CuPy
Want this set up and verified for you?
We install, configure and validate scientific software on your workstation, cluster or cloud, and train your team to run it.
Services listed on this page are available today. Products marked “early access” or “in development” on our platform page are not yet generally available.
Spotted an error or an outdated command? Tell us. We correct verified issues promptly.