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

Calling AerState::probabilities() crashes for the MPS simulator #2234

Open
aromanro opened this issue Sep 18, 2024 · 0 comments
Open

Calling AerState::probabilities() crashes for the MPS simulator #2234

aromanro opened this issue Sep 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@aromanro
Copy link
Contributor

aromanro commented Sep 18, 2024

Informations

  • Qiskit Aer version:

Latest from the main branch.

  • Python version:

Irrelevant as the call is from c++ code.

  • Operating system:

Windows 11

What is the current behavior?

Calling AerState::probabilities() for a MPS simulator crashes. Might crash for other simulators, too, but I didn't check.

The reason is that op.qubits is empty.
The call goes through (skipping here some intermediate calls) MPS::get_probabilities_vector_internal -> MPS::diagonal_of_density_matrix -> MPS::centralize_qubits -> MPS::find_centralized_indices with no qubits and it crashes because the for (uint_t index = 0; index < num_qubits - 1; index++) has an unsigned int index and num_qubits is also unsigned int so num_qubits - 1 is actually not negative, but a big number.

Steps to reproduce the problem

As described above, just call AerState::probabilities() after configuring and initializing a MPS simulator.

What is the expected behavior?

Not crashing and working as expected.

Suggested solutions

Probably the MPS::find_centralized_indices could check and avoid such a case with empty qubits, as for the correct functionality, one way would be adding something like

  for (uint_t i = 0; i < num_of_qubits_; ++i)
    op.qubits.push_back(i);

in AerState::probabilities().

@aromanro aromanro added the bug Something isn't working label Sep 18, 2024
aromanro added a commit to InvictusWingsSRL/qiskit-aer that referenced this issue Sep 18, 2024
aromanro added a commit to InvictusWingsSRL/qiskit-aer2 that referenced this issue Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant