Skip to content

write sipnet.param at 17 digits - #4285

Open
divine7022 wants to merge 5 commits into
developfrom
sipnet-param-precision
Open

divine7022 wants to merge 5 commits into
developfrom
sipnet-param-precision

Conversation

@divine7022

Copy link
Copy Markdown
Member

Description

write.config.SIPNET() writes sipnet.param with write.table, which keeps 15 significant digits. Allocations that sum to exactly 1 can sum past 1 once written: 0.25758166726134457, 0.4742485584847288, 0.26816977425392663 comes out as 0.257581667261345, 0.474248558484729, 0.268169774253927, and Sipnet exits at setup.

  • Values are now written with sprintf("%.17g"), which always reads back to the same double. Note this changes param files in the last digits (0.6 comes out 0.59999999999999998), so the tests that matched param lines as strings now compare numbers.
  • <constants> lost the same digits earlier: they come from XML as strings, so c() turned every value into 15 digit text. Each string constant now goes through type.convert() on its own, so a number set from R next to them isn't rounded either.

I hit this with joint crop priors from an ensemble.samples, where the coarse root share is 0 or within an eps of it. On Sipnet effadf3, 108 of those rows exit at setup on develop and run with this PR. Rewriting 20 members of an existing ensemble with both writers gave byte identical sipnet.out in all 20 (and events.out in 19; the other prints -0.00 for 0.00 once).

This moves the constants extraction, so whichever lands second carries the type.convert() line.

Not addressed here: harvest fractions from write.events.SIPNET() have the same 15 digit problem, and the writer's own sum_alloc > 1 warning has no slack, so it can still warn on rows that now run.

Motivation and Context

Review Time Estimate

  • Immediately
  • Within one week
  • When possible

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • My name is in the list of CITATION.cff
  • I agree that PEcAn Project may distribute my contribution under any or all of
    • the same license as the existing code,
    • and/or the BSD 3-clause license.
  • I have updated the CHANGELOG.md.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@dlebauer

dlebauer commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

My preference would be to round values to four significant figures when writing to SIPNET input files (three would probably be sufficient). For allocation, adjust largest allocation param to enforce sum to 1 after rounding.

Advantages:

  • reduce file size and I/O
  • don't write values that do not have meaning / are effectively noise
  • make values easier for humans to interpret.

Are there disadvantages to this approach?

@infotroph

Copy link
Copy Markdown
Member

Seconding David here -- I don't think any Sipnet parameter is actually sensitive enough to need that many sigfigs. But (1) emphasis on "significant"; need to allow for params on scales far from unity (e.g. baseVegResp 0.006 and plantWoodInit 34021), and (2) I'm not confident I know how many digits are needed to make all users agree we're discarding noise rather than changing their carefully set values.

Where allocations sum to >1 I support adjusting them down, but I remember suggesting something like that before and having @mdietze list a bunch of cautions that showed that was trickier than it initially sounded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants