pystencils
Pystencils is a symbolic domain-specific language and metaprogramming toolkit for writing high-performance numerical stencil kernels for a variety of hardware targets.
[!note] This is the code of repository of pystencils 2.x, the near-complete rework of the pystencils package. The legacy package pystencils 1.4 is being supported at the
v1.xbranch of this repository.
Installation
Pystencils can be installed from PyPI using pip, e.g.:
pip install pystencils~=2.0
For more information on installing pystencils, refer to the Installation Guide.
Example
Here is a code snippet that computes the average of neighboring cells:
import pystencils as ps
import numpy as np
f, g = ps.fields("f, g : [2D]")
stencil = ps.Assignment(g[0, 0],
(f[1, 0] + f[-1, 0] + f[0, 1] + f[0, -1]) / 4)
kernel = ps.create_kernel(stencil).compile()
f_arr = np.random.rand(1000, 1000)
g_arr = np.empty_like(f_arr)
kernel(f=f_arr, g=g_arr)
pystencils is mostly used for numerical simulations using finite difference or finite volume methods. It comes with automatic finite difference discretization for PDEs:
import pystencils as ps
import sympy as sp
c, v = ps.fields("c, v(2): [2D]")
adv_diff_pde = ps.fd.transient(c) - ps.fd.diffusion(c, sp.symbols("D")) + ps.fd.advection(c, v)
discretize = ps.fd.Discretization2ndOrder(dx=1, dt=0.01)
discretization = discretize(adv_diff_pde)
Documentation
Here's an overview of our documentation ressources:
Contributing
Please refer to the contribution guide for instructions on how to start contributing to pystencils.
Authors
Many thanks go to the contributors of pystencils.
Please cite us
If you use pystencils in a publication, please cite the following articles:
Overview:
- M. Bauer et al, Code Generation for Massively Parallel Phase-Field Simulations. Association for Computing Machinery, 2019. https://doi.org/10.1145/3295500.3356186
Performance Modelling:
- D. Ernst et al, Analytical performance estimation during code generation on modern GPUs. Journal of Parallel and Distributed Computing, 2023. https://doi.org/10.1016/j.jpdc.2022.11.003
Release files for pystencils 2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pystencils-2.0.tar.gz | 348.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pystencils-2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:775.0 kB
Release files / pystencils-2.0.tar.gz
| Download URL | pystencils-2.0.tar.gz |
|---|---|
| Size | 348.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eaee32b52f0123af8ffe0aac84daefef1bd495a1c29f3b39e0aa32181a918ae8
|
|
BLAKE2b-256 checksum How to use checksums |
03639d7e37e63ea8b3f55ed4a45807dbeebd8c409be44a6b5600b644f1f77dce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / pystencils-2.0-py3-none-any.whl
| Download URL | pystencils-2.0-py3-none-any.whl |
|---|---|
| Size | 426.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f96d98c430f4a887e5f3f2771cb77d53db2a23b76293054a6d0f74d9762c2f0
|
|
BLAKE2b-256 checksum How to use checksums |
974b6a57a240d948e8462e42382571faeb6228cbe63c87da812f3aaabe97cf69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|