How to reuse the same op in two different graph-ba...
# ask-ai
d
How to reuse the same op in two different graph-backed assets, but with a different parameter for the op
s
To reuse the same op in two different graph-backed assets with different parameters, you can follow the pattern of aliasing ops within a graph. This allows you to use the same op definition multiple times in the same graph, potentially with different parameters. Here's a step-by-step explanation based on the documentation: 1. Define your op with the required parameters. For example:
Copy code
python
   @op
   def my_op(context: OpExecutionContext, param: int) -> int:
       # Your op logic here
       return param + 1
2. When constructing your graph-backed assets, you can use the
.alias
method on the op invocation to give it a unique name within the graph and pass different parameters to each aliased op. For example:
Copy code
python
   @graph
   def graph_asset_one():
       # Using the op with one parameter
       my_op.alias("op_with_param_1")(param=1)
   
   @graph
   def graph_asset_two():
       # Reusing the op with a different parameter
       my_op.alias("op_with_param_2")(param=2)
3. Create asset definitions from these graphs using the
AssetsDefinition.from_graph
method. For example:
Copy code
python
   asset_def_one = AssetsDefinition.from_graph(graph_asset_one)
   asset_def_two = AssetsDefinition.from_graph(graph_asset_two)
By following these steps, you can reuse the same op in different graph-backed assets with different parameters. Each aliased op within the graph can be configured independently, allowing for the reuse of op logic while varying the parameters as needed for each asset. enable executing a subset of steps in a ... button Dagster 0.15.0: Cool for the Summer | Da... button Thank you for your feedback!