noisy_graph_states.libs module
Contains various helper functions to deal with graph transformations and numpy arrays.
The graph tool
Auxiliary functions for graph states.
Includes both functions for handling graph states as density matrices and some graph transformations that are not included directly in graphepp as of version 0.4
Functions:
|
Return the new graph after local complementation. |
|
Return the graph state in the computational basis. |
Construct a Graph object from adjacency matrix. |
|
|
Disconnect a given vertex from the rest of the graph. |
|
Apply the graph update rule corresponding to a Z-measurement. |
|
Apply the graph update rule corresponding to a Y-measurement. |
|
Apply the graph update rule corresponding to an X-measurement. |
|
Return the neighbouring vertices of a vertex. |
|
Check if two graphs are equal, i.e., they have the same edges, vertices and labels. |
|
Returns the graph state after a CNOT between source and target. |
|
Return the operator of local complementation on the n-th vertex |
|
Switch from the computational basis to a graph state basis. |
|
Switch from a graph state basis to the computational basis. |
|
Generate random nx.Graph. |
- noisy_graph_states.libs.graph.local_complementation(graph: Graph, index: int)
Return the new graph after local complementation.
Local complementation is a graph operation that inverts the subgraph induced by the neighbourhood of the index vertex.
- Parameters:
graph (nx.Graph) – The input graph.
index (int) – The label of a vertex in the graph. The local complementation operation is performed with respect to this vertex.
- Returns:
nx.Graph – The graph after the local complementation ahs been applied.
- noisy_graph_states.libs.graph.graph_state(graph)
Return the graph state in the computational basis.
- Parameters:
graph (nx.Graph) – The graph describing the graph state.
- Returns:
np.ndarray – A column-vector of the graph state given in the computational basis. shape = (2**N, 1)
- noisy_graph_states.libs.graph.graph_from_adj_matrix(adj)
Construct a Graph object from adjacency matrix.
- Parameters:
adj (np.ndarray) – The adjacency matrix. A symmetric 2D array with shape (N, N) where N is the number of vertices. An entry equal to 1 indicates an edge, while 0 indicates the absence of an edge.
- Returns:
nx.Graph – The graph corresponding to the adjacency matrix adj.
- noisy_graph_states.libs.graph.disconnect_vertex(graph, index)
Disconnect a given vertex from the rest of the graph.
This is done by removing all edges that are connecting to the specified index.
- Parameters:
graph (nx.Graph) – The input graph.
index (int) – The index-th vertex is disconnected. Counting starts at 0.
- Returns:
Graph – The updated graph.
- noisy_graph_states.libs.graph.measure_z(graph: Graph, index: int)
Apply the graph update rule corresponding to a Z-measurement.
The index vertex is disconnected from the rest of the graph.
- Parameters:
graph (nx.Graph)
index (int) – The vertex corresponding to the qubit that is measured in Z.
- Returns:
nx.Graph
- noisy_graph_states.libs.graph.measure_y(graph: Graph, index: int)
Apply the graph update rule corresponding to a Y-measurement.
First, a local complementation with respect to the index vertex is performed. Then, it is disconnected from the rest of the graph.
- Parameters:
graph (nx.Graph)
index (int) – The vertex corresponding to the qubit that is measured in Y.
- Returns:
nx.Graph
- noisy_graph_states.libs.graph.measure_x(graph: Graph, index: int, b0: int | None = None)
Apply the graph update rule corresponding to an X-measurement.
For this rule a special neighbour b0 of the index vertex is specified for this operation unless the index vertex is isolated. The following four steps are performed: 1. Local complementation with respect to the b0 vertex. 2. Local complementation with respect to the index vertex. 3. Disconnect the index vertex. 4. Local complementation with respect to the b0 vertex.
- Parameters:
graph (nx.Graph)
index (int) – The vertex corresponding to the qubit that is measured in Z.
b0 (int or None) – The special neighbour b0 of the index vertex. If None, a neighbour will automatically be picked (according to the edge listed first in the networkx graph) - or no neighbour if the index vertex is isolated.
- Returns:
nx.Graph
- noisy_graph_states.libs.graph.neighbourhood(graph, index)
Return the neighbouring vertices of a vertex.
- Parameters:
graph (nx.Graph) – The neighbours are defined according to this graph.
index (int) – The index-th vertex is considered. Counting starts at 0.
- Returns:
tuple[int] – Contains all the neighbours of the index-th vertex.
- noisy_graph_states.libs.graph.check_equality(graph1, graph2)
Check if two graphs are equal, i.e., they have the same edges, vertices and labels.
- Parameters:
graph1 (nx.Graph) – The first graph.
graph2 (nx.Graph) – The second graph.
- Returns:
bool – True if the graphs are equal, False otherwise.
- noisy_graph_states.libs.graph.update_graph_cnot(graph, source, target)
Returns the graph state after a CNOT between source and target.
- Parameters:
graph (nx.Graph) – The CNOT is applied to this graph.
source (int) – The source-th vertex is considered. Counting starts at 0.
target (int) – The target-th vertex is considered. Counting starts at 0.
- Returns:
graph (nx.Graph) – Graph after the CNOT is applied.
- noisy_graph_states.libs.graph.complement_op(graph, index)
Return the operator of local complementation on the n-th vertex
- Parameters:
graph (nx.Graph) – The graph describing the adjacencies needed to define the operator.
index (int) – The index of the vertex around which local complementation is performed.
- Returns:
np.ndarray – An operator that performs the local complementation when applied to a graph state in the computational basis. shape = (2**graph.N, 2**graph.N)
- noisy_graph_states.libs.graph.Ugraph(rho, graph)
Switch from the computational basis to a graph state basis.
Transforms a density matrix given in the computational basis to a density matrix given in the graph state basis defined by graph.
- Parameters:
rho (np.ndarray) – A density matrix given in the computational basis.
graph (nx.Graph) – The graph defining the desired graph state basis.
- Returns:
np.ndarray – The same density matrix in the graph state basis.
- noisy_graph_states.libs.graph.Ungraph(rho, graph)
Switch from a graph state basis to the computational basis.
Transforms a density matrix given in the graph state basis defined by graph to a density matrix given in the computational basis.
- Parameters:
rho (np.ndarray) – A density matrix given in the graph state basis.
graph (nx.Graph) – The graph defining the graph state basis, in which is given rho.
- Returns:
np.ndarray – The same density matrix in the computational basis.
- noisy_graph_states.libs.graph.random_graph(num_vertices, p=0.5)
Generate random nx.Graph.
Graph with num_vertices vertices. Each edge exists with probability p.
The matrix tool
A collection of useful matrix functions.
Functions:
|
|
|
|
|
Returns the matrix representation of the tensor product of an arbitrary number of matrices. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gives the N-qubit CNOT unitary with the n-th qubit as source and the m-th qubit as target |
|
gives the N-qubit CZ unitary acting on n-th and m-th qubit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- noisy_graph_states.libs.matrix.H(rho)
- noisy_graph_states.libs.matrix.I(n)
- noisy_graph_states.libs.matrix.tensor(*args)
Returns the matrix representation of the tensor product of an arbitrary number of matrices.
- noisy_graph_states.libs.matrix.znoisy(rho, n)
- noisy_graph_states.libs.matrix.xnoisy(rho, n)
- noisy_graph_states.libs.matrix.ynoisy(rho, n)
- noisy_graph_states.libs.matrix.znoise(rho, n, p)
- noisy_graph_states.libs.matrix.xnoise(rho, n, p)
- noisy_graph_states.libs.matrix.ynoise(rho, n, p)
- noisy_graph_states.libs.matrix.wnoise(rho, n, p)
- noisy_graph_states.libs.matrix.wnoise_all(rho, p)
- noisy_graph_states.libs.matrix.noise_global(rho, p)
- noisy_graph_states.libs.matrix.CNOT(n, m, N)
gives the N-qubit CNOT unitary with the n-th qubit as source and the m-th qubit as target
- noisy_graph_states.libs.matrix.CZ(n, m, N)
gives the N-qubit CZ unitary acting on n-th and m-th qubit
- noisy_graph_states.libs.matrix.Ucnot(psi, n, m)
- noisy_graph_states.libs.matrix.Ucz(psi, n, m)
- noisy_graph_states.libs.matrix.Mcnot(rho, n, m)
- noisy_graph_states.libs.matrix.Mcz(rho, n, m)
- noisy_graph_states.libs.matrix.vec_reorder(psi, sys)
- noisy_graph_states.libs.matrix.reorder(rho, sys)
- noisy_graph_states.libs.matrix.ptranspose(rho, sys)
- noisy_graph_states.libs.matrix.ptrace(rho, sys)