qwak package

Submodules

qwak.Errors module

exception Error(error_name, details)[source]

Bases: BaseException

Base class for custom exceptions in the application.

Attributes:

error_namestr

Name of the error.

detailsstr

Additional details about the error.

as_string()[source]

Return a string representation of the error message

Return type:

str

Returns:

String representation of the error message.

Return type:

str

Parameters:
  • error_name (str)

  • details (str)

exception StateOutOfBounds(details)[source]

Bases: Error

This exception is raised when the state is out of the expected bounds. Initialize the error instance with error name and details. Inherits from Error class.

Parameters:

details (str) – Additional details about the error.

Return type:

None

exception NonUnitaryState(details)[source]

Bases: Error

This exception is raised when the state is not unitary. Initialize the error instance with error name and details.

Parameters:

details (str) – Additional details about the error.

Return type:

None

exception UndefinedTimeList(details)[source]

Bases: Error

This exception is raised when the time interval for multiple walks is undefined. Initialize the error instance with error name and details.

Parameters:

details (str) – Additional details about the error.

Return type:

None

exception EmptyProbDistList(details)[source]

Bases: Error

This exception is raised when the probability distribution list is empty. Initialize the error instance with error name and details.

Parameters:

details (str) – Additional details about the error.

Return type:

None

exception MissingNodeInput(details)[source]

Bases: Error

This exception is raised when input nodes are required but not provided. Initialize the error instance with error name and details.

Parameters:

details (str) – Additional details about the error.

Return type:

None

exception MissingGraphInput(details)[source]

Bases: Error

This exception is raised when a graph is required but not provided.

Parameters:

details (str) – Additional details about the error.

qwak.GraphicalQWAK module

class GraphicalQWAK(staticN, dynamicN, staticGraph, dynamicGraph, staticStateList, dynamicStateList, staticTime, dynamicTimeList, staticGamma=None, dynamicGamma=None, qwakId='undefinedUser')[source]

Bases: object

_summary_

Parameters:
  • staticN (int) – _description_

  • dynamicN (int) – _description_

  • staticGraph (nx.Graph) – _description_

  • dynamicGraph (nx.Graph) – _description_

  • staticStateList (list) – _description_

  • dynamicStateList (list) – _description_

  • staticTime (float) – _description_

  • dynamicTimeList (list) – _description_

  • staticGamma (float) – _description_

  • dynamicGamma (float) – _description_

  • qwakId (str)

to_json()[source]

_summary_

Returns:

_description_

Return type:

str

classmethod from_json(json_var)[source]

_summary_

Parameters:
  • json_str (str) – _description_

  • json_var (str | dict)

Returns:

_description_

Return type:

Operator

getQwakId()[source]
setQwakId(newId)[source]
setStaticQWAK(newStaticQWAK)[source]
getStaticQWAK()[source]
setDynamicQWAK(newDynamicQWAK)[source]
setDynamicTimeList(newTimeList)[source]
getStaticWalk()[source]
runWalk()[source]

_summary_

Returns:

_description_

Return type:

_type_

runMultipleWalks()[source]

_summary_

Returns:

_description_

Return type:

_type_

setStaticDim(newDim, graphStr, initStateList=None)[source]

_summary_

Parameters:
  • newDim (_type_) – _description_

  • graphStr (_type_) – _description_

  • initStateList (_type_, optional) – _description_, by default None

setDynamicDim(newDim, graphStr)[source]

_summary_

Parameters:
  • newDim (_type_) – _description_

  • graphStr (_type_) – _description_

getStaticDim()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicDim()[source]

_summary_

Returns:

_description_

Return type:

_type_

setStaticGraph(newGraphStr)[source]

_summary_

Parameters:

newGraphStr (_type_) – _description_

setDynamicGraph(newGraphStr)[source]

_summary_

Parameters:

newGraphStr (_type_) – _description_

setStaticCustomGraph(customAdjacency)[source]

_summary_

Parameters:

customAdjacency (_type_) – _description_

setDynamicCustomGraph(customAdjacency)[source]

_summary_

Parameters:

customAdjacency (_type_) – _description_

getStaticGraph()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicGraph()[source]

_summary_

Returns:

_description_

Return type:

_type_

getStaticGraphToJson()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicGraphToJson()[source]

_summary_

Returns:

_description_

Return type:

_type_

getStaticAdjacencyMatrix()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicAdjacencyMatrix()[source]

_summary_

Returns:

_description_

Return type:

_type_

setStaticTime(newTime)[source]

_summary_

Parameters:

newTime (_type_) – _description_

getStaticTime()[source]

_summary_

Returns:

_description_

Return type:

_type_

setDynamicTime(newTimeList)[source]

_summary_

Parameters:

newTimeList (_type_) – _description_

getDynamicTime()[source]

_summary_

Returns:

_description_

Return type:

_type_

setDynamicInitStateList(newInitStateList)[source]

_summary_

Parameters:

newInitStateList (_type_) – _description_

setStaticInitState(initStateStr)[source]

_summary_

Parameters:

initStateStr (_type_) – _description_

getStaticInitState()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicInitStateList()[source]

_summary_

Returns:

_description_

Return type:

_type_

getStaticProbDist()[source]

_summary_

Returns:

_description_

Return type:

_type_

setStaticProbDist(newStaticProbDist)[source]
getDynamicProbDistList()[source]

_summary_

Returns:

_description_

Return type:

_type_

setDynamicProbDistList(newDynamicProbDistList)[source]
getDynamicWalkList()[source]
setDynamicWalkList(newWalkList)[source]
getStaticProbVec()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicProbVecList()[source]

_summary_

Returns:

_description_

Return type:

_type_

getStaticMean()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicMean()[source]

_summary_

Returns:

_description_

Return type:

_type_

getStaticSndMoment()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicSndMoment()[source]

