Skip to main content

Tools to integrate Langevin equations for directed-percolation and absorbing phase transition models

Project description

langevin

PyPI TestPyPi macOS Linux Windows

Tools to integrate Langevin equations of absorbing phase transition (APT) type — with a focus on solution of the directed percolation (DP) Langevin equation.

The langevin package implements the operator-splitting method originally developed by Dornic et al (2005), Pechenik & Levine (1999) and others, and improved upon by Weissmann et al (2018). It provides a Python wrapper around core C++ heavily adapted from a code base written by Paula Villa Martín, extended by Victor Buendía ("VMB"), and arising from earlier efforts by Ivan Dornic and Juan Bonachela. The wrapper provides easy access to the Langevin integrator, and broad opportunity to experiment, adapt, and extend it further.

The current C++ implementation extends the VMB code to allow run-time specification of grid dimension and size, boundary topology (bounded or periodic), boundary conditions, and initial conditions. It further provides tools for running model integration in batches, time-slicing the Langevin field grid, and recording of time-series of grid properties.

The equation solved in the demo here is the DP Langevin for a 2D grid with initial values sampled from U[0,1]:

where ρ(x,t) is the order parameter field, a and b are rate constants, D is the diffusion rate over x, ξ(x,t) is Gaussian white noise (uncorrelated, zero mean, unit variance), and η is the "demographic" noise amplitude.

See Victor Buendía's fork of Paula Villa Martín's repo for details on more general applications and on how the integration scheme is implemented.

Software design

The structure of the DP/APT Langevin-equation integrator package is broadly as follows (detailed documentation is available here).

First, there is a wrapper file called cplusplus/dp/wrapper_dplvn.cpp that uses pybind11 to link the C++ code to a Python runtime.

Next, the code is split into a hierarchy of three groups, with each corresponding file denoted by one of following prefixes: (1) sim_dplangevin_, (2) dplangevin_ and (3) langevin_:

  1. The cplusplus/dp/sim_dplangevin_* files provide a SimDP class, made available through the wrapper at the Python level, required to manage and execute DP Langevin model integration. This SimDP class instantiates a DPLangevin class integrator to do the hard work of numerical integration of the stochastic differential equation. Langevin field density grids are returned to Python (via the wrapper) as numpy arrays as are time series of the mean density field and its corresponding epochs.

  2. The cplusplus/dp/dplangevin_* files define this DPLangevin integrator class. They inherit the general BaseLangevin integrator class and implement several methods left undefined by that parent; most important, they define methods implementing the particular functional form of the directed-percolation Langevin equation and its corresponding nonlinear, deterministic integration step in the split operator scheme.

    Other types of absorbing-phase transition-type Langevin equation could be implemented with alternate subclasses of BaseLangevin and alternate versions of the SimDP class.

  3. The cplusplus/langevin_* source files provide the base BaseLangevin class that implements the operator-splitting integration method in a fairly general fashion. Grid geometry and topology, boundary conditions, initial conditions, the integration scheme, and a general form of the Langevin equation are all coded here. The core Dornic-style integrator is a heavily altered version of the Villa-Martín and Buendía code.

Installation

For here for more comprehensive installation notes that cover multiple platforms. The info below applies only to Linux and macOS.

Python environment

First, set up a suitable Python environment. The simplest tool is uv, but there are several other options. If you use conda or miniconda, take a look at the environment.yml file provided.

We recommend installing Python 3.14 since development of langevin uses this version.

For example, if you're using uv, all that's needed is to create an appropriately named folder, navigate to it, and execute:

uv venv --python=3.14
source .venv/bin/activate

where the --python option forces uv to choose that version of the Python intepreter.

Package from PyPI

Then, install the langevin package from PyPI:

pip install langevin

if you're using uv, this command will be

uv pip install langevin

This step should automatically install all the dependencies as well. If it does not, see below.

Alternative: Package from TestPyPI

If you want to access more regular updates, you can install from TestPyPI:

[uv] pip install --index https://test.pypi.org/simple/ \
            --default-index https://pypi.org/simple/  langevin

Note: the --default-index ensures that package dependencies are fetched from the main PyPI repository where needed.

Dependencies

At minimum, langevin needs Python≥3.12 and the package pybind11. To run the demos, you will also need numpy, matplotlib, jupyter, ipython, along with pandas, tqdm, and ffmpeg-python. If you are using conda or miniconda, it would be best to install them using the environment.yml file, instead of relying on pip to do the job (mixing pip and conda is not a great idea anyway, but langevin is not yet available on conda).

If you want to build locally, you will also need meson-python, wheel, pybind11, and ninja.

