viznet

Module contents

class viznet.Brush

Bases: object

Base Class of brushes.

class viznet.CLinkBrush(style, ax=None, offsets=(0.2, ), roundness=0, lw=1, color='k', zorder=0, solid_capstyle='butt')

Bases: viznet.brush.EdgeBrush

Brush for C type link.

style

e.g. ‘<->’, right-side grow with respect to the line direction.

Type:str
__init__(style, ax=None, offsets=(0.2, ), roundness=0, lw=1, color='k', zorder=0, solid_capstyle='butt')

Initialize self. See help(type(self)) for accurate signature.

class viznet.CurveBrush(style, ax=None, lw=1, color='k', zorder=0, solid_capstyle='butt', ls='-')

Bases: viznet.brush.Brush

a brush for drawing edges.

style

the style of edge, same as arrowprops in https://matplotlib.org/api/_as_gen/matplotlib.pyplot.annotate.html.

Type:str
ax

matplotlib Axes instance.

Type:Axes
lw

line width.

Type:float
color

the color of painted edge by this brush.

Type:str
__init__(style, ax=None, lw=1, color='k', zorder=0, solid_capstyle='butt', ls='-')

Initialize self. See help(type(self)) for accurate signature.

class viznet.DynamicShow(figsize=(6, 4), filename=None, dpi=300, fps=1)

Bases: object

Dynamic plot context, intended for displaying geometries. like removing axes, equal axis, dynamically tune your figure and save it.

Parameters:
  • figsize (tuple, default=(6,4)) – figure size.
  • filename (filename, str) – filename to store generated figure, if None, it will not save a figure.
figsize

figure size.

Type:tuple, default=(6,4)
filename

filename to store generated figure, if None, it will not save a figure.

Type:filename, str
ax

matplotlib Axes instance.

Type:Axes

Examples

with DynamicShow() as ds:
c = Circle([2, 2], radius=1.0) ds.ax.add_patch(c)
__init__(figsize=(6, 4), filename=None, dpi=300, fps=1)

Initialize self. See help(type(self)) for accurate signature.

class viznet.Edge(objs, start_xy, end_xy, start, end, brush)

Bases: viznet.edgenode.EdgeNode

An Edge connecting two EdgeNode instance.

obj

matplotlib line object.

Type:Patch
start_xy

start position.

Type:tuple
end_xy

end position.

Type:tuple
start

start node.

Type:EdgeNode
end

end node.

Type:EdgeNode
brush

brush.

Type:EdgeBrush
__init__(objs, start_xy, end_xy, start, end, brush)

Initialize self. See help(type(self)) for accurate signature.

ax

get the primary object.

class viznet.EdgeBrush(style, ax=None, lw=1, color='k', zorder=0, solid_capstyle='butt')

Bases: viznet.brush.Brush

a brush for drawing edges.

style

the style of edge, must be a combination of (‘>’|’<’|’-‘|’.’). * ‘>’, right arrow * ‘<’, left arrow, * ‘-‘, line, * ‘.’, dashed line.

Type:str
ax

matplotlib Axes instance.

Type:Axes
lw

line width.

Type:float
color

the color of painted edge by this brush.

Type:str
__init__(style, ax=None, lw=1, color='k', zorder=0, solid_capstyle='butt')

Initialize self. See help(type(self)) for accurate signature.

class viznet.Grid(dxy=(1, 1), ax=None, offset=(0, 0))

Bases: object

Grid for affine transformation.

Parameters:
  • dxy (tuple) – space in x, y directions.
  • ax – matplotlib.pyplot.Axes.
  • offset (tuple) – the global offset.
__init__(dxy=(1, 1), ax=None, offset=(0, 0))

Initialize self. See help(type(self)) for accurate signature.

class viznet.Node(objs, position, brush)

Bases: viznet.edgenode.EdgeNode

A patch with shape and style, defines the allowed connection points, and create pins for connection.

objs

a list matplotlib patch object, with the first the primary object.

Type:list
brush

brush.

Type:NodeBrush
__init__(objs, position, brush)

Initialize self. See help(type(self)) for accurate signature.

ax

get the primary object.

get_connection_point(direction)
Parameters:direction (1darray) – unit vector pointing to target direction.
mass_center

mass center of a node

obj

get the primary object.

pin(direction, align=None)

obtain a pin on specific surface.

