diff --git a/include/find_embedding/embedding.hpp b/include/find_embedding/embedding.hpp index 29db857b..685e6c15 100644 --- a/include/find_embedding/embedding.hpp +++ b/include/find_embedding/embedding.hpp @@ -41,7 +41,7 @@ template class embedding { public: #ifdef CPPDEBUG - char *last_diagnostic; + std::string last_diagnostic; #endif private: embedding_problem_t &ep; @@ -63,7 +63,7 @@ class embedding { embedding(embedding_problem_t &e_p) : #ifdef CPPDEBUG - last_diagnostic(nullptr), + last_diagnostic(""), #endif ep(e_p), num_qubits(ep.num_qubits()), @@ -124,7 +124,7 @@ class embedding { inline const chain &get_chain(int v) const { return var_embedding[v]; } //! Get the size of a chain - inline int chainsize(int v) const { return var_embedding[v].size(); } + inline unsigned int chainsize(int v) const { return var_embedding[v].size(); } //! Get the weight of a qubit inline int weight(int q) const { return qub_weight[q]; } @@ -369,7 +369,7 @@ class embedding { //! run a long diagnostic, and if debugging is enabled, record `current_state` so that the //! error message has a little more context. if an error is found, throw a CorruptEmbeddingException - void long_diagnostic(char *current_state) { + void long_diagnostic(std::string current_state) { run_long_diagnostic(current_state); #ifdef CPPDEBUG last_diagnostic = current_state; @@ -378,7 +378,7 @@ class embedding { //! run a long diagnostic to verify the integrity of this datastructure. the guts of this function //! are its documentation, because this function only exists for debugging purposes - void run_long_diagnostic(char *current_state) const { + void run_long_diagnostic(std::string current_state) const { int err = 0; vector tmp_weight(num_qubits + num_reserved, 0); int zeros = 0; @@ -544,7 +544,7 @@ class embedding { if (err) { ep.error("errors found in data structure, current state is '%s'. quitting\n", current_state); #ifdef CPPDEBUG - if (last_diagnostic != nullptr) ep.debug("last state was %s\n", last_diagnostic); + if (last_diagnostic.size()) ep.debug("last state was %s\n", last_diagnostic); #endif print(); throw CorruptEmbeddingException("Errors found in embedding data structure. Cannot recover."); diff --git a/include/find_embedding/find_embedding.hpp b/include/find_embedding/find_embedding.hpp index 46625702..6f61374d 100644 --- a/include/find_embedding/find_embedding.hpp +++ b/include/find_embedding/find_embedding.hpp @@ -28,18 +28,18 @@ namespace find_embedding { class parameter_processor { public: - int num_vars; - int num_qubits; + unsigned int num_vars; + unsigned int num_qubits; vector qub_reserved_unscrewed; vector var_fixed_unscrewed; - int num_reserved; + unsigned int num_reserved; graph::components qub_components; - int problem_qubits; - int problem_reserved; + unsigned int problem_qubits; + unsigned int problem_reserved; - int num_fixed; + unsigned int num_fixed; vector unscrew_vars; vector screw_vars; @@ -69,8 +69,8 @@ class parameter_processor { qubit_nbrs(qub_components.component_neighbors(0)) {} private: - inline int _reserved(optional_parameters ¶ms_) { - int r = 0; + inline unsigned int _reserved(optional_parameters ¶ms_) { + unsigned int r = 0; for (auto &vC : params_.fixed_chains) { var_fixed_unscrewed[vC.first] = 1; for (auto &q : vC.second) { @@ -87,7 +87,7 @@ class parameter_processor { vector unscrew(num_vars); assert(var_fixed_unscrewed.size() == num_vars); assert(num_fixed < num_vars); - for (int i = 0, front = 0, back = num_vars - num_fixed; i < num_vars; i++) { + for (unsigned int i = 0, front = 0, back = num_vars - num_fixed; i < num_vars; i++) { if (var_fixed_unscrewed[i]) { unscrew[back++] = i; } else { @@ -110,7 +110,7 @@ class parameter_processor { map> input_chains(map> &m) { map> n; for (auto &kv : m) { - if (kv.first < 0 || kv.first >= num_vars) throw CorruptParametersException(); + if (kv.first < 0 || static_cast(kv.first) >= num_vars) throw CorruptParametersException(); auto &ju = *(n.emplace(screw_vars[kv.first], vector{}).first); if (!qub_components.into_component(0, kv.second, ju.second)) { throw CorruptParametersException(); @@ -122,7 +122,7 @@ class parameter_processor { vector input_vars(vector &V) { vector U; for (auto &v : V) { - if (v < 0 || v >= num_vars) throw CorruptParametersException(); + if (v < 0 || static_cast(v) >= num_vars) throw CorruptParametersException(); if (!var_fixed_unscrewed[v]) U.push_back(v); } return U; diff --git a/include/find_embedding/graph.hpp b/include/find_embedding/graph.hpp index 625c174a..52054140 100644 --- a/include/find_embedding/graph.hpp +++ b/include/find_embedding/graph.hpp @@ -286,7 +286,7 @@ class components { for (auto& x : nodes_in) { try { if (index.at(x) != c) return false; - } catch (std::out_of_range& _) { + } catch (std::out_of_range& /*e*/) { return false; } nodes_out.push_back(label[x]); diff --git a/include/find_embedding/pathfinder.hpp b/include/find_embedding/pathfinder.hpp index 316509d9..84c6bf21 100644 --- a/include/find_embedding/pathfinder.hpp +++ b/include/find_embedding/pathfinder.hpp @@ -211,7 +211,7 @@ class pathfinder_base : public pathfinder_public_interface { } catch (const TimeoutException & /*e*/) { ep.major_info("problem timed out"); return -2; - } catch (const ProblemCancelledException &e) { + } catch (const ProblemCancelledException & /*e*/) { ep.major_info("problem cancelled via keyboard interrupt"); if (params.interactive) return -2; @@ -574,7 +574,8 @@ class pathfinder_base : public pathfinder_public_interface { } if (got) { - if (bestEmbedding.chainsize(u) > chainlength_bound && chainlength_bound > 0) { + if (chainlength_bound > 0 && + bestEmbedding.chainsize(u) > static_cast(chainlength_bound)) { bestEmbedding.steal_all(u); bestEmbedding.tear_out(u); } diff --git a/minorminer/utils/tests/test_polynomialembedder.py b/minorminer/utils/tests/test_polynomialembedder.py index 51e1bc49..980fe661 100644 --- a/minorminer/utils/tests/test_polynomialembedder.py +++ b/minorminer/utils/tests/test_polynomialembedder.py @@ -280,13 +280,6 @@ def test_evil_K_2_2(self): emb = proc.tightestNativeBiClique(1, 1) verify_biclique(proc, emb, 1, 1, 1, 1) - for _ in range(100): # this should be plenty - proc = processor(couplers, M=2, N=2, L=4, linear=False, proc_limit=4) - emb = proc.tightestNativeBiClique(1, 1) - if emb is not None: - break - verify_biclique(proc, emb, 1, 1, 1, 1) - def test_objectives(self): couplers = [((0, 0, 0, i), (1, 0, 0, i)) for i in range(4)] couplers += [((0, 0, 1, i), (0, 1, 1, i)) for i in range(4)]