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

Stub generation fails with pybind11-stubgen 2.4 #1135

Closed
cqc-alec opened this issue Nov 21, 2023 · 3 comments · Fixed by #1319
Closed

Stub generation fails with pybind11-stubgen 2.4 #1135

cqc-alec opened this issue Nov 21, 2023 · 3 comments · Fixed by #1319
Labels
bug Something isn't working

Comments

@cqc-alec
Copy link
Collaborator

It produces a lot of errors similar to this:

pybind11_stubgen - [  ERROR] In pytket._tket.circuit.Circuit.get_statevector : Can't find/import 'm'
@cqc-alec cqc-alec added the bug Something isn't working label Nov 21, 2023
@cqc-alec cqc-alec changed the title Stub generation fails with pybind11-syubgen 2.4 Stub generation fails with pybind11-stubgen 2.4 Nov 21, 2023
@trvto
Copy link
Contributor

trvto commented Nov 21, 2023

See sizmailov/pybind11-stubgen#190

The error comes from within pybin11's binders for Eigen (which we use) so I think there is little we can do directly

@sizmailov
Copy link

Original numpy annotations generated by pybind11 are not valid. Newer version of pybind11-stubgen correctly reports the error.

Use one of the following CLI options to rewrite the numpy annotations

--numpy-array-wrap-with-annotated
--numpy-array-use-type-var
--numpy-array-remove-parameters

@trvto
Copy link
Contributor

trvto commented Nov 22, 2023

Original numpy annotations generated by pybind11 are not valid. Newer version of pybind11-stubgen correctly reports the error.

Use one of the following CLI options to rewrite the numpy annotations

--numpy-array-wrap-with-annotated
--numpy-array-use-type-var
--numpy-array-remove-parameters

Thanks for the tip! I've tried these options and am seeing different behaviour than expected with our binders:

  • --numpy-array-use-type-var looks the nicest and doesn't produce the errors but, for our bindings at least, it consistently doesn't add the dtype parameter. For us, from, e.g. numpy.ndarray[numpy.float32[m, 1]], it adds a TypeVar M and produces numpy.ndarray[numpy.float32[M, Literal[1]]] (which mypy doesn't accept due to missing dtype), instead of the expected numpy.ndarray[tuple[M, Literal[1]], numpy.dtype[numpy.float32]].

  • --numpy-array-wrap-with-annotated seems to produce the same or similar results as without it. But the errors don't occur, which is great.

  • --numpy-array-remove-parameters does what I would expect and only produces numpy.ndarray, but we still get the errors.

I think we should be able to use the output of --numpy-array-use-type-var with some tweaking to our clean-up script that was handling numpy stuff already to get good results though. If I get around to it I can try to see if this option works as expected for a minimal example to see if it's something wrong with our binding code in particular.

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

Successfully merging a pull request may close this issue.

3 participants