• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aiidateam / aiida_core / 6586 / 6
74%
develop: 74%

Build:
DEFAULT BRANCH: develop
Ran 02 Jul 2019 10:41AM UTC
Files 403
Run time 27s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

02 Jul 2019 10:19AM UTC coverage: 67.861% (-0.06%) from 67.923%
TEST_AIIDA_BACKEND=django TEST_TYPE="tests"

push

travis-ci

sphuber
Enforcing specific float precision in `clean_value` (#3108)

The purpose of the `clean_value` utility function is to convert data
that is to be stored in node attributes or extras in such a way that it
becomes:

  1. JSON serializable, since the database model fields use JSONB
  2. The serialization/deserialization roundtrip results in no changes

The last step is especially important for the hashing of nodes. If the
serialization roundtrip changes the values, the hash computed before the
node is stored, will be different from the hash computed from its data
after it is stored.

A particularly difficult case for the `clean_value` are floats. The JSON
serialized value in the database may have a different precision than the
original float specified in memory. To make the serialization roundtrip
mutationless, all floats are rounded to 14 significant digits. This is
just below machine precision and that of the current database backends
and will guarantee that the rounded float will not change.

However, even with this rounding there is another complication. Floats
that are sufficiently large and can be interpreted as integers, will be
automatically converted to a long int by the database. Changing the type
will change the hash and destroy the desired null operation for the
serialization roundtrip. Since we cannot control the behavior of the
type casting of the database, we perform the casting of the float to an
int ourselves in `clean_values`. First the normal float rounding is
applied. If the resulting float correspond to an integer, i.e. it only
contains zeroes after the comma, it is converted to an integer. Changing
the types of floats in this way might be unexpected to the user, but it
is the only way to guarantee the hashing works, which is a tradeoff we
are willing to make.

In this commit, we enforce a maximum precision of 14 digits for floats.
This is a change with respect to what used to be done before. Since we
... (continued)

22008 of 32431 relevant lines covered (67.86%)

0.68 hits per line

Source Files on job 6586.6 (TEST_AIIDA_BACKEND=django TEST_TYPE="tests")
  • Tree
  • List 0
  • Changed 26
  • Source Changed 4
  • Coverage Changed 26
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 2193
  • Travis Job 6586.6
  • da0a5c66 on github
  • Prev Job for TEST_AIIDA_BACKEND=django TEST_TYPE="tests" on develop (#6582.5)
  • Next Job for TEST_AIIDA_BACKEND=django TEST_TYPE="tests" on develop (#6592.5)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc