cluster_sim.simulator package

class cluster_sim.simulator.ClusterState(num_nodes)

Bases: object

Adapter class containing a GraphRegister object.

Parameters:

num_nodes (int)

CX(control, qubit)
Parameters:
CZ(control, qubit)
Parameters:
H(qubit)
Parameters:

qubit (int)

I(qubit)
Parameters:

qubit (int)

M(qubit, force=-1)

Shorthand for MZ

Parameters:
MX(qubit, force=-1)
Parameters:
MY(qubit, force=-1)
Parameters:
MZ(qubit, force=-1)
Parameters:
S(qubit)
Parameters:

qubit (int)

SH(qubit)
Parameters:

qubit (int)

S_DAG(qubit)
Parameters:

qubit (int)

X(qubit)
Parameters:

qubit (int)

Y(qubit)
Parameters:

qubit (int)

Z(qubit)
Parameters:

qubit (int)

add_edge(qubit1, qubit2)
add_node(vop='YC')
Parameters:

vop (str)

property adjacency_list
property adjacency_matrix
apply_VOP(qubit, vop)

Apply vertex operators.

Parameters:
draw(label_func=<function ClusterState.<lambda>>, **kwargs)
duplicate(targets=None)

Generate a copy of the selection and return a larger object.

Parameters:

targets (list[int] | None) – The qubits to copy. Defaults to all qubits.

edge_local_complementation(edge)

Apply an edge local complementation.

Parameters:

edge (tuple[int, int]) – _description_

classmethod from_cytoscape(data)

Load a simulator from cytoscape.

classmethod from_json(json_data)

Convert the graph state to a JSON-serializable format.

Returns:

A JSON-serializable representation of the graph state.

classmethod from_networkx(graph)
Parameters:

graph (Graph)

classmethod from_rustworkx(graph)

Create a graph state from rustworkx.

Parameters:

graph (PyGraph | PyDiGraph) – rustworkx graph.

Returns:

class object

Return type:

ClusterState

classmethod from_text(text, return_log=False)

Create a cluster state from a text-based representation of operations.

Parameters:
fusion_gate(qubit1, qubit2, gate_control='I', gate_target='I', mode='success', force=0)

Apply a fusion gate.

Type II fusion of the form XXZZ corresponds to gate_control = I and gate_target = I. Type II fusion of the form XZZX corresponds to gate_control = H and gate_target = I.

For more details, see https://arxiv.org/pdf/2312.02377.

Parameters:
  • qubit1 (int) – which qubit to apply

  • qubit2 (int) – which qubit to apply

  • gate_control (str) – either I or H

  • gate_target (str) – either I or H or SH

  • mode (str, optional) – Either “success”, “failure”, or “random”. Defaults to “success”.

  • force (int) – Force the measurements according to the following mapping: - 0 : Qubit 1 = 0, Qubit 2 = 0 - 1 : Qubit 1 = 0, Qubit 2 = 1 - 2 : Qubit 1 = 1, Qubit 2 = 0 - 3 : Qubit 1 = 1, Qubit 2 = 1 - -1 : Random measurement

local_complementation(qubit)

Apply a local complementation.

Parameters:

qubit (int) – which qubit to apply

measure(qubit, force=-1, basis='Z')

Measure a node in the graph state.

Parameters:
  • qubit (int) – The qubit to measure, which is an integer from 0 to n-1.

  • force (int) – Whether to force the measurement outcome.

  • basis (str) – The basis to measure in, which is either ‘X’, ‘Y’ or ‘Z’.

classmethod random_graph(num_nodes, p=0.5, local_cliffords=False)

Generate a random graph.

Parameters:
  • num_nodes (int) – number of nodes

  • p (float) – Probability of generating an edge. Defaults to 0.5.

  • local_cliffords (bool) – Randomize local cliffords. Defaults to False.

remove_edge(qubit1, qubit2)
remove_node(qubits)
Parameters:

qubits (int | list[int])

property stabilizers
subgraph(targets=None)

Generate a copy and return a larger object.

This does not copy any edges out of the selection.

Parameters:

targets (list[int] | None) – The qubits to copy. Defaults to all qubits.

to_cytoscape(export_elements=False)

Export to cytoscape.

to_json()

Convert the graph state to a JSON-serializable format.

Returns:

A JSON-serializable representation of the graph state.

to_networkx(options={'neighbors': False, 'stabilizer': False, 'vop': True})

Export data from the underlying state.

Turning off vop = True may lead to unintended behaviour when recreating the state.

Parameters:

options (dict, optional) – Default options. Defaults to {“stabilizer” : False, “vop”: True}.

Returns:

networkx representation

Return type:

nx.Graph

to_rustworkx(options={'neighbors': False, 'stabilizer': False, 'vop': True})

Export data from the underlying state.

Turning off vop = True may lead to unintended behaviour when recreating the state.

Parameters:

options (dict, optional) – Default options. Defaults to {“stabilizer” : False, “vop”: True}.

Returns:

rustworkx representation

Return type:

rx.PyGraph

toggle_edge(qubit1, qubit2)
property vertex_operators

Submodules