_summary_

Returns:

_description_

Return type:

_type_

getStaticStDev()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicStDev()[source]

_summary_

Returns:

_description_

Return type:

_type_

getStaticSurvivalProb(k0, k1)[source]

_summary_

Parameters:
  • k0 (_type_) – _description_

  • k1 (_type_) – _description_

Returns:

_description_

Return type:

_type_

getDynamicSurvivalProb(k0, k1)[source]

_summary_

Parameters:
  • k0 (_type_) – _description_

  • k1 (_type_) – _description_

Returns:

_description_

Return type:

_type_

getStaticInversePartRatio()[source]

_summary_

Returns:

_description_

Return type:

_type_

getDynamicInvPartRatio()[source]

_summary_

Returns:

_description_

Return type:

_type_

checkPST(nodeA, nodeB)[source]

_summary_

Parameters:
  • nodeA (_type_) – _description_

  • nodeB (_type_) – _description_

Returns:

_description_

Return type:

_type_

qwak.Operator module

class Operator(graph, gamma=1, time=0, laplacian=False, markedElements=[])[source]

Bases: object

Class for the quantum walk operator.

This object is initialized with a user inputted graph, which is then used to generate the dimension of the operator and the adjacency matrix, which is the central structure required to perform walks on regular graphs. Note that this version of the software only supports regular undirected graphs, which will hopefully be generalized in the future.

The eigenvalues and eigenvectors of the adjacency matrix are also calculated during initialization, which are then used to calculate the diagonal operator through spectral decomposition. This was the chosen method since it is computationally cheaper than calculating the matrix exponent directly.

Parameters:
  • graph (nx.Graph) – Graph where the walk will be performed.

  • gamma (float) – Needs Completion.

  • time (float, optional) – Time for which to calculate the operator, by default None.

  • laplacian (bool, optional) – Allows the user to choose whether to use the Laplacian or simple adjacency matrix, by default False.

  • markedElements (list, optional) – List with marked elements for search, by default None.

buildDiagonalOperator(time=0)[source]

Builds operator matrix from optional time and transition rate parameters, defined by user.

The first step is to calculate the diagonal matrix that takes in time, transition rate and eigenvalues and convert it to a list of the diagonal entries.

The entries are then multiplied by the eigenvectors, and the last step is to perform matrix multiplication with the complex conjugate of the eigenvectors.

Return type:

None

Parameters:
  • time (float, optional) – Time for which to calculate the operator, by default 0.

  • gamma (float, optional) – Needs completion.

  • round (int, optional)

buildExpmOperator(time=0)[source]

Builds operator matrix from optional time and transition rate parameters, defined by user.

Uses the scipy function expm to calculate the matrix exponential of the adjacency matrix.

Return type:

None

Parameters:

time (float, optional) – Time for which to calculate the operator, by default 0.

_buildHamiltonian(graph, laplacian)[source]

Builds the hamiltonian of the graph, which is either the Laplacian or the simple matrix.

Return type:

ndarray

Parameters:
  • laplacian (bool) – Allows the user to choose whether to use the Laplacian or simple adjacency matrix.

  • markedElements (list) – List of elements for the search.

_buildSearchHamiltonian(hamiltonian, markedElements)[source]
_buildEigenValues(hamiltonian)[source]

Builds the eigenvalues and eigenvectors of the adjacency matrix.

Return type:

None

Parameters:

isHermitian (bool) – Checks if the adjacency matrix is Hermitian.

_hermitianTest(hamiltonian)[source]

Checks if the adjacency matrix is Hermitian.

Return type:

bool

Parameters:

hamiltonian (np.ndarray) – Adjacency matrix.

Returns:

True if Hermitian, False otherwise.

Return type:

bool

getEigenValues()[source]

Returns the eigenvalues of the adjacency matrix.

Return type:

list

Returns:

List of eigenvalues.

Return type:

list

_setEigenValues(eigenValues)[source]

Sets the eigenvalues of the adjacency matrix.

Return type:

None

Parameters:

eigenValues (list) – List of eigenvalues.

getEigenVectors()[source]

Returns the eigenvectors of the adjacency matrix.

Return type:

list

Returns:

List of eigenvectors.

Return type:

list

_setEigenVectors(eigenVectors)[source]

Sets the eigenvectors of the adjacency matrix.

Return type:

None

Parameters:

eigenVectors (list) – _description_

getHamiltonian()[source]

Returns the hamiltonian of the graph, which is either the Laplacian or the simple matrix.

Returns:

Hamiltonian of the graph.

Return type:

np.ndarray

setHamiltonian(hamiltonian)[source]

Sets the hamiltonian for the walk.

Parameters:

hamiltonian (np.ndarray) – Hamiltonian of the graph.

resetOperator()[source]

Resets Operator object.

Return type:

None

setDim(newDim, graph)[source]

Sets the current Operator objects dimension to a user defined one.

Return type:

None

Parameters:
  • newDim (int) – New dimension for the Operator object.

  • graph (nx.Graph) – New graph for the Operator object.

getDim()[source]

Gets the current graph dimension.

Return type:

int

Returns:

Dimension of Operator object.

Return type:

int

setTime(newTime)[source]

Sets the current operator time to a user defined one.

Return type:

None

Parameters:

newTime (float) – New operator time.

getTime()[source]

Gets the current operator time.

Return type:

float

Returns:

Current time of Operator object.

Return type:

float

setAdjacencyMatrix(adjacencyMatrix)[source]

Sets the adjacency matrix of the operator to a user defined one. Might make more sense to not give the user control over this parameter, and make them instead change the graph entirely.

Return type:

None

Parameters:

adjacencyMatrix (np.ndarray) – New adjacency matrix.

_setAdjacencyMatrixOnly(adjacencyMatrix)[source]

