Search code examples
pnggraphviz

Why graphviz/dot does not generate the exact same binary when using the exact same input


I'm generating a graph png file from this input architecture.graph.txt:

digraph GG { node [ fontsize="12"];
compound=true;
 subgraph cluster_general_purpose_utilities {
    label="general purpose utilities";
    "dummy_general purpose utilities" [shape=ellipse];
  }
 subgraph cluster_foo_bar_libraries {
    label="foo_bar libraries";
    "dummy_foo_bar libraries" [shape=ellipse];
  }
 subgraph cluster_foo_bar_programs {
    label="foo_bar programs";
    "dummy_foo_bar programs" [shape=diamond, fillcolor=yellow];
  }
 "dummy_foo_bar libraries" -> "dummy_general purpose utilities" [style=solid, lhead="cluster_general_purpose_utilities", ltail="cluster_foo_bar_libraries"] ;
 "dummy_foo_bar programs" -> "dummy_general purpose utilities" [style=solid, lhead="cluster_general_purpose_utilities", ltail="cluster_foo_bar_programs"] ;
 "dummy_foo_bar programs" -> "dummy_foo_bar libraries" [style=solid, lhead="cluster_foo_bar_libraries", ltail="cluster_foo_bar_programs"] ;
}

I ran dot.exe -Tpng architecture.graph.txt -o architecture.graph.1.png and dot.exe -Tpng architecture.graph.txt -o architecture.graph.2.png in a row, and I end up with two different binaries. Images look the same if I open them in an image viewer, however, when I compare the binaries, they are completely different, even the file sizes are different (architecture.graph.1.png size is 19435 bytes and architecture.graph.2.png size is 19444 bytes).

Note: If you try to reproduce, do this several times, sometimes the outputs are identical, sometimes they are not...it's not reproductible.

It's a problem because this processus is part of non regression tests that checks some outputs against golden files, and it fails because the files are different....even if the actual image is the same as far as I can see.

Is there any random behaviour in this tool? Why are the files different.

I'm using graphviz 2.43 (sorry, that's very old...) under Windows.

architecture.graph.1.png: architecture.graph.1.png

architecture.graph.2.png: architecture.graph.2.png


svg files are also different. The order of creation of "clust1", "clust2" and "clust3" is different and also some sizes/positions change.

architecture.graph.1.svg:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.43.20200408.0903 (20200408.0903)
 -->
<!-- Title: GG Pages: 1 -->
<svg width="278pt" height="265pt"
 viewBox="0.00 0.00 278.00 265.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 261)">
<title>GG</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-261 274,-261 274,4 -4,4"/>
<g id="clust3" class="cluster">
<title>cluster_foo_bar_programs</title>
<polygon fill="none" stroke="black" points="8,-174 8,-249 262,-249 262,-174 8,-174"/>
<text text-anchor="middle" x="135" y="-233.8" font-family="Times New Roman,serif" font-size="14.00">foo_bar programs</text>
</g>
<g id="clust2" class="cluster">
<title>cluster_foo_bar_libraries</title>
<polygon fill="none" stroke="black" points="57,-91 57,-166 233,-166 233,-91 57,-91"/>
<text text-anchor="middle" x="145" y="-150.8" font-family="Times New Roman,serif" font-size="14.00">foo_bar libraries</text>
</g>
<g id="clust1" class="cluster">
<title>cluster_general_purpose_utilities</title>
<polygon fill="none" stroke="black" points="23,-8 23,-83 237,-83 237,-8 23,-8"/>
<text text-anchor="middle" x="130" y="-67.8" font-family="Times New Roman,serif" font-size="14.00">general purpose utilities</text>
</g>
<!-- dummy_general purpose utilities -->
<g id="node1" class="node">
<title>dummy_general purpose utilities</title>
<ellipse fill="none" stroke="black" cx="130" cy="-34" rx="99.22" ry="18"/>
<text text-anchor="middle" x="130" y="-30.9" font-family="Times New Roman,serif" font-size="12.00">dummy_general purpose utilities</text>
</g>
<!-- dummy_foo_bar libraries -->
<g id="node2" class="node">
<title>dummy_foo_bar libraries</title>
<ellipse fill="none" stroke="black" cx="145" cy="-117" rx="80.05" ry="18"/>
<text text-anchor="middle" x="145" y="-113.9" font-family="Times New Roman,serif" font-size="12.00">dummy_foo_bar libraries</text>
</g>
<!-- dummy_foo_bar libraries&#45;&gt;dummy_general purpose utilities -->
<g id="edge1" class="edge">
<title>dummy_foo_bar libraries&#45;&gt;dummy_general purpose utilities</title>
<path fill="none" stroke="black" d="M140.78,-91C140.31,-89 139.83,-87 139.36,-85"/>
<polygon fill="black" stroke="black" points="144.59,-91.93 138.89,-83 137.78,-93.54 144.59,-91.93"/>
</g>
<!-- dummy_foo_bar programs -->
<g id="node3" class="node">
<title>dummy_foo_bar programs</title>
<polygon fill="none" stroke="black" points="135,-218 15.96,-200 135,-182 254.04,-200 135,-218"/>
<text text-anchor="middle" x="135" y="-196.9" font-family="Times New Roman,serif" font-size="12.00">dummy_foo_bar programs</text>
</g>
<!-- dummy_foo_bar programs&#45;&gt;dummy_general purpose utilities -->
<g id="edge2" class="edge">
<title>dummy_foo_bar programs&#45;&gt;dummy_general purpose utilities</title>
<path fill="none" stroke="black" d="M59.76,-174C57.25,-171.58 54.97,-168.92 53,-166 35.94,-140.75 37.43,-123.82 53.05,-92.3"/>
<polygon fill="black" stroke="black" points="56.37,-93.49 57.82,-83 50.14,-90.3 56.37,-93.49"/>
</g>
<!-- dummy_foo_bar programs&#45;&gt;dummy_foo_bar libraries -->
<g id="edge3" class="edge">
<title>dummy_foo_bar programs&#45;&gt;dummy_foo_bar libraries</title>
<path fill="none" stroke="black" d="M137.84,-174C138.15,-172 138.46,-170 138.77,-168"/>
<polygon fill="black" stroke="black" points="141.01,-176.41 139.07,-166 134.09,-175.35 141.01,-176.41"/>
</g>
</g>
</svg>

