From 49cadab18280e8c1d5e407679ba861fd86df9a89 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 11 Aug 2023 11:29:20 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20fix=20compiler=20warnings=20for?= =?UTF-8?q?=20simulation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cpp/module/QDDVis.cpp | 52 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/cpp/module/QDDVis.cpp b/cpp/module/QDDVis.cpp index ba456a5..a247762 100644 --- a/cpp/module/QDDVis.cpp +++ b/cpp/module/QDDVis.cpp @@ -235,7 +235,8 @@ Napi::Value QDDVis::Load(const Napi::CallbackInfo& info) { try { // second parameter describes the format of the algorithm - const unsigned int formatCode = (unsigned int)info[1].As(); + const auto formatCode = + static_cast(info[1].As()); if (formatCode == 1) qc->import(ss, qc::Format::OpenQASM); else if (formatCode == 2) @@ -270,17 +271,16 @@ Napi::Value QDDVis::Load(const Napi::CallbackInfo& info) { Napi::Number::New(env, static_cast(qc->getNops()))); // the third parameter (how many operations to apply immediately) - unsigned int opNum = - (unsigned int)info[2] - .As(); // at this point opNum may be bigger than the - // number of operations the algorithm has! + auto opNum = static_cast( + info[2].As()); // at this point opNum may be bigger than the + // number of operations the algorithm has! if (opNum > qc->getNops()) - opNum = qc->getNops(); + opNum = static_cast(qc->getNops()); if (opNum > 0) { - atInitial = false; - const bool process = - (bool)info[3].As(); // the fourth parameter tells us to - // process iterated operations or not + atInitial = false; + const bool process = static_cast( + info[3].As()); // the fourth parameter tells us to + // process iterated operations or not if (process) { if (sim.p != nullptr) { dd->decRef(sim); @@ -456,12 +456,12 @@ Napi::Value QDDVis::Next(const Napi::CallbackInfo& info) { state.Set("changed", Napi::Boolean::New(env, true)); if ((*iterator)->getType() == qc::Reset) { - auto qubits = (*iterator)->getTargets(); - auto totalResets = qubits.size(); - auto qubitToReset = qubits.front(); - auto qubitsReset = 0; - auto [pzero, pone] = - dd->determineMeasurementProbabilities(sim, qubitToReset, true); + auto qubits = (*iterator)->getTargets(); + auto totalResets = qubits.size(); + auto qubitToReset = qubits.front(); + auto qubitsReset = 0; + auto [pzero, pone] = dd->determineMeasurementProbabilities( + sim, static_cast(qubitToReset), true); Napi::Object reset = Napi::Object::New(env); reset.Set("qubit", Napi::Number::New(env, qubitToReset)); @@ -487,8 +487,8 @@ Napi::Value QDDVis::Next(const Napi::CallbackInfo& info) { auto qubitToMeasure = qubits.front(); auto cbitToStore = cbits.front(); auto qubitsMeasured = 0; - auto [pzero, pone] = - dd->determineMeasurementProbabilities(sim, qubitToMeasure, true); + auto [pzero, pone] = dd->determineMeasurementProbabilities( + sim, static_cast(qubitToMeasure), true); Napi::Object measurement = Napi::Object::New(env); measurement.Set("qubit", Napi::Number::New(env, qubitToMeasure)); @@ -617,9 +617,10 @@ Napi::Value QDDVis::ToLine(const Napi::CallbackInfo& info) { return state; } - unsigned int param = (unsigned int)info[0].As(); + auto param = static_cast(info[0].As()); if (param > qc->getNops()) - param = qc->getNops(); // we can't go further than to the end + // we can't go further than to the end + param = static_cast(qc->getNops()); const unsigned int targetPos = param; try { @@ -792,10 +793,10 @@ void QDDVis::UpdateExportOptions(const Napi::CallbackInfo& info) { return; } - this->showColors = (bool)info[0].As(); - this->showEdgeLabels = (bool)info[1].As(); - this->showClassic = (bool)info[2].As(); - this->usePolarCoordinates = (bool)info[3].As(); + this->showColors = static_cast(info[0].As()); + this->showEdgeLabels = static_cast(info[1].As()); + this->showClassic = static_cast(info[2].As()); + this->usePolarCoordinates = static_cast(info[3].As()); } Napi::Value QDDVis::GetExportOptions(const Napi::CallbackInfo& info) { @@ -929,7 +930,8 @@ QDDVis::ConductIrreversibleOperation(const Napi::CallbackInfo& info) { } } else { // get target classical bit - auto cbit = obj.Get("cbit").As().Int64Value(); + auto cbit = static_cast( + obj.Get("cbit").As().Int64Value()); if (classicalValueToMeasure != "none") { bool measureOne = (classicalValueToMeasure == "1"); measureQubit(qubit, measureOne, pzero, pone);