Skip to content

Commit

Permalink
Reduce warning meesages (#2013)
Browse files Browse the repository at this point in the history
* reduce warning meesages

* format

* fix Windows

* uint -> uint_t

* fix Thrust seg fault

* format
  • Loading branch information
doichanj authored Dec 22, 2023
1 parent f7fcbc2 commit 180a0b6
Show file tree
Hide file tree
Showing 51 changed files with 776 additions and 840 deletions.
2 changes: 1 addition & 1 deletion qiskit_aer/backends/wrappers/aer_circuit_binding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void bind_aer_circuit(MODULE m) {
<< ", num_registers=" << circ.num_registers;

ss << ", ops={";
for (auto i = 0; i < circ.ops.size(); ++i)
for (uint_t i = 0; i < circ.ops.size(); ++i)
if (i == 0)
ss << circ.ops[i];
else
Expand Down
10 changes: 5 additions & 5 deletions qiskit_aer/backends/wrappers/aer_state_binding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ void bind_aer_state(MODULE m) {
size_t mat_len = (1UL << qubits.size());
auto ptr = values.unchecked<2>();
cmatrix_t mat(mat_len, mat_len);
for (auto i = 0; i < mat_len; ++i)
for (auto j = 0; j < mat_len; ++j)
for (uint_t i = 0; i < mat_len; ++i)
for (uint_t j = 0; j < mat_len; ++j)
mat(i, j) = ptr(i, j);
state.apply_unitary(qubits, mat);
});
Expand All @@ -144,10 +144,10 @@ void bind_aer_state(MODULE m) {
size_t mat_size = (1UL << control_qubits.size());
auto ptr = values.unchecked<3>();
std::vector<cmatrix_t> mats;
for (auto i = 0; i < mat_size; ++i) {
for (uint_t i = 0; i < mat_size; ++i) {
cmatrix_t mat(mat_len, mat_len);
for (auto j = 0; j < mat_len; ++j)
for (auto k = 0; k < mat_len; ++k)
for (uint_t j = 0; j < mat_len; ++j)
for (uint_t k = 0; k < mat_len; ++k)
mat(j, k) = ptr(i, j, k);
mats.push_back(mat);
}
Expand Down
18 changes: 9 additions & 9 deletions src/controllers/aer_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ size_t Controller::get_system_memory_mb() {
size_t Controller::get_gpu_memory_mb() {
size_t total_physical_memory = 0;
#ifdef AER_THRUST_GPU
for (int_t iDev = 0; iDev < target_gpus_.size(); iDev++) {
for (uint_t iDev = 0; iDev < target_gpus_.size(); iDev++) {
size_t freeMem, totalMem;
cudaSetDevice(target_gpus_[iDev]);
cudaMemGetInfo(&freeMem, &totalMem);
Expand Down Expand Up @@ -515,7 +515,7 @@ Result Controller::execute(std::vector<std::shared_ptr<Circuit>> &circuits,
uint_t result_size;
reg_t result_offset(circuits.size());
result_size = 0;
for (int_t i = 0; i < circuits.size(); i++) {
for (uint_t i = 0; i < circuits.size(); i++) {
result_offset[i] = result_size;
result_size += circuits[i]->num_bind_params;
}
Expand All @@ -532,11 +532,11 @@ Result Controller::execute(std::vector<std::shared_ptr<Circuit>> &circuits,
// set parallelization for experiments
try {
uint_t res_pos = 0;
for (int i = 0; i < circuits.size(); i++) {
for (uint_t i = 0; i < circuits.size(); i++) {
executors[i] = make_circuit_executor(methods[i]);
required_memory_mb_list[i] =
executors[i]->required_memory_mb(config, *circuits[i], noise_model);
for (int j = 0; j < circuits[i]->num_bind_params; j++) {
for (uint_t j = 0; j < circuits[i]->num_bind_params; j++) {
result.results[res_pos++].metadata.add(required_memory_mb_list[i],
"required_memory_mb");
}
Expand Down Expand Up @@ -588,19 +588,19 @@ Result Controller::execute(std::vector<std::shared_ptr<Circuit>> &circuits,
reg_t seeds(result_size);
reg_t avg_seeds(result_size);
int_t iseed = 0;
for (int_t i = 0; i < circuits.size(); i++) {
for (uint_t i = 0; i < circuits.size(); i++) {
if (circuits[i]->num_bind_params > 1) {
for (int_t j = 0; i < circuits[i]->num_bind_params; i++)
for (uint_t j = 0; i < circuits[i]->num_bind_params; i++)
seeds[iseed++] = circuits[i]->seed_for_params[j];
} else
seeds[iseed++] = circuits[i]->seed;
}
MPI_Allreduce(seeds.data(), avg_seeds.data(), result_size, MPI_UINT64_T,
MPI_SUM, MPI_COMM_WORLD);
iseed = 0;
for (int_t i = 0; i < circuits.size(); i++) {
for (uint_t i = 0; i < circuits.size(); i++) {
if (circuits[i]->num_bind_params > 1) {
for (int_t j = 0; i < circuits[i]->num_bind_params; i++)
for (uint_t j = 0; i < circuits[i]->num_bind_params; i++)
circuits[i]->seed_for_params[j] =
avg_seeds[iseed++] / num_processes_;
} else
Expand All @@ -626,7 +626,7 @@ Result Controller::execute(std::vector<std::shared_ptr<Circuit>> &circuits,

bool all_failed = true;
result.status = Result::Status::completed;
for (int i = 0; i < result.results.size(); ++i) {
for (uint_t i = 0; i < result.results.size(); ++i) {
auto &experiment = result.results[i];
if (experiment.status == ExperimentResult::Status::completed) {
all_failed = false;
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/controller_execute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ Result controller_execute(std::vector<std::shared_ptr<Circuit>> &input_circs,
param_circ->global_phase_for_params.resize(num_params);
for (size_t j = 0; j < num_params; j++)
param_circ->global_phase_for_params[j] = params.second[j];
} else if (instr_pos >= num_instr) {
} else if ((uint_t)instr_pos >= num_instr) {
throw std::invalid_argument(
R"(Invalid parameterized qobj: instruction position out of range)");
}
auto &op = param_circ->ops[instr_pos];
if (!op.has_bind_params) {
if (param_pos >= op.params.size()) {
if ((uint_t)param_pos >= op.params.size()) {
throw std::invalid_argument(
R"(Invalid parameterized qobj: instruction param position out of range)");
}
Expand Down Expand Up @@ -160,15 +160,15 @@ Result controller_execute(std::vector<std::shared_ptr<Circuit>> &input_circs,
// negative position is for global phase
circ->global_phase_angle = params.second[j];
} else {
if (instr_pos >= num_instr) {
if ((uint_t)instr_pos >= num_instr) {
std::cout << "Invalid parameterization: instruction position "
"out of range: "
<< instr_pos << std::endl;
throw std::invalid_argument(
R"(Invalid parameterization: instruction position out of range)");
}
auto &op = param_circ->ops[instr_pos];
if (param_pos >= op.params.size()) {
if ((uint_t)param_pos >= op.params.size()) {
throw std::invalid_argument(
R"(Invalid parameterization: instruction param position out of range)");
}
Expand Down Expand Up @@ -215,7 +215,7 @@ Result controller_execute(std::vector<std::shared_ptr<Circuit>> &input_circs,
for (auto &circ : circs) {
circ->seed = seed + seed_shift;
circ->seed_for_params.resize(circ->num_bind_params);
for (int_t i = 0; i < circ->num_bind_params; i++) {
for (uint_t i = 0; i < circ->num_bind_params; i++) {
circ->seed_for_params[i] = seed + seed_shift;
seed_shift += 2113;
}
Expand Down
16 changes: 8 additions & 8 deletions src/controllers/state_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ void AerState::set_seed(int_t seed) {
reg_t AerState::allocate_qubits(uint_t num_qubits) {
assert_not_initialized();
reg_t ret;
for (auto i = 0; i < num_qubits; ++i)
for (uint_t i = 0; i < num_qubits; ++i)
ret.push_back(num_of_qubits_++);
return ret;
};
Expand Down Expand Up @@ -816,7 +816,7 @@ reg_t AerState::initialize_statevector(uint_t num_of_qubits, complex_t *data,

reg_t ret;
ret.reserve(num_of_qubits);
for (auto i = 0; i < num_of_qubits; ++i)
for (uint_t i = 0; i < num_of_qubits; ++i)
ret.push_back(i);
return ret;
};
Expand Down Expand Up @@ -861,7 +861,7 @@ reg_t AerState::initialize_density_matrix(uint_t num_of_qubits, complex_t *data,

reg_t ret;
ret.reserve(num_of_qubits);
for (auto i = 0; i < num_of_qubits; ++i)
for (uint_t i = 0; i < num_of_qubits; ++i)
ret.push_back(i);
return ret;
};
Expand Down Expand Up @@ -892,7 +892,7 @@ AER::Vector<complex_t> AerState::move_to_vector() {
throw std::runtime_error("move_to_vector() supports only statevector or "
"matrix_product_state or density_matrix methods");
}
for (auto i = 0; i < num_of_qubits_; ++i)
for (uint_t i = 0; i < num_of_qubits_; ++i)
op.qubits.push_back(i);
op.string_params.push_back("s");
op.save_type = Operations::DataSubType::single;
Expand All @@ -907,7 +907,7 @@ AER::Vector<complex_t> AerState::move_to_vector() {
.value()["s"]
.value());
clear();
return std::move(vec);
return vec;
} else if (method_ == Method::density_matrix) {
auto mat =
std::move(static_cast<DataMap<AverageData, matrix<complex_t>, 1>>(
Expand All @@ -917,7 +917,7 @@ AER::Vector<complex_t> AerState::move_to_vector() {
auto vec = Vector<complex_t>::move_from_buffer(
mat.GetColumns() * mat.GetRows(), mat.move_to_buffer());
clear();
return std::move(vec);
return vec;
} else {
throw std::runtime_error("move_to_vector() supports only statevector or "
"matrix_product_state or density_matrix methods");
Expand All @@ -941,7 +941,7 @@ matrix<complex_t> AerState::move_to_matrix() {
throw std::runtime_error("move_to_matrix() supports only statevector or "
"matrix_product_state or density_matrix methods");
}
for (auto i = 0; i < num_of_qubits_; ++i)
for (uint_t i = 0; i < num_of_qubits_; ++i)
op.qubits.push_back(i);
op.string_params.push_back("s");
op.save_type = Operations::DataSubType::single;
Expand All @@ -966,7 +966,7 @@ matrix<complex_t> AerState::move_to_matrix() {
.value())["s"]
.value());
clear();
return std::move(mat);
return mat;
} else {
throw std::runtime_error("move_to_matrix() supports only statevector or "
"matrix_product_state or density_matrix methods");
Expand Down
2 changes: 1 addition & 1 deletion src/framework/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void std::from_json(const json_t &js,
template <typename RealType>
void std::to_json(json_t &js, const AER::Vector<std::complex<RealType>> &vec) {
std::vector<std::vector<RealType>> out;
for (int64_t i = 0; i < vec.size(); ++i) {
for (size_t i = 0; i < vec.size(); ++i) {
auto &z = vec[i];
out.push_back(std::vector<RealType>{real(z), imag(z)});
}
Expand Down
3 changes: 2 additions & 1 deletion src/framework/linalg/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ T *malloc_data(size_t size) {
// Data allocated here may need to be properly aligned to be compliant with
// AVX2.
void *data = nullptr;
posix_memalign(&data, 64, sizeof(T) * size);
if (posix_memalign(&data, 64, sizeof(T) * size) != 0)
throw std::runtime_error("Cannot allocate memory by posix_memalign");
return reinterpret_cast<T *>(data);
#else
return reinterpret_cast<T *>(malloc(sizeof(T) * size));
Expand Down
34 changes: 21 additions & 13 deletions src/framework/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ enum class BinaryOp {
GreaterEqual
};

bool isBoolBinaryOp(const BinaryOp binary_op);
bool isBoolBinaryOp(const BinaryOp binary_op) {
return binary_op != BinaryOp::BitAnd && binary_op != BinaryOp::BitOr &&
binary_op != BinaryOp::BitXor;
}

uint_t truncate(const uint_t val, const size_t width);
uint_t truncate(const uint_t val, const size_t width) {
size_t shift = 64 - width;
return (val << shift) >> shift;
Expand All @@ -68,8 +70,8 @@ enum class ValueType { Bool, Uint };

class ScalarType {
public:
ScalarType(const ValueType type_, const size_t width_)
: type(type_), width(width_) {}
ScalarType(const ValueType _type, const size_t width_)
: type(_type), width(width_) {}

public:
const ValueType type;
Expand Down Expand Up @@ -97,8 +99,8 @@ class Bool : public ScalarType {

class CExpr {
public:
CExpr(const CExprType expr_type_, const std::shared_ptr<ScalarType> type_)
: expr_type(expr_type_), type(type_) {}
CExpr(const CExprType _expr_type, const std::shared_ptr<ScalarType> _type)
: expr_type(_expr_type), type(_type) {}
virtual bool eval_bool(const std::string &memory) { return false; };
virtual uint_t eval_uint(const std::string &memory) { return 0ul; };

Expand All @@ -109,9 +111,9 @@ class CExpr {

class CastExpr : public CExpr {
public:
CastExpr(std::shared_ptr<ScalarType> type,
CastExpr(std::shared_ptr<ScalarType> _type,
const std::shared_ptr<CExpr> operand_)
: CExpr(CExprType::Cast, type), operand(operand_) {}
: CExpr(CExprType::Cast, _type), operand(operand_) {}

virtual bool eval_bool(const std::string &memory) {
if (type->type != ValueType::Bool)
Expand Down Expand Up @@ -143,9 +145,9 @@ class CastExpr : public CExpr {

class VarExpr : public CExpr {
public:
VarExpr(std::shared_ptr<ScalarType> type,
const std::vector<uint_t> &cbit_idxs)
: CExpr(CExprType::Var, type), cbit_idxs(cbit_idxs) {}
VarExpr(std::shared_ptr<ScalarType> _type,
const std::vector<uint_t> &_cbit_idxs)
: CExpr(CExprType::Var, _type), cbit_idxs(_cbit_idxs) {}

virtual bool eval_bool(const std::string &memory) {
if (type->type != ValueType::Bool)
Expand All @@ -164,7 +166,6 @@ class VarExpr : public CExpr {
private:
uint_t eval_uint_(const std::string &memory) {
uint_t val = 0ul;
const uint_t memory_size = memory.size();
uint_t shift = 0;
for (const uint_t cbit_idx : cbit_idxs) {
if (memory.size() <= cbit_idx)
Expand All @@ -182,7 +183,8 @@ class VarExpr : public CExpr {

class ValueExpr : public CExpr {
public:
ValueExpr(std::shared_ptr<ScalarType> type) : CExpr(CExprType::Value, type) {}
ValueExpr(std::shared_ptr<ScalarType> _type)
: CExpr(CExprType::Value, _type) {}
};

class UintValue : public ValueExpr {
Expand Down Expand Up @@ -943,6 +945,11 @@ inline Op make_bfunc(const std::string &mask, const std::string &val,
return op;
}

Op make_gate(const std::string &name, const reg_t &qubits,
const std::vector<complex_t> &params,
const std::vector<std::string> &string_params,
const int_t conditional, const std::shared_ptr<CExpr> expr,
const std::string &label);
Op make_gate(const std::string &name, const reg_t &qubits,
const std::vector<complex_t> &params,
const std::vector<std::string> &string_params,
Expand Down Expand Up @@ -1313,12 +1320,12 @@ inline Op bind_parameter(const Op &src, const uint_t iparam,
if (src.params.size() > 0) {
uint_t stride = src.params.size() / num_params;
op.params.resize(stride);
for (int_t i = 0; i < stride; i++)
for (uint_t i = 0; i < stride; i++)
op.params[i] = src.params[iparam * stride + i];
} else if (src.mats.size() > 0) {
uint_t stride = src.mats.size() / num_params;
op.mats.resize(stride);
for (int_t i = 0; i < stride; i++)
for (uint_t i = 0; i < stride; i++)
op.mats[i] = src.mats[iparam * stride + i];
}
return op;
Expand Down Expand Up @@ -1528,6 +1535,7 @@ json_t op_to_json(const Op &op) {
return ret;
}

void to_json(json_t &js, const OpType &type);
void to_json(json_t &js, const OpType &type) {
std::stringstream ss;
ss << type;
Expand Down
5 changes: 4 additions & 1 deletion src/framework/pybind_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "misc/warnings.hpp"
DISABLE_WARNING_PUSH
#pragma GCC diagnostic ignored "-Wfloat-equal"

#include <pybind11/cast.h>
#include <pybind11/complex.h>
#include <pybind11/numpy.h>
Expand All @@ -40,6 +42,7 @@ DISABLE_WARNING_PUSH

#include <nlohmann/json.hpp>
DISABLE_WARNING_POP
#pragma GCC diagnostic warning "-Wfloat-equal"

#include "framework/json.hpp"

Expand Down Expand Up @@ -293,7 +296,7 @@ void std::from_json(const json_t &js, py::object &o) {
o = py::str(js.get<nl::json::string_t>());
} else if (js.is_array()) {
std::vector<py::object> obj(js.size());
for (auto i = 0; i < js.size(); i++) {
for (size_t i = 0; i < js.size(); i++) {
py::object tmp;
from_json(js[i], tmp);
obj[i] = tmp;
Expand Down
4 changes: 2 additions & 2 deletions src/framework/qobj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ Qobj::Qobj(const inputdata_t &input) {
// negative position is for global phase
param_circuit->global_phase_angle = params.second[j];
} else {
if (instr_pos >= num_instr) {
if ((uint_t)instr_pos >= num_instr) {
throw std::invalid_argument(
R"(Invalid parameterized qobj: instruction position out of range)");
}
auto &op = param_circuit->ops[instr_pos];
if (param_pos >= op.params.size()) {
if ((uint_t)param_pos >= op.params.size()) {
throw std::invalid_argument(
R"(Invalid parameterized qobj: instruction param position out of range)");
}
Expand Down
2 changes: 1 addition & 1 deletion src/framework/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ uint_t (*popcount)(uint_t) = is_avx2_supported() ? &_instrinsic_weight
bool (*hamming_parity)(uint_t) = &_naive_parity;
uint_t (*popcount)(uint_t) = &_naive_weight;
#endif

size_t get_system_memory_mb();
size_t get_system_memory_mb() {
size_t total_physical_memory = 0;
#if defined(__linux__)
Expand Down
Loading

0 comments on commit 180a0b6

Please sign in to comment.