Skip to content

GradientLayer end materials are frozen at construction — fitting front/back SLD is a silent no-op #373

@rozyczko

Description

@rozyczko

Summary

GradientLayer discretizes the SLD ramp once, at construction: _prepare_gradient_layers (src/easyreflectometry/sample/assemblies/gradient_layer.py:188-217) snapshots front_material.sld.value / back_material.sld.value into independent Material objects. The stored front_material/back_material are never wired into the sublayers, so mutating or fitting the end-material SLDs has no effect on the computed reflectivity.

Additional issues in the same class

  • _linear_gradient's comment says "Both front and back values are included", but only indices 0..N-1 are used, so the last sublayer sits one full step short of the back SLD (gradient_layer.py:179-185, 206). Midpoint sampling (front + (i+0.5)*step) would halve the discretization error for the same N.
  • discretisation_elements < 2 raises "must be greater than 2" (:60-61) — message contradicts the check.

Suggested fix

Constrain each sublayer SLD via the existing dependency machinery, e.g. make_dependent_on('f + i_frac * (b - f)', {...}) with f/b the end-material SLD parameters — the same pattern the assemblies already use for thickness/roughness. Alternatively, document loudly that the gradient is frozen at construction and exclude the end materials from the parameter tree.

Found during deep code review (DEEP_ANALYSIS.md §4.5).

Metadata

Metadata

Assignees

No one assigned

    Labels

    [priority] mediumNormal/default priority[scope] bugBug report or fix (major.minor.PATCH)
    No fields configured for issues without a type.

    Projects

    Status
    Bugs

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions