Skip to main content

PyTorch single/multi-grain refiner (drop-in replacement for FitPosOrStrainsOMP / FitPosOrStrainsGPU)

Project description

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 + Wenxi 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.

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.

Project details


Download files

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

Source Distribution

midas_fit_grain-0.4.1.tar.gz (81.7 kB view details)

Uploaded Source

Built Distribution

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

midas_fit_grain-0.4.1-py3-none-any.whl (78.4 kB view details)

Uploaded Python 3

File details

Details for the file midas_fit_grain-0.4.1.tar.gz.

File metadata

  • Download URL: midas_fit_grain-0.4.1.tar.gz
  • Upload date:
  • Size: 81.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for midas_fit_grain-0.4.1.tar.gz
Algorithm Hash digest
SHA256 ab41f8b91ec75252d510a7abeafb5e2ac12e83ba9fd070784002b590bd0a515e
MD5 2f8a66dc57b87c81e93e4ad34e878dc2
BLAKE2b-256 b9a05ffcd744cbb080c9ba5ae37b7ff5696875c881485cbf3b700600e74d6f98

See more details on using hashes here.

Provenance

The following attestation bundles were made for midas_fit_grain-0.4.1.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_fit_grain-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: midas_fit_grain-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 78.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for midas_fit_grain-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa618c629f0925aac27cf0e0322c69017c467e900a998ad215523b00763e4268
MD5 cdd1877c6b9edae354ea47faf884e7e4
BLAKE2b-256 65f4bd2ecf59de88d11d40e7f6870909a6648f4e0d86aaf6f7e30c913df0eae4

See more details on using hashes here.

Provenance

The following attestation bundles were made for midas_fit_grain-0.4.1-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.

Supported by

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