Skip to content

Commit

Permalink
CalcJobNode: Fix the computation of the hash (#5998)
Browse files Browse the repository at this point in the history
The `CalcJobNode.get_hash()` was returning a different hash once the
calculation had been completed, compared to the one stored in the
`_aiida_hash` extra, which was computed when the node initially got
stored.

The reason is that upon storing, the repository of the `CalcJobNode` is
empty, however, once the upload step has been completed, the input files
generated by the `CalcJob` plugin will have been written to the
repository, and so now its hash, and with it the hash of the entire node
will be different.

The solution is to exclude the repository hash from the objects that
are used to compute the node's hash. This is acceptable, since the
repository files are just a derivative of the input nodes, which are
already captured in the hash. This solution was actually already in
place and implemented by the `CalcJobNodeCaching`, however, it was never
actually used. Since there was no test, this went by unnoticed since
v2.0 at which point this code was introduced.

The solution is simply just to set `CalcJobNode._CLS_NODE_CACHING` to
the `CalcJobNodeCaching` subclass. A regression test is added to check
that the `get_hash` method matches the `_aiida_hash` extra.
  • Loading branch information
sphuber authored May 9, 2023
1 parent 3df0255 commit 685e0f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions aiida/orm/nodes/process/calculation/calcjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CalcJobNode(CalculationNode):
"""ORM class for all nodes representing the execution of a CalcJob."""

# pylint: disable=too-many-public-methods
_CLS_NODE_CACHING = CalcJobNodeCaching

CALC_JOB_STATE_KEY = 'state'
IMMIGRATED_KEY = 'imported'
Expand Down
6 changes: 6 additions & 0 deletions tests/engine/processes/calcjobs/test_calc_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@ def instantiate_process(self, state=CalcJobState.PARSING):

return process

def test_get_hash(self, get_calcjob_builder):
"""Test that :meth:`aiida.orm.CalcJobNode.get_hash` returns the same hash as what is stored in the extras."""
builder = get_calcjob_builder()
_, node = launch.run_get_node(builder)
assert node.base.extras.get(node.base.caching._HASH_EXTRA_KEY) == node.get_hash() # pylint: disable=protected-access

def test_process_status(self):
"""Test that the process status is properly reset if calculation ends successfully."""
_, node = launch.run_get_node(ArithmeticAddCalculation, code=self.remote_code, **self.inputs)
Expand Down

0 comments on commit 685e0f8

Please sign in to comment.