hiperwalk.plot_probability_distribution#

hiperwalk.plot_probability_distribution(probabilities, plot=None, animate=False, show=True, filename=None, interval=250, figsize=(10, 6), dpi=100, repeat=True, repeat_delay=2500, range=None, time_step=1, **kwargs)[source]#

Plot the probability distributions of quantum walk states.

This function allows plotting the probability distributions for multiple steps of a quantum walk evolution. The generated figures can be displayed step-by-step, saved as individual files, or used to create and save animations.

Parameters:
probabilitiesnumpy.ndarray

An array representing the probabilities of the walker being found at each vertex during the quantum walk evolution. Each column corresponds to a vertex, while each row represents a step in the walk.

plotstr, default=None

The plot type. The valid options are {'line', 'bar', 'graph', 'histogram', 'plane'}. If None, uses default plotting. Usually bar, but default plotting changes according to graph.

showbool, default=True

Whether or not to show plots or animation. With show=True we have: Using Terminal: After shown, press q to quit. If animate==False, the quantum walk will be shown step-by-step; If animate==True, the entire animation is shown in a new window. Using Jupyter Notebook: If animate==False, all the quantum walk steps are shown at once. If animate==True, the entire animation is shown as a html video.

filenamestr, default=None

The filename path (with no format) where the plot(s) will be saved. If None no file is saved. Otherwise, if animate==False, the j-step is saved in the filename-j.png file; if animate==True, the entire walk is saved in the filename.fig file.

graphoptional

The structure of the graph on which the walk takes place. The graph labels are used as plotting labels. Important: check Graph Plots subsection in other parameters.

The following types are acceptable.

  • hiperwalk.Graph

    Hiperwalk Graph. It is used to generate default plotting for specific graphs. User-specified values are not overridden.

  • networkx.classes.graph,

    NetworkX Graph

  • scipy.sparse.csr_matrix

    Adjacency matrix.

rescalebool, optional

If False or omitted, the reference maximum probability is the global one. If True, the reference maximum probability depends on the current step, changing every image or frame. For example, if the global maximum probability is 1, min_node_size, max_node_size = (300, 3000), and the maximum probability of a given step is 0.5; then for rescale=False, the step maximum node size shown is 1650 (halfway betweeen 300 and 3000), while for rescale=True, the step maximum node size shown is 3000.

animatebool, default=False

Whether or not to animate multiple plots. If False, each quantum walk step generates an image. If True, each quantum walk step is used as an animation frame.

intervalint, default=250

Time in milliseconds that each frame is shown if animate==True.

figsizetuple, default=(10, 6)

Figure size in inches. Must be a tuple in the format (WIDTH, HEIGHT).

dpifloat, default=100

Figure resolution in dots-per-inch.

repeatbool, default: True

Whether or not to repeat the animation. See matplotlib.animation.FuncAnimation

repeat_delayint, default=2500

Delay in milliseconds between animation repetitions. See matplotlib.animation.FuncAnimation

range: tuple of int, default=None

Range used for the quantum walk simulation. See QuantumWalk.simulate() for details. If range is not None, each figure or frame will have a label with the corresponding time. The values shown are time_step * np.arange(*range).

time_step: float, default=1

Time interval between simulation steps.

labelsdict, optional

Labels to be shown on graph. If graph is None, labels.keys() must be integers from 0 to num_vert - 1. If graph is not None, labels.keys() must be labels of the corresponding networkx.Graph’s nodes.

**kwargsdict, optional

Extra arguments to further customize plotting. Valid arguments depend on plot. Check Other Parameters Section for details.

Other Parameters:
Line Plots

See matplotlib.pyplot.plot for more optional keywords.

Bar Plots

See matplotlib.pyplot.bar for more optional keywords.

Graph Plots

See networkx.draw for more optional keywords.

graph :

Graph structure.

min_node_size, max_node_sizescalar, default=(300, 3000)

By default, nodes sizes depend on the probability. min_node_size and max_node_size describe the inferior and superior limits for the node sizes, respectively.

node_sizescalar or list of scalars, optional

If node_size is a scalar, all nodes will have the same size. If node_size is a list of scalars, vertices may have different sizes and the length of node_size must match probabilities. The node_size argument is ignored if both min_node_size and max_node_size are set.

cmapstr, optional

A colormap for representing vertices probabilities. if cmap='default', uses the 'viridis' colormap. For more colormap options, check Matplolib’s Colormap reference.

Histogram Plots

See matplotlib.pyplot.bar for more optional keywords. The width keyword is always overriden.

Plane Plots
dimensions: 2-tuple of int

plane dimensions in (x_dim, y_dim) format.

Raises:
ValueError

If plot has an invalid value.

KeyError

If plot == 'graph' `` and keyword ``graph is not set.

Notes

The core logic of the main implementation loop is more or less like follows.

>>> preconfigure() 
>>> for prob in probabilities: 
>>>     configure() 
>>>     plot(prob) 

preconfigure() executes configurations that do not change between plots, e.g. nodes positions in graph plots. configure() executes configurates that must be (re)done for each iteration, e.g. setting figure size. plot() calls the appropriated plotting method with customization parameters, i.e. bar, line or graph plot with the respective valid kwargs.