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

Implement the concept of 'finish status' for Calculations #1189

Merged
merged 6 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions aiida/backends/tests/calculation_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def test_calculation_updatable_not_copied(self):
Check that updatable attributes of Calculation are not copied
"""
a = Calculation()
a._set_attr('state', self.stateval)
a._set_attr(Calculation.PROCESS_STATE_KEY, self.stateval)
a.store()
b = a.copy()

# updatable attributes are not copied
with self.assertRaises(AttributeError):
b.get_attr('state')
b.get_attr(Calculation.PROCESS_STATE_KEY)

def test_calculation_updatable_attribute(self):
"""
Expand All @@ -81,16 +81,17 @@ def test_calculation_updatable_attribute(self):
a._set_attr(k, v)

# Check before storing
self.assertEquals(a.get_attr('state'), self.stateval)
a._set_attr(Calculation.PROCESS_STATE_KEY, self.stateval)
self.assertEquals(a.get_attr(Calculation.PROCESS_STATE_KEY), self.stateval)

a.store()

# Check after storing
self.assertEquals(a.get_attr('state'), self.stateval)
self.assertEquals(a.get_attr(Calculation.PROCESS_STATE_KEY), self.stateval)

# I should be able to mutate the updatable attribute but not the others
a._set_attr('state', 'FINISHED')
a._del_attr('state')
a._set_attr(Calculation.PROCESS_STATE_KEY, 'FINISHED')
a._del_attr(Calculation.PROCESS_STATE_KEY)

with self.assertRaises(ModificationNotAllowed):
a._set_attr('bool', False)
Expand All @@ -102,7 +103,7 @@ def test_calculation_updatable_attribute(self):

# After sealing, even updatable attributes should be immutable
with self.assertRaises(ModificationNotAllowed):
a._set_attr('state', 'FINISHED')
a._set_attr(Calculation.PROCESS_STATE_KEY, 'FINISHED')

with self.assertRaises(ModificationNotAllowed):
a._del_attr('state')
a._del_attr(Calculation.PROCESS_STATE_KEY)
11 changes: 11 additions & 0 deletions aiida/backends/tests/inline_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ def test_inline_calculation_process_state(self):
self.assertEquals(calculation.is_finished_ok, True)
self.assertEquals(calculation.is_failed, False)

def test_finish_status(self):
"""
If an InlineCalculation reaches the FINISHED process state, it has to have been successful
which means that the finish status always has to be 0
"""
calculation, result = self.incr_inline(inp=Int(11))
self.assertEquals(calculation.is_finished, True)
self.assertEquals(calculation.is_finished_ok, True)
self.assertEquals(calculation.is_failed, False)
self.assertEquals(calculation.finish_status, 0)

def test_incr(self):
"""
Simple test for the inline increment function.
Expand Down
48 changes: 24 additions & 24 deletions aiida/backends/tests/work/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import tempfile

from aiida.backends.testbase import AiidaTestCase
from aiida.work.persistence import Persistence
from aiida.work.persistence import Persistence, AiiDAPersister
import aiida.work.utils as util
from aiida.work.test_utils import DummyProcess
from aiida import work
Expand All @@ -38,26 +38,26 @@ def test_save_load(self):

self.assertEqual(loaded_process.state, work.ProcessState.FINISHED)

# class TestProcess(AiidaTestCase):
# def setUp(self):
# super(TestProcess, self).setUp()
# self.assertEquals(len(util.ProcessStack.stack()), 0)
#
# self.persistence = Persistence(running_directory=tempfile.mkdtemp())
#
# def tearDown(self):
# super(TestProcess, self).tearDown()
# self.assertEquals(len(util.ProcessStack.stack()), 0)
#
# def test_save_load(self):
# dp = DummyProcess()
#
# # Create a bundle
# b = self.persistence.create_bundle(dp)
# # Save a bundle and reload it
# self.persistence.save(dp)
# b2 = self.persistence._load_checkpoint(dp.pid)
# # Now check that they are equal
# self.assertEqual(b, b2)
#
# work.run(dp)

class TestAiiDAPersister(AiidaTestCase):

def setUp(self):
super(TestAiiDAPersister, self).setUp()
self.persister = AiiDAPersister()

def test_save_load_checkpoint(self):
process = DummyProcess()
bundle_saved = self.persister.save_checkpoint(process)
bundle_loaded = self.persister.load_checkpoint(process.calc.pk)

self.assertEquals(bundle_saved, bundle_loaded)

def test_delete_checkpoint(self):
process = DummyProcess()
self.assertEquals(process.calc.checkpoint, None)

self.persister.save_checkpoint(process)
self.assertTrue(isinstance(process.calc.checkpoint, basestring))

self.persister.delete_checkpoint(process.pid)
self.assertEquals(process.calc.checkpoint, None)
12 changes: 11 additions & 1 deletion aiida/backends/tests/work/test_workfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def add_mul_wf(a, b, c):

result = add_mul_wf(Int(3), Int(4), Int(5))

def test_finish_status(self):
"""
If a workfunction reaches the FINISHED process state, it has to have been successful
which means that the finish status always has to be 0
"""
result, calculation = single_return_value.run_get_node()
self.assertEquals(calculation.finish_status, 0)
self.assertEquals(calculation.is_finished_ok, True)
self.assertEquals(calculation.is_failed, False)

def test_hashes(self):
result, w1 = run_get_node(return_input, inp=Int(2))
result, w2 = run_get_node(return_input, inp=Int(2))
Expand All @@ -85,4 +95,4 @@ def test_hashes_different(self):

def _check_hash_consistent(self, pid):
wc = load_node(pid)
self.assertEqual(wc.get_hash(), wc.get_extra('_aiida_hash'))
self.assertEqual(wc.get_hash(), wc.get_extra('_aiida_hash'))
Loading