Skip to main content

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.bin and the seed orientation from BestPos_*.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.bin consumed by the existing ff_MIDAS.py merge 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 (matches FitPosOrStrainsOMP default behavior).
  • all_at_once: 12 params jointly, association computed once at entry, no mid-fit re-match.

Spot weights (c-omp refiner)

Two opt-in weights on each matched spot's contribution to the stage objectives, both off by default and bit-identical to the unweighted refiner when off (verified on LSHR, bt_20id_sep26b and datasetH):

  • RelFitRMSEWeightR0 r0 — scalar weight 1/(1 + rel/r0), rel = the merged spot's peak-fit FitRMSE/IMax, read from RelFitRMSE.bin (one float64 per ExtraInfo.bin row; the pipeline's refinement stage writes it when the key is set). r0 = 0.69 improves grain positions against EBSD (LSHR layer 1, ESTABLISHED 2026-09-28); it does not reduce strain noise.
  • SpotWeightsDirectional 1 — experimental radial / along-ring / omega weights from SpotWeights.bin (3 float64 per row, midas_transforms.io.csv.write_spot_weights_bin). Combined with RelFitRMSEWeightR0 the orientation and position stages stay scalar and only the strain stage is directional.

A set option with a missing, short or invalid file stops the refiner with a message rather than running unweighted. Reported errors (FitBest*, DiffPos, DiffOme) stay unweighted. Measurements and preregistrations: ff-hedm LAB_NOTEBOOK.md §14.

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.

Metadata

Release files for midas-fit-grain 0.11.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for midas-fit-grain 0.11.1
File Size Uploaded
midas_fit_grain-0.11.1.tar.gz 264.0 kB Details

Release files / midas_fit_grain-0.11.1.tar.gz

Download URL midas_fit_grain-0.11.1.tar.gz
Size 264.0 kB
Tags Source
SHA-256 checksum
How to use checksums
473fd1fa579a030e8d17030d67abec5b07173bbfe6829d688b13a9df598ea823
BLAKE2b-256 checksum
How to use checksums
b6ac84ba4255d5b6be376ba9154b6d275223d28831f1b6b73f5b183f3bd66e48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.11.1 This release

1 release file

0.11.0

1 release file

0.10.0

1 release file

0.9.1

1 release file

0.9.0

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.6

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.4.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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