When a processor contains nested circuits (created with the merge=False argument passed to add), the blue box enclosing each subblock is of the wrong size.
The reason is that the drawing of elements stops at one level of recursion, whereas the get_size call goes to the full depth.
By changing some of the merge=False arguments to True, one can get circuits with various degrees of nesting. In all the following examples, the size of the blue circuit box is the same, and corresponds to the size of the fully flattened circuit.
In ICircuitRenderer.render_circuit, the call to self.get_circuit_size(c, recursive=True) is the culprit since it will always return the same value, (9, 4), corresponding to the size of a completely flattened circuit.
Possible fixes:
Add a recursion_level parameter to all functions recursively traversing circuits (flatten, get_size, get_circuit_size, render_circuit, pdisplay_processor, pdisplay_circuit...), and make sure they consistently traverse the circuit graph at the appropriate depth.
Assume that one should never draw anything deeper than one level of recursion, and thus set recursive=False in the function call retrieving the size of a block. A similar change has to be done to the herald positioning code (it should flatten only one level deep to attach the heralds to the elements that are actually going to be drawn).
Assume that setting recursive=True should always go to the full recursion depth, at the risk of getting large diagrams. Thus render_circuit should pass its recursive argument when calling itself.
When a processor contains nested circuits (created with the
merge=False
argument passed toadd
), the blue box enclosing each subblock is of the wrong size.The reason is that the drawing of elements stops at one level of recursion, whereas the
get_size
call goes to the full depth.This is a circuit from a tutorial:
By changing some of the
merge=False
arguments toTrue
, one can get circuits with various degrees of nesting. In all the following examples, the size of the blue circuit box is the same, and corresponds to the size of the fully flattened circuit.In
ICircuitRenderer.render_circuit
, the call toself.get_circuit_size(c, recursive=True)
is the culprit since it will always return the same value,(9, 4)
, corresponding to the size of a completely flattened circuit.Possible fixes:
recursion_level
parameter to all functions recursively traversing circuits (flatten
,get_size
,get_circuit_size
,render_circuit
,pdisplay_processor
,pdisplay_circuit
...), and make sure they consistently traverse the circuit graph at the appropriate depth.recursive=False
in the function call retrieving the size of a block. A similar change has to be done to the herald positioning code (it shouldflatten
only one level deep to attach the heralds to the elements that are actually going to be drawn).recursive=True
should always go to the full recursion depth, at the risk of getting large diagrams. Thusrender_circuit
should pass itsrecursive
argument when calling itself.