From d5da23e0a1fea22447efe44d5d5f1a2c96b4613a Mon Sep 17 00:00:00 2001 From: alexandrupaler Date: Wed, 25 Sep 2019 14:24:39 +0200 Subject: [PATCH] updated from ext/has_set to unordered_set --- graphsim.cpp | 20 ++++++++++---------- graphsim.h | 12 +++++++----- stabilizer.cpp | 6 +++--- stabilizer.h | 12 +++++++----- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/graphsim.cpp b/graphsim.cpp index b30d577..008c3e5 100644 --- a/graphsim.cpp +++ b/graphsim.cpp @@ -65,7 +65,7 @@ void GraphRegister::toggle_edge (VertexIndex v1, VertexIndex v2) You can also use print_stabilizer.*/ Stabilizer& GraphRegister::get_full_stabilizer (void) const { - hash_set all_qubits; + unordered_set all_qubits; for (VertexIterConst i = vertices.begin(); i != vertices.end(); i++) { all_qubits.insert (i-vertices.begin()); } @@ -225,10 +225,10 @@ struct edge_hash { /*! The function takes extra care not to invert an edge twice. If vs1 and vs2 are disjunct, this cannot happen and we do not need the function. If vs1 == v2s, we can do without, too. */ -void GraphRegister::toggle_edges (const hash_set vs1, - const hash_set vs2) +void GraphRegister::toggle_edges (const unordered_set vs1, + const unordered_set vs2) { - hash_set procd_edges; + unordered_set procd_edges; for (VtxIdxIterConst i = vs1.begin(); i != vs1.end(); i++) { for (VtxIdxIterConst j = vs2.begin(); j != vs2.end(); j++) { if ((*i != *j) && @@ -253,7 +253,7 @@ int GraphRegister::graph_Z_measure (VertexIndex v, int force) #ifdef DEBUGOUTPUT print_adj_list_line (cout, v); #endif - hash_set nbg = vertices[v].neighbors; + unordered_set nbg = vertices[v].neighbors; for (VtxIdxIter i = nbg.begin(); i != nbg.end(); i++) { del_edge (v, *i); if (res) { @@ -278,7 +278,7 @@ int GraphRegister::graph_Y_measure (VertexIndex v, int force) res = force; } DBGOUT ("gYm" << v << "," << res << " "); - hash_set vnbg = vertices[v].neighbors; + unordered_set vnbg = vertices[v].neighbors; for (VtxIdxIter i = vnbg.begin(); i != vnbg.end(); i++) { if (res) { vertices[*i].byprod = vertices[*i].byprod * lco_spiZ; @@ -330,8 +330,8 @@ int GraphRegister::graph_X_measure (VertexIndex v, bool* determined, VertexIndex vb = *vertices[v].neighbors.begin(); // the choosen vertex //D cerr << "vb = " << vb << endl; // preparation step: store the neighborhood of v and vb - hash_set vn = vertices[v].neighbors; - hash_set vbn = vertices[vb].neighbors; + unordered_set vn = vertices[v].neighbors; + unordered_set vbn = vertices[vb].neighbors; // First, put the byproduct ops: if (! res) { // measured a |+>: @@ -365,7 +365,7 @@ int GraphRegister::graph_X_measure (VertexIndex v, bool* determined, // STEP 2: complement with the complete subgraph induced by the // intersection of nbg(v) and nbg(vb): // First, make the intersection - hash_set isc; + unordered_set isc; for (VtxIdxIter i = vn.begin(); i != vn.end(); i++) { if (vbn.find(*i) != vbn.end()) { isc.insert (*i); @@ -439,7 +439,7 @@ void GraphRegister::invert_neighborhood (VertexIndex v) DBGOUT ("Inverting about "); print_adj_list_line (cout, v); #endif - hash_set vn = vertices[v].neighbors; + unordered_set vn = vertices[v].neighbors; for (VtxIdxIter i = vn.begin(); i != vn.end(); i++) { for (VtxIdxIter j = i; j != vn.end(); j++) { if (*i != *j) { diff --git a/graphsim.h b/graphsim.h index 586342b..984a1bb 100644 --- a/graphsim.h +++ b/graphsim.h @@ -48,6 +48,8 @@ For GNU C++, the header file hasa to be included and hash_set has to be prefixed with namespace __gnu_cxx. If you use another compiler, you might have to change the include file and the namespace identifier. + +-> Replaced hash_set with unordered_set. Old compilers may complain, but recent ones will be happy. */ #ifndef GRAPHSIM_H @@ -97,7 +99,7 @@ struct QubitVertex { the one-way quantum computer.*/ LocCliffOp byprod; /*! neigbors is the adjacency list for this vertex */ - hash_set neighbors; + unordered_set neighbors; /*! Upon construction, a qubit vertex is initialised with the Hadamard operation as VOp, and with wmpty neighbor list. This makes it represent a |0>. */ @@ -147,8 +149,8 @@ class GraphRegister { int graph_Z_measure (VertexIndex v, int force = -1); int graph_Y_measure (VertexIndex v, int force = -1); int graph_X_measure (VertexIndex v, bool* determined = NULL, int force = -1); - void toggle_edges (const hash_set vs1, - const hash_set vs2); + void toggle_edges (const unordered_set vs1, + const unordered_set vs2); bool remove_byprod_op (VertexIndex v, VertexIndex use_not); void cphase_with_table (VertexIndex v1, VertexIndex v2); ConnectionInfo getConnectionInfo (VertexIndex v1, VertexIndex v2); @@ -161,12 +163,12 @@ iterator typedef is a handy abbreviation. */ typedef vector::iterator VertexIter; /*! Another iterator, this one for the adjacency lists QubitVertex::neigbors, and subsets. */ -typedef hash_set::iterator VtxIdxIter; +typedef unordered_set::iterator VtxIdxIter; /*! A constant version of VertexIter */ typedef vector::const_iterator VertexIterConst; /*! A constant version of VtxIdxIter */ -typedef hash_set::const_iterator VtxIdxIterConst; +typedef unordered_set::const_iterator VtxIdxIterConst; /*! Apply the local (i.e. single-qubit) operation o on vertex v. */ diff --git a/stabilizer.cpp b/stabilizer.cpp index e358962..3b36a92 100644 --- a/stabilizer.cpp +++ b/stabilizer.cpp @@ -15,7 +15,7 @@ Stabilizer::Stabilizer (const VertexIndex numQubits_): Stabilizer::Stabilizer (const GraphRegister& gr, - const hash_set& qubits): + const unordered_set& qubits): paulis (qubits.size(), vector (qubits.size(), lco_Id)), rowsigns (qubits.size()), vtxidx (qubits.size()) @@ -24,11 +24,11 @@ Stabilizer::Stabilizer (const GraphRegister& gr, // Build the graph adjacency matrix with Z's and X's in the diagonal // and apply the local Clifford unitaries: int in = 0; - for (VtxIdxIter i = qubits.begin(); i != qubits.end(); i++, in++) { + for (VtxIdxIterConst i = qubits.begin(); i != qubits.end(); i++, in++) { rowsigns[in] = RightPhase (0); vtxidx[in] = *i; int jn = 0; - for (VtxIdxIter j = qubits.begin(); j != qubits.end(); j++, jn++) { + for (VtxIdxIterConst j = qubits.begin(); j != qubits.end(); j++, jn++) { if (i==j) { paulis[in][jn] = lco_X; } else { diff --git a/stabilizer.h b/stabilizer.h index ca0ab58..e65bc24 100644 --- a/stabilizer.h +++ b/stabilizer.h @@ -11,10 +11,12 @@ defines the Stabilizer class */ #include #include "loccliff.h" -#include -#ifndef SWIG -using __gnu_cxx::hash_set; -#endif +// #include +// #ifndef SWIG +// using __gnu_cxx::hash_set; +// #endif + +#include // See note at top of file graphsim.h in case of problems compiling // the preceding lines. @@ -55,7 +57,7 @@ struct Stabilizer { vector rowsigns; vector vtxidx; Stabilizer (const VertexIndex numQubits_); - Stabilizer (const GraphRegister& gr, const hash_set& qubits); + Stabilizer (const GraphRegister& gr, const unordered_set& qubits); Stabilizer (QState * qs); void add_row (unsigned target, unsigned addend); void conjugate (unsigned row, unsigned col, const LocCliffOp trans);