13
13
from functools import partial
14
14
15
15
from .utils import variables_dict , import_required , maybe_to_list
16
+
17
+ # from .process import filter_variables
16
18
from .variable import VarIntent , VarType
17
19
18
20
@@ -136,6 +138,35 @@ def add_var_and_targets(self, p_name, var_name):
136
138
):
137
139
self ._add_var (var , p_name )
138
140
141
+ def add_feedback_arrows (self ):
142
+ """
143
+ adds dotted arrows from the last inout processes to all in processes
144
+ before the first inout process
145
+ """
146
+ # in->inout1->inout2
147
+ # ^ /
148
+ # \- - - - - /
149
+ in_vars = {}
150
+ inout_vars = {}
151
+ for p_name , p_obj in self .model ._processes .items ():
152
+ p_cls = type (p_obj )
153
+ for var_name , var in variables_dict (p_cls ).items ():
154
+ target_keys = tuple (_get_target_keys (p_obj , var_name ))
155
+ if (
156
+ var .metadata ["intent" ] == VarIntent .IN
157
+ and not target_keys in inout_vars
158
+ ):
159
+ if target_keys in in_vars :
160
+ in_vars [target_keys ].add (p_name )
161
+ else :
162
+ in_vars [target_keys ] = {p_name }
163
+ if var .metadata ["intent" ] == VarIntent .INOUT :
164
+ inout_vars [target_keys ] = p_name
165
+
166
+ for target_keys , io_p in inout_vars .items ():
167
+ for in_p in in_vars [target_keys ]:
168
+ self .g .edge (io_p , in_p , weight = "200" , style = "dashed" )
169
+
139
170
def get_graph (self ):
140
171
return self .g
141
172
@@ -146,6 +177,7 @@ def to_graphviz(
146
177
show_only_variable = None ,
147
178
show_inputs = False ,
148
179
show_variables = False ,
180
+ show_feedbacks = True ,
149
181
graph_attr = {},
150
182
** kwargs ,
151
183
):
@@ -167,6 +199,9 @@ def to_graphviz(
167
199
elif show_inputs :
168
200
builder .add_inputs ()
169
201
202
+ elif show_feedbacks :
203
+ builder .add_feedback_arrows ()
204
+
170
205
return builder .get_graph ()
171
206
172
207
@@ -211,6 +246,7 @@ def dot_graph(
211
246
show_only_variable = None ,
212
247
show_inputs = False ,
213
248
show_variables = False ,
249
+ show_feedbacks = True ,
214
250
** kwargs ,
215
251
):
216
252
"""
@@ -236,6 +272,10 @@ def dot_graph(
236
272
show_variables : bool, optional
237
273
If True, show also the other variables (default: False).
238
274
Ignored if `show_only_variable` is not None.
275
+ show_feedbacks: bool, optional
276
+ if True, draws dotted arrows to indicate what processes use updated
277
+ variables in the next timestep. (default: True)
278
+ Ignored if `show_variables` is not None
239
279
**kwargs
240
280
Additional keyword arguments to forward to `to_graphviz`.
241
281
@@ -262,6 +302,7 @@ def dot_graph(
262
302
show_only_variable = show_only_variable ,
263
303
show_inputs = show_inputs ,
264
304
show_variables = show_variables ,
305
+ show_feedbacks = show_feedbacks ,
265
306
** kwargs ,
266
307
)
267
308
0 commit comments