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.0b2.tar.gz (323.0 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.0b2-py3-none-any.whl (395.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pystencils-2.0b2.tar.gz
Algorithm Hash digest
SHA256 25a01e07742ab51d2e8169c6d09e7f3b0f286f9da8d72d3193926e653e7548e0
MD5 b600c17b878524c3e01c5fed2cd46392
BLAKE2b-256 1d81a8b2d7853e480c34e377f52642f5c140ad8d62d4c0e01fbd8cf77fb3d981

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pystencils-2.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 38c45b0004654d319dd005262dc4329a4c893a6649b27db65a7c0a2da437a1c0
MD5 366d7642b6596e011c63bd7a3261532f
BLAKE2b-256 506b8af6bd5aab28373a29e9290420d8a004808e647629c8eff58618e6e6bf16

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