Skip to content

Commit 1566a7f

Browse files
committed
FIX(<PY3.5): ORDERED DiGRAPH for old Python to fix TCs
1 parent f9b2415 commit 1566a7f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

graphkit/network.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"""
6666
import logging
6767
import os
68+
import sys
6869
import time
6970
from collections import defaultdict, namedtuple
7071
from io import StringIO
@@ -79,6 +80,22 @@
7980

8081
log = logging.getLogger(__name__)
8182

83+
84+
from networkx import DiGraph
85+
if sys.version_info < (3, 6):
86+
"""
87+
Consistently ordered variant of :class:`~networkx.DiGraph`.
88+
89+
PY3.6 has inmsertion-order dicts, but PY3.5 has not.
90+
And behvavior *and TCs) in these environments may fail spuriously!
91+
Still *subgraphs* may not patch!
92+
93+
Fix from:
94+
https://networkx.github.io/documentation/latest/reference/classes/ordered.html#module-networkx.classes.ordered
95+
"""
96+
from networkx import OrderedDiGraph as DiGraph
97+
98+
8299
class DataPlaceholderNode(str):
83100
"""
84101
Dag node naming a data-value produced or required by an operation.
@@ -123,7 +140,7 @@ class Network(plot.Plotter):
123140

124141
def __init__(self, **kwargs):
125142
# directed graph of layer instances and data-names defining the net.
126-
self.graph = nx.DiGraph()
143+
self.graph = DiGraph()
127144

128145
# this holds the timing information for each layer
129146
self.times = {}

0 commit comments

Comments
 (0)