architecture.graph.2.svg:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.43.20200408.0903 (20200408.0903)
 -->
<!-- Title: GG Pages: 1 -->
<svg width="278pt" height="265pt"
 viewBox="0.00 0.00 278.00 265.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 261)">
<title>GG</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-261 274,-261 274,4 -4,4"/>
<g id="clust2" class="cluster">
<title>cluster_foo_bar_libraries</title>
<polygon fill="none" stroke="black" points="62,-91 62,-166 238,-166 238,-91 62,-91"/>
<text text-anchor="middle" x="150" y="-150.8" font-family="Times New Roman,serif" font-size="14.00">foo_bar libraries</text>
</g>
<g id="clust3" class="cluster">
<title>cluster_foo_bar_programs</title>
<polygon fill="none" stroke="black" points="8,-174 8,-249 262,-249 262,-174 8,-174"/>
<text text-anchor="middle" x="135" y="-233.8" font-family="Times New Roman,serif" font-size="14.00">foo_bar programs</text>
</g>
<g id="clust1" class="cluster">
<title>cluster_general_purpose_utilities</title>
<polygon fill="none" stroke="black" points="33,-8 33,-83 247,-83 247,-8 33,-8"/>
<text text-anchor="middle" x="140" y="-67.8" font-family="Times New Roman,serif" font-size="14.00">general purpose utilities</text>
</g>
<!-- dummy_general purpose utilities -->
<g id="node1" class="node">
<title>dummy_general purpose utilities</title>
<ellipse fill="none" stroke="black" cx="140" cy="-34" rx="99.22" ry="18"/>
<text text-anchor="middle" x="140" y="-30.9" font-family="Times New Roman,serif" font-size="12.00">dummy_general purpose utilities</text>
</g>
<!-- dummy_foo_bar libraries -->
<g id="node2" class="node">
<title>dummy_foo_bar libraries</title>
<ellipse fill="none" stroke="black" cx="150" cy="-117" rx="80.05" ry="18"/>
<text text-anchor="middle" x="150" y="-113.9" font-family="Times New Roman,serif" font-size="12.00">dummy_foo_bar libraries</text>
</g>
<!-- dummy_foo_bar libraries&#45;&gt;dummy_general purpose utilities -->
<g id="edge1" class="edge">
<title>dummy_foo_bar libraries&#45;&gt;dummy_general purpose utilities</title>
<path fill="none" stroke="black" d="M147.19,-91C146.87,-89 146.56,-87 146.24,-85"/>
<polygon fill="black" stroke="black" points="150.94,-92.33 145.93,-83 144.02,-93.42 150.94,-92.33"/>
</g>
<!-- dummy_foo_bar programs -->
<g id="node3" class="node">
<title>dummy_foo_bar programs</title>
<polygon fill="none" stroke="black" points="135,-218 15.96,-200 135,-182 254.04,-200 135,-218"/>
<text text-anchor="middle" x="135" y="-196.9" font-family="Times New Roman,serif" font-size="12.00">dummy_foo_bar programs</text>
</g>
<!-- dummy_foo_bar programs&#45;&gt;dummy_general purpose utilities -->
<g id="edge2" class="edge">
<title>dummy_foo_bar programs&#45;&gt;dummy_general purpose utilities</title>
<path fill="none" stroke="black" d="M64.64,-174C62.16,-171.58 59.92,-168.92 58,-166 41.16,-140.45 42.12,-123.45 58.29,-91.84"/>
<polygon fill="black" stroke="black" points="61.38,-93.47 62.98,-83 55.2,-90.19 61.38,-93.47"/>
</g>
<!-- dummy_foo_bar programs&#45;&gt;dummy_foo_bar libraries -->
<g id="edge3" class="edge">
<title>dummy_foo_bar programs&#45;&gt;dummy_foo_bar libraries</title>
<path fill="none" stroke="black" d="M139.26,-174C139.73,-172 140.19,-170 140.65,-168"/>
<polygon fill="black" stroke="black" points="142.27,-176.53 141.11,-166 135.45,-174.96 142.27,-176.53"/>
</g>
</g>
</svg>


Solution

  • Seems to be a Windows-only issue. I just ran it 1000 times on a Linux system and got the same checksum 1000 times. Have you tried other output formats (gif, jpeg, svg, ...)?

    Surprisingly, the svg files are very different.
    Best suggestion: install a more recent version of Graphviz (https://www.graphviz.org/download/).

    "Fixes" that might help:

    • dot -Gphase=4
    • dot -Tcanon myfile |dot -Tpng ...
    • dot myfile | neato -n -Tpng ...
    • dot -Gcenter=true ...
    • dot -Gfontname=Courier ...
    • dot -Tpng:cairo: