Skip to content
Snippets Groups Projects
Select Git revision
  • f0de552fe1f21b5d964430ad75c28c200fec0f9e
  • master default protected
  • v2.0-dev protected
  • zikeliml/Task-96-dotExporterForAST
  • zikeliml/124-rework-tutorials
  • fma
  • fhennig/v2.0-deprecations
  • holzer-master-patch-46757
  • 66-absolute-access-is-probably-not-copied-correctly-after-_eval_subs
  • gpu_bufferfield_fix
  • hyteg
  • vectorization_sqrt_fix
  • target_dh_refactoring
  • const_fix
  • improved_comm
  • gpu_liveness_opts
  • release/1.3.7 protected
  • release/1.3.6 protected
  • release/2.0.dev0 protected
  • release/1.3.5 protected
  • release/1.3.4 protected
  • release/1.3.3 protected
  • release/1.3.2 protected
  • release/1.3.1 protected
  • release/1.3 protected
  • release/1.2 protected
  • release/1.1.1 protected
  • release/1.1 protected
  • release/1.0.1 protected
  • release/1.0 protected
  • release/0.4.4 protected
  • last/Kerncraft
  • last/OpenCL
  • last/LLVM
  • release/0.4.3 protected
  • release/0.4.2 protected
36 results

pystencils

Frederik Hennig's avatar
Frederik Hennig authored
 - Add `select_function` to `Platform` and implement it for `GenericCpu`
 - Add `SelectFunctions` AST pass

Squashed commit of the following:

commit e6b3aa856d2471b645f39d20673eb5259f7b1e1c
Author: Frederik Hennig <frederik.hennig@fau.de>
Date:   Wed Mar 27 17:15:55 2024 +0100

    add select_function stub to GenericGpu

commit 679428f053d6bfd3a5ba4d1d1ff6c903577e9ed3
Author: Frederik Hennig <frederik.hennig@fau.de>
Date:   Wed Mar 27 17:14:16 2024 +0100

    Remove IntrinsicsError in favor of MaterializaitonError. Move the latter to `backend.exceptions`.

commit 1a01cfde2f39b3394935c2a313312097d4cf66e0
Merge: d73d24c 0e4677de
Author: Frederik Hennig <frederik.hennig@fau.de>
Date:   Wed Mar 27 17:07:31 2024 +0100

    Merge branch 'backend-rework' into b_function_mat

commit d73d24cf038950f2129e717a43dd09df11d725c0
Author: Frederik Hennig <frederik.hennig@fau.de>
Date:   Tue Mar 26 18:19:08 2024 +0100

    introduce SelectFunctions and select_function protocol

commit 671f0578a39e452504243019dab28d93f0114082
Author: Frederik Hennig <frederik.hennig@fau.de>
Date:   Tue Mar 26 16:39:43 2024 +0100

    Fix documentation for Typifier and PsExpression

commit 3ec258517ad8a510118265184b5dc7805128dcd3
Author: Frederik Hennig <frederik.hennig@fau.de>
Date:   Mon Mar 25 17:14:21 2024 +0100

    Typing refactor:

      - Annotate all expressions with types
      - Refactor Typifier for cleaner information flow and better
        readability
      - Have iteration space and transformers typify newly created AST nodes
f0de552f
History

pystencils

Binder Docs pypi-package pipeline status coverage report

Run blazingly fast stencil codes on numpy arrays.

pystencils uses sympy to define stencil operations, that can be executed on numpy arrays. Exploiting the stencil structure makes pystencils run faster than normal numpy code and even as Cython and numba, as demonstrated in this notebook.

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)

Installation

pip install pystencils[interactive]

Without [interactive] you get a minimal version with very little dependencies.

All options:

  • gpu: use this if an NVIDIA or AMD GPU is available and CUDA or ROCm is installed
  • alltrafos: pulls in additional dependencies for loop simplification e.g. libisl
  • bench_db: functionality to store benchmark result in object databases
  • interactive: installs dependencies to work in Jupyter including image I/O, plotting etc.
  • doc: packages to build documentation

Options can be combined e.g.

pip install pystencils[interactive, gpu, doc]

pystencils is also fully compatible with Windows machines. If working with visual studio and cupy makes sure to run example files first to ensure that cupy can find the compiler's executable.

Documentation

Read the docs here and check out the Jupyter notebooks in doc/notebooks. The Changelog of pystencils can be found here.

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: