pyCTQW.MPI.plot

Caution

The functions available in this submodule have been designed to work with classes in the pyCTQW.MPI module; that is, they are being called implicitly by the above classes, invisible to the user.

It is not recommended that they be used by themselves, however it is possible to do so.

Summary

getGraphNodes(adj[, layout]) Returns arrays containing cartesian coordinates of the nodes/connections contained in the input adjacency matrix.
plot(x, prob, savefile, t, init_state, d, ...) Creates a plot of probability vs graph node for a specified time.
plot2P(x, psiX, psiY, savefile, t, ...) Creates a plot of probability vs graph node for two probability distributions at a specified time.
plot3P(x, psiX, psiY, psiZ, savefile, t, ...) Creates a plot of probability vs graph node for three probability distributions at a specified time.
plotEntanglement(t, entArray, savefile, ...) Creates a plot of entanglement vs time.
plotGraph(ax, pos, lineX, lineY[, prob, ...]) Creates a plot of probability vs node superimposed on a 3D visualisation of the graph vertices.
plotNodes(time, nodes, probArray, savefile) Creates a plot of probability vs time for specified nodes.
plotNodes2P(time, node, probXArray, ...) Creates a 2 particle plot of probability vs time for specified nodes.
plotNodes3P(time, node, probXArray, ...) Creates a 3 particle plot of probability vs time for specified nodes.

Functions

getGraphNodes(adj, layout='spring')[source]

Returns arrays containing cartesian coordinates of the nodes/connections contained in the input adjacency matrix.

Parameters:
  • adj (petsc4py.PETSc.Vec) – an \(N\times N\) PETSc-type adjacency matrix.
  • layout (str) –

    the format to store the position of the nodes (only used when running plotGraph()).

    • spring (default) - spring layout.
    • circle - nodes are arranged in a circle.
    • spectral - nodes are laid out according to the spectrum of the graph.
    • random - nodes are arranged in a random pattern.
Return type:

tuple of arrays

Important

Requires NetworkX

Example

>>> nodePos, lineX, lineY = pyCTQW.MPI.plots.getGraphNodes(adj,layout='spring')
where
  • nodePos contains the \((x,y)\) coordinates of the vertices
  • lineX contains the \(x\) coordinates of edges connecting vertices
  • lineY contains the \(y\) coordinates of edges connecting vertices
plot(x, prob, savefile, t, init_state, d, amp, N, rank)[source]

Creates a plot of probability vs graph node for a specified time.

Parameters:
  • N (int) – the number of nodes to be plotted
  • x (array or numpy.array of ints) – array of length \(N\) containing the nodes to be plotted
  • prob (petsc4py.PETSc.Vec) – vector of length \(N\) containing probabilities for each node in x.
  • savefile (str) – the absolute/relative path to the desired output file.
  • t (float) – the time of the measurement
  • init_state (array) – an \(n\times 2\) array, containing the initial state of the quantum walker in the format [[j1,amp1],[j2,amp2],...].
  • d (array of ints) – an array containing integers indicating the nodes where diagonal defects are to be placed (e.g. d=[0,1,4]).
  • amp (array of floats) – an array containing floats indicating the diagonal defect amplitudes corresponding to each element in d (e.g. amp=[0.5,-1,4.2]).
  • rank (int) – the rank of each MPI node calling this function.

Warning

  • The size of amp and d must be identical
  • ensure a file extension is present so that filetype is correctly set (choose one of png, pdf, ps, eps or svg).
plot2P(x, psiX, psiY, savefile, t, init_state, d, amp, N, rank)[source]

Creates a plot of probability vs graph node for two probability distributions at a specified time.

