|
4 | 4 |
|
5 | 5 | import cloudpickle |
6 | 6 |
|
| 7 | +from executorlib.standalone.select import FutureSelector |
| 8 | + |
7 | 9 |
|
8 | 10 | def generate_nodes_and_edges_for_plotting( |
9 | 11 | task_hash_dict: dict, future_hash_inverse_dict: dict |
@@ -31,7 +33,15 @@ def add_element(arg, link_to, label=""): |
31 | 33 | link_to: ID of the node to link the element to. |
32 | 34 | label (str, optional): Label for the edge. Defaults to "". |
33 | 35 | """ |
34 | | - if isinstance(arg, Future): |
| 36 | + if isinstance(arg, FutureSelector): |
| 37 | + edge_lst.append( |
| 38 | + { |
| 39 | + "start": hash_id_dict[future_hash_inverse_dict[arg._future]], |
| 40 | + "end": link_to, |
| 41 | + "label": label + str(arg._selector), |
| 42 | + } |
| 43 | + ) |
| 44 | + elif isinstance(arg, Future): |
35 | 45 | edge_lst.append( |
36 | 46 | { |
37 | 47 | "start": hash_id_dict[future_hash_inverse_dict[arg]], |
@@ -104,7 +114,24 @@ def convert_arg(arg, future_hash_inverse_dict): |
104 | 114 | Returns: |
105 | 115 | The hash representation of the argument. |
106 | 116 | """ |
107 | | - if isinstance(arg, Future): |
| 117 | + if isinstance(arg, FutureSelector): |
| 118 | + if arg not in future_hash_inverse_dict: |
| 119 | + obj_dict = { |
| 120 | + "args": (), |
| 121 | + "kwargs": { |
| 122 | + "future": future_hash_inverse_dict[arg._future], |
| 123 | + "selector": arg._selector, |
| 124 | + }, |
| 125 | + } |
| 126 | + if isinstance(arg._selector, str): |
| 127 | + obj_dict["fn"] = "get_item_from_future" |
| 128 | + else: |
| 129 | + obj_dict["fn"] = "split_future" |
| 130 | + arg_hash = cloudpickle.dumps(obj_dict) |
| 131 | + future_hash_dict[arg_hash] = arg |
| 132 | + future_hash_inverse_dict[arg] = arg_hash |
| 133 | + return future_hash_inverse_dict[arg] |
| 134 | + elif isinstance(arg, Future): |
108 | 135 | return future_hash_inverse_dict[arg] |
109 | 136 | elif isinstance(arg, list): |
110 | 137 | return [ |
|
0 commit comments