Sets the adjacency matrix of the operator to a user defined one. Might make more sense to not give the user control over this parameter, and make them instead change the graph entirely.

Return type:

None

Parameters:

adjacencyMatrix (np.ndarray) – New adjacency matrix.

getAdjacencyMatrix()[source]

Gets the current adjacency matrix of the Operator.

Return type:

ndarray

Returns:

Adjacency matrix of the Operator.

Return type:

np.ndarray

_setOperatorVec(newOperator)[source]

Sets all the parameters of the current operator to user defined ones.

Return type:

None

Parameters:

newOperator (Operator) – New user inputted Operator.

setOperator(newOperator)[source]

Sets all the parameters of the current operator to user defined ones.

Return type:

None

Parameters:

newOperator (Operator) – New user inputted Operator.

getOperator()[source]

Gets the numpy matrix associated with the current operator.

Return type:

matrix

Returns:

Current Operator object.

Return type:

np.matrix

checkPST(nodeA, nodeB)[source]

Algorithm to check PST based on the article https://arxiv.org/abs/1606.02264 authored by Rodrigo Chaves. Checks if all the conditions are true and return the VALUE if the graph has PST and False otherwise.

Parameters:
  • nodeA (_type_) – Input node.

  • nodeB (_type_) – Output node.

Returns:

Either returns the time value of PST or False.

Return type:

Float/Bool

getMarkedElements()[source]

Returns the marked elements of the operator.

Return type:

list

Returns:

List of marked elements.

Return type:

list

setMarkedElements(markedElements)[source]

Sets the marked elements of the operator.

Return type:

None

Parameters:

markedElements (list) – List of marked elements.

to_json()[source]

Converts the operator object to a JSON string.

Returns:

  • str – JSON string of the operator object.

  • rtype: str

Return type:

str

classmethod from_json(json_var)[source]

Converts a JSON string to an operator object.

Return type:

Operator

Parameters:

json_var (str, dict) – JSON string of the operator object.

Returns:

Operator object.

Return type:

Operator

static _degreeDiagonalMatrix(G)[source]

qwak.ProbabilityDistribution module

class ProbabilityDistribution(state)[source]

Bases: object

The dimension of the probability vector will then be loaded from the state inputted by the user. The vector containing the probabilities will be initialized full of zeros with the dimension obtained from the state.

Parameters:

state (State) – State to be converted into a probability.

resetProbDist()[source]

Resets the ProbabilityDistribution object.

Return type:

None

buildProbDist(state=None)[source]

Builds the probability vector by multiplying the user inputted amplitude state by its conjugate.

Return type:

None

Parameters:

state (State, optional) – State to be converted into a probability, by default None

setProbDist(newProbDist)[source]

Sets the current probability distribution to a user inputted one.

Return type:

None

Parameters:

newProbDist (ProbabilityDistribution) – New probability distribution for the object.

getStateVec()[source]

Gets the state vector associated with a distribution.

Return type:

State

Returns:

Returns the state vector of the ProbabilityDistribution object.

Return type:

State

getState()[source]

Gets the state associated with a distribution.

Return type:

State

Returns:

Returns the state of the ProbabilityDistribution object.

Return type:

State

setState(newState)[source]

Sets the current state to a user inputted one.

Return type:

None

Parameters:

newState (State) – New state for the distribution.

setDim(newDim)[source]

Sets the current dimension to a user inputted one.

Return type:

None

Parameters:

newDim (int) – New dimension for the distribution.

getDim()[source]

Gets the dimension associated with a distribution.

Return type:

int

Returns:

Returns the dimension of the ProbabilityDistribution object.

Return type:

int

setProbVec(newProbVec)[source]

Sets the current probability vector to a user inputted one.

Return type:

None

Parameters:

newProbVec (np.ndarray) – New probability vector for the distribution.

getProbVec()[source]

Gets the probability vector associated with a distribution.

Return type:

ndarray

Returns:

Returns the array of the ProbabilityDistribution object.

Return type:

np.ndarray

moment(k)[source]

Calculates the kth moment of the probability distribution.

Return type:

float

Parameters:

k (int) – User inputted moment.

Returns:

kth moment of the probability distribution.

Return type:

float

invPartRatio()[source]

Calculates the inverse participation ratio of the probability distribution.

Return type:

float

Returns:

Inverse participation ratio of the probability distribution.

Return type:

float

stDev()[source]

Calculates the standard deviation of the probability distribution.

Return type:

float

Returns:

Standard deviation of the probability distribution.

Return type:

float

survivalProb(fromNode, toNode)[source]

Calculates the survival probability of the probability distribution.

Return type:

float

Parameters:
  • fromNode (_type_) – Starting Node.

  • toNode (_type_) – Ending node.

Returns:

Survival probability of the probability distribution.

Return type:

float

searchNodeProbability(searchNode)[source]

Searches and gets the probability associated with a given node.

Return type:

float

Parameters:

searchNode (int) – User inputted node for the search.

Returns:

Probability of the searched node.

Return type:

float

to_json()[source]

Converts the ProbabilityDistribution object to a JSON string.

Returns:

  • str – JSON string of the ProbabilityDistribution object.

  • rtype: str

Return type:

str

classmethod from_json(json_var)[source]

Converts a JSON string to a ProbabilityDistribution object.

Return type:

ProbabilityDistribution

Parameters:

json_var (Union[str, dict]) – JSON string or dictionary to be converted to a ProbabilityDistribution object.

Returns:

ProbabilityDistribution object converted from JSON.

Return type:

ProbabilityDistribution

qwak.QuantumWalk module

class QuantumWalk(state, operator)[source]

Bases: object

This object is initialized with a user inputted initial state and operator. The dimension of the quantum walk will then be loaded from the initial state. The final state will contain the amplitudes of the time evolution of the initial state, as a function of the operator. This variable is initialized as an instance of State class.

