21
21
from functools import reduce
22
22
23
23
import numpy as np
24
- import networkx as nx
25
24
from future import standard_library
26
25
27
26
from ... import logging , config , LooseVersion
55
54
logger = logging .getLogger ('nipype.workflow' )
56
55
PY3 = sys .version_info [0 ] > 2
57
56
58
- try :
59
- dfs_preorder = nx .dfs_preorder
60
- except AttributeError :
61
- dfs_preorder = nx .dfs_preorder_nodes
62
- logger .debug ('networkx 1.4 dev or higher detected' )
63
-
64
57
65
58
def _parameterization_dir (param ):
66
59
"""
@@ -543,6 +536,7 @@ def _create_dot_graph(graph, show_connectinfo=False, simple_form=True):
543
536
Ensures that edge info is pickleable.
544
537
"""
545
538
logger .debug ('creating dot graph' )
539
+ import networkx as nx
546
540
pklgraph = nx .DiGraph ()
547
541
for edge in graph .edges ():
548
542
data = graph .get_edge_data (* edge )
@@ -569,6 +563,7 @@ def _write_detailed_dot(graph, dotfilename):
569
563
struct1:f2 -> struct3:here;
570
564
}
571
565
"""
566
+ import networkx as nx
572
567
text = ['digraph structs {' , 'node [shape=record];' ]
573
568
# write nodes
574
569
edges = []
@@ -748,6 +743,7 @@ def evaluate_connect_function(function_source, args, first_arg):
748
743
749
744
750
745
def get_levels (G ):
746
+ import networkx as nx
751
747
levels = {}
752
748
for n in nx .topological_sort (G ):
753
749
levels [n ] = 0
@@ -891,6 +887,7 @@ def _identity_nodes(graph, include_iterables):
891
887
are included if and only if the include_iterables flag is set
892
888
to True.
893
889
"""
890
+ import networkx as nx
894
891
return [
895
892
node for node in nx .topological_sort (graph )
896
893
if isinstance (node .interface , IdentityInterface ) and (
@@ -994,6 +991,12 @@ def generate_expanded_graph(graph_in):
994
991
and b=[3,4] this procedure will generate a graph with sub-graphs
995
992
parameterized as (a=1,b=3), (a=1,b=4), (a=2,b=3) and (a=2,b=4).
996
993
"""
994
+ import networkx as nx
995
+ try :
996
+ dfs_preorder = nx .dfs_preorder
997
+ except AttributeError :
998
+ dfs_preorder = nx .dfs_preorder_nodes
999
+
997
1000
logger .debug ("PE: expanding iterables" )
998
1001
graph_in = _remove_nonjoin_identity_nodes (graph_in , keep_iterables = True )
999
1002
# standardize the iterables as {(field, function)} dictionaries
@@ -1222,6 +1225,7 @@ def _iterable_nodes(graph_in):
1222
1225
1223
1226
Return the iterable nodes list
1224
1227
"""
1228
+ import networkx as nx
1225
1229
nodes = nx .topological_sort (graph_in )
1226
1230
inodes = [node for node in nodes if node .iterables is not None ]
1227
1231
inodes_no_src = [node for node in inodes if not node .itersource ]
@@ -1349,6 +1353,7 @@ def export_graph(graph_in,
1349
1353
Indicates whether to show the edge data on the graph. This
1350
1354
makes the graph rather cluttered. default [False]
1351
1355
"""
1356
+ import networkx as nx
1352
1357
graph = deepcopy (graph_in )
1353
1358
if use_execgraph :
1354
1359
graph = generate_expanded_graph (graph )
@@ -1716,6 +1721,7 @@ def write_workflow_resources(graph, filename=None, append=None):
1716
1721
def topological_sort (graph , depth_first = False ):
1717
1722
"""Returns a depth first sorted order if depth_first is True
1718
1723
"""
1724
+ import networkx as nx
1719
1725
nodesort = list (nx .topological_sort (graph ))
1720
1726
if not depth_first :
1721
1727
return nodesort , None
0 commit comments