Skip to main content

Speeding up stencil computations on CPUs and GPUs

Project description

pystencils

Docs pypi-package pipeline status coverage report

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.x branch 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:

Performance Modelling:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pystencils-2.0.tar.gz (348.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pystencils-2.0-py3-none-any.whl (426.2 kB view details)

Uploaded Python 3

File details

Details for the file pystencils-2.0.tar.gz.

File metadata

  • Download URL: pystencils-2.0.tar.gz
  • Upload date:
  • Size: 348.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pystencils-2.0.tar.gz
Algorithm Hash digest
SHA256 eaee32b52f0123af8ffe0aac84daefef1bd495a1c29f3b39e0aa32181a918ae8
MD5 ef43ca18337ad476eb5a9e251d9279fa
BLAKE2b-256 03639d7e37e63ea8b3f55ed4a45807dbeebd8c409be44a6b5600b644f1f77dce

See more details on using hashes here.

File details

Details for the file pystencils-2.0-py3-none-any.whl.

File metadata

  • Download URL: pystencils-2.0-py3-none-any.whl
  • Upload date:
  • Size: 426.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pystencils-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f96d98c430f4a887e5f3f2771cb77d53db2a23b76293054a6d0f74d9762c2f0
MD5 215882aa97c1c8c0e725d33c7bb309c8
BLAKE2b-256 974b6a57a240d948e8462e42382571faeb6228cbe63c87da812f3aaabe97cf69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page