Skip to main content

PtyLab.py: Unified Ptychography Toolbox

Python 3.11+ PyPI Tests Docs

Key Features | Getting Started | Installation | Documentation

PtyLab is an inverse modeling toolbox for Conventional (CPM) and Fourier (FPM) ptychography in a unified framework. See the paper for details.

Key Features

  • Classic engines: ePIE, mPIE, mqNewton, qNewton
  • Advanced corrections: position correction, defocus correction (zPIE), angle correction (aPIE), orthogonal probe relaxation (OPR)
  • Multi-modal: multi-slice, multi-wavelength, mixed-state object and probe
  • Multiple propagators: Fraunhofer, Fresnel, Angular Spectrum (ASP), scaled ASP, polychromatic variants
  • GPU acceleration: same code runs on CPU and GPU (NumPy/CuPy)
  • Live monitor: follow the object, probe, error metric and any corrected parameters (scan positions, sample-detector distance, wavelength, angle) as the iterations run
  • Differentiable ptychography (work in progress): Optional Gradient-based reconstruction module with custom models, losses and constraints leveraging automatic differentiation of PyTorch.

How it works

PtyLab.py is built around a 6D array (nlambda, nosm, npsm, nslice, N, N), i.e. wavelengths, object and probe state mixtures, depth slices, then the frame.

As shown below, the data flow to a reconstruction involves five core classes: ExperimentalData, Reconstruction, Params, Engine and Monitor.

flowchart LR
    file[(HDF5 data)] --> exp[ExperimentalData]
    exp --> recon["Reconstruction<br/>(object, probe)"]
    exp & recon & params[Params] --> engine["Engine<br/>(ePIE, mPIE, ...)"]
    engine -.->|updates| recon
    engine <-->|each iteration| corr["Optional Corrections: positions, distance, angle"]
    engine -.-> mon[Monitor<br/>live plots]
    corr -.-> mon
    engine -->|reconstruct| out["Saved to HDF5<br/>object, probe, error, corrected parameters"]

Getting started

Try the demo in Google Colab:

Open In Colab demo

To explore more features, we have extensive examples in our documentation.

Installation

Install from PyPI within your virtual environment (assuming you have installed uv):

uv pip install -U ptylab

For GPU support (Linux or Windows):

uv pip install -U "ptylab[gpu]"

Check whether the GPU is correctly configured with ptylab check gpu. For other extras such as torch and gui, see the installation guide.

Contributing

Contributions are welcome! See the contributing guide for the development setup, tests and how to open a pull request.

Citation

If you use this package, please cite:

@article{Loetgering:23,
        author = {Lars Loetgering and Mengqi Du and Dirk Boonzajer Flaes and Tomas Aidukas and Felix Wechsler and Daniel S. Penagos Molina and Max Rose and Antonios Pelekanidis and Wilhelm Eschen and J\"{u}rgen Hess and Thomas Wilhein and Rainer Heintzmann and Jan Rothhardt and Stefan Witte},
        journal = {Opt. Express},
        number = {9},
        pages = {13763--13797},
        publisher = {Optica Publishing Group},
        title = {PtyLab.m/py/jl: a cross-platform, open-source inverse modeling toolbox for conventional and Fourier ptychography},
        volume = {31},
        month = {Apr},
        year = {2023},
        doi = {10.1364/OE.485370},
}

Metadata

Release files for ptylab 0.4.1

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

Source distribution (sdist)

Source distribution for ptylab 0.4.1
File Size Uploaded Provenance Actions
ptylab-0.4.1.tar.gz 202.3 kB With provenance Details for ptylab-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ptylab 0.4.1
File Interpreter ABI Platform Actions
ptylab-0.4.1-py3-none-any.whl Python 3 none any Details for ptylab-0.4.1-py3-none-any.whl

Total release size: 430.4 kB

Release files / ptylab-0.4.1.tar.gz

Download URL ptylab-0.4.1.tar.gz
Size 202.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2342b7b7a831ab8dd9c6347f5c98bc949348528fc9ffebb67cc44aa929d0cb3b
BLAKE2b-256 checksum
How to use checksums
61f37fe66c5d170ee67c2f1436d38af39e5889572b8f5b36df5d4c75429fb4aa
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 3, 2026.

Transparency log

Release files / ptylab-0.4.1-py3-none-any.whl

Download URL ptylab-0.4.1-py3-none-any.whl
Size 228.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db3bc9a2e9df3daa5526063e1816b40b17f19d93c657151650152b86c7b65851
BLAKE2b-256 checksum
How to use checksums
a1c20d16fd2108c20fdfb07ea1533cee5d4a127388cb0a1e7023e0f882b10d91
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 3, 2026.

Transparency log

Security for ptylab 0.4.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.

Select from 2 files

Attestation for ptylab-0.4.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 3, 2026.

Transparency log

A 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.

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