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

Pytket : TypeError: Parameters to generic types must be types. Got lark.visitors.Discard. #788

Closed
hamidelmaazouz opened this issue Mar 16, 2023 · 3 comments

Comments

@hamidelmaazouz
Copy link

hamidelmaazouz commented Mar 16, 2023

Hello @ss2165 and @cqc-alec,

I am getting the following failure when I call circuit_to_qasm_str from pytket.qasm:

[...]
from pytket.qasm import circuit_to_qasm_str
../../../.cache/pypoetry/virtualenvs/scc-uCUxejjC-py3.8/lib/python3.8/site-packages/pytket/qasm/__init__.py:19: in <module>
    from .qasm import (
../../../.cache/pypoetry/virtualenvs/scc-uCUxejjC-py3.8/lib/python3.8/site-packages/pytket/qasm/qasm.py:277: in <module>
    class CircuitTransformer(Transformer):
../../../.cache/pypoetry/virtualenvs/scc-uCUxejjC-py3.8/lib/python3.8/site-packages/pytket/qasm/qasm.py:759: in CircuitTransformer
    def extern(self, tree: List[Any]) -> Type[Discard]:
/usr/lib/python3.8/typing.py:261: in inner
    return func(*args, **kwds)
/usr/lib/python3.8/typing.py:685: in __getitem__
    params = tuple(_type_check(p, msg) for p in params)
/usr/lib/python3.8/typing.py:685: in <genexpr>
    params = tuple(_type_check(p, msg) for p in params)
/usr/lib/python3.8/typing.py:149: in _type_check
    raise TypeError(f"{msg} Got {arg!r:.100}.")
E   TypeError: Parameters to generic types must be types. Got lark.visitors.Discard.

(I think) this would make sense on python 3.9+ but I have been experiencing this on both python 3.9 (using the prebuilt Pytket at https://pypi.org/project/pytket/) and python 3.8 (using the wheel I built myself as per the topic: #786)

For reference the failing method is:

    def extern(self, tree: List[Any]) -> Type[Discard]:
        # TODO parse extern defs
        return Discard

I'm not sure it should return Discard or Type[Discard], and the cause might be somewhere else.
Could you please shed some light on this ?

Best wishes,

@cqc-alec
Copy link
Collaborator

Hi, could you provide a code snippet to reproduce please?

@cqc-alec
Copy link
Collaborator

Or was the error just from the import?
I can't reproduce this with pytket 1.11.1:

(env) alec@psi:~/tmp$ python -c "from pytket.qasm import circuit_to_qasm_str"
(env) alec@psi:~/tmp$ 


@hamidelmaazouz
Copy link
Author

No the import works fine, it's just the call that fails.

Turns out my project and Pytket are using different versions of Lark. Downgrading to Lark 0.12 made the failure go away.
Lark is now at 1.1.5, and Pytket pulls 0.7

Best,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants