Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions graphsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VertexIndex> all_qubits;
unordered_set<VertexIndex> all_qubits;
for (VertexIterConst i = vertices.begin(); i != vertices.end(); i++) {
all_qubits.insert (i-vertices.begin());
}
Expand Down Expand Up @@ -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<VertexIndex> vs1,
const hash_set<VertexIndex> vs2)
void GraphRegister::toggle_edges (const unordered_set<VertexIndex> vs1,
const unordered_set<VertexIndex> vs2)
{
hash_set<Edge, edge_hash> procd_edges;
unordered_set<Edge, edge_hash> procd_edges;
for (VtxIdxIterConst i = vs1.begin(); i != vs1.end(); i++) {
for (VtxIdxIterConst j = vs2.begin(); j != vs2.end(); j++) {
if ((*i != *j) &&
Expand All @@ -253,7 +253,7 @@ int GraphRegister::graph_Z_measure (VertexIndex v, int force)
#ifdef DEBUGOUTPUT
print_adj_list_line (cout, v);
#endif
hash_set<VertexIndex> nbg = vertices[v].neighbors;
unordered_set<VertexIndex> nbg = vertices[v].neighbors;
for (VtxIdxIter i = nbg.begin(); i != nbg.end(); i++) {
del_edge (v, *i);
if (res) {
Expand All @@ -278,7 +278,7 @@ int GraphRegister::graph_Y_measure (VertexIndex v, int force)
res = force;
}
DBGOUT ("gYm" << v << "," << res << " ");
hash_set<VertexIndex> vnbg = vertices[v].neighbors;
unordered_set<VertexIndex> vnbg = vertices[v].neighbors;
for (VtxIdxIter i = vnbg.begin(); i != vnbg.end(); i++) {
if (res) {
vertices[*i].byprod = vertices[*i].byprod * lco_spiZ;
Expand Down Expand Up @@ -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<VertexIndex> vn = vertices[v].neighbors;
hash_set<VertexIndex> vbn = vertices[vb].neighbors;
unordered_set<VertexIndex> vn = vertices[v].neighbors;
unordered_set<VertexIndex> vbn = vertices[vb].neighbors;
// First, put the byproduct ops:
if (! res) {
// measured a |+>:
Expand Down Expand Up @@ -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<VertexIndex> isc;
unordered_set<VertexIndex> isc;
for (VtxIdxIter i = vn.begin(); i != vn.end(); i++) {
if (vbn.find(*i) != vbn.end()) {
isc.insert (*i);
Expand Down Expand Up @@ -439,7 +439,7 @@ void GraphRegister::invert_neighborhood (VertexIndex v)
DBGOUT ("Inverting about ");
print_adj_list_line (cout, v);
#endif
hash_set<VertexIndex> vn = vertices[v].neighbors;
unordered_set<VertexIndex> vn = vertices[v].neighbors;
for (VtxIdxIter i = vn.begin(); i != vn.end(); i++) {
for (VtxIdxIter j = i; j != vn.end(); j++) {
if (*i != *j) {
Expand Down
12 changes: 7 additions & 5 deletions graphsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ For GNU C++, the header file <ext/hash_set> 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
Expand Down Expand Up @@ -97,7 +99,7 @@ struct QubitVertex {
the one-way quantum computer.*/
LocCliffOp byprod;
/*! neigbors is the adjacency list for this vertex */
hash_set<VertexIndex> neighbors;
unordered_set<VertexIndex> 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>. */
Expand Down Expand Up @@ -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<VertexIndex> vs1,
const hash_set<VertexIndex> vs2);
void toggle_edges (const unordered_set<VertexIndex> vs1,
const unordered_set<VertexIndex> vs2);
bool remove_byprod_op (VertexIndex v, VertexIndex use_not);
void cphase_with_table (VertexIndex v1, VertexIndex v2);
ConnectionInfo getConnectionInfo (VertexIndex v1, VertexIndex v2);
Expand All @@ -161,12 +163,12 @@ iterator typedef is a handy abbreviation. */
typedef vector<QubitVertex>::iterator VertexIter;
/*! Another iterator, this one for the adjacency lists QubitVertex::neigbors,
and subsets. */
typedef hash_set<VertexIndex>::iterator VtxIdxIter;
typedef unordered_set<VertexIndex>::iterator VtxIdxIter;

/*! A constant version of VertexIter */
typedef vector<QubitVertex>::const_iterator VertexIterConst;
/*! A constant version of VtxIdxIter */
typedef hash_set<VertexIndex>::const_iterator VtxIdxIterConst;
typedef unordered_set<VertexIndex>::const_iterator VtxIdxIterConst;


/*! Apply the local (i.e. single-qubit) operation o on vertex v. */
Expand Down
6 changes: 3 additions & 3 deletions stabilizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Stabilizer::Stabilizer (const VertexIndex numQubits_):


Stabilizer::Stabilizer (const GraphRegister& gr,
const hash_set<VertexIndex>& qubits):
const unordered_set<VertexIndex>& qubits):
paulis (qubits.size(), vector<LocCliffOp> (qubits.size(), lco_Id)),
rowsigns (qubits.size()),
vtxidx (qubits.size())
Expand All @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions stabilizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ defines the Stabilizer class */
#include <cassert>
#include "loccliff.h"

#include <ext/hash_set>
#ifndef SWIG
using __gnu_cxx::hash_set;
#endif
// #include <ext/hash_set>
// #ifndef SWIG
// using __gnu_cxx::hash_set;
// #endif

#include <unordered_set>
// See note at top of file graphsim.h in case of problems compiling
// the preceding lines.

Expand Down Expand Up @@ -55,7 +57,7 @@ struct Stabilizer {
vector<RightPhase> rowsigns;
vector<VertexIndex> vtxidx;
Stabilizer (const VertexIndex numQubits_);
Stabilizer (const GraphRegister& gr, const hash_set<VertexIndex>& qubits);
Stabilizer (const GraphRegister& gr, const unordered_set<VertexIndex>& qubits);
Stabilizer (QState * qs);
void add_row (unsigned target, unsigned addend);
void conjugate (unsigned row, unsigned col, const LocCliffOp trans);
Expand Down