Parameters:
  • direction ('top'|'bottom'|'left'|'right'|float) – specifies the surface to place a pin, or theta to specift the direction.
  • align (viznet.EdgeNode|tuple|None, default=None) – align y-axis for ‘left’ and ‘right’ pin, x-axis for ‘top’ and ‘bottom’ pin.
Returns:

the pin for wire connection.

Return type:

viznet.Pin

class viznet.NodeBrush(style, ax=None, color=None, size='normal', roundness=0, zorder=0, rotate=0.0, ls='-', lw=None, edgecolor=None, props=None)

Bases: viznet.brush.Brush

a brush class used to draw node.

style

refer keys for viznet.theme.NODE_THEME_DICT.

Type:str
ax

matplotlib Axes instance.

Type:Axes
color

the color of painted node by this brush, it will overide theme color if is not None.

Type:str|None
size

size of node.

Type:‘huge’|’large’|’normal’|’small’|’tiny’|’dot’|tuple|float
roundness

the roundness of edges.

Type:float
zorder

same to matplotlib zorder.

Type:int
rotate

angle for rotation.

Type:float
ls

line style.

Type:str
props

other arguments passed to handler.

Type:dict
__init__(style, ax=None, color=None, size='normal', roundness=0, zorder=0, rotate=0.0, ls='-', lw=None, edgecolor=None, props=None)

Initialize self. See help(type(self)) for accurate signature.

class viznet.Pin

Bases: numpy.ndarray, viznet.edgenode.EdgeNode

Simple Dot used for connecting wires.

class viznet.QuantumCircuit(num_bit, ax=None, x=0, y0=0, locs=None, **kwargs)

Bases: object

Parameters:
  • ax – matplotlib.pyplot.Axes.
  • num_bit (int) – number of bits.
  • y0 (float) – the y offset.
__init__(num_bit, ax=None, x=0, y0=0, locs=None, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

block(sls, pad_x=0.35, pad_y=0.35, brush=None)

strike out a block.

Parameters:
  • sls (int) – the slice for starting and ending lines.
  • pad_x (float) – x padding between gates and box.
  • pad_y (float) – y padding between gates and box.
  • brush (NodeBrush|None) – the brush used to paint this box.
Returns:

context that return boxes.

Return type:

context

focus(lines)

focus to target lines

Parameters:lines (list) – the target lines to put up.
gate(brush, position, text='', fontsize=18, noline=False)

place a gate at specific position.

get_position(line, x=None)

get the position of specific line

viznet.connect121(start_nodes, end_nodes, brush)
Parameters:
  • start_token (str) – the start layer generation token (pointed from).
  • end_token (str) – the end layer generation token (pointed to).
  • brush (EdgeBrush) – edge brush instance.
viznet.connecta2a(start_nodes, end_nodes, brush)
Parameters:
  • start_token (str) – the start layer generation token (pointed from).
  • end_token (str) – the end layer generation token (pointed to).
  • brush (EdgeBrush) – edge brush instance.
viznet.dict2circuit(datamap, handler=None, blockdict=None, putstart=None)

parse a dict (probabily from a yaml file) to a circuit.

Parameters:
  • datamap (dict) – the dictionary defining a circuit.
  • handler (None|QuantumCircuit) – the handler.
  • blockdict (dict, default=datamap) – the dictionary for block includes.
  • putstart (bool, default=handler==None) – put a start at the begining if True.
viznet.node_ring(brush, num_node, center, radius)

add a sequence of nodes placed on a ring.

Parameters:
  • brush (NodeBrush) – node brush.
  • num_node (int) – number of node to be added.
  • center (tuple) – center of this ring.
  • radius (float) – the raidus of the ring.
Returns:

a list of nodes

Return type:

list

viznet.node_sequence(brush, num_node, center, space=(1, 0))

add a sequence of nodes along direction specified by space.

Parameters:
  • brush (NodeBrush) – brush instance.
  • num_node (int) – number of node to be added.
  • center (tuple) – center of this sequence.
  • space (tuple|float) – space between nodes.
Returns:

a list of node names, you can visit this node by accesing self.node_dict[node_name].

Return type:

list

viznet.vizcode(handler, code, blockdict={})

visualize a code

Parameters:
  • handler (QuantumCircuit) – circuit handler.
  • code (str) – the string defining a primitive gate.
  • blockdict (dict, default={}) – the refence dict for block includes.