imas.util.calc_hash

imas.util.calc_hash(node: IDSBase) bytes

Calculate the hash of the provided IDS object.

Hashes are calculated as follows:

  1. Data nodes:

    1. STR_0D: hash of value (encoded as UTF-8)

    2. STR_1D: hash of concatenation of

      • Length of the STR_1D (64-bit little-endian integer)

      • hash of value[0] (encoded as UTF-8)

      • hash of value[1] (encoded as UTF-8)

    3. INT_0D: hash of value (32-bit little-endian signed integer)

    4. FLT_0D: hash of value (64-bit IEEE 754 floating point number)

    5. CPX_0D: hash of value (128-bit: real, imag)

    6. ND arrays: hash of concatenation of

      • Dimension (8-bit integer)

      • Shape (dimension * 64-bits little-endian integer)

      • Concatenated data (little-endian, Fortran memory layout)

  2. Array of structures nodes: hash of concatenation of

    • Length of the AoS (64-bit little-endian integer)

    • Hash of structure[0]

    • Hash of structure[1]

  3. Structure nodes:

    1. Sort all children alphabetically

    2. Remove empty children. Children are empty when:

      • INT_0D: equal to EMPTY_INT

      • FLT_0D: equal to EMPTY_FLOAT

      • CPX_0D: equal to EMPTY_COMPLEX

      • ND arrays: array is empty

      • STR_0D: equal to ""

      • STR_1D: length is 0

      • Array of structures: length is 0

      • Structure: all children are empty

    3. Remove ids_properties/version_put structure

    4. Calculate hash of concatenation of

      • Name of child[0] (encoded as UTF-8)

      • Hash of child[0]

The hash function used is xxhash.xxh3_64 from the xxhash package.

Example

cp = imas.IDSFactory().core_profiles()
cp.ids_properties.homogeneous_time = 0

print(imas.util.calc_hash(cp).hex())  # 3b9b929756a242fd

Last update: 2026-01-28