Summary
EasyScience's make_dependent_on is unit-aware (it evaluates the expression with scipp units and overwrites the dependent parameter's unit with the result's unit). The library fights this instead of using it:
MaterialDensity creates its scattering-length parameters from the SLD defaults dict (material_density.py:88-99 passes default_dict=DEFAULTS['sld']), so a scattering length carries the unit 1/angstrom^2.
- The dependency expression includes a magic
1e-23 (material_density.py:113) so that after scipp normalizes g/cm^3 * A^-2 * mol/g the numeric value lands right — while the parameter's unit becomes kmol/m^5, dimensionally meaningless for an SLD.
tests/sample/elements/materials/test_material_density.py:54 asserts the rendered string '2.074e-6 kmol/m^5', baking the nonsense into the contract.
Root cause, library-wide: the SLD unit string is '1 / angstrom^2' while values are stored in the 1e-6 A^-2 convention (material.py:17-35; _dict_repr hard-codes an e-6 suffix into display strings). This factor-of-1e6 gap between declared unit and stored value will keep generating bugs whenever someone trusts the unit metadata.
Suggested fix
Give scattering lengths the unit angstrom (as layer_area_per_molecule.py:30-47 already does correctly — its constraint a/(b*p)*1e6 yields both the right value and a sensible unit), express SLD in a properly scaled unit (scipp supports 1e-6/angstrom^2-style scales) or store true A^-2, delete the 1e-23 fudge, and fix the enshrining test.
Found during deep code review (DEEP_ANALYSIS.md §4.4).
Summary
EasyScience's
make_dependent_onis unit-aware (it evaluates the expression with scipp units and overwrites the dependent parameter's unit with the result's unit). The library fights this instead of using it:MaterialDensitycreates its scattering-length parameters from the SLD defaults dict (material_density.py:88-99passesdefault_dict=DEFAULTS['sld']), so a scattering length carries the unit1/angstrom^2.1e-23(material_density.py:113) so that after scipp normalizesg/cm^3 * A^-2 * mol/gthe numeric value lands right — while the parameter's unit becomeskmol/m^5, dimensionally meaningless for an SLD.tests/sample/elements/materials/test_material_density.py:54asserts the rendered string'2.074e-6 kmol/m^5', baking the nonsense into the contract.Root cause, library-wide: the SLD unit string is
'1 / angstrom^2'while values are stored in the 1e-6 A^-2 convention (material.py:17-35;_dict_reprhard-codes ane-6suffix into display strings). This factor-of-1e6 gap between declared unit and stored value will keep generating bugs whenever someone trusts the unit metadata.Suggested fix
Give scattering lengths the unit
angstrom(aslayer_area_per_molecule.py:30-47already does correctly — its constrainta/(b*p)*1e6yields both the right value and a sensible unit), express SLD in a properly scaled unit (scipp supports1e-6/angstrom^2-style scales) or store true A^-2, delete the1e-23fudge, and fix the enshrining test.Found during deep code review (DEEP_ANALYSIS.md §4.4).