Parameters:
  • state (State) – Initial state which will be the basis of the time dependant evolution.

  • operator (Operator) – Operator which will evolve the initial state.

buildWalk(initState=None, operator=None)[source]

Builds the final state of the quantum walk by setting it to the matrix multiplication of the operator by the initial state.

Return type:

None

Parameters:
  • initState (State, optional) – Initial state which will be the basis of the time dependant evolution, by default None.

  • operator (Operator, optional) – Operator which will evolve the initial state, by default None.

resetWalk()[source]

Resets the components of the QuantumWalk object.

Return type:

None

setInitState(newInitState)[source]

Sets the initial state of the quantum walk to a new user inputted one.

Return type:

None

Parameters:

newInitState (State) – New initial state for the quantum walk.

getInitState()[source]

Gets the initial state of the quantum walk.

Return type:

State

Returns:

Initial state of the quantum walk.

Return type:

State

setDim(newDim)[source]

Sets the current quantum walk dimension to a user defined one.

Return type:

None

Parameters:

newDim (int) – New QuantumWalk dimension.

getDim()[source]

Gets the current state dimension.

Return type:

int

Returns:

QuantumWalk dimension.

Return type:

int

setOperator(newOperator)[source]

Sets the current operator to a user defined one.

Return type:

None

Parameters:

newOperator (Operator) – New quantum walk operator.

getOperator()[source]

Gets the current operator.

Return type:

Operator

Returns:

Current QuantumWalk Operator object.

Return type:

Operator

setWalk(newWalk)[source]

Sets all the parameters of the current quantum walk to user defined ones.

Return type:

None

Parameters:

newWalk (QuantumWalk) – New quantum walk.

getFinalState()[source]

Gets the final state of the QuantumWalk.

Return type:

State

Returns:

Final state of the QuantumWalk.

Return type:

State

setFinalState(newFinalState)[source]

Sets the final state of the QuantumWalk.

Return type:

None

Parameters:
  • finalState (State) – Final state of the QuantumWalk.

  • newFinalState (State)

getAmpVec()[source]

Gets the vector of the final state amplitudes of the QuantumWalk.

Return type:

ndarray

Returns:

Vector of the final state.

Return type:

np.ndarray

searchNodeAmplitude(searchNode)[source]

Searches and gets the amplitude associated with a given node.

Return type:

complex

Parameters:

searchNode (int) – User inputted node for the search.

Returns:

Amplitude of the search node.

Return type:

complex

transportEfficiency()[source]

Calculates the transport efficiency of the quantum walk.

Return type:

float

Returns:

Transport efficiency of the quantum walk.

Return type:

float

to_json()[source]

Serializes the QuantumWalk object to JSON format.

Return type:

str

Returns:

JSON string representation of the QuantumWalk object.

Return type:

str

classmethod from_json(json_var)[source]

Deserializes a JSON string to a QuantumWalk object.

Return type:

QuantumWalk

Parameters:
  • json_str (str) – JSON string representation of the QuantumWalk object.

  • json_var (str)

Returns:

Deserialized QuantumWalk object.

Return type:

QuantumWalk

qwak.State module

class State(n, nodeList=None, customStateList=None)[source]

Bases: object

Object is initialized with a mandatory user inputted dimension, an optional stateList parameter which will be used to create the amplitudes for each node in the state and an internal stateVec which will be a Numpy ndarray representing the column vector.

Parameters:
  • n (int) – Desired dimension of the state.

  • nodeList (list, optional) – List containing what nodes will have uniform superposition in the state, by default None.

  • customStateList (list, optional) – Custom amplitudes for the state, by default None.

buildState(nodeList=None, customStateList=None)[source]

Builds state vector from state list, by creating a balanced superposition of all nodes in the nodeList. This will be changed in the future to make nodeList make more sense.

Return type:

None

Parameters:
  • nodeList (list, optional) – List containing what nodes will have uniform superposition in the state, by default None.

  • customStateList (list, optional) – Custom amplitudes for the state, by default None.

_checkStateOutOfBounds(node)[source]

Checks if the state is out of bounds for the system.

Return type:

None

Parameters:

node (int) – Node to check.

Raises:

StateOutOfBounds – Out of bounds exception.

_checkUnitaryStateList(customStateList)[source]

Checks if the sum of the square of the amplitudes is 1.

Return type:

None

Parameters:

customStateList (list) – Custom state list.

Raises:

NonUnitaryState – Non unitary state exception.

herm()[source]

Returns the Hermitian conjugate of the state vector.

Return type:

ndarray

Returns:

Hermitian conjugate of the state vector.

Return type:

np.ndarray

inv()[source]

Returns the inverse of the state vector.

Return type:

ndarray

Returns:

Inverse of the state vector.

Return type:

np.ndarray

resetState()[source]

Resets the components of the State.

Return type:

None

setDim(newDim, newNodeList=None)[source]

Sets the current state dimension to a user defined one.

Return type:

None

Parameters:
  • newDim (int) – New state dimension.

  • newNodeList (list, optional) – List containing the new nodes, by default None.

getDim()[source]

Gets the current state dimension.

Return type:

int

Returns:

State dimension.

Return type:

int

setNodeList(newNodeList)[source]

Sets current node list to a user inputted one.

Return type:

None

Parameters:

newNodeList (list) – List containing the new nodes.

getNodeList()[source]

Gets the current list of nodes.

Return type:

list

Returns:

Current list of nodes.

Return type:

list

setStateVec(newVec)[source]

Sets the column vector associated with the state to a user defined one.

Return type:

None

Parameters:

newVec (np.ndarray) – New column vector for the state.

getStateVec()[source]

Gets the column vector associated with the state.

Return type:

ndarray

Returns:

Vector of the State.

Return type:

np.ndarray

setState(newState)[source]

Sets all the parameters of the current state to user defined ones.