Parameters:
  • N (int) – the number of nodes to be plotted
  • x (array or numpy.array of ints) – array of length \(N\) containing the nodes to be plotted
  • psiX (petsc4py.PETSc.Vec) – vector of length \(N\) containing probabilities for each node in x.
  • psiY (petsc4py.PETSc.Vec) – vector of length \(N\) containing probabilities for each node in x.
  • savefile (str) – the absolute/relative path to the desired output file.
  • t (float) – the time of the measurement
  • init_state (array) – an \(n\times 3\) array, containing the initial state of the quantum walker in the format [[x1,y1,amp1],[x2,y2,amp2],...].
  • d (array of ints) – an array containing integers indicating the nodes where diagonal defects are to be placed (e.g. d=[0,1,4]).
  • amp (array of floats) – an array containing floats indicating the diagonal defect amplitudes corresponding to each element in d (e.g. amp=[0.5,-1,4.2]).
  • rank (int) – the rank of each MPI node calling this function.

Warning

  • The size of a and d must be identical
  • ensure a file extension is present so that filetype is correctly set (choose one of png, pdf, ps, eps or svg).
plot3P(x, psiX, psiY, psiZ, savefile, t, init_state, d, amp, N, rank)[source]

Creates a plot of probability vs graph node for three probability distributions at a specified time.

Parameters:
  • N (int) – the number of nodes to be plotted
  • x (array or numpy.array of ints) – array of length \(N\) containing the nodes to be plotted
  • psiX (petsc4py.PETSc.Vec) – vector of length \(N\) containing probabilities for each node in x.
  • psiY (petsc4py.PETSc.Vec) – vector of length \(N\) containing probabilities for each node in x.
  • psiZ (petsc4py.PETSc.Vec) – vector of length \(N\) containing probabilities for each node in x.
  • savefile (str) – the absolute/relative path to the desired output file.
  • t (float) – the time of the measurement
  • init_state (array) – an \(n\times 3\) array, containing the initial state of the quantum walker in the format [[x1,y1,amp1],[x2,y2,amp2],...].
  • d (array of ints) – an array containing integers indicating the nodes where diagonal defects are to be placed (e.g. d=[0,1,4]).
  • amp (array of floats) – an array containing floats indicating the diagonal defect amplitudes corresponding to each element in d (e.g. amp=[0.5,-1,4.2]).
  • rank (int) – the rank of each MPI node calling this function.

Warning

  • The size of a and d must be identical
  • ensure a file extension is present so that filetype is correctly set (choose one of png, pdf, ps, eps or svg).
plotEntanglement(t, entArray, savefile, initstate, d, a)[source]

Creates a plot of entanglement vs time.

Parameters:
  • t (array of floats) – array containing the time data.
  • entArray (array or numpy.array of floats) – array of length matching t containing the entanglement data to be plotted.
  • savefile (str) – the absolute/relative path to the desired output file.
  • initstate (array) – an \(n\times 3\) array, containing the initial state of the quantum walker in the format [[x1,y1,amp1],[x2,y2,amp2],...].
  • d (array of ints) – an array containing integers indicating the nodes where diagonal defects are to be placed (e.g. d=[0,1,4]).
  • a (array of floats) – an array containing floats indicating the diagonal defect amplitudes corresponding to each element in d (e.g. amp=[0.5,-1,4.2]).

Warning

  • The size of a and d must be identical
  • ensure a file extension is present so that filetype is correctly set (choose one of png, pdf, ps, eps or svg).
plotGraph(ax, pos, lineX, lineY, prob=None, prob2=None, nodesize=None, barscale=1, barcolor='green', baralpha=0.25, barcolor2='blue', baralpha2=0.25, bartext=False, bartextcolor='black', bartextbg=None, btoffset=[-0.025, -0.025, 0.05], bartext2=False, bartextcolor2='black', bartextbg2=None, btoffset2=[-0.025, -0.025, -0.05], nodecolor='red', nodealpha=0.5, nodetext=True, nodetextcolor='black', nodetextbg=None, nodetextbg2=None, ntoffset=[0, 0, -0.15])[source]

Creates a plot of probability vs node superimposed on a 3D visualisation of the graph vertices.

