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

Improve primitives typehints #9841

Open
ElePT opened this issue Mar 23, 2023 · 2 comments
Open

Improve primitives typehints #9841

ElePT opened this issue Mar 23, 2023 · 2 comments
Labels
mod: primitives Related to the Primitives module type: feature request New feature or request

Comments

@ElePT
Copy link
Contributor

ElePT commented Mar 23, 2023

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).

@ElePT ElePT added the type: feature request New feature or request label Mar 23, 2023
@woodsp-ibm woodsp-ibm added the mod: primitives Related to the Primitives module label Mar 23, 2023
@1ucian0
Copy link
Member

1ucian0 commented Mar 30, 2023

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

@ElePT
Copy link
Contributor Author

ElePT commented Mar 30, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: primitives Related to the Primitives module type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants