:py:mod:`cotengra.plot` ======================= .. py:module:: cotengra.plot .. autoapi-nested-parse:: Hypergraph, optimizer, and contraction tree visualization tools. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: cotengra.plot.show_and_close cotengra.plot.use_neutral_style cotengra.plot.plot_trials_alt cotengra.plot.plot_scatter cotengra.plot.plot_trials cotengra.plot.plot_scatter_alt cotengra.plot.tree_to_networkx cotengra.plot.hypergraph_compute_plot_info_G cotengra.plot.rotate cotengra.plot.span cotengra.plot.massage_pos cotengra.plot.layout_pygraphviz cotengra.plot.get_nice_pos cotengra.plot.plot_tree cotengra.plot.plot_tree_ring cotengra.plot.plot_tree_tent cotengra.plot.plot_tree_span cotengra.plot.tree_to_df cotengra.plot.plot_contractions cotengra.plot.plot_contractions_alt cotengra.plot.slicefinder_to_df cotengra.plot.plot_slicings cotengra.plot.plot_slicings_alt cotengra.plot.plot_hypergraph cotengra.plot.plot_tree_rubberband cotengra.plot.plot_tree_flat cotengra.plot.plot_tree_circuit Attributes ~~~~~~~~~~ .. autoapisummary:: cotengra.plot.NEUTRAL_STYLE cotengra.plot._scatter_labels cotengra.plot.HAS_FA2 cotengra.plot.HAS_PYGRAPHVIZ .. py:function:: show_and_close(fn) .. py:data:: NEUTRAL_STYLE .. py:function:: use_neutral_style(fn) .. py:function:: plot_trials_alt(self, y=None, width=800, height=300) Plot the trials interactively using altair. .. py:data:: _scatter_labels .. py:function:: plot_scatter(self, x='size', y='flops', cumulative_time=False, plot_best=False, figsize=(5, 5)) .. py:function:: plot_trials(self, *, x='trial', y='score', figsize=(8, 3), cumulative_time=True, plot_best=True, **kwargs) .. py:function:: plot_scatter_alt(self, x='size', y='flops', color='run:Q', color_scheme='purplebluegreen', shape='method:N', width=400, height=400) Plot the trials total flops vs max size. .. py:function:: tree_to_networkx(tree) .. py:function:: hypergraph_compute_plot_info_G(H, G, highlight=(), node_color=(0.5, 0.5, 0.5, 1.0), edge_color=(0.0, 0.0, 0.0), edge_alpha=1 / 3, colormap='Spectral_r', centrality=False, sliced_inds=(), edge_style='-', hyperedge_style='--', sliced_style=':') Imbue the networkx representation, ``G``, of hypergraph, ``H`` with relevant plot information as node and edge attributes. .. py:function:: rotate(xy, theta) Return a rotated set of points. .. py:function:: span(xy) Return the vertical span of the points. .. py:function:: massage_pos(pos, nangles=100, flatten=False) Rotate a position dict's points to cover a small vertical span .. py:function:: layout_pygraphviz(G, prog='neato', dim=2, **kwargs) .. py:data:: HAS_FA2 .. py:data:: HAS_PYGRAPHVIZ .. py:function:: get_nice_pos(G, *, dim=2, layout='auto', initial_layout='auto', iterations='auto', k=None, use_forceatlas2=False, flatten=False) .. py:function:: plot_tree(tree, layout='ring', hypergraph_layout='auto', hypergraph_layout_opts=None, k=0.01, iterations=500, span=None, order=None, order_y_pow=1.0, edge_scale=1.0, node_scale=1.0, highlight=(), edge_color='size', edge_colormap='GnBu', edge_max_width=None, node_colormap='YlOrRd', node_color='flops', node_max_size=None, figsize=(5, 5), raw_edge_color=None, raw_edge_alpha=None, tree_root_height=True, tree_alpha=0.8, colorbars=True, plot_raw_graph=True, plot_leaf_labels=False, ax=None) Plot a contraction tree using matplotlib. .. py:function:: plot_tree_ring(tree, **kwargs) .. py:function:: plot_tree_tent(tree, **kwargs) .. py:function:: plot_tree_span(tree, **kwargs) .. py:function:: tree_to_df(tree) .. py:function:: plot_contractions(tree, order=None, color_size=(0.6, 0.4, 0.7), color_cost=(0.3, 0.7, 0.5), figsize=(8, 3)) .. py:function:: plot_contractions_alt(tree, x='peak-size', y='flops', color='stage', size='scaling', width=400, height=400, point_opacity=0.8, color_scheme='lightmulti', x_scale='log', y_scale='log', color_scale='log', size_scale='linear') .. py:function:: slicefinder_to_df(slice_finder, relative_flops=False) .. py:function:: plot_slicings(slice_finder, color_scheme='RdYlBu_r', relative_flops=False, figsize=(6, 3), point_opacity=0.8) .. py:function:: plot_slicings_alt(slice_finder, color_scheme='redyellowblue', relative_flops=False) .. py:function:: plot_hypergraph(H, *, edge_color=True, node_color=True, highlight=(), centrality='simple', colormap='plasma', pos=None, dim=2, layout='auto', initial_layout='auto', iterations='auto', k=None, use_forceatlas2=False, flatten=False, node_size=None, node_scale=1.0, edge_alpha=1 / 3, edge_style='solid', hyperedge_style='dashed', draw_edge_labels=None, fontcolor=(0.5, 0.5, 0.5), edge_labels_font_size=8, edge_labels_font_family='monospace', node_labels_font_size=10, node_labels_font_family='monospace', info=None, ax=None, figsize=(5, 5)) .. py:function:: plot_tree_rubberband(tree, order=None, colormap='Spectral', with_edge_labels=None, with_node_labels=None, highlight=(), centrality=False, layout='auto', node_size=None, node_color=(0.5, 0.5, 0.5, 1.0), edge_color=(0.5, 0.5, 0.5), edge_alpha=1 / 3, edge_style='solid', hyperedge_style='dashed', draw_edge_labels=None, edge_labels_font_size=8, edge_labels_font_family='monospace', iterations=500, ax=None, figsize=(5, 5)) Plot a ``ContractionTree`` using 'rubberbands' to represent intermediate contractions / subgraphs. This can be intuitive for small and / or planar contractions. .. py:function:: plot_tree_flat(tree, edge_color=True, leaf_color=True, node_color=(0.5, 0.5, 0.5, 0.5), hyperedge_style='dashed', multiedge_spread=0.05, multiedge_smoothing=0.5, multiedge_midlength=0.5, fontcolor=(0.5, 0.5, 0.5), edge_labels_font_size=6, edge_labels_font_family='monospace', node_labels_font_size=8, node_labels_font_family='monospace', show_sliced=True, figsize=None) Plot a ``ContractionTree`` as a flat, 2D diagram, including all indices at every intermediate contraction. This can be useful for small contractions, and does not require any graph layout algorithm. :param tree: The contraction tree to plot. :type tree: ContractionTree :param edge_color: Whether to color the edges, or a specific color to use. If ``True`` (default), each edge will be colored according to a hash of its index. :type edge_color: bool or color, optional :param leaf_color: Whether to color the input nodes, or a specific color to use. If ``True`` (default), each leaf node will be colored with an automatically generated sequence according to its linear position in the input. :type leaf_color: bool or color, optional :param node_color: Whether to color the intermediate nodes, or a specific color to use. If ``True`` (default), each intermediate node will be colored with the average color of its children. :type node_color: bool or color, optional :param hyperedge_style: The linestyle to use for hyperedges, i.e. indices that don't appeary exactly twice on either inputs or the output. :type hyperedge_style: str, optional :param multiedge_spread: The spread of multi-edges between nodes. :type multiedge_spread: float, optional :param multiedge_smoothing: The smoothing of multi-edges between nodes. :type multiedge_smoothing: float, optional :param multiedge_midlength: The midlength of multi-edges between nodes. :type multiedge_midlength: float, optional :param fontcolor: The color to use for edge and node labels. :type fontcolor: color, optional :param edge_labels_font_size: The font size to use for edge labels. :type edge_labels_font_size: int, optional :param edge_labels_font_family: The font family to use for edge labels. :type edge_labels_font_family: str, optional :param node_labels_font_size: The font size to use for node labels. :type node_labels_font_size: int, optional :param node_labels_font_family: The font family to use for node labels. :type node_labels_font_family: str, optional :param show_sliced: Whether to list sliced indices at the top left. :type show_sliced: bool, optional :param figsize: The size of the figure to create, if not specified will be based on the number of nodes in the tree. :type figsize: tuple, optional :returns: * **fig** (*matplotlib.figure.Figure*) -- The figure containing the plot. * **ax** (*matplotlib.axes.Axes*) -- The axes containing the plot. .. py:function:: plot_tree_circuit(tree, edge_colormap='GnBu', edge_max_width=None, node_colormap='YlOrRd', node_max_size=None, figsize=None)