Return type:

None

Parameters:

newState (State) – New state.

to_json()[source]

In contrast, the to_json method is not marked with the @classmethod decorator because it is a method that is called on an instance of the Operator class.

This means that it can access the attributes of the instance on which it is called, and it uses these attributes to generate the JSON string representation of the Operator instance.

Since it requires access to the attributes of a specific Operator instance, it cannot be called on the Operator class itself.

Return type:

str

Returns:

JSON string representation of the Operator instance.

Return type:

str

classmethod from_json(json_var)[source]

The from_json method is marked with the @classmethod decorator because it is a method that is called on the class itself, rather than on an instance of the class.

This is necessary because it is used to create a new instance of the Operator class from a JSON string, and it does not require an instance of the Operator class to do so.

Parameters:

json_var (Union([str, dict])) – JSON string or dictionary representation of the Operator instance.

Returns:

Operator instance from JSON string or dictionary representation.

Return type:

Operator

qwak.StochasticOperator module

class StochasticOperator(graph, noiseParam=None, sinkNode=None, sinkRate=None)[source]

Bases: object

Stochastic quantum walker on QuTip. Class containing an open quantum system described by a Lindblad equation obtained from the adjacency matrix.

Theoretical model: Whitfield, J. D. et al. Quantum stochastic walks: A generalization of classical random walks and quantum walks.

@author: Lorenzo Buffoni @github: https://github.com/Buffoni

Parameters:
  • graph (networkx.Graph) – The graph representing the quantum walk space.

  • noiseParam (float, optional) – The noise parameter controlling the quantum-classical mix (default is 0 for a fully quantum system).

  • sinkNode (int, optional) – The index of the sink node in the graph (default is None, indicating no sink node).

  • sinkRate (float, optional) – The rate at which probability is transferred to the sink node (default is 1).

buildStochasticOperator(noiseParam=None, sinkNode=None, sinkRate=None)[source]

Creates the Hamiltonian and the Lindblad operators for the walker given an adjacency matrix and other parameters.

Return type:

None

Parameters:
  • noiseParam (float, optional) – The noise parameter controlling the quantum-classical mix (default is 0 for a fully quantum system).

  • sinkNode (int, optional) – The index of the sink node in the graph (default is None, indicating no sink node).

  • sinkRate (float, optional) – The rate at which probability is transferred to the sink node (default is 1).

_buildLaplacian()[source]

Internal method to build the Laplacian matrix from the adjacency matrix of the graph.

Return type:

None

_buildQuantumHamiltonian()[source]

Internal method to build the quantum Hamiltonian from the graph’s adjacency matrix.

Return type:

None

_buildClassicalHamiltonian()[source]

Internal method to build the classical Hamiltonian (Lindblad operators).

Return type:

None

getClassicalHamiltonian()[source]

Returns the classical Hamiltonian (Lindblad operators) of the system.

Return type:

list

Returns:

A list of Qobj representing the Lindblad operators.

Return type:

list[Qobj]

setClassicalHamiltonian(newClassicalHamiltonian)[source]

Sets a new classical Hamiltonian for the system.

Return type:

None

Parameters:

newClassicalHamiltonian (list of Qobj) – The new list of Lindblad operators to set as the classical Hamiltonian.

getQuantumHamiltonian()[source]

Returns the quantum Hamiltonian of the system.

Return type:

Qobj

Returns:

The quantum Hamiltonian as a QuTiP object.

Return type:

Qobj

setQuantumHamiltonian(newQuantumHamiltonian)[source]

Sets a new quantum Hamiltonian for the system.

Return type:

None

Parameters:

newQuantumHamiltonian (Qobj) – The new quantum Hamiltonian as a QuTiP object.

setSinkNode(newSinkNode)[source]

Sets a new sink node for the system.

Return type:

None

Parameters:

newSinkNode (int) – The index of the new sink node in the graph.

getSinkNode()[source]

Returns the index of the current sink node in the graph.

Return type:

int

Returns:

The index of the sink node.

Return type:

int

getLaplacian()[source]

Returns the Laplacian matrix of the graph.

Return type:

ndarray

Returns:

The Laplacian matrix.

Return type:

np.ndarray

qwak.StochasticProbabilityDistribution module

class StochasticProbabilityDistribution(state)[source]

Bases: object

A class to represent the probability distribution of a quantum state in a stochastic system.

Initializes the probability distribution with a given quantum state.

Parameters:

state (Qobj) – Initial state which will be the basis of the time dependant evolution.

buildProbDist(state=None)[source]

Builds or updates the probability distribution of the system based on the given quantum state.

Return type:

None

Parameters:

state (Qobj, optional) – The quantum state to be used for updating the probability distribution. If None, the existing final state is used. Default is None.

getProbVec()[source]

Returns the probability vector representing the distribution of the current state.

Return type:

ndarray

Returns:

The probability vector of the current state, flattened.

Return type:

np.ndarray

setProbVec(newFinalState)[source]

Sets a new final state for the probability distribution.

Return type:

None

Parameters:

newFinalState (np.ndarray) – The new final state to be set for the probability distribution.

qwak.StochasticQuantumWalk module

class StochasticQuantumWalk(state, operator)[source]

Bases: object

This object is initialized with a user inputted initial state and operator. The dimension of the quantum walk will then be loaded from the initial state. The final state will contain the amplitudes of the time evolution of the initial state, as a function of the operator. This variable is initialized as an instance of QObj class.

Parameters:
  • state (State) – Initial state which will be the basis of the time dependant evolution.

  • operator (StochasticOperator) – Operator which will evolve the initial state.

buildWalk(time, observables=[], opts={'store_final_state': True, 'store_states': False})[source]

Constructs the quantum walk over a specified time frame.

Return type:

None

