Note
Go to the end to download the full example code.
10. Inspecting circuit size¶
Model counts describe a function’s solutions. Nodes and pairs describe the stored circuit. We can inspect that storage to locate the node with the largest number of alternatives.
node_sizes() returns a snapshot of the stored internal nodes as
(vtree_node, local_node, pair_count) tuples. The snapshot does not borrow
native storage, so it stays readable after the circuit is consumed.
def widest_node(circuit):
return max(circuit.node_sizes(), key=lambda node: node[2], default=None)
level, node, pairs = widest_node(exclusive)
print(f"Widest XOR node: {pairs} pairs at vtree node {level}")
Widest XOR node: 2 pairs at vtree node 4
A Python vtree is a home: each circuit stores levels only for the variables
it uses. A literal is decided by its variable’s leaf alone, so it stores no
internal node and widest_node returns None.
Widest literal node: None
Total XOR pairs: 2
Satisfying assignments: 8
Storage identifiers belong to this particular diagram and can change after
a transformation. Use semantic queries such as equivalent() to compare
functions. For a visual inspection, to_dot() exports a Graphviz graph.