[docs]classNXGraphState(BaseGraphState):"""Graph state simulator implemented with networkx. See :class:`~graphix.graphsim.basegraphstate.BaseGraphState` for more details. """
[docs]def__init__(self,nodes:list[int]=None,edges:list[tuple[int,int]]=None,vops:dict[int,int]=None):""" 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) """super().__init__()self._graph=nx.Graph()ifnodesisnotNone:self.add_nodes_from(nodes)ifedgesisnotNone:self.add_edges_from(edges)ifvopsisnotNone:self.apply_vops(vops)
[docs]defadd_edges_from(self,edges):self._graph.add_edges_from(edges)# adding edges may add new nodesforu,vinedges:ifunotinself._graph.nodes:self._graph.nodes[u]["loop"]=Falseself._graph.nodes[u]["sign"]=Falseself._graph.nodes[u]["hollow"]=Falseifvnotinself._graph.nodes:self._graph.nodes[v]["loop"]=Falseself._graph.nodes[v]["sign"]=Falseself._graph.nodes[v]["hollow"]=False
[docs]defnumber_of_edges(self,u:int|None=None,v:int|None=None)->int:ifuisNoneandvisNone:returnlen(self.edges)elifuisNoneorvisNone:raiseValueError("u and v must be specified together")returnself._graph.number_of_edges(u,v)