lambeq.core¶
lambeq.core.globals¶
- class lambeq.core.globals.VerbosityLevel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Level of verbosity for progress reporting.
Table 4 Available Options¶ Option
Value
Description
PROGRESS
'progress'
Use progress bar.
TEXT
'text'
Give text report.
SUPPRESS
'suppress'
No output.
All outputs are printed to stderr. Visual Studio Code does not always display progress bars correctly, use
'progress'
level reporting in Visual Studio Code at your own risk.- PROGRESS = 'progress'¶
- SUPPRESS = 'suppress'¶
- TEXT = 'text'¶
lambeq.core.types¶
Types¶
A standardised set of types that can be used with lambeq.
- class lambeq.core.types.AtomicType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Ty
,Enum
Standard pregroup atomic types.
- CONJUNCTION = Ty(conj)¶
- NOUN = Ty(n)¶
- NOUN_PHRASE = Ty(n)¶
- PREPOSITIONAL_PHRASE = Ty(p)¶
- PUNCTUATION = Ty(punc)¶
- SENTENCE = Ty(s)¶
- __init__(name: str | None = None, objects: list[~typing.Self] = <factory>, z: int = 0) None ¶
- category: ClassVar[Category] = Category(name='grammar', Ty=<class 'lambeq.backend.grammar.Ty'>, Box=<class 'lambeq.backend.grammar.Box'>, Layer=<class 'lambeq.backend.grammar.Layer'>, Diagram=<class 'lambeq.backend.grammar.Diagram'>)¶
- count(other: Self) int ¶
- classmethod from_json(data: Dict[str, Any] | str) Self ¶
Decode a JSON object or string into a
Ty
.- Returns:
Ty
The type generated from the JSON data.
- insert(other: Self, index: int) Self ¶
Insert a type at the specified index in the complex type list.
- Parameters:
- otherTy
The type to insert. Can be atomic or complex.
- indexint
The position where the type should be inserted.
- property is_atomic: bool¶
- property is_complex: bool¶
- property is_empty: bool¶
- property l: Self¶
- name: str = None¶
- objects: list[Self]¶
- property r: Self¶
- repeat(times: int) Self ¶
- replace(other: Self, index: int) Self ¶
Replace a type at the specified index in the complex type list.
- Parameters:
- otherTy
The type to insert. Can be atomic or complex.
- indexint
The position where the type should be inserted.
- rotate(z: int) Self ¶
Rotate the type, changing the winding number.
- tensor(other: Self | Iterable[Self], *rest: Self) Self ¶
- to_json(is_top_level: bool = True) Dict[str, Any] ¶
Encode this type to a JSON object.
- Parameters:
- is_top_levelbool, optional
This flag indicates that this object is the top-most object and should have the global metadata (e.g. category). This should be set to False when calling to_json on attribute instances to avoid duplication of said global metadata.
- unwind() Self ¶
- z: int = 0¶
lambeq.core.utils¶
- lambeq.core.utils.normalise_duration(duration_secs: float | None) str [source]¶
Normalise a duration value in seconds into a more human-readable form.
>>> normalise_duration(4890.0) '1h21m30s' >>> normalise_duration(65.0) '1m5s' >>> normalise_duration(0.29182375) '0.29s' >>> normalise_duration(0.29682375) '0.30s' >>> normalise_duration(None) 'None'
- Parameters:
- duration_secsfloat
The duration value in seconds.