Skip to main content

Logo

PyAPD

PyPI CI

PyAPD is a Python library for generating anisotropic power diagrams (APDs) and polynomial diagrams — GPU-accelerated generalisations of Voronoi diagrams applicable to any problem requiring optimal assignment of regions with prescribed volumes, shapes, and anisotropy. The main application is geometric modelling of polycrystalline microstructures, but the framework extends naturally to other domain decomposition and geometric modelling problems.

  • Optimal APDs and polynomial diagrams in 2D and 3D
  • Prescribed-volume region generation with fine control over shape and orientation
  • Arbitrary domain support (non-rectangular EBSD scans, masked grids)
  • EBSD data loading, fitting, and export (.ang, .h5oina, MTEX validation)
  • GPU-accelerated via KeOps; CPU fallback supported

Installation

Install with pip:

pip install PyAPD

Requires PyTorch and KeOps; see setup.py for full dependencies.

Tutorials

  • Core tutorial — apd_system API, weight optimisation, Lloyd's algorithm, 2D/3D examples:
    example_usage.ipynb nbviewer Open In Colab

  • Arbitrary domains — non-rectangular pixel clouds, masked grids, set_pixels / mask_pixels:
    arbitrary_domains.ipynb nbviewer Open In Colab

  • EBSD interoperability — loading EBSD grain data, APD fitting, .ang export, .h5oina import, MTEX validation:
    ebsd_interoperability.ipynb nbviewer Open In Colab

Google Colab: notebooks run on CPU by default. To enable GPU: Runtime > Change runtime type > T4 GPU (free) or A100 (subscription). Without a GPU you will see a KeOps warning but the library remains fully functional.

Publications

(1) CMS 2024:

M. Buze, J. Feydy, S.M. Roper, K. Sedighiani, D.P. Bourne, Anisotropic power diagrams for polycrystal modelling: Efficient generation of curved grains via optimal transport, Computational Materials Science, 245, 2024. DOI · Link

Companion notebooks

The examples from the paper can be found in notebooks/paper_examples/, including all notebooks as run, generated data, and figures. Notebooks that load pre-computed data will not run out of the box in Google Colab — the relevant data files would need to be uploaded manually.

  • Runtime tests
    1. APD generation
      • Gathering data nbviewer Open In Colab
      • Plotting the data for the 2D case nbviewer Open In Colab and for the 3D case nbviewer Open In Colab
    2. Finding optimal APDs
      • Gathering data nbviewer Open In Colab
      • Plotting the data for the 3D multi-phase case nbviewer Open In Colab
    3. EBSD data examples
      • Fitting to data and artificial sample generation nbviewer Open In Colab
      • Pixel level comparison nbviewer Open In Colab
    4. Additive manufacturing example nbviewer Open In Colab

(2) Preprint:

v0.2.0 accompanies a preprint on polynomial diagrams (generalisations of APDs):

D.P. Bourne, M. Buze, T. Gallouët, Q. Mérigot, Polynomial diagrams for microstructure modelling, arXiv:2605.20816 (2026). arXiv

The companion notebooks (EBSD benchmark on Tata Steel data, synthetic APD reconstruction) can be found in notebooks/paper_examples/pmd_paper/:

  • Large EBSD benchmark nbviewer Open In Colab
  • Small EBSD benchmark nbviewer Open In Colab
  • Synthetic APD reconstruction nbviewer Open In Colab

Results shown are pre-computed on an A100 GPU; result pkl files are not included in the repository.

Citing this work

If you use PyAPD for academic research, please cite the paper to which our library is tied:

@article{PyAPD,
title = {Anisotropic power diagrams for polycrystal modelling: Efficient generation of curved grains via optimal transport},
journal = {Computational Materials Science},
volume = {245},
pages = {113317},
year = {2024},
issn = {0927-0256},
doi = {https://doi.org/10.1016/j.commatsci.2024.113317},
url = {https://www.sciencedirect.com/science/article/pii/S092702562400538X},
author = {M. Buze and J. Feydy and S.M. Roper and K. Sedighiani and D.P. Bourne},
keywords = {Anisotropic power diagrams, Polycrystalline materials, Microstructure generation, Optimal transport},
}

If you use the polynomial diagram functionality (min_diagram_system) or the EBSD interoperability features introduced in v0.2.0, please also cite:

@misc{PyAPD_PMD,
  author        = {David P. Bourne and Maciej Buze and Thomas Gallouët and Quentin Mérigot},
  title         = {Polynomial diagrams for microstructure modelling},
  year          = {2026},
  eprint        = {2605.20816},
  archivePrefix = {arXiv},
}

Metadata

Release files for PyAPD 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyAPD 0.2.0
File Size Uploaded
pyapd-0.2.0.tar.gz 37.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyAPD 0.2.0
File Interpreter ABI Platform
pyapd-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 71.0 kB

Release files / pyapd-0.2.0.tar.gz

Download URL pyapd-0.2.0.tar.gz
Size 37.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b6ecf9201da7287573c6c9e233a3740e5a9537fa97944bf09ced5f32c9ab0985
BLAKE2b-256 checksum
How to use checksums
0b05e697706a840b6c0dd4b61e70e3cec8b4cc7b76a73966e5927aaa16d47751
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / pyapd-0.2.0-py3-none-any.whl

Download URL pyapd-0.2.0-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b900c725a5348bc64c242ba49b7c3dde934afc15c7074f49a9b97172277783d8
BLAKE2b-256 checksum
How to use checksums
0d34ba3a3fb9ef3e7dcdeac5f008f7c635b7870ef1421e748ffb504751f48aee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.17

1 release file

0.0.16

1 release file

0.0.15

1 release file

0.0.14

1 release file

0.0.13

1 release file

0.0.12

1 release file

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page