Anoop Sharma
03/25/2022, 6:09 PMop
using the OpDefinition
instantiation but I am struggling to provide compute_fn
parameter for that. As I understand, it cannot directly be the base function that you use the @op
decorator on. But not sure how to generate a valid compute_fn
to pass to OpDefinition
. Any ideas or references?jamie
03/25/2022, 6:41 PMOpDefinition
. However, in almost all cases you should define ops using the @op
decorator. If you can tell us a bit more about your use case, we might be able to help figure out how to do it using @op
!
def my_func(context, _):
yield Output(1, "my_out")
op_def = OpDefinition(name="op_def", input_defs=[], compute_fn=my_func, output_defs=[OutputDefinition(name="my_out", dagster_type=int)])
Anoop Sharma
03/25/2022, 6:43 PMAnoop Sharma
03/25/2022, 6:44 PMjamie
03/25/2022, 6:53 PM@op
def run_script(context, script_file):
# code to run the script (subprocess.call(script_file), etc)
@op(out=DynamicOut())
def get_scripts():
for f in directory:
yield DynamicOut(f, mapping_key=f)
@graph
def run_all_scripts():
scripts = get_scripts()
scripts.map(run_script)
This will collect all of the scripts in some directory in get_scripts
and then because you are working with dynamic outputs, a run_script
op will run once for each script returned from get_scripts
. Then in run_script
you can write whatever logic you need to execute the contents of a script