L1 text intermediate representation (IR)#1824
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive refactoring and expansion of the Qualtran-L1 Intermediate Representation (IR). Key changes include new AST nodes for representing L1 code, a parser for converting L1 text into an AST, and an evaluator to convert the AST back into executable qualtran.Bloq objects. New utility functions like dump_l1 and load_module are added for serialization and deserialization of Bloqs to and from L1 text. The CompositeBloq class is enhanced with decomposed_from and bloq_key attributes for improved debugging and a wire_symbol method for drawing. Additionally, a new Jupyter notebook (L1-Text-IR.ipynb) is added to document the L1 IR. A review comment highlights an issue with the shape type hint in qualtran/l1/nodes.py, suggesting it should accommodate sympy.Expr values in addition to integers.
As part of #1824 , I want to be better about our convention for importing bloqs and `__str__` representations in the qualtran standard library (i.e. `qualtran.bloqs`). There's no additional restriction on custom, user-authored bloqs. These changes make sure: - bloqs are generally imported "one level up" from their file. e.g. `ControlledAddOrSubtract` is defined in `qualtran/bloqs/arithmetic/controlled_add_or_subtract.py` but it prefers to be imported from `qualtran.bloqs.arithmetic`. This is codified in the (existing) default `_pkg_(cls) -> str` classmethod. You can override it if you want something different. - The `__str__` representation looks like an object string (cc #1823). This PR removes some special symbols in favor of more Python-looking strings. note that this causes more bloq examples to be loadable (visible in the re-generated manifest)
Qualtran-L1 Intermediate Representation
The L1 intermediate representation (IR) for Qualtran is a host-language-agnostic interchange format for hierarchical composite quantum programs. The Python
qualtranlibrary (Qualtran-L2) can compile to Qualtran-L1.*.qltfile contains a full hierarchical record of the quantum funciton vs. "lazy" evaluation of decompositions in L2.