midas-fit-grain
PyTorch single- and multi-grain refiner. Drop-in replacement for the C executables
FitPosOrStrainsOMP / FitPosOrStrainsGPU in MIDAS FF-HEDM.
Status: 0.2.x — sparse-output pre-allocation fix (trailing-skipped seeds
no longer truncate OrientPosFit / FitBest / ProcessKey) and
vectorized pixel-residual fast path (~N_g× fewer kernel launches per LM
iteration vs the per-grain Python loop). Park22 + datasetC CP-Ti real-data
validated. The C path remains the ff_MIDAS default;
this package is opt-in via --refine-backend python.
Notebooks
Worked-example Jupyter notebooks live in notebooks/. They are not shipped with pip install — get them by cloning the MIDAS repository.
What it does
For each grain in SpotsToIndex.csv:
- Reads matched spots from
ExtraInfo.binand the seed orientation fromBestPos_*.csv(the indexer's per-spot output). - Refines 12 parameters: position (3) + Bunge Euler (3) + lattice (6).
- Writes byte-identical
OrientPosFit.bin/FitBest.bin/Key.binconsumed by the existingff_MIDAS.pymerge stage.
Solvers
--solver {lbfgs,adam,lm,nelder_mead} — default lbfgs.
Loss functions
--loss {pixel,angular,internal_angle} — default pixel.
| Loss | Residual | Equivalent C function |
|---|---|---|
pixel |
(y, z) pixel positions on detector |
FitErrorsPosT (FitPosOrStrainsOMP) |
angular |
(2θ, η, ω) in radians |
optimize_single_grain (midas-diffract) |
internal_angle |
angle between ĝ_pred and ĝ_obs (rad) |
CalcInternalAngle (FitOrientationOMP) |
Fit modes
--mode {iterative,all_at_once} — default iterative.
iterative: position → re-match → orientation → re-match → strain → re-match → joint polish (matchesFitPosOrStrainsOMPdefault behavior).all_at_once: 12 params jointly, association computed once at entry, no mid-fit re-match.
Backends
MIDAS_FIT_GRAIN_DEVICE and MIDAS_FIT_GRAIN_DTYPE follow the same precedence
contract as midas-index (cuda > mps > cpu auto-detect; f64 on CPU,
f32 on accelerators). Per-grain refinement is batched into a single forward
call across the block, so scaling depends on B × S (grains × spots/grain),
not per-grain Python overhead.
CLI
midas-fit-grain paramstest.txt <blockNr> <numBlocks> <numLines> <numProcs> \
[--solver lbfgs] [--loss pixel] [--mode iterative]
Argv shape mirrors the C binary so the ff_MIDAS subprocess line is one-for-one.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file midas_fit_grain-0.8.0.tar.gz.
File metadata
- Download URL: midas_fit_grain-0.8.0.tar.gz
- Upload date:
- Size: 205.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0fd7482c2f0ea452e826bb76b59f6010ae68af2f6cd6b5596a2537cefbda8e9
|
|
| MD5 |
6797bfd00a23e8722c5d7422b7bfe374
|
|
| BLAKE2b-256 |
bc7999d403b3bab61019ec3f62896764d460d4cbc452fe7c6b9c6490a864f3d4
|
Provenance
The following attestation bundles were made for midas_fit_grain-0.8.0.tar.gz:
Publisher:
python-packages.yml on marinerhemant/MIDAS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
midas_fit_grain-0.8.0.tar.gz -
Subject digest:
b0fd7482c2f0ea452e826bb76b59f6010ae68af2f6cd6b5596a2537cefbda8e9 - Sigstore transparency entry: 2463632472
- Sigstore integration time:
-
Permalink:
marinerhemant/MIDAS@8590dea64c6e2bf6eb94a14bc5480c475497e8d8 -
Branch / Tag:
refs/tags/midas-fit-grain-v0.8.0 - Owner: https://github.com/marinerhemant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-packages.yml@8590dea64c6e2bf6eb94a14bc5480c475497e8d8 -
Trigger Event:
release
-
Statement type: