Graph state simulator

graphix.graphsim module

This provides an efficient graph state simulator using the decorated graph method.

Graph simulator.

class graphix.graphsim.GraphState(incoming_graph_data=None, *, backend=None, **attr)[source]

Graph state simulator implemented with networkx.

Performs Pauli measurements on graph states.

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)

__init__(nodes: Iterable[int] | None = None, edges: Iterable[tuple[int, int]] | None = None, vops: Mapping[int, Clifford] | None = None) None[source]

Instantiate a graph simulator.

Parameters:
  • nodes (Iterable[int]) – A container of nodes

  • edges (Iterable[tuple[int, int]]) – list of tuples (i,j) for pairs to be entangled.

  • vops (Mapping[int, Clifford]) – dict of local Clifford gates with keys for node indices and Cliffords

add_node(node_for_adding: int, **attr: Any) None[source]

Wrap networkx.Graph.add_node to initialize MBQCGraphNode attributes.

add_nodes_from(nodes_for_adding: Iterable[int | tuple[int, MBQCGraphNode]], **attr: Any) None[source]

Wrap networkx.Graph.add_nodes_from to initialize MBQCGraphNode attributes.

advance(node: int) None[source]

Flip 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: Mapping[int, Clifford]) None[source]

Apply local Clifford operators to the graph state from a dictionary.

Parameters:

vops (Mapping[int, Clifford]) – dict containing node indices as keys and local Clifford

Return type:

None

draw(fill_color: str = 'C0', **kwargs: dict[str, Any]) None[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 – 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: int) None[source]

Flip 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

get_isolates() list[int][source]

Return a list of isolated nodes (nodes with no edges).

get_vops() dict[int, Clifford][source]

Apply local Clifford operators to the graph state from a dictionary.

Returns:

vops – dict containing node indices as keys and local Cliffords

Return type:

dict[int, Clifford]

h(node: int) None[source]

Apply H gate to a qubit (node).

Parameters:

node (int) – graph node to apply H gate

Return type:

None

local_complement(node: int) None[source]

Perform local complementation of a graph.

measure_x(node: int, choice: Outcome = 0) Outcome[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: Outcome = 0) Outcome[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: Outcome = 0) Outcome[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

s(node: int) None[source]

Apply S gate to a qubit (node).

Parameters:

node (int) – graph node to apply S gate

Return type:

None

to_statevector() Statevec[source]

Convert the graph state into a state vector.

z(node: int) None[source]

Apply Z gate to a qubit (node).

Parameters:

node (int) – graph node to apply Z gate

Return type:

None