You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that we are exiting on ensureNonNegative failures, we no longer need the "clamping" checks in balance.h|c. We should remove those, and update calls to the balance checker in sipnet.c:updatePoolsAndBalance()
Remove all clamping functionality from src/sipnet/balance.h|c:
trim the BalanceTracker struct
remove references to the removed fields
rework the various updateBalanceTracker* functions
Rework sipnet.c:updatePoolsAndBalance() to no longer need to clamp check step (note that updateBalanceTrackerPostUpdate should be moved to replace updateBalanceTrackerPostClamp)
Update the balance test (tests/sipnet/test_modeling/testBalance.c) if needed
Hi @Alomir, I'd like to work on this if it's available. Here's my plan:
balance.h / balance.c
Remove clampedC, clampedN, finalC and finalN from BalanceTracker, along with their initialization in initBalanceTracker().
Remove updateBalanceTrackerPostClamp(), and move the system input/output calculation into updateBalanceTrackerPostUpdate(), without adding clamped mass to inputs.
In checkBalance(), compute the pool delta as postTotal - preTotal, and drop clamped from the log messages.
sipnet.c:updatePoolsAndBalance()
New order: updateBalanceTrackerPreUpdate(), then the pool updates, then checkForMortality(), then ensureNonNegativeStocks(), then updateBalanceTrackerPostUpdate(), then checkBalance(). So PostUpdate takes the place of the old PostClamp call.
Tests
Remove the clampedC and clampedN assertions in testCompleteHarvest.c.
Check the direct PreUpdate/PostUpdate usage in testCompleteHarvest.c and testEventHarvest.c.
Small values reset to zero: ensureNonNegative() still zeroes values in [-EPS, 0). Since the post-update totals would now be taken after that step, those tiny adjustments will appear in the balance delta. I expect them to stay under tolerance, but I'll confirm with the smoke tests. Let me know if you'd rather handle that differently.
Error message bug: the logError call in ensureNonNegative() has a format mismatch. It passes label, *var, year, ... to "%s year %d ...", so the value isn't printed correctly. I can fix that here or in a separate PR, whichever you prefer.
This is a good question; any one instance of a tiny adjustment would be fine, but it is would be possible for several to add up to more than -EPS. My first thought would be to take into account the summation nature of that final total, and use, say, -10*EPS as the final tolerance. Still plenty small to be believable as noise, but big enough to allow for accumulation. Let me know if you have another idea.
Opened #425 for this. It's built on top of #414, so that commit shows there until #414 is merged.
I went with 10 * EPS as the balance tolerance as you suggested. I applied it in both directions, since the zeroing in ensureNonNegative only ever adds mass, so the sign shouldn't matter. Happy to change it if you meant something else.
Activity
priyanshusky0 commentedon Oct 24, 2026
Hi @Alomir, I'd like to work on this if it's available. Here's my plan:
balance.h / balance.c
sipnet.c:updatePoolsAndBalance()
Tests
Questions:
Alomir commentedon Oct 27, 2026
Yes definitely, you're the right person for this. As for your questions:
-EPS. My first thought would be to take into account the summation nature of that final total, and use, say,-10*EPSas the final tolerance. Still plenty small to be believable as noise, but big enough to allow for accumulation. Let me know if you have another idea.priyanshusky0 commentedon Oct 28, 2026
@Alomir
Opened #425 for this. It's built on top of #414, so that commit shows there until #414 is merged.
I went with
10 * EPSas the balance tolerance as you suggested. I applied it in both directions, since the zeroing inensureNonNegativeonly ever adds mass, so the sign shouldn't matter. Happy to change it if you meant something else.All unit and smoke tests pass.
Remove clamping from balance checks (PecanProject#416)