# Rendering produces varying and frequently wrong results

**URL:** <https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656>\
**Category:** Help\
**Created:** [May 16, 2021, 1:51pm UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656 "2021-05-16T13:51:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tillmann](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/tillmann/32/379_2.png) [@tillmann](https://forum.graphviz.org/u/tillmann)\
**Post date:** [May 16, 2021, 1:51pm UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/1 "2021-05-16T13:51:28Z")

</div>

Hello Graphviz team,

experimenting with a diagram definition containing 3 subgraphs of type “cluster”, I found that the result of rendering it varies almost with every invocation and often doesn’t include one of the subgraphs.

The definition is

```
digraph R {
	node [shape=record style=rounded]
	layout=dot;
	splines=true;
	
	subgraph cluster_flow1 {
		label="first flow" style="filled" color="lightgreen"
		0
	} 
	
	subgraph cluster_flow2 {
		label="second flow" style="filled" color="azure"
		1
		2
		t[shape=ellipse label="'First task'"];
		0->1
		1->t
		1->2:n
	}

	subgraph cluster_flow3 {
		label="third flow" style="filled" color="azure"
		5
		6
		0->5
		5->6:n
		6->6
	}
}

```

The command that I use to produce an image (I tried PNG and SVG) is:

```
dot -Tpng -O erratic-layout.gv

```

The results vary almost call by call.

The subgraph with ID “cluster\_flow1” is shown correctly at times:  
 ![erratic-layout.gv-a](https://global.discourse-cdn.com/graphviz/original/1X/bfd1cba826be3ca11a176c5905cb8d6121cac71a.png)

But often it is missing, and the node “0” (which is declared in that subgraph) appears in subgraph “cluster\_flow2” instead.  
In addition, the horizontal positions of “cluster\_flow2” and “cluster\_flow3” are exchanged at times.

I’m using version 2.47.1 (20210417.1919) on Windows 10 (64 bit) at the command-line.

Do I have a mistake in my definition file or did I stumble over a known (or unknown) bug?

Regards,  
Tillmann

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [May 16, 2021, 3:43pm UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/2 "2021-05-16T15:43:36Z")

</div>

Curious, on my Linux system, two versions of **dot** consistently give the “correct” answer

- dot - graphviz version 2.47.2~dev.20210515.1947 (20210515.1947)
- dot - graphviz version 2.43.0 (0)

---

<div class="post-metadata">

**Author:** ![tillmann](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/tillmann/32/379_2.png) [@tillmann](https://forum.graphviz.org/u/tillmann)\
**Post date:** [May 16, 2021, 7:40pm UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/3 "2021-05-16T19:40:47Z")

</div>

I tried the same code on [http://webgraphviz.com](http://webgraphviz.com), this also produced the correct result consistently.

---

<div class="post-metadata">

**Author:** ![schmoo2k](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/schmoo2k/32/29_2.png) [@schmoo2k](https://forum.graphviz.org/u/schmoo2k)\
**Post date:** [May 17, 2021, 6:30am UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/4 "2021-05-17T06:30:25Z")

</div>

I can reproduce it in the latest wasm version (GraphViz 2.47.1) - you can see it here:  
[Possible Issue / Gordon Smith / Observable (observablehq.com)](https://observablehq.com/@gordonsmith/possible-issue)

(Click the “play” button in the top right hand corner of the DOT text)

---

<div class="post-metadata">

**Author:** ![schmoo2k](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/schmoo2k/32/29_2.png) [@schmoo2k](https://forum.graphviz.org/u/schmoo2k)\
**Post date:** [May 17, 2021, 6:32am UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/5 "2021-05-17T06:32:54Z")

</div>

The “workaround” is to move the 0 → 1 and 0 → 5 edges out of the subgraphs…

---

<div class="post-metadata">

**Author:** ![tillmann](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/tillmann/32/379_2.png) [@tillmann](https://forum.graphviz.org/u/tillmann)\
**Post date:** [May 17, 2021, 10:32am UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/6 "2021-05-17T10:32:22Z")

</div>

Hello schmoo2k,  
do you think the problem hinges on the specific value 0 of the edge sources or  
is it _generally_ a good idea to make _edge definitions outside the subgraph blocks?_

---

<div class="post-metadata">

**Author:** ![schmoo2k](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/schmoo2k/32/29_2.png) [@schmoo2k](https://forum.graphviz.org/u/schmoo2k)\
**Post date:** [May 17, 2021, 10:40am UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/7 "2021-05-17T10:40:41Z")

</div>

I have always put my edges at what I would consider a logical scope (IOW 0-\>1 doesn’t belong inside the second subgraph because “0” is not in that subgraph).  
I am not saying this is correct behaviour, just its the way I felt was “correct” and it stood out when I looked at it, which is how I stumbled onto the workaround…

---

<div class="post-metadata">

**Author:** ![schmoo2k](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/schmoo2k/32/29_2.png) [@schmoo2k](https://forum.graphviz.org/u/schmoo2k)\
**Post date:** [May 17, 2021, 10:43am UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/8 "2021-05-17T10:43:31Z")

</div>

No simply changing “0” to “10” in your example has the same issue.

---

<div class="post-metadata">

**Author:** ![erg](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/erg/32/34_2.png) [@erg](https://forum.graphviz.org/u/erg)\
**Post date:** [May 20, 2021, 8:28pm UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/9 "2021-05-20T20:28:23Z")

</div>

The original graph description exposes a known problem in dot. As the documentation notes:

> If an edge belongs to a cluster, its endpoints belong to that cluster. Thus, where you put an edge can effect a layout, as clusters are sometimes laid out recursively.

Unfortunately, dot does not allow a node to be in multiple clusters, which can cause problems, such as a cluster disappearing, depending on which cluster dot chooses to place the node in. The dot program warns about this in some cases but it doesn’t check that every node only occurs in a single cluster. Barring adding such a check, the above note should probably be made stronger.

In any case, the suggested workaround is the correct fix: The two edges should be moved out of the clusters.

---

<div class="post-metadata">

**Author:** ![tillmann](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/tillmann/32/379_2.png) [@tillmann](https://forum.graphviz.org/u/tillmann)\
**Post date:** [May 21, 2021, 6:56am UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/10 "2021-05-21T06:56:18Z")

</div>

Thank you erg and schmoo2k,

unfortunately, I cannot mark two answers as solution. I chose schmoo2k’s as his was the first to put me on the right track, though yours, erg, definitely adds to my understanding - please share the credits!

---

<div class="post-metadata">

**Author:** ![Vithanco](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/vithanco/32/292_2.png) [@Vithanco](https://forum.graphviz.org/u/Vithanco)\
**Post date:** [May 23, 2021, 8:32am UTC](https://forum.graphviz.org/t/rendering-produces-varying-and-frequently-wrong-results/656/11 "2021-05-23T08:32:56Z")

</div>

Sounds like we should implement a checker that creates warnings in these cases. I don’t want to think how many people gave up on Graphviz because they didn’t ask here.
