Skip to content

Commit

Permalink
Implement the get_options method for JobCalculation
Browse files Browse the repository at this point in the history
What is currently defined as the `options` for a `JobCalculation`, are specific
attributes that were also stored as node attributes through `set_` methods. These
were called setters and are all defined explicitly, along with the corresponding
getters. With the introduction of the `Process` paradigm, these could no longer be
called manually by the user on the calculation node, and so the `options` dictionary
was invented, to allow the user to specify these attributes.

However, after a calculation was completed, there was no easy way to retrieve this
dictionary with the collection of these attributes. Here we implement this method
the `get_options` method which by default will only return those attributes that
were explicitly set, but which can be overridden to provide the default values for
those that were not explicitly set.

The set of available options, along with their valid types, whether they are required
docstring and more, are now defined as a dictionary member of the `AbstractJobCalculation`
class. The `JobProcess` now uses this to dynamically build up the `options` port namespace
in its inputs specification, just like the rest of the input ports are build dynamically
based on the use methods.
  • Loading branch information
sphuber committed Sep 18, 2018
1 parent 110b4eb commit 28d6d38
Show file tree
Hide file tree
Showing 17 changed files with 388 additions and 173 deletions.
8 changes: 4 additions & 4 deletions .ci/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ def create_calculation(code, counter, inputval, use_cache=False):
'retrieve_temporary_files': ['triple_value.tmp']
})
calc = code.new_calc()
calc.set_max_wallclock_seconds(5 * 60) # 5 min
calc.set_resources({"num_machines": 1})
calc.set_withmpi(False)
calc.set_parser_name('simpleplugins.templatereplacer.doubler')
calc.set_option('max_wallclock_seconds', 5 * 60) # 5 min
calc.set_option('resources', {"num_machines": 1})
calc.set_option('withmpi', False)
calc.set_option('parser_name', 'simpleplugins.templatereplacer.doubler')

calc.use_parameters(parameters)
calc.use_template(template)
Expand Down
38 changes: 19 additions & 19 deletions aiida/backends/tests/export_and_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_1(self):

calc = JobCalculation()
calc.set_computer(self.computer)
calc.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
calc.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
calc.store()

calc.add_link_from(sd)
Expand Down Expand Up @@ -474,7 +474,7 @@ def test_5(self):

jc1 = JobCalculation()
jc1.set_computer(self.computer)
jc1.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc1.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc1.set_user(user)
jc1.label = 'jc1'
jc1.store()
Expand All @@ -490,7 +490,7 @@ def test_5(self):

jc2 = JobCalculation()
jc2.set_computer(self.computer)
jc2.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc2.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc2.label = 'jc2'
jc2.store()
jc2.add_link_from(sd2, label='l2')
Expand Down Expand Up @@ -557,7 +557,7 @@ def test_6(self):

jc1 = JobCalculation()
jc1.set_computer(self.computer)
jc1.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc1.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc1.set_user(user)
jc1.label = 'jc1'
jc1.store()
Expand Down Expand Up @@ -593,7 +593,7 @@ def test_6(self):

jc2 = JobCalculation()
jc2.set_computer(self.computer)
jc2.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc2.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc2.label = 'jc2'
jc2.store()
jc2.add_link_from(sd2_imp, label='l2')
Expand Down Expand Up @@ -661,7 +661,7 @@ def test_7(self):

jc1 = JobCalculation()
jc1.set_computer(self.computer)
jc1.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc1.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc1.set_user(user)
jc1.label = 'jc1'
jc1.store()
Expand Down Expand Up @@ -930,7 +930,7 @@ def test_complex_graph_import_export(self):
try:
calc1 = JobCalculation()
calc1.set_computer(self.computer)
calc1.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
calc1.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
calc1.label = "calc1"
calc1.store()
calc1._set_state(u'RETRIEVING')
Expand All @@ -952,7 +952,7 @@ def test_complex_graph_import_export(self):

