-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation: advanced concepts of workchain design
Wrote extensive documentation on all the features of the WorkChain and how to write robust, maintainable and modular workchains. Described all the features of the ProcessSpec with the newly added Ports and PortNamespaces, the context and how to add futures, the reporting system and how to abort workchains and set their finish status.
- Loading branch information
Showing
11 changed files
with
508 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
docs/source/concepts/include/snippets/workflows/expose_inputs/run_complex.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
docs/source/concepts/include/snippets/workflows/expose_inputs/run_simple.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
#!/usr/bin/env runaiida | ||
|
||
from __future__ import print_function | ||
|
||
from aiida.orm.data.bool import Bool | ||
from aiida.orm.data.float import Float | ||
from aiida.orm.data.int import Int | ||
from aiida.work import run | ||
|
||
from simple_parent import SimpleParentWorkChain | ||
|
||
if __name__ == '__main__': | ||
print(run( | ||
SimpleParentWorkChain, | ||
a=Int(1), b=Float(1.2), c=Bool(True) | ||
)) | ||
# Result: {u'e': 1.2, u'd': 1, u'f': True} | ||
result = run(SimpleParentWorkChain, a=Int(1), b=Float(1.2), c=Bool(True)) | ||
print(result) | ||
# {u'e': 1.2, u'd': 1, u'f': True} |
16 changes: 5 additions & 11 deletions
16
docs/source/concepts/include/snippets/workflows/expose_inputs/simple_parent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
from aiida.work import ToContext, WorkChain, run | ||
|
||
from child import ChildWorkChain | ||
|
||
|
||
class SimpleParentWorkChain(WorkChain): | ||
|
||
@classmethod | ||
def define(cls, spec): | ||
super(SimpleParentWorkChain, cls).define(spec) | ||
|
||
spec.expose_inputs(ChildWorkChain) | ||
spec.expose_outputs(ChildWorkChain) | ||
|
||
spec.outline(cls.run_child, cls.finalize) | ||
|
||
def run_child(self): | ||
return ToContext(child=self.submit( | ||
ChildWorkChain, | ||
**self.exposed_inputs(ChildWorkChain) | ||
)) | ||
child = self.submit(ChildWorkChain, **self.exposed_inputs(ChildWorkChain)) | ||
return ToContext(child=child) | ||
|
||
def finalize(self): | ||
self.out_many( | ||
self.exposed_outputs( | ||
self.ctx.child, | ||
ChildWorkChain | ||
) | ||
self.exposed_outputs(self.ctx.child, ChildWorkChain) | ||
) |
21 changes: 21 additions & 0 deletions
21
docs/source/concepts/include/snippets/workflows/workchains/run_workchain_submit_append.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from aiida.orm.data.int import Int | ||
from aiida.work.workchain import WorkChain, ToContext, append_ | ||
|
||
class SomeWorkChain(WorkChain): | ||
|
||
@classmethod | ||
def define(cls, spec): | ||
super(SomeWorkChain, cls).define(spec) | ||
spec.outline( | ||
cls.submit_workchains, | ||
cls.inspect_workchains, | ||
) | ||
|
||
def submit_workchains(self) | ||
for i in range(3): | ||
future = self.submit(SomeWorkChain) | ||
self.to_context(workchains=append_(future)) | ||
|
||
def inspect_workchains(self) | ||
for workchain in self.ctx.workchains: | ||
assert workchain.is_finished_ok |
19 changes: 19 additions & 0 deletions
19
docs/source/concepts/include/snippets/workflows/workchains/run_workchain_submit_complete.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from aiida.orm.data.int import Int | ||
from aiida.work.workchain import WorkChain, ToContext | ||
|
||
class SomeWorkChain(WorkChain): | ||
|
||
@classmethod | ||
def define(cls, spec): | ||
super(SomeWorkChain, cls).define(spec) | ||
spec.outline( | ||
cls.submit_workchain, | ||
cls.inspect_workchain, | ||
) | ||
|
||
def submit_workchain(self) | ||
future = self.submit(SomeWorkChain) | ||
return ToContext(workchain=future) | ||
|
||
def inspect_workchain(self) | ||
assert self.ctx.workchain.is_finished_ok |
23 changes: 23 additions & 0 deletions
23
docs/source/concepts/include/snippets/workflows/workchains/run_workchain_submit_parallel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from aiida.orm.data.int import Int | ||
from aiida.work.workchain import WorkChain, ToContext | ||
|
||
class SomeWorkChain(WorkChain): | ||
|
||
@classmethod | ||
def define(cls, spec): | ||
super(SomeWorkChain, cls).define(spec) | ||
spec.outline( | ||
cls.submit_workchains, | ||
cls.inspect_workchains, | ||
) | ||
|
||
def submit_workchains(self) | ||
for i in range(3): | ||
future = self.submit(SomeWorkChain) | ||
key = 'workchain_{}'.format(i) | ||
self.to_context(key=future) | ||
|
||
def inspect_workchains(self) | ||
for i in range(3): | ||
key = 'workchain_{}'.format(i) | ||
assert self.ctx[key].is_finished_ok |
17 changes: 17 additions & 0 deletions
17
...rce/concepts/include/snippets/workflows/workfunctions/example_problem_workfunction_run.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from aiida.work.launch import run_get_node, run_get_pid | ||
from aiida.work.workfunctions import workfunction | ||
|
||
a = 1 | ||
b = 2 | ||
|
||
@workfunction | ||
def add(a, b): | ||
return a + b | ||
|
||
# Passing inputs as arguments | ||
result, node = run_get_node(add, a, b) | ||
result, pid = run_get_pid(add, a, b) | ||
|
||
# Passing inputs as keyword arguments | ||
result, node = run_get_node(add, a=a, b=b) | ||
result, pid = run_get_pid(add, a=a, b=b) |
Oops, something went wrong.