-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
marginal_distribution raises for NumPy array indices #8283
Comments
This should be easy to fix and backport for 0.21.1, we just need to change the is empty check on the input validation there to something that works with lists and numpy arrays. I'm pretty sure the python->rust boundary will work fine as is if it gets a numpy array (although it won't be as efficient as declaring an input type as a numpy array, which is easy to add support for in addition to a generic sequence input) |
Yeah it is a simple fix. Was going to do it myself but saw that I would need to modify type hints, and I draw the line at type hinting. |
This commit fixes an issue with the marginal_distribution() function where it would previously error if a numpy arrray of ints was passed in for the indices parameter. This was caused by the input validation looking for empty input by checking `not indices` which isn't valid for numpy arrays. This commit fixes this by adjusting the check for empty lists to work with any sequence input. Fixes Qiskit#8283
) * Fix handling of numpy arrays for indices in marginal_distribution This commit fixes an issue with the marginal_distribution() function where it would previously error if a numpy arrray of ints was passed in for the indices parameter. This was caused by the input validation looking for empty input by checking `not indices` which isn't valid for numpy arrays. This commit fixes this by adjusting the check for empty lists to work with any sequence input. Fixes #8283 * Update releasenotes/notes/fix-numpy-indices-marginal-dist-45889e49ba337d84.yaml Co-authored-by: Jim Garrison <jim@garrison.cc> Co-authored-by: Jim Garrison <jim@garrison.cc>
) * Fix handling of numpy arrays for indices in marginal_distribution This commit fixes an issue with the marginal_distribution() function where it would previously error if a numpy arrray of ints was passed in for the indices parameter. This was caused by the input validation looking for empty input by checking `not indices` which isn't valid for numpy arrays. This commit fixes this by adjusting the check for empty lists to work with any sequence input. Fixes #8283 * Update releasenotes/notes/fix-numpy-indices-marginal-dist-45889e49ba337d84.yaml Co-authored-by: Jim Garrison <jim@garrison.cc> Co-authored-by: Jim Garrison <jim@garrison.cc> (cherry picked from commit f868129)
) (#8396) * Fix handling of numpy arrays for indices in marginal_distribution This commit fixes an issue with the marginal_distribution() function where it would previously error if a numpy arrray of ints was passed in for the indices parameter. This was caused by the input validation looking for empty input by checking `not indices` which isn't valid for numpy arrays. This commit fixes this by adjusting the check for empty lists to work with any sequence input. Fixes #8283 * Update releasenotes/notes/fix-numpy-indices-marginal-dist-45889e49ba337d84.yaml Co-authored-by: Jim Garrison <jim@garrison.cc> Co-authored-by: Jim Garrison <jim@garrison.cc> (cherry picked from commit f868129) Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Environment
What is happening?
marginal_distribution
raises error when passes a NumPy array of indices:--> 225 if indices is not None and (not indices or not set(indices).issubset(range(num_clbits))):
226 raise QiskitError(f"indices must be in range [0, {num_clbits - 1}].")
228 if isinstance(counts, Counts):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
How can we reproduce the issue?
Try above
What should happen?
It should work for both lists and arrays.
Any suggestions?
No response
The text was updated successfully, but these errors were encountered: