Skip to content

Conversation

@egpbos
Copy link
Contributor

@egpbos egpbos commented Dec 20, 2022

This Pull request:

Changes or fixes:

The behavior of -= and += on a KahanSum were not symmetric, leading to slight bit-wise inaccuracies. In fits, where such operations are done a lot of times (e.g. through the offsetting mechanism in RooFit which subtracts a constant KahanSum term after each likelihood evaluation), this can add up to significant numerical divergence. This in turn makes it hard to test the accuracy of new numerical implementations. In particular, we are trying to fix a bug in MultiProcess::LikelihoodJob, which builds on this KahanSum fix.

This commit adds test cases around the precision limits, making sure that all behavior is now symmetric and internally consistent.

To aid in the test cases and also make the KahanSum objects more versatile, the commit also adds some extra - and + operators. Using these, we verify some additional desirable symmetry properties: that x - x = 0, and y + (-x) = y - x.

The improved implementation is based on an algorithm for combining Kahan sums and carry terms used in literature (citation in comments).

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

The behavior of -= and += on a KahanSum were not symmetric, leading to slight bit-wise inaccuracies. In fits, where such operations are done a lot of times (e.g. through the offsetting mechanism in RooFit which subtracts a constant KahanSum term after each likelihood evaluation), this can add up to significant numerical divergence. This in turn makes it hard to test the accuracy of new numerical implementations.

This commit adds test cases around the precision limits, making sure that all behavior is now symmetric and internally consistent.

To aid in the test cases and also make the KahanSum objects more versatile, the commit also adds some extra - and + operators. Using these, we verify some additional desirable symmetry properties: that x - x = 0, and y + (-x) = y - x.

The improved implementation is based on an algorithm for combining Kahan sums and carry terms used in literature (citation in comments).
@egpbos egpbos requested a review from lmoneta as a code owner December 20, 2022 13:56
@phsft-bot
Copy link

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac12/noimt, mac11/cxx14, windows10/cxx14
How to customize builds

Copy link
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement. Looks good, just a comment on the += and -= operators

The KahanSum operators +, -, +=, -= and unary - can all be used for any number of accumulators, even mixing two KahanSums with different numbers of accumulators. This works fine, because on the left hand side only the first accumulator is modified,so the exact number doesn't matter, and on the right hand side only Sum and Carry are ever called, and those internally already accumulate over whatever number of accumlators it has, so there it also doesn't matter. This commit extends the template parameters to include all these possibilities that were restricted before to only certain combinations (mostly with N=1).
@phsft-bot
Copy link

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac12/noimt, mac11/cxx14, windows10/cxx14
How to customize builds

Copy link
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Patrick for updating!
I think it looks fine now

@phsft-bot
Copy link

Build failed on windows10/cxx14.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Failing tests:

@guitargeek guitargeek merged commit a9bb7a1 into root-project:master Dec 21, 2022
@phsft-bot
Copy link

Build failed on ROOT-performance-centos8-multicore/cxx17.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2022-12-21T15:02:06.147Z] /data/sftnight/workspace/root-pullrequests-build/build/include/RooAbsData.h:229:7: warning: unknown attribute 'REMOVE_THIS_NOW' ignored [-Wunknown-attributes]
  • [2022-12-21T15:02:07.631Z] /data/sftnight/workspace/root-pullrequests-build/build/include/RooFitLegacy/RooMinuit.h:151:3: warning: unknown attribute 'REMOVE_THIS_NOW' ignored [-Wunknown-attributes]
  • [2022-12-21T15:02:15.286Z] /data/sftnight/workspace/root-pullrequests-build/build/include/ROOT/RConfig.hxx:495:73: warning: ‘REMOVE_THIS_NOW’ attribute directive ignored [-Wattributes]
  • [2022-12-21T15:02:17.451Z] /data/sftnight/workspace/root-pullrequests-build/build/include/ROOT/RConfig.hxx:495:73: warning: ‘REMOVE_THIS_NOW’ attribute directive ignored [-Wattributes]
  • [2022-12-21T15:02:39.749Z] /data/sftnight/workspace/root-pullrequests-build/build/include/ROOT/RDataSource.hxx:213:11: warning: unknown attribute 'REMOVE_THIS_NOW' ignored [-Wunknown-attributes]
  • [2022-12-21T15:02:41.025Z] /data/sftnight/workspace/root-pullrequests-build/build/include/ROOT/RCsvDS.hxx:112:1: warning: unknown attribute 'REMOVE_THIS_NOW' ignored [-Wunknown-attributes]
  • [2022-12-21T15:02:41.280Z] /data/sftnight/workspace/root-pullrequests-build/build/include/ROOT/RSqliteDS.hxx:117:1: warning: unknown attribute 'REMOVE_THIS_NOW' ignored [-Wunknown-attributes]
  • [2022-12-21T15:02:41.280Z] /data/sftnight/workspace/root-pullrequests-build/build/include/ROOT/RNTupleDS.hxx:96:1: warning: unknown attribute 'REMOVE_THIS_NOW' ignored [-Wunknown-attributes]
  • [2022-12-21T15:02:41.280Z] /data/sftnight/workspace/root-pullrequests-build/build/include/ROOT/RNTupleDS.hxx:98:1: warning: unknown attribute 'REMOVE_THIS_NOW' ignored [-Wunknown-attributes]
  • [2022-12-21T15:02:47.623Z] /data/sftnight/workspace/root-pullrequests-build/root/core/foundation/inc/ROOT/RConfig.hxx:495:73: warning: ‘REMOVE_THIS_NOW’ attribute directive ignored [-Wattributes]

And 366 more

Failing tests:

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.

4 participants