Parameters:
  • time (float) – The time over which the walk is to be simulated.

  • observables (list, optional) – A list of observables to monitor during the walk. Defaults to an empty list.

  • opts (Options, optional) – QuTiP options for the simulation. Defaults to storing states and the final state.

getFinalState()[source]

Returns the final quantum state after the completion of the walk.

Return type:

Qobj

Returns:

  • Qobj – The final state of the quantum walk.

setFinalState(newFinalState)[source]

Sets a new final state for the quantum walk.

Return type:

None

Parameters:

newFinalState (Qobj) – The new final state to be set for the quantum walk.

getDim()[source]

Returns the dimension of the quantum walk’s state space.

Return type:

int

Returns:

The dimension of the quantum walk.

Return type:

int

qwak.StochasticQwak module

class StochasticQWAK(graph, initStateList=None, customStateList=None, noiseParam=None, sinkNode=None, sinkRate=None)[source]

Bases: object

This class integrates the components of a stochastic quantum walk including the graph, initial state, stochastic operator, quantum walk dynamics, and probability distribution. Initializes a StochasticQWAK instance with a graph and optional parameters.

Parameters:
  • graph (nx.Graph) – The graph over which the quantum walk is performed.

  • initStateList (list, optional) – List of nodes to initialize the quantum state.

  • customStateList (list, optional) – Custom states for the quantum walk.

  • noiseParam (float, optional) – Parameter controlling noise in the stochastic operator.

  • sinkNode (int, optional) – Node acting as a sink in the quantum walk.

  • sinkRate (float, optional) – Rate of transfer to the sink node.

runWalk(time=0, initStateList=None, customStateList=None, noiseParam=None, sinkNode=None, sinkRate=None, observables=[], opts={'store_final_state': True, 'store_states': True})[source]

Executes the stochastic quantum walk.

Return type:

None

Parameters:
  • time (float, optional) – Duration of the quantum walk.

  • initStateList (list, optional) – Initial state list for the quantum walk.

  • customStateList (list, optional) – Custom state list for the quantum walk.

  • noiseParam (float, optional) – Noise parameter for the operator.

  • sinkNode (int, optional) – Sink node index in the graph.

  • sinkRate (float, optional) – Rate of transfer to the sink node.

  • observables (list, optional) – List of observables to monitor during the walk.

  • opts (Options, optional) – QuTiP options for the simulation.

setProbDist(newProbDist)[source]

Sets a new probability distribution for the quantum walk.

Return type:

None

Parameters:

newProbDist (StochasticProbabilityDistribution) – The new probability distribution to set.

getProbDist()[source]

Returns the current probability distribution of the quantum walk.

Return type:

StochasticProbabilityDistribution

Returns:

The current probability distribution.

Return type:

StochasticProbabilityDistribution

getProbVec()[source]

Returns the probability vector of the current quantum state.

Return type:

ndarray

Returns:

The probability vector.

Return type:

np.ndarray

getQuantumHamiltonian()[source]

Retrieves the quantum Hamiltonian of the stochastic operator.

Return type:

Qobj

Returns:

The quantum Hamiltonian governing the evolution of the quantum walk.

Return type:

Qobj

getClassicalHamiltonian()[source]

Retrieves the classical Hamiltonian (Lindblad operators) of the stochastic operator.

Return type:

list

Returns:

A list of Lindblad operators representing the classical component of the quantum walk.

Return type:

list[Qobj]

getLaplacian()[source]

Retrieves the Laplacian matrix of the graph associated with the stochastic operator.

Return type:

ndarray

Returns:

The Laplacian matrix of the graph.

Return type:

np.ndarray

qwak.qwak module

class QWAK(graph, time=0, timeList=None, gamma=1, initStateList=None, customStateList=None, laplacian=False, markedElements=[], qwakId='userUndef')[source]

Bases: object

Data access class that combines all three components required to perform a continuous-time quantum walk, given by the multiplication of an operator (represented by the Operator class) by an initial state (State class). This multiplication is achieved in the StaticQuantumwalk class, which returns a final state (State Class) representing the amplitudes of each state associated with a graph node. These amplitudes can then be transformed to probability distributions (ProbabilityDistribution class) suitable for plotting with matplotlib, or your package of choice.

Default values for the initial state, time and transition rate are a column vector full of 0s, 0 and 1, respectively. Methods runWalk or buildWalk must then be used to generate the results of the quantum walk.

Parameters:
  • graph (nx.Graph) – NetworkX graph where the walk takes place. Also used for defining the dimensions of the quantum walk.

  • time (float) – Time interval for the quantum walk, by default None.

  • timeList (list) – List with time intervals for multiple walks, by default None.

  • initStateList (list[int], optional) – List with chosen initial states for uniform superposition, by default None

  • customStateList (list[(int,complex)], optional) – Custom init state, by default None.

  • laplacian (bool, optional) – Allows the user to choose whether to use the Laplacian or simple adjacency matrix, by default False.

  • markedElements (list, optional) – List with marked elements for search, by default None.

  • qwakId (str, optional) – User-defined ID for the QWAK instance, by default ‘userUndef’.

  • gamma (float)

runWalk(time=0, initStateList=None, customStateList=None)[source]

Builds class’ attributes, runs the walk and calculates the amplitudes and probability distributions with the given parameters. These can be accessed with their respective get methods.

Return type:

None

Parameters:
  • time (float, optional) – Time for which to calculate the quantum walk, by default 0.

  • initStateList (list[int], optional) – List with chosen initial states for uniform superposition, by default None.

  • customStateList (list[(int,complex)], optional) – Custom init state, by default None.

Raises:
  • stOBErr – State out of bounds exception.

  • nUErr – State not unitary exception.

runExpmWalk(time=0, initStateList=None, customStateList=None)[source]

Builds class’ attributes, runs the walk and calculates the amplitudes and probability distributions with the given parameters. These can be accessed with their respective get methods.