To turn density field image sequences into animations, langevin uses ffmpeg-python, which assumes that ffmpeg is itself installed on your system.

On Linux platforms, matplotlib has a tendency to complain about missing fonts, e.g., Arial, generating large numbers of warnings in some of the notebooks. This can be fixed by installing the missing fonts and ensuring that matplotlib's cache is refreshed.

Platform support

We currently have pre-built binary wheels macOS 14, macOS 15, the latest macOS build, and multiple flavors of Linux (most of which have been tested), as well as Windows (but not yet tested).

Build from source

If your platform is not explicitly supported with a pre-built binary, the following will force a build from source:

[uv] pip install -v langevin --no-binary langevin

The package can also be built "by hand." Some build info is provided in the cplusplus/ directory. The build system is meson-python, using pybind11 as the C++ wrapper.

Usage

Simple demonstration scripts are provided in demos/. More complete examples are provided in the simulation/ directory. The easiest route is to git clone the repo to get these files, or you can download one-by-one.

References

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

langevin-2025.12.16a1.tar.gz (23.7 MB view details)

Uploaded Source

Built Distributions

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

langevin-2025.12.16a1-cp314-cp314-win_amd64.whl (158.4 kB view details)

Uploaded CPython 3.14Windows x86-64

langevin-2025.12.16a1-cp314-cp314-manylinux_2_39_x86_64.whl (9.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

langevin-2025.12.16a1-cp314-cp314-macosx_15_0_arm64.whl (195.0 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

langevin-2025.12.16a1-cp314-cp314-macosx_14_0_arm64.whl (194.6 kB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

File details

Details for the file langevin-2025.12.16a1.tar.gz.

File metadata

  • Download URL: langevin-2025.12.16a1.tar.gz
  • Upload date:
  • Size: 23.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for langevin-2025.12.16a1.tar.gz
Algorithm Hash digest
SHA256 73855df902495f13b19b746ee93ea9a2cca34ceb28c4ab81a342909a63035109
MD5 b5f8511fc4b0f2deb5386cbf24489243
BLAKE2b-256 57497c1739cc4fbd6f183938e28c05cd6007bd035b35f0effa8fa66aa0258fb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for langevin-2025.12.16a1.tar.gz:

Publisher: publish-pypi.yml on cstarkjp/Langevin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langevin-2025.12.16a1-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for langevin-2025.12.16a1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 6dbdd26c244c7ee4efcb28db04bfcc2dcaf18e61582356cda0a65f37c1820527
MD5 3daaf79c3c32a1b66288cb7f49b70b6d
BLAKE2b-256 e99f03de13197c6d302991289a9ab8415ca743991afcad04e153eb69eef78470

See more details on using hashes here.

Provenance

The following attestation bundles were made for langevin-2025.12.16a1-cp314-cp314-win_amd64.whl:

Publisher: publish-pypi.yml on cstarkjp/Langevin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langevin-2025.12.16a1-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for langevin-2025.12.16a1-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 bc2dba59584701a8d75f126cb9f9c22f9650de685a56ce0c7fc005733975da3d
MD5 fb149fc781c886520f4d2f81b616593a
BLAKE2b-256 078476f1e5a401737b5d0a7b461b7469fc19237b3ee57497ba86097e9d221faa

See more details on using hashes here.

Provenance

The following attestation bundles were made for langevin-2025.12.16a1-cp314-cp314-manylinux_2_39_x86_64.whl:

Publisher: publish-pypi.yml on cstarkjp/Langevin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langevin-2025.12.16a1-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for langevin-2025.12.16a1-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b05cc4f2b8d8d44344e1b22e04f28b3ee9b701c6a219b55d656bcb16a7e4ccb9
MD5 13263defb8e84d950252ef6b716c8d55
BLAKE2b-256 08d0fe1e8e7c8908c5b1f6b5c7f89e2d883bdd6a2f9f20627b262a6e455b3c30

See more details on using hashes here.

Provenance

The following attestation bundles were made for langevin-2025.12.16a1-cp314-cp314-macosx_15_0_arm64.whl:

Publisher: publish-pypi.yml on cstarkjp/Langevin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langevin-2025.12.16a1-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for langevin-2025.12.16a1-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 674692c258358a94071cdd64aae6b6d14893e5949ef22627dc960f81ef013385
MD5 e3f5fb55d4f32604f4dbe59b5f487672
BLAKE2b-256 d37ec0cb399a8dc93c3d6069f8a61891f7818020b171c353f4f8fc2e08cc9dc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for langevin-2025.12.16a1-cp314-cp314-macosx_14_0_arm64.whl:

Publisher: publish-pypi.yml on cstarkjp/Langevin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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