Skip to content

Accept CRIM volumetric fractions that sum to one within rounding - #868

Merged
agianno merged 1 commit into
gprMax:masterfrom
SajalDevX:fix/debyefit-crim-fraction-sum
Oct 2, 2026
Merged

agianno merged 1 commit into
gprMax:masterfrom
SajalDevX:fix/debyefit-crim-fraction-sum

Conversation

@SajalDevX

Copy link
Copy Markdown
Contributor

Fix CRIM volumetric-fraction sum check in DebyeFit

Crim.check_inputs() compared np.sum(volumetric_fractions) to 1 with exact float equality. Because of that, valid mixtures like [0.7, 0.2, 0.1] or [0.6, 0.3, 0.1] (both sum to 0.9999999999999999) were rejected, and the fit exited with "The summation of volumetric volumes should be equal to 1". Whether a mixture passed could depend only on the order of the fractions: [0.1, 0.2, 0.7] passed but [0.7, 0.2, 0.1] failed.

Changes

  • gprMax/toolboxes/DebyeFit/Debye_Fit.py: compare the sum to 1 with np.isclose(..., rtol=0.0, atol=1e-9) instead of !=. This allows for rounding error but still rejects fractions that really don't add up to one.
  • tests/toolboxes/test_debye_fit.py: add regression tests. One checks that fractions summing to 1 within rounding are accepted. The other checks that fractions that don't sum to 1 ([0.7, 0.2, 0.2], [0.5, 0.3, 0.1]) are still rejected.

Testing

  • python -m pytest tests/toolboxes/test_debye_fit.py: before the fix, the two new "accepts" cases fail with SystemExit. After the fix, all 10 tests pass.
  • I ran a short end-to-end Crim(...).run() with [0.7, 0.2, 0.1]. It now finishes and prints the #material / #add_dispersion_debye commands.
  • I ran black and isort (repo pre-commit settings) on the changed lines. The only remaining warnings in test_debye_fit.py were already on master, and I left them alone to keep the diff small.

Fixes #867

Crim.check_inputs() compared np.sum(volumetric_fractions) to 1 with an
exact float equality, so valid mixtures such as [0.7, 0.2, 0.1] or
[0.6, 0.3, 0.1] (which sum to 0.9999999999999999 in binary floating
point) were rejected and the fit exited with "The summation of
volumetric volumes should be equal to 1".

Compare the sum against 1 with a small absolute tolerance (1e-9)
instead, which absorbs floating-point rounding while still rejecting
fractions that genuinely do not add up to one. Add regression tests
for both cases.
@agianno

agianno commented Oct 2, 2026

Copy link
Copy Markdown
Member

Thanks for finding this float comparison and fixing it. Once tests pass will merge into master.

@agianno
agianno merged commit 6271f11 into gprMax:master Oct 2, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DebyeFit CRIM rejects valid volumetric fractions such as [0.7, 0.2, 0.1]

2 participants