pyLSET: A Python Package for Level Set Simulations
pyLSET is a Python package for level set simulations of interface networks in 2D and 3D, with grain boundaries in polycrystals as the primary application. It runs on CPUs or GPUs through PyTorch. pyLSET is the level set sibling of the Python-based phase field crystal code pyPFC.
Features
- Fixed Cartesian grids in 2D and 3D, with the dimensionality set by the input data.
- Periodic or mirror boundary conditions, set independently along each axis.
- One signed distance function
phiper domain, positive inside, or optional coloring that stores domains that are not neighbors in shared fields to reduce memory use, with dynamic recoloring that prevents domains sharing a field from merging. - Signed distance fields from pixel or voxel label arrays (for example grain maps from diffraction contrast tomography) with the methods 'EDT', 'FMM', 'FSM' and 'Brute'.
- Curvature driven evolution with explicit strong stability preserving Runge–Kutta schemes and an automatic time step.
- Interface mobility and energy as constants, fields or functions of the two domains and the interface normal, with neighbor identification at junctions, misorientation utilities (Read–Shockley energy, sigmoidal mobility) and 'Heterogeneous', 'Gradient' and 'Stiffness' (inclination dependent, 2D) formulations.
- Reinitialization by a second order reinitialization equation with subcell resolution ('PDE'), fast sweeping ('FSM'), fast marching ('FMM') or exact distances to the extracted interface ('Brute').
- Interaction correction of voids and overlaps by projection ('MBO', 'Losasso') or by source terms ('Lagrange' with a global multiplier, 'Source' with per domain weights). With an energy function, the 'Source' weights near junctions follow from the local pair energies, which reproduces the equilibrium junction angles and the junction speed of unequal energies (see example 02).
- Stored energy per domain as an additional driving force, so that domains grow into neighbors with higher stored energy, as in recrystallization.
- Advection of the interfaces by a prescribed velocity field, given as arrays or as a function of position and time, with first order upwind, second order ENO or fifth order WENO differences (with the weights of Jiang and Peng or, by default, of Borges et al.).
- A flag per domain stating whether its level set is evolved or immobile, for free surfaces, particles or inclusions, with a Neumann contact condition (zero normal derivative, so that interfaces meet immobile surfaces at 90 degrees) or a Dirichlet contact condition (interfaces pinned where they meet immobile surfaces).
- CPU or GPU execution and selectable floating point precision.
- Output of grid data (
.vti), interfaces (.vtp) and time series (.pvd) for post-processing in software handling VTK-formatted files, and a pyLSET HDF5 format.
Installation
From the repository folder:
pip install -e .
Optional dependencies are installed with pip install -e ".[fmm]" (scikit-fmm for the 'FMM' method), ".[edt]" (a faster multilabel EDT), ".[mesh]" (Gmsh for mesh_domain()), ".[test]" and ".[docs]".
Quick start
import pylset
sim = pylset.setup_simulation([128.0, 128.0], [128, 128], device_type='CPU', use_coloring=True)
labels = sim.do_voronoi_labels(60, seed=7) # or a grain map from experiments
sim.set_phi(sim.do_sdf(labels))
for step in range(1, 2001):
sim.do_step_update()
if step % 20 == 0:
sim.do_reinitialization()
sim.do_interaction_correction()
sim.do_reinitialization()
sim.do_recoloring()
sim.write_vtk_image('grains', [sim.get_phi_max(), sim.get_domain_map()], ['phi_max', 'grain_id'])
sim.write_vtk_interfaces('grain_boundaries')
See examples/ for Jupyter notebooks and docs/ for the documentation, which is built with mkdocs serve.
Tests
python -m unittest discover -s tests -v
The tests run on the CPU by default. Set PYLSET_TEST_DEVICE=gpu:1 to run them on GPU 1 and PYLSET_TEST_DTYPE=float32 for single precision.
License
pyLSET is distributed under the GNU General Public License v3.0 or later. See LICENSE.
References
Further details on level set modeling and example applications can be found in:
- E. Jacobsson, H. Hallberg, J. Hektor and M. Ristinmaa, Modelling diffusive phase transformations in multiphase systems using the Voronoi implicit interface method, Modelling and Simulation in Materials Science and Engineering, 33(2):025006, 2025
- E. Jacobsson, H. Hallberg, J. Hektor, S. Iyengar and M. Ristinmaa, A level set approach to modeling diffusional phase transformations under finite strains with application to the formation of Cu6Sn5, Computational Materials Science, 244:113284, 2024
- H. Hallberg and Vasily V. Bulatov, Modeling of grain growth under fully anisotropic grain boundary energy, Modelling and Simulation in Materials Science and Engineering, 27(4):045002, 2019
- H. Hallberg, F. Adamski, S. Baïz and O. Castelnau, Microstructure and property modifications of cold rolled IF steel by local laser annealing, Metallurgical and Materials Transactions A, 48(10):4786-4802, 2017.
- H. Hallberg and P.A.T. Olsson, Investigation of microstructure evolution during self-annealing in thin Cu films by combining mesoscale level set and ab-initio modeling, Journal of the Mechanics and Physics of Solids, 90:160-178, 2016
- H. Hallberg and Y. Zhu, Stability of grain boundary texture during isothermal grain growth in UO2 considering anisotropic grain boundary properties, Journal of Nuclear Materials, 465:664-673, 2015
- H. Hallberg, Influence of anisotropic grain boundary properties on the evolution of grain boundary character distribution during grain growth - A 2D level set study, Modelling and Simulation in Materials Science and Engineering, 22(8):085005, 2014
- H. Hallberg, A modified level set approach to 2D modeling of dynamic recrystallization, Modelling and Simulation in Materials Science and Engineering, 21(8):085012, 2013
Metadata
Release files for pylset 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pylset-0.0.1.tar.gz | 104.2 kB | With provenance | Details for pylset-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pylset-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for pylset-0.0.1-py3-none-any.whl |
Total release size: 196.6 kB
Release files / pylset-0.0.1.tar.gz
| Download URL | pylset-0.0.1.tar.gz |
|---|---|
| Size | 104.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
857eeafcb743efd2031288e74ab4c648576c79643cba7b263b8b9b4b08cb9b4d
|
|
BLAKE2b-256 checksum How to use checksums |
c3224ff072ba3f809f14d4033ed006ad5a5a960ff34bfcfd27b847be9fd220c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / pylset-0.0.1-py3-none-any.whl
| Download URL | pylset-0.0.1-py3-none-any.whl |
|---|---|
| Size | 92.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
276686ca46ab6f321b361960cce4f76f0fa807bb4b193acc19883020fcd52698
|
|
BLAKE2b-256 checksum How to use checksums |
78a127b06687fa64b2cb1f27d4d92f6c8b7f08319c21fe4790828aee35be862c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logSecurity for pylset 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pylset-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.