CQCL / lambeq

A high-level Python library for Quantum Natural Language Processing

Home Page:https://cqcl.github.io/lambeq/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parameterization tutorial example failing

079035 opened this issue · comments

commented

https://cqcl.github.io/lambeq/tutorials/parameterise.html

While running:

from pytket.circuit.display import render_circuit_jupyter

tket_circuit = circuit.to_tk()

render_circuit_jupyter(tket_circuit)

Error occurs while calling to_tk():

[72/1971]

File /ext3/miniconda3/lib/python3.12/site-packages/lambeq/backend/quantum.py:384, in Diagram.to_tk(self)
    338 def to_tk(self):
    339     """Export to t|ket>.
    340
    341     Returns
   (...)
    382
    383     """
--> 384     from lambeq.backend.converters.tk import to_tk
    385     return to_tk(self)

File /ext3/miniconda3/lib/python3.12/site-packages/lambeq/backend/converters/__init__.py:11
      1 """lambeq's converter module"""
      3 __all__ = [
      4     'from_discopy',
      5     'to_discopy',
      6     'from_tk',
      7     'to_tk',
      8 ]
---> 11 from lambeq.backend.converters.discopy import from_discopy, to_discopy
     12 from lambeq.backend.converters.tk import from_tk, to_tk

File /ext3/miniconda3/lib/python3.12/site-packages/lambeq/backend/converters/discopy.py:28
[48/1971]
     25 from typing import cast, Type, TypeVar, Union
     27 try:
---> 28     from discopy import quantum as dq
     29     from discopy import tensor as dt
     30     from discopy.grammar import pregroup as dg

File /ext3/miniconda3/lib/python3.12/site-packages/discopy/__init__.py:5
      1 # -*- coding: utf-8 -*-
      3 """ DisCoPy: the Python toolkit for computing with string diagrams. """
----> 5 from discopy import (
      6     cat,
      7     monoidal,
      8     braided,
      9     symmetric,
     10     markov,
     11     traced,
     12     closed,
     13     rigid,
     14     pivotal,
     15     ribbon,
     16     compact,
     17     frobenius,
     18     hypergraph,
     19     python,
[24/1971]
     20     matrix,
     21     tensor,
     22     quantum,
     23     grammar,
     24     drawing,
     25     utils,
     26     config,
     27     messages,
     28 )
     30 from discopy.version import (
     31     version as __version__,
     32     version_tuple as __version_info__)

File /ext3/miniconda3/lib/python3.12/site-packages/discopy/monoidal.py:60
     57 from dataclasses import dataclass
     58 from warnings import warn
---> 60 from discopy import cat, drawing, hypergraph, messages
     61 from discopy.cat import Ob
     62 from discopy.utils import (
     63     factory,
     64     factory_name,
   (...)
     69     AxiomError,
     70 )

File /ext3/miniconda3/lib/python3.12/site-packages/discopy/hypergraph.py:94
     88 SpiderTypes = Union[Mapping[Spider, "Ty"], Iterable["Ty"]]
     89 """
     90 Mapping from :class:`Spider` to atomic :class:`frobenius.Ty`.
     91 """
---> 94 class Hypergraph(Composable, Whiskerable, NamedGeneric['category', 'functor']):
     95     """
     96     A hypergraph is given by:
     97
   (...)
    175     >>> assert (f @ g).wires == ((0, 1), (((0,), (2,)), ((1,), (3,))), (2, 3))
    176     """
    177     category = None

File /ext3/miniconda3/lib/python3.12/site-packages/discopy/utils.py:148, in NamedGeneric.__class_getitem__(_, attributes)
    145 if not isinstance(attributes, tuple):
    146     attributes = (attributes,)
--> 148 class Result(Generic[TypeVar(attributes)]):
    149     def __class_getitem__(cls, values):
    150         if hasattr(cls, "__is_named_generic__"):

TypeError: typevar() argument 'name' must be str, not tuple

I am using the latest versions of qiskit and lambeq libraries. This same error occurs on a fresh virtual environment.

Not sure why this occurs. Would appreciate any help.

Thank you.

commented

Note for future viewers: It turns out the preceding code works on Python 3.11 but not on 3.12.

This has been solved with this DisCoPy PR: discopy/discopy#267
Note that lambeq doesn't support 3.12 officially yet.

commented

Seems like this merge does not appear in Pip's latest discopy (1.1.6).
Will there be a new release? Although I have no problem copying the code for now :)

Thank you.

Just released a new version, let us know if this fixes the issue!

commented

Works smooth!