calc2 = JobCalculation()
calc2.set_computer(self.computer)
calc2.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
calc2.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
calc2.label = "calc2"
calc2.store()
calc2.add_link_from(pd1, link_type=LinkType.INPUT)
Expand Down Expand Up @@ -1024,7 +1024,7 @@ def test_same_computer_import(self):
calc1_label = "calc1"
calc1 = JobCalculation()
calc1.set_computer(self.computer)
calc1.set_resources({"num_machines": 1,
calc1.set_option('resources', {"num_machines": 1,
"num_mpiprocs_per_machine": 1})
calc1.label = calc1_label
calc1.store()
Expand All @@ -1033,7 +1033,7 @@ def test_same_computer_import(self):
calc2_label = "calc2"
calc2 = JobCalculation()
calc2.set_computer(self.computer)
calc2.set_resources({"num_machines": 2,
calc2.set_option('resources', {"num_machines": 2,
"num_mpiprocs_per_machine": 2})
calc2.label = calc2_label
calc2.store()
Expand Down Expand Up @@ -1148,7 +1148,7 @@ def test_same_computer_different_name_import(self):
calc1_label = "calc1"
calc1 = JobCalculation()
calc1.set_computer(self.computer)
calc1.set_resources({"num_machines": 1,
calc1.set_option('resources', {"num_machines": 1,
"num_mpiprocs_per_machine": 1})
calc1.label = calc1_label
calc1.store()
Expand All @@ -1168,7 +1168,7 @@ def test_same_computer_different_name_import(self):
calc2_label = "calc2"
calc2 = JobCalculation()
calc2.set_computer(self.computer)
calc2.set_resources({"num_machines": 2,
calc2.set_option('resources', {"num_machines": 2,
"num_mpiprocs_per_machine": 2})
calc2.label = calc2_label
calc2.store()
Expand Down Expand Up @@ -1258,7 +1258,7 @@ def test_different_computer_same_name_import(self):
calc1_label = "calc1"
calc1 = JobCalculation()
calc1.set_computer(self.computer)
calc1.set_resources({"num_machines": 1,
calc1.set_option('resources', {"num_machines": 1,
"num_mpiprocs_per_machine": 1})
calc1.label = calc1_label
calc1.store()
Expand All @@ -1279,7 +1279,7 @@ def test_different_computer_same_name_import(self):
calc2_label = "calc2"
calc2 = JobCalculation()
calc2.set_computer(self.computer)
calc2.set_resources({"num_machines": 2,
calc2.set_option('resources', {"num_machines": 2,
"num_mpiprocs_per_machine": 2})
calc2.label = calc2_label
calc2.store()
Expand All @@ -1300,7 +1300,7 @@ def test_different_computer_same_name_import(self):
calc3_label = "calc3"
calc3 = JobCalculation()
calc3.set_computer(self.computer)
calc3.set_resources({"num_machines": 2,
calc3.set_option('resources', {"num_machines": 2,
"num_mpiprocs_per_machine": 2})
calc3.label = calc3_label
calc3.store()
Expand Down Expand Up @@ -1387,7 +1387,7 @@ def test_correct_import_of_computer_json_params(self):
calc1_label = "calc1"
calc1 = JobCalculation()
calc1.set_computer(self.computer)
calc1.set_resources({"num_machines": 1,
calc1.set_option('resources', {"num_machines": 1,
"num_mpiprocs_per_machine": 1})
calc1.label = calc1_label
calc1.store()
Expand Down Expand Up @@ -1540,15 +1540,15 @@ def construct_complex_graph(self, export_combination = 0):

pw1 = JobCalculation()
pw1.set_computer(self.computer)
pw1.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
pw1.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
pw1.store()

d3 = Int(1).store()
d4 = Int(1).store()

pw2 = JobCalculation()
pw2.set_computer(self.computer)
pw2.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
pw2.set_option('resources', {"num_machines": 1, "num_mpiprocs_per_machine": 1})
pw2.store()

d5 = Int(1).store()
Expand Down Expand Up @@ -1944,7 +1944,7 @@ def test_that_input_code_is_exported_correctly(self):

jc = JobCalculation()
jc.set_computer(self.computer)
jc.set_resources(
jc.set_option('resources',
{"num_machines": 1, "num_mpiprocs_per_machine": 1})
jc.store()

Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def output_test(pk, testname, skip_uuids_from_inputs=[]):
from aiida.orm.importexport import export_tree
c = load_node(pk, sub_class=JobCalculation)
outfolder = "test_{}_{}".format(
c.get_parser_name().replace('.', '_'),
c.get_option('parser_name').replace('.', '_'),
testname)

if not is_valid_folder_name(outfolder):
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/tests/tcodexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ def test_cif_structure_roundtrip(self):
code.store()

calc = JobCalculation(computer=self.computer)
calc.set_resources({'num_machines': 1,
calc.set_option('resources', {'num_machines': 1,
'num_mpiprocs_per_machine': 1})
calc.add_link_from(code, "code")
calc.set_environment_variables({'PATH': '/dev/null', 'USER': 'unknown'})
calc.set_option('environment_variables', {'PATH': '/dev/null', 'USER': 'unknown'})

with tempfile.NamedTemporaryFile(mode='w+', prefix="Fe") as f:
f.write("<UPF version=\"2.0.1\">\nelement=\"Fe\"\n")
Expand Down
Loading

0 comments on commit 28d6d38

Please sign in to comment.