Metadata-Version: 2.5
Name: pnps
Version: 0.2.0
Summary: Forward model of PNPS pulse-measurement traces in bulk media
Project-URL: Homepage, https://github.com/LupoLab/pnps
Project-URL: Documentation, https://pnps.readthedocs.io/en/stable/
Project-URL: Source, https://github.com/LupoLab/pnps
Project-URL: Issues, https://github.com/LupoLab/pnps/issues
Project-URL: Changelog, https://github.com/LupoLab/pnps/blob/main/CHANGELOG.md
Author: Christian Brahms
Author-email: "John C. Travers" <jtravs@gmail.com>
License-Expression: GPL-3.0-or-later
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.14
Requires-Dist: h5py>=3.11
Requires-Dist: jaxtyping>=0.3.11
Requires-Dist: numba>=0.67
Requires-Dist: numpy>=2.0
Requires-Dist: scipy>=1.14
Requires-Dist: solprop>=0.4
Description-Content-Type: text/markdown

# pnps

[![CI](https://github.com/LupoLab/pnps/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/LupoLab/pnps/actions/workflows/ci.yml)
[![Documentation](https://readthedocs.org/projects/pnps/badge/?version=stable)](https://pnps.readthedocs.io/en/stable/)
[![codecov](https://codecov.io/gh/LupoLab/pnps/graph/badge.svg)](https://codecov.io/gh/LupoLab/pnps)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![basedpyright](https://img.shields.io/badge/basedpyright-checked-42b983)](https://docs.basedpyright.com)
[![PyPI](https://img.shields.io/pypi/v/pnps.svg)](https://pypi.org/project/pnps/)
[![Python 3.14](https://img.shields.io/badge/python-3.14-blue.svg)](https://www.python.org/downloads/)
[![Licence: GPL-3.0-or-later](https://img.shields.io/badge/licence-GPL--3.0--or--later-blue.svg)](https://github.com/LupoLab/pnps/blob/main/LICENSE)
[![REUSE](https://img.shields.io/badge/REUSE-compliant-green)](https://reuse.software)

> **Status: experimental.** pnps is young (0.x). Its model and validation are described
> in the manual, but the interface may still change between minor releases; pin the
> version you use and read the changelog before upgrading.

**Simulated FROG traces of a real instrument, from first principles.**

pnps is a forward model of PNPS (parametrized nonlinear process spectrum) pulse
measurements in bulk media: transient-grating (TG) and self-diffraction (SD) FROG. It
takes the instrument as it is built:

- a beam is cut into beamlets by the chromatic holes of a mask;
- they cross in a thin fused-silica slab, carried through it by the full 3-D envelope
  propagation equation;
- the four-wave-mixing signal *emerges* in its own corner of momentum space;
- chromatic collection windows reduce it to the spectra a spectrometer records.

Phase matching, walk-off, geometric delay smearing and the vignetting of every
aperture come out of the propagation; none is a correction added afterwards. The
traces are ground truth for developing and testing pulse-retrieval algorithms.

![A TG-FROG and an SD-FROG trace of a 3 fs pulse at 260 nm](https://raw.githubusercontent.com/LupoLab/pnps/main/docs/_static/readme-traces.png)

*A 3 fs pulse at 260 nm through 10 µm of fused silica, measured by the
transient-grating boxcar and by self-diffraction, each through a 1 mm collection
window. `docs/scripts/readme_figure.py` makes the figure.*

```python
import numpy as np
from pnps import Config, HE11Beam, WindowSpec, signal_centre
from pnps.scan import run_scan

x, y = signal_centre("tg", mask_diam=1e-3, mask_spacing=1e-3)
cfg = Config(
    lam0=260e-9,
    tau_fwhm=1e-15,
    energy=0.1e-6,
    thickness=40e-6,
    mask_diam=1e-3,
    mask_spacing=1e-3,
    beam=HE11Beam(a=125e-6, f_coll=5.0, f_foc=0.1),  # a hollow-capillary beam
    windows=(WindowSpec(holex=x, holey=y, holediam=1e-3, zmask=0.1),),
    lam_lims=(143e-9, 600e-9),
    trange=250e-15,
    r_max=366e-6,
    n_transverse=192,
)
taus = np.linspace(-20e-15, 20e-15, 41)
path = run_scan(
    cfg, taus, "example", zsave=np.array([0.0, 20e-6, 40e-6]), h_target=0.5e-6
)
```

## What it does

- **The instrument**: the folded-boxcar TG geometry or the two-beam SD geometry;
  hollow-capillary (HE11), Gaussian or uniform illumination; chromatic input holes and
  collection windows, rendered exactly or with smooth edges; synthetic pulses with
  chirp, or a measured or simulated field injected from a file.
- **The physics**: the 3-D envelope unidirectional propagation equation in fused
  silica, with dispersion, diffraction, the Kerr effect and, optionally, the delayed
  Raman response, from the silica model of [optmat](https://github.com/LupoLab/optmat).
- **Verified numerics**: a fixed step certified by Richardson extrapolation on the
  measured trace, absorbers inside the exact linear operator rather than windows in
  the loop, and a validation ladder against an exact linear propagator and a
  semi-analytic first-Born signal.
- **Scale**: propagation by [solprop](https://github.com/LupoLab/solprop) on CPUs and
  NVIDIA and AMD GPUs; sharded, resumable scans; run files and a `pnps` command for
  Slurm clusters; a memory budget before launch.
- **Output**: HDF5 scan files in the layout the
  [Croak](https://github.com/LupoLab/croak) retrieval package reads, with the input
  pulse and the vignetted beamlet as ground truth.

## Installation

```sh
pip install pnps   # with solprop and its compiled backend, solprop-native
```

GPUs need solprop's native backend built from source; see the manual's installation
page. To work on pnps itself, clone the repository and run `uv sync`
([`CONTRIBUTING.md`](https://github.com/LupoLab/pnps/blob/main/CONTRIBUTING.md)).

## Running on CPUs

Set the thread budget with `SOLPROP_THREADS` (or let the allocation set it), and
**leave OpenMP's thread binding unset**: no `OMP_PROC_BIND` or `OMP_PLACES` in the
environment or the job script. Under binding, starting solprop's native backend pins
the process's main thread to one CPU, and a run then uses about one core of its
allocation: five times slower per step at the production shape on 16 cores. pnps
restores the thread's CPUs when it finds it pinned, and warns
(`ThreadBindingWarning`). Confining a process to a set of cores, with Slurm,
`taskset` or `numactl`, is fine. The manual's
[clusters page](https://pnps.readthedocs.io/en/stable/clusters.html) has the
measurements and an example Slurm script.

## Documentation

The manual is at [pnps.readthedocs.io](https://pnps.readthedocs.io/en/stable/): the model,
how to simulate a trace, input pulses, masks and windows, accuracy and validation, the
engine, clusters, performance, and the API.

## Related projects

- [solprop](https://github.com/LupoLab/solprop) integrates the propagation.
- [optmat](https://github.com/LupoLab/optmat) provides the fused-silica model.
- [Croak](https://github.com/LupoLab/croak) retrieves pulses from measured and simulated
  traces, and reads pnps's scan files.

## About

pnps was written by John Travers and Christian Brahms to model the transient-grating and
self-diffraction FROG instruments used to measure few-femtosecond deep-ultraviolet
pulses. Like solprop, it is developed almost entirely by AI coding agents under the lead
developer's direction, within a strict harness of derivations, reference comparisons,
convergence checks and complete test coverage. The code is free software under the
[GNU General Public License, version 3 or (at your option) any later
version](https://github.com/LupoLab/pnps/blob/main/LICENSE), and the documentation is
under [CC BY 4.0](https://github.com/LupoLab/pnps/blob/main/LICENSES/CC-BY-4.0.txt).
Contributions are welcome: see
[CONTRIBUTING.md](https://github.com/LupoLab/pnps/blob/main/CONTRIBUTING.md). If you use
pnps in published work, please cite it as described in
[`CITATION.cff`](https://github.com/LupoLab/pnps/blob/main/CITATION.cff), with the
version you used.
