Replies: 2 comments 3 replies
-
|
Maybe an additional question. Would my approach also work with |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
You can define fixed fields in the dynamic namespace. # out1 and out2 always exist
dynamic(int, out1=int, out2=int])You can define the output as optional if it only exists in a particular case: dynamic(t.Any, out1=t.Annotated[t.Any, meta(required=False)])Here is an example: from aiida_workgraph import task, dynamic, meta
import typing as t
from aiida import load_profile
load_profile()
@task
def generate_dynamic_outputs_with_fixed_field(
n: int,
) -> t.Annotated[
dict,
dynamic(t.Any, known_output=t.Annotated[t.Any, meta(required=False)]),
]:
"""Generate a dict of square numbers with a fixed field 'known_output'."""
results = {f'square_{i}': i**2 for i in range(n)}
results['known_output'] = n
return results
@task
def add(x, y):
return x + y
@task.graph
def SquareNumbersGenerator(n: int):
out1 = generate_dynamic_outputs_with_fixed_field(n=n)
return add(out1.known_output, 2).result
wg = SquareNumbersGenerator.build(n=5)
results = wg.run()
print("result: ", results)The doc misses this part 😢 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there any recommended procedure for linking dynamic ports in a namespace? For example, say that I have a workgraph
wg1which has dynamic output namespacescf_outputsand I want to link the portscf_outputs.zeroto the input of another task (I knowzerowill exist in the namespace for the particular case I am trying to construct). Usingscf_outputs.zerodoes not work, because the names of the dynamic ports are not in the OutputSpec ofwg1. Right now I am using aworkfunctionto still link them,This seems to work, but I was wondering if there is a recommended, perhaps better way of linking these kind of dynamic ports?
Beta Was this translation helpful? Give feedback.
All reactions