Return type:

None

Parameters:
  • time (float, optional) – Time for which to calculate the quantum walk, by default 0.

  • initStateList (list[int], optional) – List with chosen initial states for uniform superposition, by default None.

  • customStateList (list[(int,complex)], optional) – Custom init state, by default None.

Raises:
  • stOBErr – State out of bounds exception.

  • nUErr – State not unitary exception.

runMultipleWalks(timeList=None, initStateList=None, customStateList=None)[source]

Runs the walk for multiple times and stores the probability distributions in a list.

Return type:

None

Parameters:
  • timeList (list, optional) – List of times for which to calculate the quantum walk, by default None.

  • initStateList (list, optional) – List with chosen initial states for uniform superposition, by default None.

  • customStateList (list, optional) – Custom init state, by default None.

Raises:

UndefinedTimeList – Raised when the timeList is None.

runMultipleExpmWalks(timeList=None, initStateList=None, customStateList=None)[source]

Runs the walk for multiple times and stores the probability distributions in a list.

Return type:

None

Parameters:
  • timeList (list, optional) – List of times for which to calculate the quantum walk, by default None.

  • initStateList (list, optional) – List with chosen initial states for uniform superposition, by default None.

  • customStateList (list, optional) – Custom init state, by default None.

Raises:

UndefinedTimeList – Raised when the timeList is None.

resetWalk()[source]

Resets the components of a walk.

Return type:

None

setDim(newDim, graphStr=None, graph=None, initStateList=None)[source]

Sets the current walk dimensions to a user defined one. Also takes a graph string to be evaluated and executed as a NetworkX graph generator.

Return type:

None

Parameters:
  • newDim (int) – New dimension for the quantum walk.

  • graphStr (str) – Graph string to generate the graph with the new dimension.

  • graph (nx.Graph, optional) – Graph with the new dimension.

  • initStateList (list[int], optional) – Init state list with new dimension.

getDim()[source]

Gets the current graph dimension.

Return type:

int

Returns:

Dimension of graph.

Return type:

int

setGraph(newGraph, initStateList=None)[source]

Sets the current graph to a user defined one. Also recalculates the current operator and walk dimension.

Return type:

None

Parameters:

newGraph (nx.Graph) – New NetworkX graph.

getGraph()[source]

Gets the current graph.

Return type:

Graph

Returns:

Current graph.

Return type:

nx.Graph

setCustomGraph(customAdjMatrix)[source]

Sets the current graph to a user defined one.

Return type:

None

Parameters:

customAdjMatrix (np.ndarray) – Adjacency matrix of the new graph.

setInitState(newInitState)[source]

Sets the current initial state to a user defined one.

Return type:

None

Parameters:

newInitState (State) – New initial state.

getInitState()[source]

Gets the initial state.

Return type:

State

Returns:

Initial State.

Return type:

State

setTime(newTime)[source]

Sets the current walk time to a user defined one.

Return type:

None

Parameters:

newTime (float) – New time.

setTimeList(newTimeList)[source]

Sets the current walk time to a user defined one.

Return type:

None

Parameters:

newTimeList (list) – New time list.

getTime()[source]

Gets the current walk time.

Return type:

float

Returns:

Current value of time.

Return type:

float

getTimeList()[source]

Gets the current walk time.

Return type:

float

Returns:

Current value of time.

Return type:

float

setAdjacencyMatrix(newAdjMatrix, initStateList=None)[source]

Sets the current adjacency matrix to a user defined one.

Return type:

None

Parameters:
  • newAdjMatrix (np.ndarray) – New adjacency matrix.

  • initStateList (list, optional) – New initial state list, by default None.

getAdjacencyMatrix()[source]

Gets the current adjacency matrix.

Return type:

ndarray

Returns:

Current adjacency matrix.

Return type:

np.ndarray

setHamiltonian(newHamiltonian)[source]

Sets the current Hamiltonian to a user defined one.

Return type:

None

Parameters:

newHamiltonian (np.ndarray) – New Hamiltonian.

getHamiltonian()[source]

Gets the current Hamiltonian.

Return type:

ndarray

Returns:

Current Hamiltonian.

Return type:

np.ndarray

setOperator(newOperator)[source]

Sets the current walk operator a user defined one.

Return type:

None

Parameters:

newOperator (Operator) – New operator object.

getOperator()[source]

Gets the current walk operator.

Return type:

Operator

Returns:

Current operator object.

Return type:

Operator

setWalk(newWalk)[source]

Sets current walk amplitudes to a user defined state. This might not be needed and removed in the future.

Return type:

None

Parameters:

newWalk (State) – New walk amplitudes.

getWalk()[source]

Gets current QuantumWalk object

Return type:

QuantumWalk

Returns:

Current state amplitudes.

Return type:

QuantumWalk

getFinalState()[source]

Gets current QuantumWalk State.

Return type:

State

Returns:

State of the QuantumWalk.

Return type:

State

getAmpVec()[source]

Gets the array of the QuantumWalk state.

Return type:

ndarray

Returns:

Array of the QuantumWalk state.

Return type:

np.ndarray

setProbDist(newProbDist)[source]

Sets current walk probability distribution to a user defined one. This might not be needed and removed in the future.

Return type:

None

Parameters:

newProbDist (ProbabilityDistribution) – New probability distribution.

getProbDist()[source]

Gets the current probability distribution.

Return type:

ProbabilityDistribution

Returns:

ProbabilityDistribution object.

Return type:

ProbabilityDistribution

getProbDistList()[source]

Returns a list of probability distributions in the case of multiple walks.

Return type:

list

Returns:

List of ProbabilityDistribution objects.

Return type:

list

setProbDistList(newProbDistList)[source]

Sets the current probability distribution list to a user defined one.

Return type:

None

Parameters:

