Utility functions for the hierarqcal package. These are mostly plotting functions.

Usage:

hierq = Qinit(4) + Qcycle(2) + Qmask(pattern="inside") + Qinit(7) + Qpermute() + Qmask(filter="1000001")
# Single motif
fig, ax = plot_motif(hierq.tail)
# Plot all motif
figs = plot_motifs(hierq, all_motifs=True, figsize=(4,4))
hierarqcal.utils.contract(t0, t1, indices)
hierarqcal.utils.get_tensor_as_f(u)
hierarqcal.utils.plot_circuit(hierq, depth=20, cycle_color='#0096ff', mask_color='#ff7e79', permute_colour='#a9449d', init_colour='#92a9bd')
hierarqcal.utils.plot_motif(primitive, cycle_color='#0096ff', mask_color='#ff7e79', permute_colour='#a9449d', init_colour='#92a9bd', pivot_colour='#0096ff', node_large=0.12, node_small=0.08, edge_width=1.5, figsize=(4, 4), font_size=15, color_dict={'during': 'orange', 'end': 'red', 'start': 'green'}, start_angle=0, **kwargs)

Plot a primitive in its directed graph representation

Parameters
  • primitive (Qmotif) – The primitive to plot, such as Qcycle, Qmask or Qpermute.

  • cycle_color (str, optional) – The colour of nodes for cycle motifs. Defaults to “#0096ff”.

  • mask_color (str, optional) – The colour of nodes for masking motifs. Defaults to “#ff7e79”.

  • permute_colour (str, optional) – The colour of nodes for permute motifs. Defaults to “#a9449d”.

  • init_colour (str, optional) – The colour of nodes for init motifs. Defaults to “#92a9bd”.

  • node_large (int, optional) – The size of the nodes for non masked qubits. Defaults to 400.

  • node_small (int, optional) – The size of the nodes for the masked qubits. Defaults to 150.

  • edge_width (float, optional) – The width of the edges. Defaults to 1.5.

  • figsize (tuple, optional) – The size of the figure. Defaults to (4, 4).

  • **kwargs – Additional keyword arguments to pass to the networkx draw function.

Returns

A tuple containing:
  • fig (matplotlib.figure.Figure): The figure object.

  • ax (matplotlib.axes._subplots.AxesSubplot): The axes object.

Return type

(tuple)

hierarqcal.utils.tensor_to_matrix_colmajor(t0, indices)
hierarqcal.utils.tensor_to_matrix_rowmajor(t0, indices)