Expand description
Application-neutral native refinement and project workflows.
This crate is the shared host boundary for Python adapters and future
native application consumers. It contains no PyO3, Tauri, GUI, or
file-format types.
Applications normally use it through
phasesmith::workflows.
§Workflow families
- Backgrounds: differentiable Chebyshev, polynomial, point, amorphous, and composite models.
- Le Bail: intensity extraction with optional profile/lattice refinement, covariance, checkpoints, and dynamic reflection domains.
- TOF Le Bail: typed microsecond-domain fixed-instrument calculation and nonnegative intensity extraction with fused d/instrument derivatives.
- Rietveld: calculation, prepared objective products, structural and general refinement, staged recipes, and joint multi-histogram refinement.
- Quantitative analysis: validated Hill–Howard phase fractions.
- Infrastructure: typed parameters, bounds, constraints, residuals, cancellation, limits, events, clocks, diagnostics, and checkpoints.
§Selecting the level
Use calculate_* functions for a deterministic forward calculation. Use a
Prepared*Objective when integrating a custom optimizer and consuming
values/JVP/VJP products directly. Use refine_* for the built-in solver, and
the corresponding _with_runtime variant when an application needs
cancellation, progress events, or checkpoint sinks.
LeBailInput and RietveldInput own validated observations and domain
state. Result/checkpoint records and structured event diagnostics are the
stable programmatic output; human-readable event messages should not be
parsed.
§Application integration
Workflows are synchronous and application-neutral. A desktop or async host
runs them on its chosen worker mechanism, connects
RefinementRuntime to its cancellation/event bridge, and uses
phasesmith-persistence for native project state. The joint_pbso4 example
in this package demonstrates a complete Rust-only X-ray/neutron refinement.
The facade provides collected mathematical references for
refinement
and
background models.
Structs§
- Affine
Constraint - Define
target = multiplier * source + offset. - Amorphous
Background - Sum of broad area-normalized Gaussian amorphous components.
- Amorphous
Peak - One area-normalized broad Gaussian component in degrees
2theta. - Background
Basis - Row-major sample-by-parameter analytical background derivatives.
- Cancellation
Token - Thread-safe first-request-wins cooperative cancellation token.
- Chebyshev
Background - Chebyshev series on one explicit closed degree domain.
- Coincident
Reflection Group - Numerically coincident profile columns and their matrix rank.
- Composite
Background - Ordered additive composition of analytical models.
- Constraint
Derivative Matrix - Row-major derivative
d physical values / d scaled free values. - Constraint
Transform - Validated ordered mapping between free solver coordinates and all values.
- Covariance
Matrix - Square row-major covariance over scaled free parameters.
- CwLattice
Geometry - CW reflection geometry and independent lattice derivatives.
- Evaluated
Sample Physics - Evaluated contribution arrays plus stable provider derivative names.
- Fixed
Constraint - Set one target parameter to a constant during expansion.
- Generated
Lattice Domain - Generated guarded reflection arrays and topology-transfer diagnostics.
- Intensity
Extraction Result - One non-negative multiplicative redistribution result.
- Joint
Rietveld Checkpoint - Complete accepted state for deterministic joint continuation.
- Joint
Rietveld Gradient - Complete accepted-state value and gradient of a joint objective.
- Joint
Rietveld Histogram - One experiment in a joint native Rietveld objective.
- Joint
Rietveld Iteration Record - One accepted joint Gauss–Newton iteration.
- Joint
Rietveld Layout - Stable shared/local parameter packing for a joint objective.
- Joint
Rietveld Metrics - Aggregate powder residual metrics over all joint histograms.
- Joint
Rietveld Product - One histogram’s profile and directional derivative.
- Joint
Rietveld Refinement Options - Numerical and bounded-runtime controls for a joint native refinement.
- Joint
Rietveld Refinement Result - Final accepted joint native refinement result.
- Joint
Rietveld Topology Change - One topology change owned by a specific histogram.
- Lattice
Bounds - Finite box bounds in one lattice parameterization.
- Lattice
Parameterization - Independent physical lattice variables for one exact crystallographic setting.
- Lattice
Reflection Domain - Bounded monochromatic reflection topology with stable intensity transfer.
- LeBail
Calculation - Native fixed-phase pattern result used by extraction and adapters.
- LeBail
Checkpoint - Complete immutable continuation state for the fixed-reflection workflow.
- LeBail
Input - Observations, instrument, and ordered fixed-reflection phases.
- LeBail
Iteration Record - One immutable accepted fixed-reflection iteration.
- LeBail
Options - Deterministic controls for fixed-reflection extraction.
- LeBail
Phase - One fixed reflection phase whose integrated intensities are extracted.
- LeBail
Result - Complete native fixed-reflection Le Bail result.
- Linear
Constraint - Define
target = offset + sum(coefficient * source). - Linear
Term - One source/coefficient pair in a linear constraint.
- Monotonic
Clock - Process-local monotonic clock backed by
Instant. - Parameter
Bounds - Closed lower and upper scalar bounds.
- Parameter
Change - One accepted physical profile-parameter change.
- Parameter
Key - Stable structured identity for one refinable scalar.
- Parameter
Set - Deterministically ordered immutable scalar specifications.
- Parameter
Spec - Value, unit, scale, bounds, and selection for one scalar.
- Phase
Pattern Component - One display-ready phase curve.
- Phase
Scale Estimation Result - Diagnostics and restart-ready input produced by phase-scale initialization.
- Phase
Weight Fraction - One normalized crystalline weight fraction.
- Point
Background - Linear interpolation through fixed knots with refinable values.
- Polynomial
Background - Power series on the normalized input-grid coordinate
[-1, 1]. - Prepared
General Free Linearization - Complete weighted Jacobian in scaled free-parameter coordinates.
- Prepared
General Rietveld Objective - Reusable complete physical objective for one accepted native state.
- Prepared
Joint Rietveld Objective - Prepared matrix-free sum of all histogram objectives.
- Prepared
Rietveld Linearization - One reusable parameter-major physical structural Jacobian and its values.
- Prepared
Rietveld Objective - Reusable structural values and derivative products for one accepted state.
- Prepared
Structural TofMulti Bank Objective - Prepared matrix-free structural TOF sum over all banks.
- Profile
Estimation Input - Validated input for one predominantly single-phase profile estimate.
- Profile
Estimation Options - Deterministic controls for staged effective-profile estimation.
- Profile
Estimation Result - Final effective starting profile and the complete staged selection audit.
- Profile
Estimation Stage - Compact audit record for one attempted stage.
- Quantitative
Phase - Metadata required by the Hill–Howard scale relation.
- Quantitative
Phase Analysis - Weight fractions and their row-major covariance propagated from phase scales.
- Refinement
Event - One immutable orchestration-boundary event.
- Refinement
Limits - Hard upper bounds independent of convergence criteria.
- Refinement
Runtime - Stateful method-independent refinement boundary guard.
- Refinement
Stop - Normal cooperative/budget termination returned at a safe boundary.
- Reflection
Intensity - Final stable reflection identity and intensity.
- Residual
Evaluation - Full residual arrays and standard masked powder metrics.
- Residual
Options - Weighting and degrees-of-freedom controls for residual evaluation.
- Rietveld
Analysis - One complete runnable single-histogram native Rietveld analysis.
- Rietveld
Calculation - Display-ready structural calculation and residual metrics.
- Rietveld
Calculation Options - Deterministic calculation controls shared by later native refinement.
- Rietveld
Checkpoint - Complete accepted state for deterministic native continuation.
- Rietveld
Covariance Matrix - Square row-major covariance over the complete physical parameter order.
- Rietveld
Covariance Options - Controls for the optional small parameter-space identifiability analysis.
- Rietveld
General Checkpoint - Complete accepted state for deterministic constrained continuation.
- Rietveld
General Refinement Result - Final complete native constrained-refinement result.
- Rietveld
Input - Observations, experiment state, and ordered structural phases.
- Rietveld
Iteration Record - One accepted native Rietveld Gauss–Newton iteration.
- Rietveld
Parameter Correlation - One nearly collinear pair of scaled-free Jacobian columns.
- Rietveld
Parameter Layout - Ordered complete physical parameters and state transforms.
- Rietveld
Parameter Selection - Complete selected built-in parameter families for one native Rietveld run.
- Rietveld
Phase - One owned monochromatic structural phase and its sample-physics inputs.
- Rietveld
Phase Calculation - One labeled phase contribution and its crystallographic intermediates.
- Rietveld
Project State - Revisioned native project plus zero or one runnable analysis per histogram.
- Rietveld
Recipe - Auditable explicit or intelligent stage sequence.
- Rietveld
Recipe Sinks - Cloneable host observers shared across every stage runtime.
- Rietveld
Refinement Options - Numerical and bounded-runtime controls for native structural refinement.
- Rietveld
Refinement Result - Final accepted native structural refinement result.
- Rietveld
Stage - One caller-visible active parameter set and acceptance policy.
- Rietveld
Stage Result - Auditable outcome from one attempted recipe stage.
- Rietveld
Structural Layout - Ordered physical parameters and exact transforms to/from engine layouts.
- Rietveld
Structural Selection - Structural parameter families selected for one native Rietveld layout.
- Rietveld
Topology Change - Reflection-topology change attached to an accepted structural step.
- Rietveld
Workflow Result - Complete or safely stopped native staged workflow.
- Sample
Physics Parameter - One stable refinable built-in sample-physics scalar.
- Site
Coordinate Model - Symmetry-allowed coordinate tangent basis for one asymmetric site.
- Structural
TofBank - One observed bank and every bank-local structural-TOF quantity.
- Structural
TofBank Calculation - One bank’s display-ready structural TOF calculation.
- Structural
TofMulti Bank Analysis - One complete runnable structural multi-bank TOF analysis.
- Structural
TofMulti Bank Calculation - Ordered multi-bank structural TOF calculation.
- Structural
TofMulti Bank Checkpoint - Complete last-accepted state for deterministic continuation.
- Structural
TofMulti Bank Gradient - Complete objective values and gradient in joint physical order.
- Structural
TofMulti Bank Input - Shared structural phase plus one or more explicit TOF banks.
- Structural
TofMulti Bank Iteration Record - One atomically accepted structural TOF step.
- Structural
TofMulti Bank Layout - Stable shared/local physical parameter packing for structural TOF banks.
- Structural
TofMulti Bank Product - One bank’s profile and joint-parameter directional derivative.
- Structural
TofMulti Bank Project State - Revisioned project plus disjoint structural multi-bank TOF analyses.
- Structural
TofMulti Bank Refinement Options - Numerical and bounded-runtime controls for structural multi-bank TOF.
- Structural
TofMulti Bank Refinement Result - Final accepted structural TOF refinement state.
- TofBank
Instrument Model - Selected bank-local coefficients in deterministic solver order.
- TofBank
Instrument State - One accepted bank-local instrument.
- TofChebyshev
Background - Refinable Chebyshev series on one explicit TOF interval.
- TofChebyshev
Basis - Sample-major analytical Chebyshev coefficient derivatives.
- TofGeometry
Correlation - One unresolved lattice/instrument weighted-column pair.
- TofGeometry
Diagnostics - Identifiability diagnostics for the final joint geometry system.
- TofInstrument
Correlation - One unresolved weighted-Jacobian column pair.
- TofInstrument
Diagnostics - Identifiability diagnostics for the final selected instrument system.
- TofInstrument
Parameter Bound - Closed physical bounds for one selected bank-local instrument coefficient.
- TofInstrument
Parameter Change - One accepted physical bank-local coefficient change.
- TofLattice
Geometry - TOF reflection geometry and independent lattice derivatives.
- TofLattice
Parameter Change - One accepted physical lattice-parameter change.
- TofLe
Bail Analysis - One complete runnable fixed-instrument TOF Le Bail analysis.
- TofLe
Bail Bank - One detector bank in an atomic multi-bank extraction.
- TofLe
Bail Calculation - Display-ready TOF profile plus the fused derivative product.
- TofLe
Bail Checkpoint - Complete immutable continuation state for fixed-instrument TOF extraction.
- TofLe
Bail Input - Observations, fixed TOF instrument, and ordered phases.
- TofLe
Bail Iteration Record - One accepted extraction cycle.
- TofLe
Bail Options - Deterministic fixed-instrument TOF extraction controls.
- TofLe
Bail Phase - One fixed-topology phase in a TOF Le Bail extraction.
- TofLe
Bail Project State - Revisioned native project plus zero or one TOF analysis per TOF histogram.
- TofLe
Bail Result - Complete fixed-instrument TOF extraction result.
- TofMulti
Bank Checkpoint - Complete immutable continuation state for atomic multi-bank extraction.
- TofMulti
Bank Checkpoint Bank - One bank’s last accepted state inside a joint checkpoint.
- TofMulti
Bank Geometry Analysis - One complete runnable joint multi-bank TOF geometry analysis.
- TofMulti
Bank Geometry Checkpoint - Complete last-accepted joint geometry state.
- TofMulti
Bank Geometry Checkpoint Bank - One bank’s complete accepted joint-geometry checkpoint state.
- TofMulti
Bank Geometry Input - Shared-cell model plus selected bank-local instrument coefficients.
- TofMulti
Bank Geometry Iteration Record - One atomically accepted extraction plus joint geometry cycle.
- TofMulti
Bank Geometry Options - Controls for one genuinely joint lattice/instrument step.
- TofMulti
Bank Geometry Project State - Revisioned project plus disjoint joint multi-bank TOF geometry analyses.
- TofMulti
Bank Geometry Result - Complete joint shared-cell plus local-instrument result.
- TofMulti
Bank Input - Two or more TOF banks sharing fixed phase/reflection geometry.
- TofMulti
Bank Instrument Checkpoint - Complete last-accepted state for exact instrument continuation.
- TofMulti
Bank Instrument Checkpoint Bank - One bank’s accepted checkpoint state.
- TofMulti
Bank Instrument Input - Multi-bank observations plus selected local instrument coefficients.
- TofMulti
Bank Instrument Iteration Record - One atomically accepted extraction plus bank-local instrument cycle.
- TofMulti
Bank Instrument Options - Controls for alternating local Le Bail updates and one instrument step.
- TofMulti
Bank Instrument Result - Complete result from analytical bank-local TOF instrument refinement.
- TofMulti
Bank Iteration Record - One atomically accepted multi-bank redistribution cycle.
- TofMulti
Bank Lattice Checkpoint - Complete last-accepted state for exact shared-lattice continuation.
- TofMulti
Bank Lattice Input - Multi-bank observations plus one or more shared phase-cell models.
- TofMulti
Bank Lattice Iteration Record - One atomically accepted local-extraction plus shared-lattice cycle.
- TofMulti
Bank Lattice Options - Controls for alternating local Le Bail updates and one shared lattice step.
- TofMulti
Bank Lattice Result - Complete result from shared analytical multi-bank TOF lattice refinement.
- TofMulti
Bank Metrics - Aggregate residual metrics over every included sample in all banks.
- TofMulti
Bank Result - Complete result from one atomic multi-bank fixed-cell extraction.
- TofMulti
Bank Result Bank - One bank’s accepted display state.
- TofReflection
Intensity - Stable final reflection intensity.
- TofShared
Lattice Phase - One phase whose symmetry-independent cell is shared across every detector bank.
- TofShared
Lattice State - One accepted shared-cell value.
Enums§
- Background
Error - Invalid analytical background definition, grid, or replacement.
- Background
Model - Closed native union used by application-neutral request records.
- Cancellation
Error - Invalid cancellation token operation.
- Constraint
- Supported native scalar constraint records.
- Constraint
Error - Invalid native scalar constraint or transform input.
- Diagnostic
Value - Finite JSON-scalar diagnostic value.
- Joint
Rietveld Error - Invalid joint native Rietveld parameter or objective state.
- Joint
Rietveld Refinement Error - Invalid joint constrained-refinement state.
- Lattice
Error - Invalid lattice parameterization, bounds, geometry, or domain generation.
- LeBail
Error - Invalid native fixed-reflection Le Bail state or operation.
- Parameter
Error - Invalid native parameter identity or scalar specification.
- Phase
Scale Estimation Error - Failure to build or solve the weighted phase-scale initialization problem.
- Profile
Estimation Error - Errors from effective-profile estimation.
- Profile
Estimation Mode - Requested complexity for effective-profile estimation.
- Profile
Estimation Stage Kind - Stable name for one attempted estimation stage.
- Quantitative
Error - Invalid quantitative-phase input.
- Refinement
Event Kind - Stable machine-readable event categories.
- Residual
Error - Invalid input to native residual evaluation.
- Rietveld
Error - Invalid owned native Rietveld calculation state.
- Rietveld
General Objective Error - Invalid complete native Rietveld objective state.
- Rietveld
General Parameter Error - Invalid complete native Rietveld parameter state.
- Rietveld
General Refinement Error - Invalid complete constrained Rietveld refinement state.
- Rietveld
Instrument Parameter - Supported built-in monochromatic instrument and position parameters.
- Rietveld
Objective Error - Invalid prepared Rietveld objective state.
- Rietveld
Parameter Error - Invalid native Rietveld parameter-layout state.
- Rietveld
Project Error - Invalid project-level native Rietveld state.
- Rietveld
Recipe Error - Invalid staged Rietveld workflow state.
- Rietveld
Recipe Mode - Origin of a staged Rietveld recipe.
- Rietveld
Refinement Error - Invalid native structural refinement state.
- Rietveld
Sample Physics Model - One closed built-in sample-physics model.
- Runtime
Error - Invalid runtime configuration, event, control order, or host callback.
- Sample
Physics Error - Invalid built-in sample-physics state.
- Structural
TofMulti Bank Error - Invalid structural multi-bank TOF request or objective product.
- Structural
TofMulti Bank Refinement Error - Invalid bounded structural TOF refinement state.
- Structural
TofProject Error - Invalid project-level structural TOF state.
- Termination
Reason - Stable refinement termination categories shared by every method.
- TofGeometry
Parameter Key - Stable identity of one joint physical geometry column.
- TofLe
Bail Error - Invalid TOF Le Bail request or numerical state.
- TofMulti
Bank Error - Invalid multi-bank TOF request, shared contract, or numerical state.
- TofMulti
Bank Geometry Error - Invalid joint shared-cell/bank-local-instrument TOF state.
- TofMulti
Bank Instrument Error - Invalid bank-local TOF instrument request or numerical state.
- TofMulti
Bank Lattice Error - Invalid shared-lattice TOF request or numerical state.
- TofMulti
Bank Project Error - Invalid project-level joint multi-bank TOF state.
- TofProject
Error - Invalid project-level fixed-instrument TOF state.
Constants§
- DEFAULT_
MAX_ LINEARIZATION_ ELEMENTS - Default upper bound for reusable native structural Jacobians.
Traits§
- Checkpoint
Sink - Application-owned durable sink for one typed accepted-state checkpoint.
- Differentiable
Background - Shared immutable analytical-background contract.
- Refinement
Event Sink - Synchronous event consumer called only at orchestration boundaries.
- Runtime
Clock - Monotonic second source injectable for deterministic tests.
Functions§
- build_
lebail_ parameter_ set - Build bounded typed specifications for selected fixed-geometry parameters.
- build_
lebail_ parameter_ set_ with_ lattice - Build bounded typed specifications including optional lattice variables.
- calculate_
lebail_ pattern - Calculate all fixed phases through one native fused accumulation.
- calculate_
lebail_ pattern_ with_ background - Calculate all fixed phases plus an optional analytical residual background.
- calculate_
rietveld_ pattern - Calculate a complete built-in monochromatic structural pattern.
- calculate_
tof_ lebail_ pattern - Calculate one TOF pattern and all direct profile derivatives in one pass.
- cw_
lattice_ geometry - Calculate d-spacings, CW positions, and analytical independent-variable chains.
- estimate_
effective_ profile - Estimate an effective CW starting profile from one dominant phase.
- estimate_
initial_ phase_ scales - Estimate and install deterministic weighted non-negative phase scales.
- evaluate_
residuals - Evaluate masked residual arrays and standard powder residual metrics.
- evaluate_
tof_ residuals - Evaluate residuals on an explicitly microsecond-domain TOF pattern.
- extract_
lebail_ intensities - Perform one non-negative multiplicative redistribution step.
- initialize_
lebail_ intensities - Return deterministic positive starting intensities in phase order.
- intelligent_
rietveld_ recipe - Propose transparent cumulative stages from caller-authorized families.
- iterate_
lebail_ once - Advance exactly one accepted Le Bail iteration for custom orchestration.
- lebail_
background_ parameter_ key - Return the stable key for one refinable residual-background coefficient.
- lebail_
instrument_ parameter_ key - Return the stable key for one supported CW profile coefficient.
- lebail_
lattice_ parameter_ key - Return the stable key for one symmetry-independent lattice variable.
- lebail_
phase_ scale_ key - Return the stable key for a phase scale.
- lebail_
reflection_ position_ key - Return the stable key for one independent reflection position.
- quantitative_
phase_ analysis - Calculate Hill–Howard crystalline weight fractions in input order.
- quantitative_
phase_ analysis_ with_ covariance - Calculate weight fractions and analytically propagate a phase-scale covariance.
- refine_
general_ rietveld - Refine the complete native layout with a process-local runtime.
- refine_
general_ rietveld_ with_ runtime - Refine the complete native layout through a caller-owned runtime.
- refine_
joint_ rietveld - Refine a joint objective through a process-local runtime.
- refine_
joint_ rietveld_ with_ runtime - Refine a joint objective through a caller-owned runtime.
- refine_
lebail - Run fixed-reflection Le Bail extraction with a workflow-owned runtime.
- refine_
lebail_ with_ runtime - Run fixed-reflection extraction with host-owned cancellation/events/checkpoints.
- refine_
rietveld - Refine with a process-local runtime and optional cancellation token.
- refine_
rietveld_ with_ runtime - Refine through a caller-owned runtime for events and durable checkpoints.
- refine_
structural_ tof_ multibank - Refine a guarded structural TOF objective through a process-local runtime.
- refine_
structural_ tof_ multibank_ with_ runtime - Refine with caller-owned cancellation, event, and checkpoint sinks.
- refine_
tof_ lebail - Run deterministic nonnegative TOF Le Bail redistribution.
- refine_
tof_ lebail_ with_ runtime - Run TOF Le Bail extraction with host-owned cancellation, events, and checkpoints.
- refine_
tof_ multibank - Run atomic fixed-cell TOF Le Bail extraction over two or more banks.
- refine_
tof_ multibank_ geometry - Refine shared cells and selected bank-local instruments in one system.
- refine_
tof_ multibank_ geometry_ with_ runtime - Refine joint geometry with host cancellation/events and continuation.
- refine_
tof_ multibank_ instrument - Refine selected bank-local instrument coefficients against all TOF banks.
- refine_
tof_ multibank_ instrument_ with_ runtime - Refine selected bank-local instruments with cancellation and continuation.
- refine_
tof_ multibank_ lattice - Refine shared phase cells against the summed objective over all TOF banks.
- refine_
tof_ multibank_ lattice_ with_ runtime - Refine shared cells with host cancellation/events and optional continuation.
- refine_
tof_ multibank_ with_ runtime - Run atomic multi-bank extraction with host runtime and optional continuation.
- run_
rietveld_ recipe - Execute explicit stages while promoting only accepted physical states.
- run_
rietveld_ recipe_ with_ sinks - Execute a recipe with optional shared event and checkpoint consumers.
- starting_
profile_ from_ fwhm - Construct a valid all-Gaussian starting profile from an approximate FWHM.
- tof_
lattice_ geometry - Calculate d-spacings, TOF positions, and analytical independent-variable chains.
- validate_
rietveld_ recipe - Validate a complete staged recipe without calculating or refining a pattern.