midas-diffract 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- midas_diffract-0.1.0/LICENSE +31 -0
- midas_diffract-0.1.0/PKG-INFO +122 -0
- midas_diffract-0.1.0/README.md +95 -0
- midas_diffract-0.1.0/midas_diffract/__init__.py +55 -0
- midas_diffract-0.1.0/midas_diffract/forward.py +1559 -0
- midas_diffract-0.1.0/midas_diffract/hkls.py +180 -0
- midas_diffract-0.1.0/midas_diffract/losses.py +494 -0
- midas_diffract-0.1.0/midas_diffract/optimize.py +248 -0
- midas_diffract-0.1.0/midas_diffract.egg-info/PKG-INFO +122 -0
- midas_diffract-0.1.0/midas_diffract.egg-info/SOURCES.txt +19 -0
- midas_diffract-0.1.0/midas_diffract.egg-info/dependency_links.txt +1 -0
- midas_diffract-0.1.0/midas_diffract.egg-info/requires.txt +9 -0
- midas_diffract-0.1.0/midas_diffract.egg-info/top_level.txt +1 -0
- midas_diffract-0.1.0/pyproject.toml +44 -0
- midas_diffract-0.1.0/setup.cfg +4 -0
- midas_diffract-0.1.0/tests/test_c_comparison.py +562 -0
- midas_diffract-0.1.0/tests/test_forward.py +1115 -0
- midas_diffract-0.1.0/tests/test_hkls.py +249 -0
- midas_diffract-0.1.0/tests/test_losses.py +388 -0
- midas_diffract-0.1.0/tests/test_strain_tensor.py +153 -0
- midas_diffract-0.1.0/tests/test_tilts.py +196 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, UChicago Argonne, LLC, operator of Argonne National
|
|
4
|
+
Laboratory, and the midas-diffract authors.
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer.
|
|
12
|
+
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
18
|
+
contributors may be used to endorse or promote products derived from
|
|
19
|
+
this software without specific prior written permission.
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
24
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
25
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
26
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
27
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
28
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
29
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
30
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
31
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: midas-diffract
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: End-to-end differentiable forward model for High-Energy Diffraction Microscopy (FF, NF, pf-HEDM)
|
|
5
|
+
Author: Simon Zhang, Nina Andrejevic, Mathew Cherukara
|
|
6
|
+
Author-email: Hemant Sharma <hsharma@anl.gov>
|
|
7
|
+
License-Expression: BSD-3-Clause
|
|
8
|
+
Project-URL: Homepage, https://github.com/marinerhemant/MIDAS
|
|
9
|
+
Project-URL: Documentation, https://github.com/marinerhemant/MIDAS
|
|
10
|
+
Project-URL: Issues, https://github.com/marinerhemant/MIDAS/issues
|
|
11
|
+
Keywords: HEDM,3DXRD,differentiable physics,PyTorch,forward model,crystallography,polycrystal,grain
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: numpy>=1.22
|
|
20
|
+
Requires-Dist: torch>=2.0
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
24
|
+
Provides-Extra: hkls
|
|
25
|
+
Requires-Dist: midas-hkls>=0.1.0; extra == "hkls"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# midas-diffract
|
|
29
|
+
|
|
30
|
+
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](https://github.com/marinerhemant/MIDAS).
|
|
31
|
+
|
|
32
|
+
Companion paper: Sharma, Zhang, Andrejevic & Cherukara, *An End-to-End Differentiable Forward Model for High-Energy Diffraction Microscopy*, IUCrJ (in preparation, 2026).
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install midas-diffract # core forward model + losses + optimizer
|
|
38
|
+
pip install midas-diffract[hkls] # also installs midas-hkls for the
|
|
39
|
+
# pure-Python reflection-list helper
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Optional PyTorch CUDA or MPS back-ends are used automatically if available.
|
|
43
|
+
|
|
44
|
+
## Quick start
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import torch
|
|
48
|
+
import midas_diffract as md
|
|
49
|
+
from midas_hkls import Lattice, SpaceGroup # optional, see [hkls]
|
|
50
|
+
|
|
51
|
+
# Detector + scan geometry
|
|
52
|
+
geom = md.HEDMGeometry(
|
|
53
|
+
Lsd=1_000_000.0, # um
|
|
54
|
+
y_BC=1024.0, z_BC=1024.0,
|
|
55
|
+
px=200.0,
|
|
56
|
+
omega_start=0.0, omega_step=0.25, n_frames=1440,
|
|
57
|
+
n_pixels_y=2048, n_pixels_z=2048,
|
|
58
|
+
min_eta=6.0,
|
|
59
|
+
wavelength=0.172979, # Angstroms
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# Reflection list: either compute from a SpaceGroup + Lattice via the
|
|
63
|
+
# midas-hkls helper, or supply (hkls_cart, thetas, hkls_int) yourself
|
|
64
|
+
# (e.g. parsed from MIDAS GetHKLList output).
|
|
65
|
+
sg = SpaceGroup.from_number(225) # FCC
|
|
66
|
+
lat = Lattice.for_system("cubic", a=4.08) # Au
|
|
67
|
+
hkls_cart, thetas, hkls_int = md.hkls_for_forward_model(
|
|
68
|
+
sg, lat, wavelength_A=geom.wavelength, two_theta_max_deg=15.0,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
model = md.HEDMForwardModel(
|
|
72
|
+
hkls=hkls_cart, thetas=thetas, geometry=geom, hkls_int=hkls_int,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# Forward pass: grain state -> predicted spots. All inputs are leaves
|
|
76
|
+
# of the autograd graph.
|
|
77
|
+
euler = torch.tensor([[45.0, 30.0, 60.0]], requires_grad=True) * (3.14159 / 180)
|
|
78
|
+
pos = torch.tensor([[0.0, 0.0, 0.0]], requires_grad=True)
|
|
79
|
+
latc = torch.tensor([4.08, 4.08, 4.08, 90.0, 90.0, 90.0], requires_grad=True)
|
|
80
|
+
spots = model(euler, pos, lattice_params=latc)
|
|
81
|
+
|
|
82
|
+
# Scalar loss -> gradients w.r.t. orientation, position, lattice
|
|
83
|
+
loss = ((spots.omega * spots.valid) ** 2).sum()
|
|
84
|
+
loss.backward()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Output modes
|
|
88
|
+
|
|
89
|
+
- `md.HEDMForwardModel.predict_spot_coords(spots, space="angular")` — returns
|
|
90
|
+
`(2θ, η, ω)` in radians for each valid reflection (FF and pf-HEDM).
|
|
91
|
+
- `md.HEDMForwardModel.predict_spot_coords(spots, space="detector")` — returns
|
|
92
|
+
`(y_pixel, z_pixel, frame_nr)` in fractional units (FF and pf-HEDM).
|
|
93
|
+
- `md.HEDMForwardModel.predict_images(spots, ...)` — renders a differentiable
|
|
94
|
+
3D detector volume via Gaussian splatting (NF-HEDM output mode).
|
|
95
|
+
|
|
96
|
+
## Validation
|
|
97
|
+
|
|
98
|
+
The forward model has been validated to pixel-exact agreement against the
|
|
99
|
+
canonical C simulators `ForwardSimulationCompressed` and `simulateNF` in the
|
|
100
|
+
MIDAS distribution. See the companion paper and the MIDAS repository
|
|
101
|
+
`fwd_sim/paper/` directory for reproducibility scripts.
|
|
102
|
+
|
|
103
|
+
## Scope
|
|
104
|
+
|
|
105
|
+
`midas-diffract` v0.1.0 is deliberately focused on the forward model and its
|
|
106
|
+
gradient chain. The following capabilities build on this substrate and are
|
|
107
|
+
released separately as they mature:
|
|
108
|
+
|
|
109
|
+
- Sub-voxel grain mixtures
|
|
110
|
+
- Physics-informed regularisation
|
|
111
|
+
- Bayesian uncertainty quantification via HMC / variational inference
|
|
112
|
+
- Temporal 4D-HEDM tracking
|
|
113
|
+
- Coupling to differentiable crystal plasticity (JAX-FEM)
|
|
114
|
+
- EM spot ownership for ambiguous FF patterns
|
|
115
|
+
|
|
116
|
+
## Citation
|
|
117
|
+
|
|
118
|
+
If you use `midas-diffract` in published work, please cite the companion paper.
|
|
119
|
+
|
|
120
|
+
## Licence
|
|
121
|
+
|
|
122
|
+
BSD-3-Clause.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# midas-diffract
|
|
2
|
+
|
|
3
|
+
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](https://github.com/marinerhemant/MIDAS).
|
|
4
|
+
|
|
5
|
+
Companion paper: Sharma, Zhang, Andrejevic & Cherukara, *An End-to-End Differentiable Forward Model for High-Energy Diffraction Microscopy*, IUCrJ (in preparation, 2026).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install midas-diffract # core forward model + losses + optimizer
|
|
11
|
+
pip install midas-diffract[hkls] # also installs midas-hkls for the
|
|
12
|
+
# pure-Python reflection-list helper
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Optional PyTorch CUDA or MPS back-ends are used automatically if available.
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import torch
|
|
21
|
+
import midas_diffract as md
|
|
22
|
+
from midas_hkls import Lattice, SpaceGroup # optional, see [hkls]
|
|
23
|
+
|
|
24
|
+
# Detector + scan geometry
|
|
25
|
+
geom = md.HEDMGeometry(
|
|
26
|
+
Lsd=1_000_000.0, # um
|
|
27
|
+
y_BC=1024.0, z_BC=1024.0,
|
|
28
|
+
px=200.0,
|
|
29
|
+
omega_start=0.0, omega_step=0.25, n_frames=1440,
|
|
30
|
+
n_pixels_y=2048, n_pixels_z=2048,
|
|
31
|
+
min_eta=6.0,
|
|
32
|
+
wavelength=0.172979, # Angstroms
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# Reflection list: either compute from a SpaceGroup + Lattice via the
|
|
36
|
+
# midas-hkls helper, or supply (hkls_cart, thetas, hkls_int) yourself
|
|
37
|
+
# (e.g. parsed from MIDAS GetHKLList output).
|
|
38
|
+
sg = SpaceGroup.from_number(225) # FCC
|
|
39
|
+
lat = Lattice.for_system("cubic", a=4.08) # Au
|
|
40
|
+
hkls_cart, thetas, hkls_int = md.hkls_for_forward_model(
|
|
41
|
+
sg, lat, wavelength_A=geom.wavelength, two_theta_max_deg=15.0,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
model = md.HEDMForwardModel(
|
|
45
|
+
hkls=hkls_cart, thetas=thetas, geometry=geom, hkls_int=hkls_int,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# Forward pass: grain state -> predicted spots. All inputs are leaves
|
|
49
|
+
# of the autograd graph.
|
|
50
|
+
euler = torch.tensor([[45.0, 30.0, 60.0]], requires_grad=True) * (3.14159 / 180)
|
|
51
|
+
pos = torch.tensor([[0.0, 0.0, 0.0]], requires_grad=True)
|
|
52
|
+
latc = torch.tensor([4.08, 4.08, 4.08, 90.0, 90.0, 90.0], requires_grad=True)
|
|
53
|
+
spots = model(euler, pos, lattice_params=latc)
|
|
54
|
+
|
|
55
|
+
# Scalar loss -> gradients w.r.t. orientation, position, lattice
|
|
56
|
+
loss = ((spots.omega * spots.valid) ** 2).sum()
|
|
57
|
+
loss.backward()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Output modes
|
|
61
|
+
|
|
62
|
+
- `md.HEDMForwardModel.predict_spot_coords(spots, space="angular")` — returns
|
|
63
|
+
`(2θ, η, ω)` in radians for each valid reflection (FF and pf-HEDM).
|
|
64
|
+
- `md.HEDMForwardModel.predict_spot_coords(spots, space="detector")` — returns
|
|
65
|
+
`(y_pixel, z_pixel, frame_nr)` in fractional units (FF and pf-HEDM).
|
|
66
|
+
- `md.HEDMForwardModel.predict_images(spots, ...)` — renders a differentiable
|
|
67
|
+
3D detector volume via Gaussian splatting (NF-HEDM output mode).
|
|
68
|
+
|
|
69
|
+
## Validation
|
|
70
|
+
|
|
71
|
+
The forward model has been validated to pixel-exact agreement against the
|
|
72
|
+
canonical C simulators `ForwardSimulationCompressed` and `simulateNF` in the
|
|
73
|
+
MIDAS distribution. See the companion paper and the MIDAS repository
|
|
74
|
+
`fwd_sim/paper/` directory for reproducibility scripts.
|
|
75
|
+
|
|
76
|
+
## Scope
|
|
77
|
+
|
|
78
|
+
`midas-diffract` v0.1.0 is deliberately focused on the forward model and its
|
|
79
|
+
gradient chain. The following capabilities build on this substrate and are
|
|
80
|
+
released separately as they mature:
|
|
81
|
+
|
|
82
|
+
- Sub-voxel grain mixtures
|
|
83
|
+
- Physics-informed regularisation
|
|
84
|
+
- Bayesian uncertainty quantification via HMC / variational inference
|
|
85
|
+
- Temporal 4D-HEDM tracking
|
|
86
|
+
- Coupling to differentiable crystal plasticity (JAX-FEM)
|
|
87
|
+
- EM spot ownership for ambiguous FF patterns
|
|
88
|
+
|
|
89
|
+
## Citation
|
|
90
|
+
|
|
91
|
+
If you use `midas-diffract` in published work, please cite the companion paper.
|
|
92
|
+
|
|
93
|
+
## Licence
|
|
94
|
+
|
|
95
|
+
BSD-3-Clause.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""midas-diffract: End-to-end differentiable forward model for HEDM.
|
|
2
|
+
|
|
3
|
+
A PyTorch-based differentiable forward simulator for far-field, near-field,
|
|
4
|
+
and point-focused High-Energy Diffraction Microscopy, with pixel-exact
|
|
5
|
+
agreement against the canonical C reference simulators in MIDAS.
|
|
6
|
+
|
|
7
|
+
See the companion paper for methodology:
|
|
8
|
+
Sharma, Zhang, Andrejevic, Cherukara, "An End-to-End Differentiable Forward
|
|
9
|
+
Model for High-Energy Diffraction Microscopy," IUCrJ (in prep, 2026).
|
|
10
|
+
|
|
11
|
+
Quick start
|
|
12
|
+
-----------
|
|
13
|
+
import torch
|
|
14
|
+
import midas_diffract as md
|
|
15
|
+
|
|
16
|
+
# Construct the forward model from geometry + reflection list
|
|
17
|
+
geom = md.HEDMGeometry(Lsd=..., y_BC=..., z_BC=..., px=..., ...)
|
|
18
|
+
model = md.HEDMForwardModel(hkls=hkls_cart, thetas=thetas,
|
|
19
|
+
geometry=geom, hkls_int=hkls_int)
|
|
20
|
+
|
|
21
|
+
# Forward: grain state -> predicted spots
|
|
22
|
+
euler = torch.tensor([[phi1, Phi, phi2]], requires_grad=True)
|
|
23
|
+
pos = torch.tensor([[x, y, z]], requires_grad=True)
|
|
24
|
+
spots = model(euler, pos, lattice_params=latc)
|
|
25
|
+
|
|
26
|
+
# Scalar loss -> gradient to all inputs via autograd
|
|
27
|
+
loss = (spots.omega * spots.valid).pow(2).sum()
|
|
28
|
+
loss.backward()
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
__version__ = "0.1.0"
|
|
32
|
+
|
|
33
|
+
from .forward import (
|
|
34
|
+
HEDMForwardModel,
|
|
35
|
+
HEDMGeometry,
|
|
36
|
+
ScanConfig,
|
|
37
|
+
TriVoxelConfig,
|
|
38
|
+
SpotDescriptors,
|
|
39
|
+
)
|
|
40
|
+
from .hkls import hkls_for_forward_model
|
|
41
|
+
from .losses import SpotMatchingLoss
|
|
42
|
+
from .optimize import optimize_single_grain, evaluate_recovery
|
|
43
|
+
|
|
44
|
+
__all__ = [
|
|
45
|
+
"HEDMForwardModel",
|
|
46
|
+
"HEDMGeometry",
|
|
47
|
+
"ScanConfig",
|
|
48
|
+
"TriVoxelConfig",
|
|
49
|
+
"SpotDescriptors",
|
|
50
|
+
"SpotMatchingLoss",
|
|
51
|
+
"hkls_for_forward_model",
|
|
52
|
+
"optimize_single_grain",
|
|
53
|
+
"evaluate_recovery",
|
|
54
|
+
"__version__",
|
|
55
|
+
]
|