directed_heavy_square_graph(d, bidirectional=False, multigraph=True)#

Generate an directed heavy square graph.

Fig. 6 of An ASCII diagram of the graph is given by:

...       S   ...
   \     / \
   ... D   D   D ...
       |   |   |
   ... F-S-F-S-F-...
       |   |   |
   ... D   D   D ...
       |   |   |
   ... F-S-F-S-F-...
       |   |   |
       |   |   |
   ... D   D   D ...
        \ /     \
   ...   S       ...


This function generates the four-frequency variant of the heavy square code. This function implements Fig 10.b left of the paper. This function doesn’t support the variant Fig 10.b right.

  • d (int) – distance of the code. If d is set to 1 a PyDiGraph with a single node will be returned. d must be an odd number.

  • bidirectional – A parameter to indicate if edges should exist in both directions between nodes. Defaults to False.

  • multigraph (bool) – When set to False the output PyDiGraph object will not be not be a multigraph and won’t allow parallel edges to be added. Instead calls which would create a parallel edge will update the existing edge.


The generated directed heavy square graph

Return type:



IndexError – If d is even.

import rustworkx.generators
from rustworkx.visualization import graphviz_draw

graph = rustworkx.generators.directed_heavy_square_graph(3)
graphviz_draw(graph, lambda node: dict(
        color='black', fillcolor='lightblue', style='filled'))