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

Can't set measurements with len=1 NumPy array #7600

Closed
nonhermitian opened this issue Feb 1, 2022 · 1 comment · Fixed by #7618
Closed

Can't set measurements with len=1 NumPy array #7600

nonhermitian opened this issue Feb 1, 2022 · 1 comment · Fixed by #7618
Labels
bug Something isn't working

Comments

@nonhermitian
Copy link
Contributor

nonhermitian commented Feb 1, 2022

Environment

  • Qiskit Terra version: lastest
  • Python version:
  • Operating system:

What is happening?

This fails for len=1 arrays:

qc = QuantumCircuit(2, 1)
qc.measure([0], np.array([0]))
~/mambaforge/envs/qiskit/lib/python3.8/site-packages/qiskit/circuit/quantumcircuit.py in _bit_argument_conversion(bit_representation, in_array)
   1106             raise CircuitError("Index out of range.") from ex
   1107         except TypeError as ex:
-> 1108             raise CircuitError(
   1109                 f"Type error handling {bit_representation} ({type(bit_representation)})"
   1110             ) from ex

CircuitError: "Type error handling [0] (<class 'numpy.ndarray'>)"

For length 2 or higher it works. Also works if cast to list.

How can we reproduce the issue?

See above

What should happen?

It should work for any length array

Any suggestions?

No response

@nonhermitian nonhermitian added the bug Something isn't working label Feb 1, 2022
@jakelishman
Copy link
Member

>>> int(np.array([0]))
0

???

Seems like pretty weird Numpy behaviour, but that's where the issue comes in. Should be an easy fix.

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
2 participants