class mentpy.GraphState(networkx.classes.graph.Graph)

A graph state class that inherits from networkx.Graph.

Examples

Create a 1D cluster state \(|G>\) of five qubits

In [1]: g = mp.GraphState()

In [2]: g.add_edges_from([(0,1), (1,2), (2,3), (3, 4)])

In [3]: print(g)
GraphState with 5 nodes and 4 edges

See also

mentpy.mbqc.MBQCircuit

Classes

adjlist_inner_dict_factory

alias of dict

adjlist_outer_dict_factory

alias of dict

edge_attr_dict_factory

alias of dict

graph_attr_dict_factory

alias of dict

node_attr_dict_factory

alias of dict

node_dict_factory

alias of dict

Constructors

GraphState(*args, **kwargs)

Initialize a graph state. See networkx.Graph for more information.

String representation

__repr__()

Return repr(self).

__str__()

Returns a short summary of the graph.

Special methods

__contains__(n)

Returns True if n is a node, False otherwise. Use: ‘n in G’.

__eq__(other)

Return self==value.

__getitem__(n)

Returns a dict of neighbors of node n. Use: ‘G[n]’.

__iter__()

Iterate over the nodes. Use: ‘for n in G’.

__len__()

Returns the number of nodes in the graph. Use: ‘len(G)’.

Methods

add_edge(u_of_edge, v_of_edge, **attr)

Add an edge between u and v.

add_edges_from(ebunch_to_add, **attr)

Add all the edges in ebunch_to_add.

add_node(node_for_adding, **attr)

Add a single node node_for_adding and update node attributes.

add_nodes_from(nodes_for_adding, **attr)

Add multiple nodes.

add_weighted_edges_from(ebunch_to_add, weight='weight', **attr)

Add weighted edges in ebunch_to_add with specified weight attr

adjacency()

Returns an iterator over (node, adjacency dict) tuples for all nodes.

clear()

Remove all nodes and edges from the graph.

clear_edges()

Remove all edges from the graph without altering nodes.

copy(as_view=False)

Returns a copy of the graph.

edge_subgraph(edges)

Returns the subgraph induced by the specified edges.

get_edge_data(u, v, default=None)

Returns the attribute dictionary associated with edge (u, v).

has_edge(u, v)

Returns True if the edge (u, v) is in the graph.

has_node(n)

Returns True if the graph contains the node n.

index_mapping()

Return a mapping of the nodes to their indices.

is_directed()

Returns True if graph is directed, False otherwise.

is_multigraph()

Returns True if graph is a multigraph, False otherwise.

nbunch_iter(nbunch=None)

Returns an iterator over nodes contained in nbunch that are also in the graph.

neighbors(n)

Returns an iterator over all neighbors of node n.

number_of_edges(u=None, v=None)

Returns the number of edges between two nodes.

number_of_nodes()

Returns the number of nodes in the graph.

order()

Returns the number of nodes in the graph.

remove_edge(u, v)

Remove the edge between u and v.

remove_edges_from(ebunch)

Remove all edges specified in ebunch.

remove_node(n)

Remove node n.

remove_nodes_from(nodes)

Remove multiple nodes.

size(weight=None)

Returns the number of edges or total of all edge weights.

stabilizers()

Generate the stabilizers of a graph state.

subgraph(nodes)

Returns a SubGraph view of the subgraph induced on nodes.

to_directed(as_view=False)

Returns a directed representation of the graph.

to_directed_class()

Returns the class to use for empty directed copies.

to_undirected(as_view=False)

Returns an undirected copy of the graph.

to_undirected_class()

Returns the class to use for empty undirected copies.

update(edges=None, nodes=None)

Update the graph using nodes/edges/graphs as input.

Properties

property adj

Graph adjacency object holding the neighbors of each node.

property degree

A DegreeView for the Graph as G.degree or G.degree().

property edges

An EdgeView of the Graph as G.edges or G.edges().

property name

String identifier of the graph.

property nodes

A NodeView of the Graph as G.nodes or G.nodes().