newProbDistList (list) – New probability distribution list.

getProbVec()[source]

Gets the current probability distribution vector.

Return type:

ndarray

Returns:

Probability Distribution vector.

Return type:

np.ndarray

getProbVecList()[source]

Returns a list of probability distribution vectors in the case of multiple walks.

Return type:

list

Returns:

List of probability distribution vectors.

Return type:

list

searchNodeAmplitude(searchNode)[source]

User inputted node for search

Return type:

complex

Parameters:

searchNode (int) – User inputted node for the search.

Returns:

Amplitude associated with the search node.

Return type:

complex

searchNodeProbability(searchNode)[source]

Searches and gets the probability associated with a given node.

Return type:

float

Parameters:

searchNode (int) – User inputted node for the search.

Returns:

Probability associated with the search node.

Return type:

float

getMean(resultRounding=None)[source]

Gets the mean of the probability distribution.

Return type:

float

Parameters:

resultRounding (int, optional) – Rounding of the result, by default None.

Returns:

Mean of the probability distribution.

Return type:

float

getMeanList(resultRounding=None)[source]

Gets the mean of the probability distribution list.

Return type:

list

Parameters:

resultRounding (int, optional) – Rounding of the results, by default None.

Returns:

List of means of the probability distributions.

Return type:

list

getSndMoment(resultRounding=None)[source]

Gets the second moment of the probability distribution.

Return type:

float

Parameters:

resultRounding (int, optional) – Rounding of the result, by default None.

Returns:

Second moment of the probability distribution.

Return type:

float

getStDev(resultRounding=None)[source]

Gets the standard deviation of the probability distribution.

Return type:

float

Parameters:

resultRounding (int, optional) – Rounding of the result, by default None.

Returns:

Standard deviation of the probability distribution.

Return type:

float

getStDevList(resultRounding=None)[source]

Gets the standard deviation of the probability distribution list.

Return type:

list

Parameters:

resultRounding (int, optional) – Rounding of the results, by default None.

Returns:

List of standard deviations of the probability distributions.

Return type:

list

getInversePartRatio(resultRounding=None)[source]

Gets the inverse participation ratio of the probability distribution.

Return type:

float

Parameters:

resultRounding (int, optional) – Rounding of the result, by default None.

Returns:

Inverse participation ratio of the probability distribution.

Return type:

float

getInversePartRatioList(resultRounding=None)[source]

Gets the inverse participation ratio of the probability distribution list.

Return type:

list

Parameters:

resultRounding (int, optional) – Rounding of the results, by default None.

Returns:

List of inverse participation ratios of the probability distributions.

Return type:

list

getSurvivalProb(fromNode, toNode, resultRounding=None)[source]

Gets the survival probability of the probability distribution.

Return type:

float

Parameters:
  • fromNode (_type_) – Starting node.

  • toNode (_type_) – Ending node.

  • resultRounding (int, optional) – Rounding of the result, by default None.

Returns:

Survival probability of the probability distribution.

Return type:

float

Raises:

MissingNodeInput – Missing input node error.

getSurvivalProbList(fromNode, toNode, resultRounding=None)[source]

Gets the survival probability of the probability distribution list.

Return type:

list

Parameters:
  • fromNode (_type_) – Starting node.

  • toNode (_type_) – Ending node.

  • resultRounding (int, optional) – Rounding of the results, by default None.

Returns:

List of survival probabilities of the probability distributions.

Return type:

list

Raises:

MissingNodeInput – Missing input node error.

checkPST(fromNode, toNode)[source]

Checks if a structure allows for PST between certain nodes.

Return type:

Union[str, bool]

Parameters:
  • fromNode (_type_) – Starting node.

  • toNode (_type_) – Ending node.

Returns:

_description_

Return type:

Union([str,bool])

Raises:

MissingNodeInput – Missing input node error.

checkPST_sympy(fromNode, toNode)[source]

Checks if a structure allows for PST between certain nodes.

Return type:

Union[str, bool]

Parameters:
  • fromNode (_type_) – Starting node.

  • toNode (_type_) – Ending node.

Returns:

_description_

Return type:

Union([str,bool])

Raises:

MissingNodeInput – Missing input node error.

getTransportEfficiency()[source]

Gets the transport efficiency of the quantum walk.

Return type:

float

Returns:

Transport efficiency of the quantum walk.

Return type:

float

getMarkedElements()[source]

Gets the marked elements of the quantum walk.

Return type:

list

Returns:

Marked elements of the quantum walk.

Return type:

list

setMarkedElements(markedElements)[source]

Sets the marked elements of the quantum walk.

Return type:

None

Parameters:

markedElements (list) – Marked elements of the quantum walk.

getQWAK()[source]

Gets the QWAK instance.

Returns:

QWAK instance.

Return type:

QWAK

setQWAK(newQWAK)[source]

Sets the QWAK instance’s attributes to the ones of the given QWAK instance.

Return type:

None

Parameters:

newQWAK (QWAK) – QWAK instance to copy the attributes from.

getQWAKId()[source]

Gets the QWAK instance’s ID.

Return type:

str

Returns:

QWAK instance’s ID.

Return type:

str

to_json(isDynamic=False)[source]

Returns a JSON representation of the QWAK instance

Return type:

str

Parameters:

isDynamic (bool, optional) – If True, the JSON will contain the timeList, probDistList and walkList attributes, by default False.

Returns:

JSON representation of the QWAK instance.

Return type:

str

classmethod from_json(json_var, isDynamic=False)[source]

Returns a QWAK instance from a JSON representation.

Return type:

QWAK

Parameters:
  • json_var (str) – JSON representation of the QWAK instance.

  • isDynamic (bool, optional) – If True, the JSON will contain the timeList and probDistList attributes, by default False.

Returns:

QWAK instance from a JSON representation.

Return type:

QWAK

Module contents