Skip to main content

ReflectoSim

Tests License: MIT

Four curves drawn from examples/lab_films.toml: the reflectivity before noise and the Poisson counts

Realistic synthetic X-ray reflectivity (XRR) data for machine learning: priors over layer stacks and instruments, counting noise, and a dataset format that records how to regenerate it.

It is for anyone training or testing an inverse model for XRR who needs simulated curves that look like measured ones: random multilayers with roughness tied to thickness and a minimum contrast between neighbours, a native oxide placed where you say, Gaussian resolution, footprint, Kα₂, 2θ offset, background and Poisson counts. The package holds all the forward physics (Parratt recursion with Névot-Croce roughness, the resolution integral, a differentiable torch forward) and the generation on top of it. ReflectoFit, the fitting engine, depends on it, so a network trained on these curves and a fit of the same measurement use the same physics.

Status: early development.

Visual overview

ReflectoSim prior-to-dataset pipeline

The example prior bounds below are configurable input ranges, not empirical distributions. Coupled thickness/roughness and SLD-contrast constraints can alter the accepted distributions.

Parameter bounds from examples/lab_films.toml

The XRR curves at the top of this README are generated by the simulator; solid curves show the pre-noise signal and dots show normalized Poisson counts. For a detailed interpretation, the layer-order diagram, units, reproducibility and caveats, see the visual guide.

Install

Not on PyPI yet. From a clone, with uv:

git clone https://github.com/NaNIsaac/ReflectoSim
cd ReflectoSim
uv sync

First run

Simulate 1000 curves of one to three films on SiO₂ on Si from the example prior, then summarise the file:

uv run reflectosim sim --prior examples/lab_films.toml --n 1000 --seed 20261024,1 -o train.npz
uv run reflectosim describe train.npz

train.npz holds q, counts, reflectivity (before noise), counts_scale and one array per parameter (layer0.thickness, oxide.sld, tth_offset, ...; NaN where a curve has fewer layers). Its metadata holds the priors, the seed and the versions; reflectosim.priors.from_metadata turns it back into priors and the same seed gives the same file. Use a .h5 name for HDF5 (uv sync --extra hdf5).

Priors

A prior is a TOML file; examples/lab_films.toml shows every field. The native oxide position has no default: oxide = "under" puts it on the substrate, "over" on top of the films, "none" leaves it out. The two orders give curves that differ by tens of percent, so every prior states its choice.

Python

import numpy as np
from reflectosim import InstrumentPrior, StackPrior, simulate, tth_to_q

stack = StackPrior(
    n_layers=(1, 3),
    thickness=(20, 250),
    sld=(5, 80),
    roughness=(2, 10),
    min_contrast=4.0,
    oxide="none",
)
instrument = InstrumentPrior(
    sigma_q=(5e-4, 3e-3), tth_offset=(-0.01, 0.01), log_background=(-8.5, -7.0), log_counts=(6, 8)
)
batch = simulate(
    stack, instrument, tth_to_q(np.linspace(0.05, 8, 500)), n=10_000, seed=(20261024, 1)
)
batch.counts, batch.reflectivity, batch.params["layer0.thickness"]

Development

uv run pytest

License

MIT

Metadata

Release files for reflectosim 0.1.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 reflectosim 0.1.0
File Size Uploaded Provenance Actions
reflectosim-0.1.0.tar.gz 27.8 kB With provenance Details for reflectosim-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 60.6 kB

Release files / reflectosim-0.1.0.tar.gz

Download URL reflectosim-0.1.0.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f2def4725877f1a7262510ca5203b6fa1625679be691fd25b6cd9eed939a40f2
BLAKE2b-256 checksum
How to use checksums
2ff3684ca3bab5fa75fd462bd8a54d704a950a15916f88451a6a4338bcb8b6f7
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 5, 2026.

Transparency log

Release files / reflectosim-0.1.0-py3-none-any.whl

Download URL reflectosim-0.1.0-py3-none-any.whl
Size 32.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50a8c79b2af1c283f977e2f38a6c0a30384cbde99a2a87863bad33f73c77d5c0
BLAKE2b-256 checksum
How to use checksums
30c82942285fce217a954f9f0c551f48eac1e011741d3e419b0a2b14d96891e9
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 5, 2026.

Transparency log

Security for reflectosim 0.1.0

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 reflectosim-0.1.0.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 5, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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