-
Notifications
You must be signed in to change notification settings - Fork 224
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
Enforcing specific precision in clean_value for floats #3108
Conversation
d5ea42d
to
b2a02de
Compare
This will guarantee a larger uniformity in what gets stored across backends. This fixes aiidateam#2631 Note that this commit also fixes the problem of the bigint vs. float part of the discussion that is mentioned in the thread, i.e. that numbers like 1.2e20, floats in python, become long ints in the database. Here we forcefully convert numbers >=1.e14 to integers to alleviate the problem and ensure that a roundtrip via the database does not change the hash. IMPORTANT: in this commit, we enforce a maximum precision of 14 digits in AiiDA - this is a change with respect to what used to be before. Note also that we are *not* going to truncate old AiiDA values, so behavior before and after this commit will change even if the stored value is the same. Note that this commit changes the hashing functionality, so we will need to ask users to rehash everything.
b2a02de
to
1acc7b1
Compare
Tests added in a second commit; also removed annoying output during tests of migrations |
Also, capturing output during migrations to avoid seeing warning messages (e.g. to rerun 'verdi rehash')
1acc7b1
to
b4ba1c5
Compare
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.
great work @giovannipizzi thanks a lot
for the record: converting floats to string and back again to control decimal rounding/truncation seems to be a very efficient way to do it, see discussion here https://news.ycombinator.com/item?id=20816827 |
Thanks! |
Fixes #2631
This will guarantee a larger uniformity in what gets stored across backends.
Note that this commit also fixes the problem of the bigint vs. float
part of the discussion that is mentioned in the thread, i.e.
that numbers like 1.2e20, floats in python, become long ints
in the database. Here we forcefully convert numbers >=1.e14 to
integers to alleviate the problem and ensure that a roundtrip
via the database does not change the hash.
IMPORTANT: in this commit, we enforce a maximum precision of 14
digits in AiiDA - this is a change with respect to what used
to be before. Note also that we are not going to truncate old
AiiDA values, so behavior before and after this commit will change
even if the stored value is the same.
Note that this commit changes the hashing functionality, so we
will need to ask users to rehash everything.