Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.11k stars 2.35k forks source link

Improve primitives typehints #9841

Closed ElePT closed 2 months ago

ElePT commented 1 year ago

What should we add?

At the moment, the primitives run() method typehints use collections.abc.Sequence for batches of circuits, parameter values or observables. However, we want to support inputs of type np.ndarray, which don't implement the Sequence protocol (they don't implement count() or index()).

After an internal discussion, it looks like a good solution is to change the typehints from Sequence to Iterable (numpy arrays do satisfy Iterable), and normalize the input to tuple or list for internal use. This would require some changes in type checking/error handling (in particular, in BasePrimitive._validate_circuits).

1ucian0 commented 1 year ago

Is any of these https://github.com/Qiskit/qiskit-terra/pulls?q=is%3Apr+label%3Amypy a fix for this issue?

ElePT commented 1 year ago

TL;DR: No

I noticed this issue while reviewing #8263, but considered out of scope for this PR, as it affects the primitive base class, and therefore other implementations of the primitives.

t-imamichi commented 2 months ago

I close this because the Primitives V1 is deprecated #12575