Graph state simulator¶
graphix.graphsim module¶
This provides an efficient graph state simulator using the decorated graph method.
- class graphix.graphsim.GraphState(nodes=None, edges=None, vops=None, use_rustworkx: bool = False)[source]¶
Factory class for graph state simulator.
- class graphix.graphsim.BaseGraphState[source]¶
Base class for graph state simulator.
Performs Pauli measurements on graph states. You can choose between networkx and rustworkx as the backend. The default is rustworkx if installed, otherwise networkx.
ref: M. Elliot, B. Eastin & C. Caves, JPhysA 43, 025301 (2010) and PRA 77, 042307 (2008)
- Each node has attributes:
- hollow:
True if node is hollow (has local H operator)
- sign:
True if node has negative sign (local Z operator)
- loop:
True if node has loop (local S operator)
- abstract add_edges_from(edges: list[tuple[int, int]]) None[source]¶
Add edges and initialize node properties of newly added nodes.
- Parameters:
edges (list[tuple[int, int]]) – must be given as list of 2-tuples (u, v)
- Return type:
None
- abstract add_nodes_from(nodes: list[int]) None[source]¶
Add nodes and initialize node properties.
- Parameters:
nodes (list[int]) – A list of nodes.
- Return type:
None
- abstract adjacency() iter[source]¶
Returns an iterator over (node, adjacency dict) tuples for all nodes.
- Returns:
An iterator over (node, adjacency dictionary) for all nodes in the graph.
- Return type:
iter
- advance(node: int) None[source]¶
Flips the loop (local S) of a node. If the loop already exist, sign is also flipped, reflecting the relation SS=Z. Note that application of S gate is different from advance if there exist an edge from the node.
- Parameters:
node (int) – graph node to advance the loop.
- Return type:
None
- apply_vops(vops: dict) None[source]¶
Apply local Clifford operators to the graph state from a dictionary
- Parameters:
vops (dict) – dict containing node indices as keys and local Clifford indices as values (see graphix.clifford.CLIFFORD)
- Return type:
None
- abstract degree() iter[tuple[int, int]][source]¶
Returns an iterator for (node, degree) tuples, where degree is the number of edges adjacent to the node
- draw(fill_color: str = 'C0', **kwargs)[source]¶
Draw decorated graph state. Negative nodes are indicated by negative sign of node labels.
- Parameters:
fill_color (str, optional) – fill color of nodes
kwargs (keyword arguments, optional) – additional arguments to supply networkx.draw().
- equivalent_fill_node(node: int) int[source]¶
Fill the chosen node by graph transformation rules E1 and E2, If the selected node is hollow and isolated, it cannot be filled and warning is thrown.
- Parameters:
node (int) – node to fill.
- Returns:
result – if the selected node is hollow and isolated, result is 1. if filled and isolated, 2. otherwise it is 0.
- Return type:
int
- equivalent_graph_E1(node: int) None[source]¶
Tranform a graph state to a different graph state representing the same stabilizer state. This rule applies only to a node with loop.
- Parameters:
node1 (int) – A graph node with a loop to apply rule E1
- Return type:
None
- equivalent_graph_E2(node1: int, node2: int) None[source]¶
Tranform a graph state to a different graph state representing the same stabilizer state. This rule applies only to two connected nodes without loop.
- Parameters:
node1 (int) – connected graph nodes to apply rule E2
node2 (int) – connected graph nodes to apply rule E2
- Return type:
None
- flip_fill(node: int) None[source]¶
Flips the fill (local H) of a node.
- Parameters:
node (int) – graph node to flip the fill
- Return type:
None
- flip_sign(node) None[source]¶
Flips the sign (local Z) of a node. Note that application of Z gate is different from flip_sign if there exist an edge from the node.
- Parameters:
node (int) – graph node to flip the sign
- Return type:
None
- abstract get_isolates() list[int][source]¶
Returns a list of isolated nodes (nodes with no edges).
- Returns:
A list of isolated nodes.
- Return type:
list[int]
- get_vops() dict[source]¶
Apply local Clifford operators to the graph state from a dictionary
- Parameters:
vops (dict) – dict containing node indices as keys and local Clifford indices as values (see graphix.clifford.CLIFFORD)
- abstract property graph: Graph | PyGraph¶
- h(node: int) None[source]¶
Apply H gate to a qubit (node).
- Parameters:
node (int) – graph node to apply H gate
- Return type:
None
- abstract local_complement(node: int) None[source]¶
Perform local complementation of a graph
- Parameters:
node (int) – chosen node for the local complementation
- Return type:
None
- measure_x(node: int, choice: int = 0) int[source]¶
perform measurement in X basis According to original paper, we realise X measurement by applying H gate to the measured node before Z measurement.
- Parameters:
node (int) – qubit index to be measured
choice (int, 0 or 1) – choice of measurement outcome. observe (-1)^choice
- Returns:
result – measurement outcome. 0 or 1.
- Return type:
int
- measure_y(node: int, choice: int = 0) int[source]¶
perform measurement in Y basis According to original paper, we realise Y measurement by applying S,Z and H gate to the measured node before Z measurement.
- Parameters:
node (int) – qubit index to be measured
choice (int, 0 or 1) – choice of measurement outcome. observe (-1)^choice
- Returns:
result – measurement outcome. 0 or 1.
- Return type:
int
- measure_z(node: int, choice: int = 0) int[source]¶
perform measurement in Z basis To realize the simple Z measurement on undecorated graph state, we first fill the measured node (remove local H gate)
- Parameters:
node (int) – qubit index to be measured
choice (int, 0 or 1) – choice of measurement outcome. observe (-1)^choice
- Returns:
result – measurement outcome. 0 or 1.
- Return type:
int
- abstract neighbors(node: int) iter[source]¶
Returns an iterator over all neighbors of node n.
- Parameters:
node (int) – A node in the graph
- Returns:
An iterator over all neighbors of node n.
- Return type:
iter
- abstract number_of_edges(u: int | None = None, v: int | None = None) int[source]¶
Returns the number of edges between two nodes.
- Parameters:
u (int, optional) – A node in the graph
v (int, optional) – A node in the graph
- Returns:
The number of edges in the graph. If u and v are specified, return the number of edges between those nodes.
- Return type:
int
- abstract remove_edge(u: int, v: int) None[source]¶
Remove an edge from the graph.
- Parameters:
u (int) – A node in the graph
v (int) – A node in the graph
- Return type:
None
- abstract remove_edges_from(edges: list[tuple[int, int]]) None[source]¶
Remove all edges specified in the list.
- Parameters:
edges (list of tuples) – A list of edges to remove from the graph.
- Return type:
None
- abstract remove_node(node: int) None[source]¶
Remove a node from the graph.
- Parameters:
node (int) – A node in the graph
- Return type:
None
- abstract remove_nodes_from(nodes: list[int]) None[source]¶
Remove all nodes specified in the list.
- Parameters:
nodes (list) – A list of nodes to remove from the graph.
- Return type:
None
- s(node: int) None[source]¶
Apply S gate to a qubit (node).
- Parameters:
node (int) – graph node to apply S gate
- Return type:
None
- class graphix.graphsim.NXGraphState(nodes: list[int] | None = None, edges: list[tuple[int, int]] | None = None, vops: dict[int, int] | None = None)[source]¶
Graph state simulator implemented with networkx. See
BaseGraphStatefor more details.- __init__(nodes: list[int] | None = None, edges: list[tuple[int, int]] | None = None, vops: dict[int, int] | None = None)[source]¶
- Parameters:
nodes (list[int]) – A container of nodes (list, dict, etc)
edges (list[tuple[int, int]]) – list of tuples (i,j) for pairs to be entangled.
vops (dict[int, int]) – dict of local Clifford gates with keys for node indices and values for Clifford index (see graphix.clifford.CLIFFORD)
- add_edges_from(edges)[source]¶
Add edges and initialize node properties of newly added nodes.
- Parameters:
edges (list[tuple[int, int]]) – must be given as list of 2-tuples (u, v)
- Return type:
None
- add_nodes_from(nodes)[source]¶
Add nodes and initialize node properties.
- Parameters:
nodes (list[int]) – A list of nodes.
- Return type:
None
- adjacency() iter[source]¶
Returns an iterator over (node, adjacency dict) tuples for all nodes.
- Returns:
An iterator over (node, adjacency dictionary) for all nodes in the graph.
- Return type:
iter
- degree() iter[tuple[int, int]][source]¶
Returns an iterator for (node, degree) tuples, where degree is the number of edges adjacent to the node
- property edges: EdgeView¶
- get_isolates() list[int][source]¶
Returns a list of isolated nodes (nodes with no edges).
- Returns:
A list of isolated nodes.
- Return type:
list[int]
- property graph: Graph¶
- local_complement(node)[source]¶
Perform local complementation of a graph
- Parameters:
node (int) – chosen node for the local complementation
- Return type:
None
- neighbors(node) iter[source]¶
Returns an iterator over all neighbors of node n.
- Parameters:
node (int) – A node in the graph
- Returns:
An iterator over all neighbors of node n.
- Return type:
iter
- property nodes: NodeView¶
- number_of_edges(u: int | None = None, v: int | None = None) int[source]¶
Returns the number of edges between two nodes.
- Parameters:
u (int, optional) – A node in the graph
v (int, optional) – A node in the graph
- Returns:
The number of edges in the graph. If u and v are specified, return the number of edges between those nodes.
- Return type:
int
- remove_edge(u: int, v: int) None[source]¶
Remove an edge from the graph.
- Parameters:
u (int) – A node in the graph
v (int) – A node in the graph
- Return type:
None
- remove_edges_from(edges: list[tuple[int, int]]) None[source]¶
Remove all edges specified in the list.
- Parameters:
edges (list of tuples) – A list of edges to remove from the graph.
- Return type:
None
- remove_node(node: int) None[source]¶
Remove a node from the graph.
- Parameters:
node (int) – A node in the graph
- Return type:
None
- class graphix.graphsim.RXGraphState(nodes: list[int] | None = None, edges: list[tuple[int, int]] | None = None, vops: dict[int, int] | None = None)[source]¶
Graph state simulator implemented with rustworkx. See
BaseGraphStatefor more details.- __init__(nodes: list[int] | None = None, edges: list[tuple[int, int]] | None = None, vops: dict[int, int] | None = None)[source]¶
- Parameters:
nodes (list[int]) – A container of nodes (list, dict, etc)
edges (list[tuple[int, int]]) – list of tuples (i,j) for pairs to be entangled.
vops (dict[int, int]) – dict of local Clifford gates with keys for node indices and values for Clifford index (see graphix.clifford.CLIFFORD)
- add_edges_from(edges)[source]¶
Add edges and initialize node properties of newly added nodes.
- Parameters:
edges (list[tuple[int, int]]) – must be given as list of 2-tuples (u, v)
- Return type:
None
- add_nodes_from(nodes: list[int])[source]¶
Add nodes and initialize node properties.
- Parameters:
nodes (list[int]) – A list of nodes.
- Return type:
None
- adjacency() iter[source]¶
Returns an iterator over (node, adjacency dict) tuples for all nodes.
- Returns:
An iterator over (node, adjacency dictionary) for all nodes in the graph.
- Return type:
iter
- degree() iter[tuple[int, int]][source]¶
Returns an iterator for (node, degree) tuples, where degree is the number of edges adjacent to the node
- get_isolates() list[int][source]¶
Returns a list of isolated nodes (nodes with no edges).
- Returns:
A list of isolated nodes.
- Return type:
list[int]
- property graph: PyGraph¶
- local_complement(node)[source]¶
Perform local complementation of a graph
- Parameters:
node (int) – chosen node for the local complementation
- Return type:
None
- neighbors(node) iter[source]¶
Returns an iterator over all neighbors of node n.
- Parameters:
node (int) – A node in the graph
- Returns:
An iterator over all neighbors of node n.
- Return type:
iter
- number_of_edges(u: int | None = None, v: int | None = None) int[source]¶
Returns the number of edges between two nodes.
- Parameters:
u (int, optional) – A node in the graph
v (int, optional) – A node in the graph
- Returns:
The number of edges in the graph. If u and v are specified, return the number of edges between those nodes.
- Return type:
int
- remove_edge(u: int, v: int) None[source]¶
Remove an edge from the graph.
- Parameters:
u (int) – A node in the graph
v (int) – A node in the graph
- Return type:
None
- remove_edges_from(edges: list[tuple[int, int]]) None[source]¶
Remove all edges specified in the list.
- Parameters:
edges (list of tuples) – A list of edges to remove from the graph.
- Return type:
None
- remove_node(node: int) None[source]¶
Remove a node from the graph.
- Parameters:
node (int) – A node in the graph
- Return type:
None
- class graphix.graphsim.NodeList(node_nums: list[int] = [], node_datas: list[dict] = [], node_indices: list[int] = [])[source]¶
Node list class for RXGraphState In rustworkx, node data is stored in a tuple (node_num, node_data), and adding/removing nodes by node_num is not supported. This class defines a node list with node_num as key.
- class graphix.graphsim.EdgeList(edge_nums: list[tuple[int, int]] = [], edge_datas: list[dict] = [], edge_indices: list[int] = [])[source]¶
Edge list class for RXGraphState In rustworkx, edge data is stored in a tuple (parent, child, edge_data), and adding/removing edges by (parent, child) is not supported. This class defines a edge list with (parent, child) as key.
- __init__(edge_nums: list[tuple[int, int]] = [], edge_datas: list[dict] = [], edge_indices: list[int] = [])[source]¶