cluster_sim.simulator.cluster_state module

class cluster_sim.simulator.cluster_state.ClusterState(num_nodes)

Bases: object

Adapter class containing a GraphRegister object.

Parameters:

num_nodes (int)

CX(control, qubit)
Parameters:
CZ(control, qubit)
Parameters:
H(qubit)
Parameters:

qubit (int)

I(qubit)
Parameters:

qubit (int)

M(qubit, force=-1)

Shorthand for MZ

Parameters:
MX(qubit, force=-1)
Parameters:
MY(qubit, force=-1)
Parameters:
MZ(qubit, force=-1)
Parameters:
S(qubit)
Parameters:

qubit (int)

SH(qubit)
Parameters:

qubit (int)

S_DAG(qubit)
Parameters:

qubit (int)

X(qubit)
Parameters:

qubit (int)

Y(qubit)
Parameters:

qubit (int)

Z(qubit)
Parameters:

qubit (int)

add_edge(qubit1, qubit2)
add_node(vop='YC')
Parameters:

vop (str)

property adjacency_list
property adjacency_matrix
apply_VOP(qubit, vop)

Apply vertex operators.

Parameters:
draw(label_func=<function ClusterState.<lambda>>, **kwargs)
duplicate(targets=None)

Generate a copy of the selection and return a larger object.

Parameters:

targets (list[int] | None) – The qubits to copy. Defaults to all qubits.

edge_local_complementation(edge)

Apply an edge local complementation.

Parameters:

edge (tuple[int, int]) – _description_

classmethod from_cytoscape(data)

Load a simulator from cytoscape.

classmethod from_json(json_data)

Convert the graph state to a JSON-serializable format.

Returns:

A JSON-serializable representation of the graph state.

classmethod from_networkx(graph)
Parameters:

graph (Graph)

classmethod from_rustworkx(graph)

Create a graph state from rustworkx.

Parameters:

graph (PyGraph | PyDiGraph) – rustworkx graph.

Returns:

class object

Return type:

ClusterState

classmethod from_text(text, return_log=False)

Create a cluster state from a text-based representation of operations.

Parameters:
fusion_gate(qubit1, qubit2, gate_control='I', gate_target='I', mode='success', force=0)

Apply a fusion gate.

Type II fusion of the form XXZZ corresponds to gate_control = I and gate_target = I. Type II fusion of the form XZZX corresponds to gate_control = H and gate_target = I.

For more details, see https://arxiv.org/pdf/2312.02377.

Parameters:
  • qubit1 (int) – which qubit to apply

  • qubit2 (int) – which qubit to apply

  • gate_control (str) – either I or H

  • gate_target (str) – either I or H or SH

  • mode (str, optional) – Either “success”, “failure”, or “random”. Defaults to “success”.

  • force (int) – Force the measurements according to the following mapping: - 0 : Qubit 1 = 0, Qubit 2 = 0 - 1 : Qubit 1 = 0, Qubit 2 = 1 - 2 : Qubit 1 = 1, Qubit 2 = 0 - 3 : Qubit 1 = 1, Qubit 2 = 1 - -1 : Random measurement

local_complementation(qubit)

Apply a local complementation.

Parameters:

qubit (int) – which qubit to apply

measure(qubit, force=-1, basis='Z')

Measure a node in the graph state.

Parameters:
  • qubit (int) – The qubit to measure, which is an integer from 0 to n-1.

  • force (int) – Whether to force the measurement outcome.

  • basis (str) – The basis to measure in, which is either ‘X’, ‘Y’ or ‘Z’.

classmethod random_graph(num_nodes, p=0.5, local_cliffords=False)

Generate a random graph.

Parameters:
  • num_nodes (int) – number of nodes

  • p (float) – Probability of generating an edge. Defaults to 0.5.

  • local_cliffords (bool) – Randomize local cliffords. Defaults to False.

remove_edge(qubit1, qubit2)
remove_node(qubits)
Parameters:

qubits (int | list[int])

property stabilizers
subgraph(targets=None)

Generate a copy and return a larger object.

This does not copy any edges out of the selection.

Parameters:

targets (list[int] | None) – The qubits to copy. Defaults to all qubits.

to_cytoscape(export_elements=False)

Export to cytoscape.

to_json()

Convert the graph state to a JSON-serializable format.

Returns:

A JSON-serializable representation of the graph state.

to_networkx(options={'neighbors': False, 'stabilizer': False, 'vop': True})

Export data from the underlying state.

Turning off vop = True may lead to unintended behaviour when recreating the state.

Parameters:

options (dict, optional) – Default options. Defaults to {“stabilizer” : False, “vop”: True}.

Returns:

networkx representation

Return type:

nx.Graph

to_rustworkx(options={'neighbors': False, 'stabilizer': False, 'vop': True})

Export data from the underlying state.

Turning off vop = True may lead to unintended behaviour when recreating the state.

Parameters:

options (dict, optional) – Default options. Defaults to {“stabilizer” : False, “vop”: True}.

Returns:

rustworkx representation

Return type:

rx.PyGraph

toggle_edge(qubit1, qubit2)
property vertex_operators