Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for https://github.com/Qiskit/qiskit-aer/issues/2292 #2300

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
prelude: >
MPS::apply_multi_qubit_gate could crash in some circumstances
fixes:
- |
A matrix was attempted to be constructed despite having `is_diagonal`
parameter set to true and the passed matrix being a vector. The attempt
to access the element incorrectly resulted in a crash. Now a vector is
constructed when `is_diagonal` is true. For more information refer to
`#2292 <https://github.com/Qiskit/qiskit-aer/issues/2292>`

Original file line number Diff line number Diff line change
Expand Up @@ -789,13 +789,22 @@ void MPS::apply_multi_qubit_gate(const reg_t &qubits, const cmatrix_t &mat,
// change qubit order in the matrix - instead of doing swaps on the qubits
uint_t nqubits = qubits.size();
uint_t sidelen = 1 << nqubits;
cmatrix_t new_mat(sidelen, sidelen);
for (uint_t col = 0; col < sidelen; ++col) {
for (uint_t row = 0; row < sidelen; ++row) {
if (row == col)
new_mat(new_vec[row], new_vec[row]) = mat(row, row);
else
cmatrix_t new_mat(is_diagonal ? 1 : sidelen, sidelen);

if (is_diagonal) {
for (uint_t col = 0; col < sidelen; ++col) {
new_mat(0, new_vec[col]) =
mat.GetRows() == 1
? mat(0, col)
: mat(col,
col); // this is just in case something passes a matrix
// instead of a vector even if is_diagonal is true
}
} else {
for (uint_t col = 0; col < sidelen; ++col) {
for (uint_t row = 0; row < sidelen; ++row) {
new_mat(new_vec[row], new_vec[col]) = mat(row, col);
}
}
}

Expand Down