提交 87b0ed54 authored 作者: Christof Angermueller's avatar Christof Angermueller

Improve OpFromGraph nodes and mapping inputs/outputs

上级 ae83230d
...@@ -36,3 +36,7 @@ Theano.suo ...@@ -36,3 +36,7 @@ Theano.suo
*.DS_Store *.DS_Store
*.bak *.bak
.ipynb_checkpoints .ipynb_checkpoints
doc/d3printing/GSoC/150724_opfrom/bundle/
doc/d3printing/GSoC/150724_opfrom/bundle2/
...@@ -82,4 +82,9 @@ svg { ...@@ -82,4 +82,9 @@ svg {
border: 1px solid black; border: 1px solid black;
border-radius: 8px; border-radius: 8px;
pointer-events: none; pointer-events: none;
}
path.hull {
fill: lightsteelblue;
fill-opacity: 0.3;
} }
\ No newline at end of file
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var path='opfrom.dot'; // '%% DOT_FILE %%' var path = 'opfrom.dot'; // '%% DOT_FILE %%';
var dotGraph; var dotGraph;
var graph = {}; var graph = {};
var nodes = []; var nodes = [];
...@@ -85,13 +85,6 @@ ...@@ -85,13 +85,6 @@
.attr("d", "M0,0 L4,2 L0,4 Z") .attr("d", "M0,0 L4,2 L0,4 Z")
.attr('fill', function(d) { return d.color;}); .attr('fill', function(d) { return d.color;});
d3.text(path, function(data) {
dotGraph = graphlibDot.read(data);
processDotGraph(dotGraph);
graph = forceGraph(dotGraph);
setupGraph();
});
// Zoom behaviour // Zoom behaviour
function zoom(d) { function zoom(d) {
var trans = d3.event.translate; var trans = d3.event.translate;
...@@ -107,6 +100,18 @@ ...@@ -107,6 +100,18 @@
bZoom.event(svg); bZoom.event(svg);
svg.on("dblclick.zoom", null); svg.on("dblclick.zoom", null);
var curve = d3.svg.line()
.interpolate("cardinal-closed")
.tension(.85);
// Read and initialize graph
d3.text(path, function(data) {
dotGraph = graphlibDot.read(data);
processDotGraph(dotGraph);
graph = forceGraph(dotGraph);
setupGraph();
});
</script> </script>
</body> </body>
</html> </html>
digraph G { digraph G {
graph [bb="0,0,2478,251"]; graph [bb="0,0,2605,316"];
node [label="\N"]; node [label="\N"];
subgraph cluster__1 { subgraph cluster_n1 {
graph [bb="8,168,723,243", graph [bb="1159,80,1874,308"];
label="theano.compile.builders.OpFromGraph object at 0x1141d3a50", n11 [fillcolor="#FFAABB",
lheight=0.21,
lp="365.5,231.5",
lwidth=4.89
];
_2 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=z TensorType(float64, scalar)", label="Elemwise{Composite{(i0 + (i1 * i2))}}",
pos="605,194", pos="1509,194",
shape=ellipse,
style=filled,
type=colored,
width=4.3102];
n15 [fillcolor=dodgerblue,
height=0.5,
label="TensorType(float32, scalar)",
pos="1509,106",
shape=box, shape=box,
style=filled, style=filled,
width=3.0556]; width=2.3889];
_3 [fillcolor=limegreen, n11 -> n15 [label="TensorType(float32, scalar)",
lp="1587,150",
pos="e,1509,124.08 1509,175.6 1509,163.75 1509,147.82 1509,134.29"];
n12 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=y TensorType(float64, scalar)", label="name=x TensorType(float32, scalar)",
pos="366,194", pos="1755,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
_4 [fillcolor=limegreen, n12 -> n11 [label="0 TensorType(float32, scalar)",
lp="1790.5,238",
pos="e,1603.7,208.31 1733.7,263.92 1718.7,252.69 1697.6,238.53 1677,230 1657.1,221.75 1635,215.37 1613.5,210.46"];
n13 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=y TensorType(float64, scalar)", label="name=y TensorType(float32, scalar)",
pos="127,194", pos="1516,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
n13 -> n11 [label="1 TensorType(float32, scalar)",
lp="1593.5,238",
pos="e,1508.7,212.04 1512.6,263.98 1511.5,258.29 1510.6,251.89 1510,246 1509.3,238.24 1508.9,229.79 1508.8,222.04"];
n14 [fillcolor=limegreen,
height=0.5,
label="name=z TensorType(float32, scalar)",
pos="1277,282",
shape=box,
style=filled,
width=3.0556];
n14 -> n11 [label="2 TensorType(float32, scalar)",
lp="1422.5,238",
pos="e,1407,207.64 1293.3,263.77 1305,252.46 1321.6,238.29 1339,230 1357.1,221.35 1377.3,214.83 1397.3,209.92"];
} }
subgraph cluster__5 { subgraph cluster_n6 {
graph [bb="1755,168,2470,243", graph [bb="1882,80,2597,308"];
label="theano.compile.builders.OpFromGraph object at 0x1141d3a50 id=1", n61 [fillcolor="#FFAABB",
lheight=0.21, height=0.5,
lp="2112.5,231.5", label="Elemwise{Composite{(i0 + (i1 * i2))}}",
lwidth=5.29 pos="2232,194",
]; shape=ellipse,
_6 [fillcolor=limegreen, style=filled,
type=colored,
width=4.3102];
n65 [fillcolor=dodgerblue,
height=0.5, height=0.5,
label="name=x TensorType(float64, scalar)", label="TensorType(float32, scalar)",
pos="2351,194", pos="2232,106",
shape=box,
style=filled,
width=2.3889];
n61 -> n65 [label="TensorType(float32, scalar)",
lp="2310,150",
pos="e,2232,124.08 2232,175.6 2232,163.75 2232,147.82 2232,134.29"];
n62 [fillcolor=limegreen,
height=0.5,
label="name=x TensorType(float32, scalar)",
pos="2478,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
_7 [fillcolor=limegreen, n62 -> n61 [label="0 TensorType(float32, scalar)",
lp="2512.5,238",
pos="e,2326.7,208.31 2456.7,263.92 2441.7,252.69 2420.6,238.53 2400,230 2380.1,221.75 2358,215.37 2336.5,210.46"];
n63 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=y TensorType(float64, scalar)", label="name=y TensorType(float32, scalar)",
pos="2112,194", pos="2239,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
_8 [fillcolor=limegreen, n63 -> n61 [label="1 TensorType(float32, scalar)",
lp="2316.5,238",
pos="e,2231.7,212.04 2235.6,263.98 2234.5,258.29 2233.6,251.89 2233,246 2232.3,238.24 2231.9,229.79 2231.8,222.04"];
n64 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=z TensorType(float64, scalar)", label="name=z TensorType(float32, scalar)",
pos="1873,194", pos="2000,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0556]; width=3.0556];
n64 -> n61 [label="2 TensorType(float32, scalar)",
lp="2145.5,238",
pos="e,2130,207.64 2016.3,263.77 2028,252.46 2044.6,238.29 2062,230 2080.1,221.35 2100.3,214.83 2120.3,209.92"];
} }
_1 [height=0.5, n1 [height=0.5,
label="theano.compile.builders.OpFromGraph object at 0x1141d3a50", label="theano.compile.builders.OpFromGraph object at 0x10cc0bb90",
pos="972,194", pos="238,194",
shape=ellipse, shape=ellipse,
width=6.6414]; subg=cluster_n1,
_9 [fillcolor="#FFAABB", subg_map_inputs="[['n2', 'n12'], ['n3', 'n13'], ['n3', 'n14']]",
subg_map_outputs="[['n15', 'n5']]",
width=6.6185];
n5 [fillcolor="#FFAABB",
height=0.5, height=0.5,
label="Elemwise{Add}[(0, 0)]", label="Elemwise{Add}[(0, 0)]",
pos="1229,106", pos="553,106",
shape=ellipse, shape=ellipse,
style=filled, style=filled,
type=colored, type=colored,
width=2.6784]; width=2.6784];
_1 -> _9 [label="1 TensorType(float64, scalar)", n1 -> n5 [label="1 TensorType(float32, scalar)",
lp="1207.5,150", lp="507.5,150",
pos="e,1184,122.05 1021.9,176.32 1065.6,161.66 1129.2,140.38 1174.4,125.28"]; pos="e,500.93,121.21 298.36,176.52 353.72,161.41 435.35,139.12 491.17,123.88"];
_5 [height=0.5, n2 [fillcolor=limegreen,
label="theano.compile.builders.OpFromGraph object at 0x1141d3a50 id=1", height=0.5,
pos="1487,194", label="name=z TensorType(float32, scalar)",
pos="674,282",
shape=box,
style=filled,
width=3.0556];
n2 -> n1 [label="0 TensorType(float32, scalar)",
lp="684.5,238",
pos="e,430.16,204.72 633.61,263.87 622.72,258.66 611.15,252.56 601,246 591.73,240.01 592.17,234.31 582,230 555.22,218.66 499.43,210.89 \
440.43,205.61"];
n6 [height=0.5,
label="theano.compile.builders.OpFromGraph object at 0x10cc0bb90 id=1",
pos="780,194",
shape=ellipse, shape=ellipse,
width=7.167]; subg=cluster_n6,
_5 -> _9 [color=red, subg_map_inputs="[['n7', 'n62'], ['n3', 'n63'], ['n2', 'n64']]",
label="0 TensorType(float64, scalar)", subg_map_outputs="[['n65', 'n5']]",
lp="1464.5,150", width=7.1441];
pos="e,1274.2,122.05 1436.9,176.32 1393,161.66 1329.2,140.38 1283.8,125.28"]; n2 -> n6 [label="2 TensorType(float32, scalar)",
_10 [fillcolor=dodgerblue, lp="863.5,238",
pos="e,781.5,212.41 749.62,263.79 758.11,259.2 765.89,253.37 772,246 777.39,239.5 779.89,230.87 780.91,222.57"];
n3 [fillcolor=limegreen,
height=0.5,
label="name=y TensorType(float32, scalar)",
pos="224,282",
shape=box,
style=filled,
width=3.0625];
n3 -> n1 [label="1 TensorType(float32, scalar)",
lp="308.5,238",
pos="e,230.34,212.12 222.91,263.85 222.64,253.89 222.89,241.14 225,230 225.51,227.29 226.22,224.51 227.03,221.76"];
n3 -> n1 [label="2 TensorType(float32, scalar)",
lp="136.5,238",
pos="e,102.14,208.8 113.52,277.73 67.058,272.21 28.738,259.28 53,230 59.571,222.07 74.117,215.92 92.313,211.16"];
n3 -> n6 [label="1 TensorType(float32, scalar)",
lp="494.5,238",
pos="e,568.49,204.32 334.59,266.1 354.29,261.19 374.18,254.66 392,246 401.93,241.17 400.82,234.27 411,230 439.03,218.24 496.65,210.39 \
558.18,205.17"];
n6 -> n5 [color=red,
label="0 TensorType(float32, scalar)",
lp="770.5,150",
pos="e,593.76,122.44 735.69,176.21 697.67,161.81 642.89,141.06 603.24,126.03"];
n7 [fillcolor=limegreen,
height=0.5,
label="name=x TensorType(float32, scalar)",
pos="984,282",
shape=box,
style=filled,
width=3.0625];
n7 -> n6 [label="0 TensorType(float32, scalar)",
lp="1050.5,238",
pos="e,908.79,209.62 977.09,263.71 971.67,252.39 963.02,238.21 951,230 941.03,223.19 930.02,217.65 918.54,213.16"];
n9 [fillcolor=dodgerblue,
height=0.5, height=0.5,
label="TensorType(float64, scalar) id=5", label="TensorType(float32, scalar) id=5",
pos="1229,18", pos="553,18",
shape=box, shape=box,
style=filled, style=filled,
width=2.7847]; width=2.7847];
_9 -> _10 [label="TensorType(float64, scalar)", n5 -> n9 [label="TensorType(float32, scalar)",
lp="1307,62", lp="631,62",
pos="e,1229,36.084 1229,87.597 1229,75.746 1229,59.817 1229,46.292"]; pos="e,553,36.084 553,87.597 553,75.746 553,59.817 553,46.292"];
} }
...@@ -82,4 +82,9 @@ svg { ...@@ -82,4 +82,9 @@ svg {
border: 1px solid black; border: 1px solid black;
border-radius: 8px; border-radius: 8px;
pointer-events: none; pointer-events: none;
} }
\ No newline at end of file
path.hull {
fill: lightsteelblue;
fill-opacity: 0.3;
}
digraph G { digraph G {
graph [bb="0,0,2482,251"]; graph [bb="0,0,2606,316"];
node [label="\N"]; node [label="\N"];
subgraph cluster__1 { subgraph cluster_n1 {
graph [bb="8,168,723,243", graph [bb="1160,80,1875,308"];
label="theano.compile.builders.OpFromGraph object at 0x114552bd0", n11 [fillcolor="#FFAABB",
lheight=0.21,
lp="365.5,231.5",
lwidth=4.90
];
_2 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=z TensorType(float64, scalar)", label="Elemwise{Composite{(i0 + (i1 * i2))}}",
pos="605,194", pos="1510,194",
shape=ellipse,
style=filled,
type=colored,
width=4.3102];
n15 [fillcolor=dodgerblue,
height=0.5,
label="TensorType(float32, scalar)",
pos="1510,106",
shape=box, shape=box,
style=filled, style=filled,
width=3.0556]; width=2.3889];
_3 [fillcolor=limegreen, n11 -> n15 [label="TensorType(float32, scalar)",
lp="1588,150",
pos="e,1510,124.08 1510,175.6 1510,163.75 1510,147.82 1510,134.29"];
n12 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=y TensorType(float64, scalar)", label="name=x TensorType(float32, scalar)",
pos="366,194", pos="1756,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
_4 [fillcolor=limegreen, n12 -> n11 [label="0 TensorType(float32, scalar)",
lp="1791.5,238",
pos="e,1604.7,208.31 1734.7,263.92 1719.7,252.69 1698.6,238.53 1678,230 1658.1,221.75 1636,215.37 1614.5,210.46"];
n13 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=y TensorType(float64, scalar)", label="name=y TensorType(float32, scalar)",
pos="127,194", pos="1517,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
n13 -> n11 [label="1 TensorType(float32, scalar)",
lp="1594.5,238",
pos="e,1509.7,212.04 1513.6,263.98 1512.5,258.29 1511.6,251.89 1511,246 1510.3,238.24 1509.9,229.79 1509.8,222.04"];
n14 [fillcolor=limegreen,
height=0.5,
label="name=z TensorType(float32, scalar)",
pos="1278,282",
shape=box,
style=filled,
width=3.0556];
n14 -> n11 [label="2 TensorType(float32, scalar)",
lp="1423.5,238",
pos="e,1408,207.64 1294.3,263.77 1306,252.46 1322.6,238.29 1340,230 1358.1,221.35 1378.3,214.83 1398.3,209.92"];
} }
subgraph cluster__5 { subgraph cluster_n6 {
graph [bb="1759,168,2474,243", graph [bb="1883,80,2598,308"];
label="theano.compile.builders.OpFromGraph object at 0x114552bd0 id=1", n61 [fillcolor="#FFAABB",
lheight=0.21, height=0.5,
lp="2116.5,231.5", label="Elemwise{Composite{(i0 + (i1 * i2))}}",
lwidth=5.31 pos="2233,194",
]; shape=ellipse,
_6 [fillcolor=limegreen, style=filled,
type=colored,
width=4.3102];
n65 [fillcolor=dodgerblue,
height=0.5, height=0.5,
label="name=x TensorType(float64, scalar)", label="TensorType(float32, scalar)",
pos="2355,194", pos="2233,106",
shape=box,
style=filled,
width=2.3889];
n61 -> n65 [label="TensorType(float32, scalar)",
lp="2311,150",
pos="e,2233,124.08 2233,175.6 2233,163.75 2233,147.82 2233,134.29"];
n62 [fillcolor=limegreen,
height=0.5,
label="name=x TensorType(float32, scalar)",
pos="2479,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
_7 [fillcolor=limegreen, n62 -> n61 [label="0 TensorType(float32, scalar)",
lp="2513.5,238",
pos="e,2327.7,208.31 2457.7,263.92 2442.7,252.69 2421.6,238.53 2401,230 2381.1,221.75 2359,215.37 2337.5,210.46"];
n63 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=y TensorType(float64, scalar)", label="name=y TensorType(float32, scalar)",
pos="2116,194", pos="2240,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
_8 [fillcolor=limegreen, n63 -> n61 [label="1 TensorType(float32, scalar)",
lp="2317.5,238",
pos="e,2232.7,212.04 2236.6,263.98 2235.5,258.29 2234.6,251.89 2234,246 2233.3,238.24 2232.9,229.79 2232.8,222.04"];
n64 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=z TensorType(float64, scalar)", label="name=z TensorType(float32, scalar)",
pos="1877,194", pos="2001,282",
shape=box, shape=box,
style=filled, style=filled,
width=3.0556]; width=3.0556];
n64 -> n61 [label="2 TensorType(float32, scalar)",
lp="2146.5,238",
pos="e,2131,207.64 2017.3,263.77 2029,252.46 2045.6,238.29 2063,230 2081.1,221.35 2101.3,214.83 2121.3,209.92"];
} }
_1 [height=0.5, n1 [height=0.5,
label="theano.compile.builders.OpFromGraph object at 0x114552bd0", label="theano.compile.builders.OpFromGraph object at 0x1100c70d0",
pos="973,194", pos="239,194",
shape=ellipse, shape=ellipse,
width=6.6504]; subg=cluster_n1,
_9 [fillcolor="#FFAABB", subg_map_inputs="[['n2', 'n12'], ['n3', 'n13'], ['n3', 'n14']]",
subg_map_outputs="[['n15', 'n5']]",
width=6.6414];
n5 [fillcolor="#FFAABB",
height=0.5, height=0.5,
label="Elemwise{Add}[(0, 0)]", label="Elemwise{Add}[(0, 0)]",
pos="1231,106", pos="554,106",
shape=ellipse, shape=ellipse,
style=filled, style=filled,
type=colored, type=colored,
width=2.6784]; width=2.6784];
_1 -> _9 [label="1 TensorType(float64, scalar)", n1 -> n5 [label="1 TensorType(float32, scalar)",
lp="1209.5,150", lp="508.5,150",
pos="e,1185.8,122.05 1023.1,176.32 1067,161.66 1130.8,140.38 1176.2,125.28"]; pos="e,501.93,121.21 299.36,176.52 354.72,161.41 436.35,139.12 492.17,123.88"];
_5 [height=0.5, n2 [fillcolor=limegreen,
label="theano.compile.builders.OpFromGraph object at 0x114552bd0 id=1", height=0.5,
pos="1490,194", label="name=z TensorType(float32, scalar)",
pos="675,282",
shape=box,
style=filled,
width=3.0556];
n2 -> n1 [label="0 TensorType(float32, scalar)",
lp="685.5,238",
pos="e,431.16,204.72 634.61,263.87 623.72,258.66 612.15,252.56 602,246 592.73,240.01 593.17,234.31 583,230 556.22,218.66 500.43,210.89 \
441.43,205.61"];
n6 [height=0.5,
label="theano.compile.builders.OpFromGraph object at 0x1100c70d0 id=1",
pos="781,194",
shape=ellipse, shape=ellipse,
width=7.1761]; subg=cluster_n6,
_5 -> _9 [color=red, subg_map_inputs="[['n7', 'n62'], ['n3', 'n63'], ['n2', 'n64']]",
label="0 TensorType(float64, scalar)", subg_map_outputs="[['n65', 'n5']]",
lp="1466.5,150", width=7.167];
pos="e,1276.3,122.05 1439.8,176.32 1395.6,161.66 1331.5,140.38 1286,125.28"]; n2 -> n6 [label="2 TensorType(float32, scalar)",
_10 [fillcolor=dodgerblue, lp="864.5,238",
pos="e,782.5,212.41 750.62,263.79 759.11,259.2 766.89,253.37 773,246 778.39,239.5 780.89,230.87 781.91,222.57"];
n3 [fillcolor=limegreen,
height=0.5,
label="name=y TensorType(float32, scalar)",
pos="225,282",
shape=box,
style=filled,
width=3.0625];
n3 -> n1 [label="1 TensorType(float32, scalar)",
lp="309.5,238",
pos="e,231.34,212.12 223.91,263.85 223.64,253.89 223.89,241.14 226,230 226.51,227.29 227.22,224.51 228.03,221.76"];
n3 -> n1 [label="2 TensorType(float32, scalar)",
lp="137.5,238",
pos="e,102.68,208.9 114.52,277.73 68.058,272.21 29.738,259.28 54,230 60.527,222.12 74.92,216.01 92.944,211.26"];
n3 -> n6 [label="1 TensorType(float32, scalar)",
lp="495.5,238",
pos="e,569.49,204.32 335.59,266.1 355.29,261.19 375.18,254.66 393,246 402.93,241.17 401.82,234.27 412,230 440.03,218.24 497.65,210.39 \
559.18,205.17"];
n6 -> n5 [color=red,
label="0 TensorType(float32, scalar)",
lp="771.5,150",
pos="e,594.76,122.44 736.69,176.21 698.67,161.81 643.89,141.06 604.24,126.03"];
n7 [fillcolor=limegreen,
height=0.5,
label="name=x TensorType(float32, scalar)",
pos="985,282",
shape=box,
style=filled,
width=3.0625];
n7 -> n6 [label="0 TensorType(float32, scalar)",
lp="1051.5,238",
pos="e,909.79,209.62 978.09,263.71 972.67,252.39 964.02,238.21 952,230 942.03,223.19 931.02,217.65 919.54,213.16"];
n9 [fillcolor=dodgerblue,
height=0.5, height=0.5,
label="TensorType(float64, scalar) id=5", label="TensorType(float32, scalar) id=5",
pos="1231,18", pos="554,18",
shape=box, shape=box,
style=filled, style=filled,
width=2.7847]; width=2.7847];
_9 -> _10 [label="TensorType(float64, scalar)", n5 -> n9 [label="TensorType(float32, scalar)",
lp="1309,62", lp="632,62",
pos="e,1231,36.084 1231,87.597 1231,75.746 1231,59.817 1231,46.292"]; pos="e,554,36.084 554,87.597 554,75.746 554,59.817 554,46.292"];
} }
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var path = 'index.dot' var path = 'index.dot';
var dotGraph; var dotGraph;
var graph = {}; var graph = {};
var nodes = []; var nodes = [];
...@@ -85,13 +85,6 @@ ...@@ -85,13 +85,6 @@
.attr("d", "M0,0 L4,2 L0,4 Z") .attr("d", "M0,0 L4,2 L0,4 Z")
.attr('fill', function(d) { return d.color;}); .attr('fill', function(d) { return d.color;});
d3.text(path, function(data) {
dotGraph = graphlibDot.read(data);
processDotGraph(dotGraph);
graph = forceGraph(dotGraph);
setupGraph();
});
// Zoom behaviour // Zoom behaviour
function zoom(d) { function zoom(d) {
var trans = d3.event.translate; var trans = d3.event.translate;
...@@ -107,6 +100,18 @@ ...@@ -107,6 +100,18 @@
bZoom.event(svg); bZoom.event(svg);
svg.on("dblclick.zoom", null); svg.on("dblclick.zoom", null);
var curve = d3.svg.line()
.interpolate("cardinal-closed")
.tension(.85);
// Read and initialize graph
d3.text(path, function(data) {
dotGraph = graphlibDot.read(data);
processDotGraph(dotGraph);
graph = forceGraph(dotGraph);
setupGraph();
});
</script> </script>
</body> </body>
</html> </html>
...@@ -82,4 +82,9 @@ svg { ...@@ -82,4 +82,9 @@ svg {
border: 1px solid black; border: 1px solid black;
border-radius: 8px; border-radius: 8px;
pointer-events: none; pointer-events: none;
} }
\ No newline at end of file
path.hull {
fill: lightsteelblue;
fill-opacity: 0.3;
}
digraph G { digraph G {
graph [bb="0,0,1450,251"]; graph [bb="0,0,1998,340"];
node [label="\N"]; node [label="\N"];
subgraph cluster__1 { subgraph cluster_n1 {
graph [bb="8,168,723,243", graph [bb="773,8,1990,332"];
label="theano.compile.builders.OpFromGraph object at 0x114648450", subgraph cluster_n11 {
lheight=0.21, graph [bb="1505,96,1982,324"];
lp="365.5,231.5", n111 [fillcolor="#FFAABB",
lwidth=4.90 height=0.5,
]; label="Elemwise{mul,no_inplace}",
_2 [fillcolor=limegreen, pos="1717,210",
shape=ellipse,
style=filled,
type=colored,
width=3.0943];
n114 [fillcolor=dodgerblue,
height=0.5,
label="TensorType(float32, scalar)",
pos="1717,122",
shape=box,
style=filled,
width=2.3889];
n111 -> n114 [label="TensorType(float32, scalar)",
lp="1795,166",
pos="e,1717,140.08 1717,191.6 1717,179.75 1717,163.82 1717,150.29"];
n112 [fillcolor=limegreen,
height=0.5,
label="name=x TensorType(float32, scalar)",
pos="1863,298",
shape=box,
style=filled,
width=3.0625];
n112 -> n111 [label="0 TensorType(float32, scalar)",
lp="1892.5,254",
pos="e,1750.2,227.23 1838.1,279.79 1823,269.57 1803.2,256.58 1785,246 1776.8,241.24 1767.9,236.42 1759.4,231.94"];
n113 [fillcolor=limegreen,
height=0.5,
label="name=y TensorType(float32, scalar)",
pos="1624,298",
shape=box,
style=filled,
width=3.0625];
n113 -> n111 [label="1 TensorType(float32, scalar)",
lp="1701.5,254",
pos="e,1645.8,223.99 1616.5,279.94 1613.1,269.27 1611.1,255.75 1618,246 1623,238.94 1629.5,233.29 1636.9,228.78"];
}
n11 [height=0.5,
label="theano.compile.builders.OpFromGraph object at 0x1105b0c50",
pos="1258,210",
shape=ellipse,
subg=cluster_n11,
subg_map_inputs="[['n12', 'n112'], ['n13', 'n113']]",
subg_map_outputs="[['n114', 'n15']]",
width=6.6414];
n15 [fillcolor="#FFAABB",
height=0.5, height=0.5,
label="name=x TensorType(float64, scalar)", label="Elemwise{Add}[(0, 0)]",
pos="604,194", pos="1030,122",
shape=ellipse,
style=filled,
type=colored,
width=2.6784];
n11 -> n15 [color=red,
label="0 TensorType(float32, scalar)",
lp="1266.5,166",
pos="e,1081.2,137.27 1223.3,192.13 1200.9,181.61 1171.1,168.18 1144,158 1127.1,151.64 1108.4,145.55 1091.2,140.28"];
n12 [fillcolor=limegreen,
height=0.5,
label="name=x TensorType(float32, scalar)",
pos="1307,298",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
_3 [fillcolor=limegreen, n12 -> n11 [label="0 TensorType(float32, scalar)",
lp="1370.5,254",
pos="e,1267.7,228.08 1297.1,279.6 1290.1,267.39 1280.7,250.87 1272.9,237.09"];
n13 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=y TensorType(float64, scalar)", label="name=y TensorType(float32, scalar)",
pos="365,194", pos="1068,298",
shape=box, shape=box,
style=filled, style=filled,
width=3.0625]; width=3.0625];
_4 [fillcolor=limegreen, n13 -> n11 [label="1 TensorType(float32, scalar)",
lp="1191.5,254",
pos="e,1151.9,226.21 1077.3,279.8 1084.3,268.51 1094.9,254.35 1108,246 1118.5,239.31 1130.1,233.89 1142.2,229.51"];
n17 [fillcolor=dodgerblue,
height=0.5, height=0.5,
label="name=z TensorType(float64, scalar)", label="TensorType(float32, scalar) id=4",
pos="126,194", pos="1030,34",
shape=box,
style=filled,
width=2.7847];
n15 -> n17 [label="TensorType(float32, scalar)",
lp="1108,78",
pos="e,1030,52.084 1030,103.6 1030,91.746 1030,75.817 1030,62.292"];
n16 [fillcolor=limegreen,
height=0.5,
label="name=z TensorType(float32, scalar)",
pos="891,210",
shape=box, shape=box,
style=filled, style=filled,
width=3.0556]; width=3.0556];
n16 -> n15 [label="1 TensorType(float32, scalar)",
lp="1056.5,166",
pos="e,1003.2,139.58 918.79,191.8 940.57,178.33 971.02,159.49 994.55,144.93"];
} }
_1 [height=0.5, n1 [height=0.5,
label="theano.compile.builders.OpFromGraph object at 0x114648450", label="theano.compile.builders.OpFromGraph object at 0x1105a91d0",
pos="972,194", pos="524,210",
shape=ellipse, shape=ellipse,
width=6.6504]; subg=cluster_n1,
_5 [fillcolor="#FFAABB", subg_map_inputs="[['n2', 'n12'], ['n3', 'n13'], ['n4', 'n16']]",
subg_map_outputs="[['n17', 'n6']]",
width=6.6414];
n6 [fillcolor="#FFAABB",
height=0.5, height=0.5,
label="Elemwise{Add}[(0, 0)]", label="Elemwise{Add}[(0, 0)]",
pos="1156,106", pos="214,122",
shape=ellipse, shape=ellipse,
style=filled, style=filled,
type=colored, type=colored,
width=2.6784]; width=2.6784];
_1 -> _5 [color=red, n1 -> n6 [color=red,
label="0 TensorType(float64, scalar)", label="0 TensorType(float32, scalar)",
lp="1164.5,150", lp="480.5,166",
pos="e,1121.9,122.94 1008.4,176.01 1038.4,161.97 1081.1,142.02 1112.8,127.18"]; pos="e,265.49,137.28 464.6,192.52 410.31,177.46 330.36,155.28 275.44,140.04"];
_7 [fillcolor=dodgerblue, n2 [fillcolor=limegreen,
height=0.5, height=0.5,
label="TensorType(float64, scalar) id=4", label="name=x TensorType(float32, scalar)",
pos="1156,18", pos="354,298",
shape=box, shape=box,
style=filled, style=filled,
width=2.7847]; width=3.0625];
_5 -> _7 [label="TensorType(float64, scalar)", n2 -> n1 [label="0 TensorType(float32, scalar)",
lp="1234,62", lp="465.5,254",
pos="e,1156,36.084 1156,87.597 1156,75.746 1156,59.817 1156,46.292"]; pos="e,418.96,226.25 359.32,279.9 363.67,268.65 370.95,254.49 382,246 390.32,239.61 399.64,234.37 409.44,230.08"];
_6 [fillcolor=limegreen, n3 [fillcolor=limegreen,
height=0.5, height=0.5,
label="name=z TensorType(float64, scalar)", label="name=y TensorType(float32, scalar)",
pos="1340,194", pos="593,298",
shape=box,
style=filled,
width=3.0625];
n3 -> n1 [label="1 TensorType(float32, scalar)",
lp="648.5,254",
pos="e,537.71,228.08 579.04,279.6 568.96,267.04 555.22,249.91 543.98,235.91"];
n4 [fillcolor=limegreen,
height=0.5,
label="name=z TensorType(float32, scalar)",
pos="110,298",
shape=box, shape=box,
style=filled, style=filled,
width=3.0556]; width=3.0556];
_6 -> _5 [label="1 TensorType(float64, scalar)", n4 -> n1 [label="2 TensorType(float32, scalar)",
lp="1364.5,150", lp="281.5,254",
pos="e,1202.1,121.95 1313.3,175.88 1296.2,165.33 1273.3,151.95 1252,142 1239.2,136.01 1225.1,130.36 1211.7,125.42"]; pos="e,355.01,222.75 133.36,279.81 150.39,268.22 174.5,253.68 198,246 226.06,236.82 284.9,229.34 344.97,223.68"];
n4 -> n6 [label="1 TensorType(float32, scalar)",
lp="192.5,210",
pos="e,173.05,138.3 105.03,279.8 99.747,257.95 94.027,219.76 109,192 120.82,170.09 142.96,154.01 163.88,142.9"];
n7 [fillcolor=dodgerblue,
height=0.5,
label="TensorType(float32, scalar) id=4",
pos="214,34",
shape=box,
style=filled,
width=2.7847];
n6 -> n7 [label="TensorType(float32, scalar)",
lp="292,78",
pos="e,214,52.084 214,103.6 214,91.746 214,75.817 214,62.292"];
} }
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var path = 'index.dot' var path = 'index.dot';
var dotGraph; var dotGraph;
var graph = {}; var graph = {};
var nodes = []; var nodes = [];
...@@ -85,13 +85,6 @@ ...@@ -85,13 +85,6 @@
.attr("d", "M0,0 L4,2 L0,4 Z") .attr("d", "M0,0 L4,2 L0,4 Z")
.attr('fill', function(d) { return d.color;}); .attr('fill', function(d) { return d.color;});
d3.text(path, function(data) {
dotGraph = graphlibDot.read(data);
processDotGraph(dotGraph);
graph = forceGraph(dotGraph);
setupGraph();
});
// Zoom behaviour // Zoom behaviour
function zoom(d) { function zoom(d) {
var trans = d3.event.translate; var trans = d3.event.translate;
...@@ -107,6 +100,18 @@ ...@@ -107,6 +100,18 @@
bZoom.event(svg); bZoom.event(svg);
svg.on("dblclick.zoom", null); svg.on("dblclick.zoom", null);
var curve = d3.svg.line()
.interpolate("cardinal-closed")
.tension(.85);
// Read and initialize graph
d3.text(path, function(data) {
dotGraph = graphlibDot.read(data);
processDotGraph(dotGraph);
graph = forceGraph(dotGraph);
setupGraph();
});
</script> </script>
</body> </body>
</html> </html>
...@@ -56,18 +56,33 @@ class GraphFormatter(object): ...@@ -56,18 +56,33 @@ class GraphFormatter(object):
'unused': 'lightgrey' 'unused': 'lightgrey'
} }
self.max_label_size = 70 self.max_label_size = 70
self.node_prefix = 'n'
def get_node_id(self): def add_node(self, node):
self.nnodes += 1 assert not node in self.nodes
id_ = '_%d' % (self.nnodes) _id = '%s%d' % (self.node_prefix, len(self.nodes) + 1)
return id_ self.nodes[node] = _id
return _id
def to_pydot(self, fct): def node_id(self, node):
if node in self.nodes:
return self.nodes[node]
else:
return self.add_node(node)
def to_pydot(self, fct, graph=None):
"""Create pydot graph from function. """Create pydot graph from function.
:param fct: a compiled Theano function, a Variable, an Apply or :param fct: a compiled Theano function, a Variable, an Apply or
a list of Variable. a list of Variable.
""" """
if graph is None:
graph = pd.Dot()
self.nodes = {}
self.var_str = {}
self.all_strings = set()
self.apply_name_cache = {}
if isinstance(fct, Function): if isinstance(fct, Function):
mode = fct.maker.mode mode = fct.maker.mode
...@@ -99,13 +114,6 @@ class GraphFormatter(object): ...@@ -99,13 +114,6 @@ class GraphFormatter(object):
raise RuntimeError("Failed to import pydot. You must install pydot" raise RuntimeError("Failed to import pydot. You must install pydot"
" for `pydotprint` to work.") " for `pydotprint` to work.")
g = pd.Dot()
self.var_str = {}
self.all_strings = set()
self.apply_name_cache = {}
self.nnodes = 0
# Update the inputs that have an update function # Update the inputs that have an update function
self.input_update = {} self.input_update = {}
...@@ -119,15 +127,9 @@ class GraphFormatter(object): ...@@ -119,15 +127,9 @@ class GraphFormatter(object):
apply_shape = 'ellipse' apply_shape = 'ellipse'
var_shape = 'box' var_shape = 'box'
for node_idx, node in enumerate(topo): for node in topo:
aid, astr, aprof = self.apply_name(node, fct, topo, mode, profile) node_id = self.node_id(node)
is_opfrom = isinstance(node.op, builders.OpFromGraph) astr, aprof = self.apply_name(node, fct, topo, mode, profile)
if is_opfrom:
parent = pd.Cluster(aid, label=astr)
g.add_subgraph(parent)
else:
parent = g
use_color = None use_color = None
for opName, color in self.colorCodes.items(): for opName, color in self.colorCodes.items():
...@@ -135,62 +137,91 @@ class GraphFormatter(object): ...@@ -135,62 +137,91 @@ class GraphFormatter(object):
use_color = color use_color = color
if use_color is None: if use_color is None:
nw_node = pd.Node(aid, label=astr, shape=apply_shape, profile=aprof) pd_node = pd.Node(node_id, label=astr, shape=apply_shape, profile=aprof)
else: else:
nw_node = pd.Node(aid, label=astr, style='filled', fillcolor=use_color, pd_node = pd.Node(node_id, label=astr, style='filled', fillcolor=use_color,
shape=apply_shape, type='colored', profile=aprof) shape=apply_shape, type='colored', profile=aprof)
g.add_node(nw_node) graph.add_node(pd_node)
def make_node(label, **kwargs): def make_node(_id, label, **kwargs):
t = {k:v for k,v in kwargs.items() if v is not None} t = {k:v for k,v in kwargs.items() if v is not None}
return pd.Node(self.get_node_id(), label=label, **t) return pd.Node(_id, label=label, **t)
for id, var in enumerate(node.inputs): for id, var in enumerate(node.inputs):
param = {} edge_params = {}
if hasattr(node.op, 'view_map') and id in reduce( if hasattr(node.op, 'view_map') and id in reduce(list.__add__, node.op.view_map.values(), []):
list.__add__, node.op.view_map.values(), []): edge_params['color'] = self.node_colors['output']
param['color'] = self.node_colors['output']
elif hasattr(node.op, 'destroy_map') and id in reduce( elif hasattr(node.op, 'destroy_map') and id in reduce(
list.__add__, node.op.destroy_map.values(), []): list.__add__, node.op.destroy_map.values(), []):
param['color'] = 'red' edge_params['color'] = 'red'
edge_label = str(var.type) edge_label = str(var.type)
if len(node.inputs) > 1: if len(node.inputs) > 1:
edge_label = str(id) + ' ' + edge_label edge_label = str(id) + ' ' + edge_label
var_id = self.node_id(var.owner if var.owner else var)
if var.owner is None: if var.owner is None:
id_ = self.var_name(var) var_name = self.var_name(var)
n = make_node(id_, style='filled', n = make_node(var_id, var_name, style='filled',
fillcolor=self.node_colors['input'], fillcolor=self.node_colors['input'],
shape=var_shape, profile=aprof) shape=var_shape, profile=aprof)
parent.add_node(n) graph.add_node(n)
if not is_opfrom:
g.add_edge(pd.Edge(n.get_name(), aid, label=edge_label, **param)) graph.add_edge(pd.Edge(var_id, node_id, label=edge_label, **edge_params))
elif not is_opfrom:
id_, name, prof = self.apply_name(var.owner, fct, topo, mode, profile)
g.add_edge(pd.Edge(id_, aid,
label=edge_label, **param))
for id, var in enumerate(node.outputs): for id, var in enumerate(node.outputs):
varstr = self.var_name(var) var_id = self.node_id(var)
var_name = self.var_name(var)
edge_label = str(var.type) edge_label = str(var.type)
if var in outputs: if var in outputs:
n = make_node(varstr, style='filled', n = make_node(var_id, var_name, style='filled',
fillcolor=self.node_colors['output'], fillcolor=self.node_colors['output'],
shape=var_shape, profile=aprof) shape=var_shape, profile=aprof)
g.add_node(n) graph.add_node(n)
g.add_edge(pd.Edge(aid, n.get_name(), label=edge_label)) graph.add_edge(pd.Edge(node_id, var_id, label=edge_label))
elif len(var.clients) == 0: elif len(var.clients) == 0:
n = make_node(varstr, style='filled', n = make_node(var_id, var_name, style='filled',
fillcolor=self.node_colors['unused'], fillcolor=self.node_colors['unused'],
shape=var_shape, profile=aprof) shape=var_shape, profile=aprof)
g.add_node(n) graph.add_node(n)
g.add_edge(pd.Edge(aid, n.get_name(), label=edge_label)) graph.add_edge(pd.Edge(node_id, var_id, label=edge_label))
elif var.name or not self.compact: elif var.name or not self.compact:
id_, name, prof = self.apply_name(var.owner, fct, topo, mode, profile) graph.add_edge(pd.Edge(node_id, var_id, label=edge_label))
g.add_edge(pd.Edge(aid, id_, label=edge_label))
if isinstance(node.op, builders.OpFromGraph):
return g subgraph = pd.Cluster(node_id)
gf = GraphFormatter()
gf.node_prefix = node_id
gf.to_pydot(node.op.fn, subgraph)
graph.add_subgraph(subgraph)
pd_node.get_attributes()['subg'] = subgraph.get_name()
def format_map(m):
return str([list(x) for x in m])
# Inputs mapping
ext_inputs = [self.node_id(x) for x in node.inputs]
int_inputs = [gf.node_id(x) for x in node.op.fn.maker.fgraph.inputs]
assert len(ext_inputs) == len(int_inputs)
h = format_map(zip(ext_inputs, int_inputs))
pd_node.get_attributes()['subg_map_inputs'] = h
# Outputs mapping
ext_outputs = []
for n in topo:
for i in n.inputs:
h = i.owner if i.owner else i
if h is node:
ext_outputs.append(self.node_id(n))
int_outputs = node.op.fn.maker.fgraph.outputs
int_outputs = [gf.node_id(x) for x in int_outputs]
assert len(ext_outputs) == len(int_outputs)
h = format_map(zip(int_outputs, ext_outputs))
pd_node.get_attributes()['subg_map_outputs'] = h
return graph
...@@ -272,6 +303,6 @@ class GraphFormatter(object): ...@@ -272,6 +303,6 @@ class GraphFormatter(object):
suffix) suffix)
self.all_strings.add(applystr) self.all_strings.add(applystr)
rv = (self.get_node_id(), applystr, prof) rv = (applystr, prof)
self.apply_name_cache[node] = rv self.apply_name_cache[node] = rv
return rv return rv
...@@ -82,4 +82,9 @@ svg { ...@@ -82,4 +82,9 @@ svg {
border: 1px solid black; border: 1px solid black;
border-radius: 8px; border-radius: 8px;
pointer-events: none; pointer-events: none;
} }
\ No newline at end of file
path.hull {
fill: lightsteelblue;
fill-opacity: 0.3;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论