Skip to main content

midas-diffract

End-to-end differentiable forward model for High-Energy Diffraction Microscopy (HEDM), covering far-field (FF), near-field (NF), and point-focused (pf-HEDM) geometries. Pixel-exact agreement with the canonical C reference simulators in MIDAS.

Companion paper: Sharma, Zhang, Andrejevic & Cherukara, An End-to-End Differentiable Forward Model for High-Energy Diffraction Microscopy, IUCrJ (in preparation, 2026).

Installation

pip install midas-diffract           # core forward model + losses + optimizer
pip install midas-diffract[hkls]     # also installs midas-hkls for the
                                     # pure-Python reflection-list helper

Optional PyTorch CUDA or MPS back-ends are used automatically if available.

Quick start

import torch
import midas_diffract as md
from midas_hkls import Lattice, SpaceGroup           # optional, see [hkls]

# Detector + scan geometry
geom = md.HEDMGeometry(
    Lsd=1_000_000.0,              # um
    y_BC=1024.0, z_BC=1024.0,
    px=200.0,
    omega_start=0.0, omega_step=0.25, n_frames=1440,
    n_pixels_y=2048, n_pixels_z=2048,
    min_eta=6.0,
    wavelength=0.172979,           # Angstroms
)

# Reflection list: either compute from a SpaceGroup + Lattice via the
# midas-hkls helper, or supply (hkls_cart, thetas, hkls_int) yourself
# (e.g. parsed from MIDAS GetHKLList output).
sg = SpaceGroup.from_number(225)                        # FCC
lat = Lattice.for_system("cubic", a=4.08)               # Au
hkls_cart, thetas, hkls_int = md.hkls_for_forward_model(
    sg, lat, wavelength_A=geom.wavelength, two_theta_max_deg=15.0,
)

model = md.HEDMForwardModel(
    hkls=hkls_cart, thetas=thetas, geometry=geom, hkls_int=hkls_int,
)

# Forward pass: grain state -> predicted spots. All inputs are leaves
# of the autograd graph.
euler = torch.tensor([[45.0, 30.0, 60.0]], requires_grad=True) * (3.14159 / 180)
pos   = torch.tensor([[0.0, 0.0, 0.0]],  requires_grad=True)
latc  = torch.tensor([4.08, 4.08, 4.08, 90.0, 90.0, 90.0], requires_grad=True)
spots = model(euler, pos, lattice_params=latc)

# Scalar loss -> gradients w.r.t. orientation, position, lattice
loss = ((spots.omega * spots.valid) ** 2).sum()
loss.backward()

Output modes

  • md.HEDMForwardModel.predict_spot_coords(spots, space="angular") — returns (2θ, η, ω) in radians for each valid reflection (FF and pf-HEDM).
  • md.HEDMForwardModel.predict_spot_coords(spots, space="detector") — returns (y_pixel, z_pixel, frame_nr) in fractional units (FF and pf-HEDM).
  • md.HEDMForwardModel.predict_images(spots, ...) — renders a differentiable 3D detector volume via Gaussian splatting (NF-HEDM output mode).

Validation

The forward model has been validated to pixel-exact agreement against the canonical C simulators ForwardSimulationCompressed and simulateNF in the MIDAS distribution. See the companion paper and the MIDAS repository fwd_sim/paper/ directory for reproducibility scripts.

Scope

midas-diffract v0.1.x is deliberately focused on the forward model and its gradient chain. The following capabilities build on this substrate and are released separately as they mature:

  • Sub-voxel grain mixtures
  • Physics-informed regularisation
  • Bayesian uncertainty quantification via HMC / variational inference
  • Temporal 4D-HEDM tracking
  • Coupling to differentiable crystal plasticity (JAX-FEM)
  • EM spot ownership for ambiguous FF patterns

Citation

If you use midas-diffract in published work, please cite the companion paper.

Licence

BSD-3-Clause.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

midas_diffract-0.7.0.tar.gz (87.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

midas_diffract-0.7.0-py3-none-any.whl (53.8 kB view details)

Uploaded Python 3

File details

Details for the file midas_diffract-0.7.0.tar.gz.

File metadata

  • Download URL: midas_diffract-0.7.0.tar.gz
  • Upload date:
  • Size: 87.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for midas_diffract-0.7.0.tar.gz
Algorithm Hash digest
SHA256 94cdc54d50ed935979eb9a7d3f50a5cfede5f88b1afb483b9ac0006897a441d4
MD5 a39397868ff4c8331334fbdcafec8255
BLAKE2b-256 a76486b33ab6a7111132b879e297af4e0c8e4071432bb4d1f4b5e3b8c897122e

See more details on using hashes here.

Provenance

The following attestation bundles were made for midas_diffract-0.7.0.tar.gz:

Publisher: python-packages.yml on marinerhemant/MIDAS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file midas_diffract-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: midas_diffract-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 53.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for midas_diffract-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 005afa5f8b2b38f057ec6ba0710875ce39742c818c0c6a8cb17f661999acf185
MD5 c276ddacbc2b91b6a62e42f27465f787
BLAKE2b-256 a49c241c2cde828e773d277713d84ccaffcd91c2f7b50bd7797374864522cee7

See more details on using hashes here.

Provenance

The following attestation bundles were made for midas_diffract-0.7.0-py3-none-any.whl:

Publisher: python-packages.yml on marinerhemant/MIDAS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 files

0.6.0

2 files

0.4.0

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page