Skip to content
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

Merged
merged 3 commits into from
Jul 2, 2019

Conversation

giovannipizzi
Copy link
Member

@giovannipizzi giovannipizzi commented Jul 1, 2019

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.

@coveralls
Copy link

coveralls commented Jul 1, 2019

Coverage Status

Coverage decreased (-0.02%) to 74.157% when pulling 98cbe8d on giovannipizzi:fix_2631_float_hash into e58716a on aiidateam:develop.

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.
@giovannipizzi
Copy link
Member Author

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')
Copy link
Contributor

@sphuber sphuber left a 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

@sphuber sphuber merged commit da0a5c6 into aiidateam:develop Jul 2, 2019
@sphuber sphuber mentioned this pull request Jul 5, 2019
@giovannipizzi giovannipizzi deleted the fix_2631_float_hash branch July 26, 2019 17:49
@dev-zero
Copy link
Contributor

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

@giovannipizzi
Copy link
Member Author

Thanks!

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.

Storing a node changes its hash, due to float rounding
4 participants