Smilei PIC simulation tutorial: Python namelists, normalised units and happi
Updated · Scientifically reviewed by Dinkar Mishra, PhD on
Short answer
Smilei is an open-source, MPI + OpenMP parallel PIC code configured with Python "namelists". Compile it with make (it needs a C++ compiler, MPI, parallel HDF5 and Python), write a namelist defining Main (geometry, cells, time step), lasers, species and diagnostics in normalised units based on a reference frequency, run mpirun -np N ./smilei namelist.py, and analyse output with Smilei's happi Python module.
Who this is for
Students and researchers in laser–plasma, astrophysical plasma and beam physics starting with the Smilei code.
Software
Smilei current releaseHDF5 (parallel), MPI, Python 3 per Smilei docs
Prerequisites
- A Linux machine or cluster with a C++ compiler, MPI, parallel HDF5 and Python 3 with NumPy, as listed in the Smilei installation guide. On clusters, load the corresponding modules.
- Familiarity with laser–plasma parameters, for example and critical density (see the a₀ calculator).
Step 1: compile
git clone https://github.com/SmileiPIC/Smilei.git
cd Smilei
make -j 8 # requires HDF5_ROOT_DIR or an h5pcc wrapper, as described in the docs
make happi # installs the Python post-processing module
Step 2: understand the units
With reference frequency equal to the laser frequency :
| Quantity | Code unit | Value for λ₀ = 0.8 µm |
|---|---|---|
| Time | 0.42 fs | |
| Length | 0.127 µm (λ₀ = 2π) | |
| Density | cm⁻³ |
Step 3: write a namelist
A minimal 2D laser–plasma namelist (laser_plasma.py). Smilei defines Main, LaserGaussian2D, Species and the diagnostics when it executes the file:
import math
l0 = 2.0 * math.pi # laser wavelength in code units
t0 = l0 # laser period
Lx, Ly = 40 * l0, 20 * l0
dx, dy = l0 / 24, l0 / 12
Main(
geometry="2Dcartesian",
interpolation_order=2,
cell_length=[dx, dy],
grid_length=[Lx, Ly],
number_of_patches=[16, 8],
timestep=0.95 * dx / math.sqrt(2),
simulation_time=60 * t0,
EM_boundary_conditions=[["silver-muller"], ["periodic"]],
)
LaserGaussian2D(
box_side="xmin",
a0=2.0,
omega=1.0,
focus=[10 * l0, Ly / 2],
waist=4 * l0,
time_envelope=tgaussian(center=8 * t0, fwhm=5 * t0),
)
def density(x, y):
return 0.01 if x > 10 * l0 else 0.0 # 0.01 n_c plateau
Species(
name="electron",
position_initialization="regular",
momentum_initialization="cold",
particles_per_cell=4,
mass=1.0,
charge=-1.0,
number_density=density,
boundary_conditions=[["remove"], ["periodic"]],
)
DiagScalar(every=50)
DiagFields(every=200, fields=["Ex", "Ey", "Rho_electron"])
Step 4: run
export OMP_NUM_THREADS=4
mpirun -np 4 ./smilei laser_plasma.py
Use MPI ranks × OpenMP threads equal to the cores you have. Smilei balances work across patches automatically.
Step 5: analyse with happi
import happi
S = happi.Open(".")
S.Scalar("Utot").plot() # total energy history
S.Field(0, "Ey", timesteps=2000).plot() # laser field snapshot
S.Field(0, "-Rho_electron", timesteps=2000).plot(vmax=0.05)
Verify
- Energy history (
Utot): no unexplained growth before the laser enters the plasma. Steady growth suggests numerical heating. - Laser amplitude in vacuum matches the requested (fields are normalised, so the peak transverse field equals for linear polarisation).
- Resolution: halve
dxanddyand compare your key results; see PIC convergence testing.
Troubleshooting
- Compilation fails to find HDF5: Smilei requires parallel HDF5. Set
HDF5_ROOT_DIRto the parallel installation, or load the cluster’shdf5-mpimodule. - The namelist fails with a Python error: Smilei reports the traceback. Check block and argument names against the documentation of your version.
- Poor performance: use more patches than MPI ranks (several per rank) to enable load balancing, and pin OpenMP threads.
Assumptions and limitations
- The namelist is a teaching example with plausible parameters. Argument names follow the documentation at the time of writing, so check them for your Smilei release.
- Normalised units make inputs compact but require care when reporting results in SI.
- GPU support in Smilei is evolving. Do not assume GPU acceleration without checking the release notes.
Frequently asked questions
What are Smilei's normalised units?+
Quantities are normalised to a reference angular frequency ωr (often the laser frequency): times to 1/ωr, lengths to c/ωr, densities to the corresponding critical density nc, and fields to me c ωr/e. With ωr = laser frequency, the laser wavelength is 2π in code units.
How do I convert to SI units?+
Choose the reference frequency (for example from a 0.8 µm wavelength) and multiply code values by the reference quantities. happi can also convert units for plots if you provide the reference frequency.
Does Smilei run on GPUs?+
Smilei has been developing GPU support; check the documentation of the current release for supported features and hardware. Its CPU performance is strong thanks to patch-based load balancing and vectorisation.
What makes Smilei different from other PIC codes?+
Dynamic load balancing through "patches", a Python input interface, and extensive physics modules (ionisation, collisions, QED, envelope models, particle merging) in one open-source code.
References
- Smilei documentation · Smilei developers
- Derouillat et al., Smilei: a collaborative, open-source, multi-purpose particle-in-cell code for plasma simulation, Comput. Phys. Commun. 222, 351 (2018) · Peer-reviewed article
- Smilei source code · GitHub
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.