Parameters:
  • ax (mpl_toolkits.mplot3d.plt3d.Axes3D) – a matplotlib 3D axes to plot the graph on.
  • pos (array) – \((x,y)\) coordinates of the graph vertices.
  • lineX (array) – \(x\) coordinates of graph edges connecting vertices.
  • lineY (array) – \(y\) coordinates of graph edges connecting vertices.
  • probP (petsc4py.PETSc.Vec) – the probability to be represented as bars placed above/below each graph vertex for P=(1|2) repectively. If None, the graph is plotted without any probability.
Keyword Arguments:
 
  • nodesize (float) – size of the vertices in the plot. If left blank, this is determined automatically.

  • nodecolor (str) – vertex color (default 'red').

    For more details on how to specify a color, see the matplotlib documentation.

  • nodealpha (float) – value between 0 and 1 specifying the vertex opacity (default 0.25)

  • nodetext (bool) – if set True, the vertices are labelled by number.

  • nodetextcolor (str) – vertex label text color (default 'black').

  • nodetextbg (str) – vertex label background color (default 'None').

  • ntofffset (array of floats) – the \((x,y,z)\) vertex label offset relative to the vertex (default [0.,0.,-0.15]).

  • barscaleP (float) – scaled height of the probability bars (default 1).

  • barcolorP (str) – probability bar color (default 'green').

  • baralphaP (float) – value between 0 and 1 specifying the opacity (default 0.25)

  • bartext (bool) – if set True, the probability bars are labelled with their value.

  • bartextcolorP (str) – probability label text color (default 'black').

  • bartextbgP (str) – probability label background color (default 'None').

  • btoffsetP (array of floats) – the \((x,y,z)\) probability label offset relative to the top of the probability bars (default [-0.025,-0.025,0.05])

Important

  • Where an argument ends with P above, substitute P=(1|2) to access the property for particle 1 and 2 respectively.
  • Only MPI node 0 will run this function; all others will just Pass. Thus if the probP vectors are distributed over multiple nodes, they must first be gathered to node 0
  • This function does not initialize a 3D matplotlib figure/axes; that must be done independently, and passed through the ax argument.
plotNodes(time, nodes, probArray, savefile, p=0)[source]

Creates a plot of probability vs time for specified nodes.

Parameters:
  • time (array or numpy.array of floats) – array containing the nodes to be plotted
  • nodes (array) – the node numbers to be plotted.
  • probArray (numpy.array of floats) – 2D array containing probabilities over time for each node.
  • savefile (str) – the absolute/relative path to the desired output file.
  • p (int) – (0-3) - the particle that is being plotted. If p=0, then it is assumed that this is a 1 particle system.

Warning

  • ensure a file extension is present so that filetype is correctly set (choose one of png, pdf, ps, eps or svg).
plotNodes2P(time, node, probXArray, probYArray, savefile)[source]

Creates a 2 particle plot of probability vs time for specified nodes.

Parameters:
  • time (array or numpy.array of floats) – array containing the nodes to be plotted
  • nodes (array) – the node numbers to be plotted.
  • probXArray (numpy.array of floats) – 2D array containing particle 1 probabilities over time for each node.
  • probYArray (numpy.array of floats) – 2D array containing particle 2 probabilities over time for each node.
  • savefile (str) – the absolute/relative path to the desired output file.

Warning

  • ensure a file extension is present so that filetype is correctly set (choose one of png, pdf, ps, eps or svg).
plotNodes3P(time, node, probXArray, probYArray, probZArray, savefile)[source]

Creates a 3 particle plot of probability vs time for specified nodes.

Parameters:
  • time (array or numpy.array of floats) – array containing the nodes to be plotted
  • nodes (array) – the node numbers to be plotted.
  • probXArray (numpy.array of floats) – 2D array containing particle 1 probabilities over time for each node.
  • probYArray (numpy.array of floats) – 2D array containing particle 2 probabilities over time for each node.
  • probZArray (numpy.array of floats) – 2D array containing particle 3 probabilities over time for each node.
  • savefile (str) – the absolute/relative path to the desired output file.

Warning

  • ensure a file extension is present so that filetype is correctly set (choose one of png, pdf, ps, eps or svg).