-
-
Notifications
You must be signed in to change notification settings - Fork 84
Eliminate the Variable class
#262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Variable class
tests/test_uncertainties.py
Outdated
| "3.4(nan)e10": (3.4e10, float("nan")), | ||
| # NaN value: | ||
| "nan+/-3.14e2": (float("nan"), 314), | ||
| # "Double-floats" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These floats are too large to work with. Prior to this PR the large float value could be saved into the AffineScalarFunc object and displayed, but any arithmetic with such large values would result in an OverflowError. In the new framework even displaying a UFloat the first time requires a calculation, even if it's as simple as sqrt(x**2). So in the new framework the OverflowError appears immediately.
|
All the tests are passing except some having to do with the uarray inverse and pseudo inverse functions. The code for this is pretty complicated. It might make sense to just rewrite the code to convert array-compatible functions to ufloat array compatible functions. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #262 +/- ##
==========================================
- Coverage 86.75% 85.42% -1.33%
==========================================
Files 18 19 +1
Lines 1706 1832 +126
==========================================
+ Hits 1480 1565 +85
- Misses 226 267 +41
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Wow all tests are passing now. That's a big milestone for this PR. If folks are interested I'd be curious to hear general feedback on the source code changes in this PR. I tried to do as little wholesale rewriting as possible but did chose to do some of that in Here's a summary of the changes so far. See #251 for a more thorough discussion of these changes and their motivations.
Some todo items
Other notes:
|
|
@newville sorry, this PR originally targeted I think merging this PR into (1) to address the performance regression. Before I would say it had a major performance regression. Now the regression is only ~20%. At least on the one performance benchmark we have. See #327. |
|
|
||
| def __init__(self: UAtom, tag: Optional[str] = None): | ||
| self.tag = tag | ||
| self.uuid: int = random.getrandbits(64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to note how Python ints work in practice. They are variable in size. There is a 28 byte overhead for all ints. Beyond that, every 30 bits in size adds 4 more bytes. So getting 64 bits will give 36 byte objects (except when you randomly get a number smaller than 2**59). Maybe it would be better to do getrandbits(60) here so the overhead per UAtom is 32 bytes instead of 36 if 60 bits seems like enough randomness. I wondered if randbytes() would be more efficient but bytes has an overhead of 34 bytes instead of the 28 for int. bytes scales linearly in the number of bytes stored but remains less efficient than int at these small sizes (8 bytes / 64 bits would be 42 bytes total). A float would take only 24 bytes but I worry about populating those bytes in an unbiased way.
pre-commit run --all-fileswith no errorsThis PR:
Variableclass and eliminates theAffineScalarFunc.derivativesproperty.AffineScalarFuncclass is renamed toUFloatwithAffineScalarFuncleft as a legacy name.LinearComboclass is refactored into theUComboclass but the architectural role is similar: track the uncertainties ofUFloatobjects as a lazily expanded combination of objects with uncertaintyUAtomobject is introduced as the fundamental element which captures uncertainty. EachUAtommodels a random variable with zero mean and unity standard deviation/variance. EachUAtomhas auuidand allUAtomare mutually statistically independent. The expanded version of theUCombomapsdict[UAtom, float].For more detail/discussion see #251 (comment)
Note that as of the time opening this PR the PR is still a work in progress. Not all elements in the bullet list above are implemented and a good handful of tests are still failing.