Fix MPS size estimator (#2229)

This commit is contained in:
Jun Doi 2024-09-13 14:42:03 +09:00 committed by GitHub
parent dd7a261fb0
commit 5ae37257ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 11 deletions

View File

@ -0,0 +1,7 @@
---
fixes:
- |
SIGSEGV raised when the circuits with unsupported gates is
passed to MPS simulator, because of `std::set.find()` in
size estimator for MPS.
This fix avoids SIGSEGV if unsupported gates is passed.

View File

@ -74,17 +74,19 @@ uint_t MPSSizeEstimator::estimate(const std::vector<Operations::Op> &ops,
case Operations::OpType::gate:
if (ops[i].qubits.size() > 1) {
auto it = gateset.find(ops[i].name);
switch (it->second) {
case Gates::rxx:
case Gates::ryy:
case Gates::rzx:
pi2 = std::real(ops[i].params[0]) / M_PI;
pi2_int = (double)std::round(pi2);
if (!AER::Linalg::almost_equal(pi2, pi2_int))
apply_qubits(ops[i].qubits);
break;
default:
break;
if (it != gateset.end()) {
switch (it->second) {
case Gates::rxx:
case Gates::ryy:
case Gates::rzx:
pi2 = std::real(ops[i].params[0]) / M_PI;
pi2_int = (double)std::round(pi2);
if (!AER::Linalg::almost_equal(pi2, pi2_int))
apply_qubits(ops[i].qubits);
break;
default:
break;
}
}
}
break;