Skip to content

L1 text intermediate representation (IR)#1824

Merged
mpharrigan merged 9 commits intoquantumlib:mainfrom
mpharrigan:2026-03/l1-init
Mar 9, 2026
Merged

L1 text intermediate representation (IR)#1824
mpharrigan merged 9 commits intoquantumlib:mainfrom
mpharrigan:2026-03/l1-init

Conversation

@mpharrigan
Copy link
Copy Markdown
Collaborator

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 qualtran library (Qualtran-L2) can compile to Qualtran-L1.

  • L1 quantum functions are represented as text vs. L2 bloqs represented as in-memory Python objects.
  • a L1 *.qlt file contains a full hierarchical record of the quantum funciton vs. "lazy" evaluation of decompositions in L2.
  • Compile-time classical parameters are filled in and static in L1 vs. templated families of quantum subroutines via bloq classes in L2.
image image

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread qualtran/l1/nodes.py
@mpharrigan mpharrigan merged commit 1c6e5e0 into quantumlib:main Mar 9, 2026
9 checks passed
mpharrigan added a commit that referenced this pull request Mar 16, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant