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

[MLIR] Perform constant-folding on quantum.insert and quantum.extract indices #161

Merged
merged 5 commits into from Jun 14, 2023

Conversation

pengmai
Copy link
Contributor

@pengmai pengmai commented Jun 13, 2023

Context: When extracting qubits from quantum registers, the frontend always materializes constant wire indices in the IR instead of as attributes on the insert or extract op.

Code such as:

qml.X(wires=0)

results in:

...
%c0_i64 = arith.constant 0 : i64
quantum.extract %qreg[%c0_i64]

Description of the Change: Known constants on quantum.insert and quantum.extract ops are folded into attributes. The above example results in:

quantum.extract %qreg[0]

There is also an additional verifier to make sure that an index is defined (this previously caused a segfault if an insert or extract was created without an index. The MLIR parser disallows this, but it can be done from C++/Python).

Benefits: Intermediate transformations (such as quantum function splitting) will be able to more easily tell if wires are constant or dynamic when they operate on the IR.

@pengmai pengmai marked this pull request as ready for review June 13, 2023 21:35
Copy link
Collaborator

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for the change! :)

Copy link
Contributor

@erick-xanadu erick-xanadu left a comment

Choose a reason for hiding this comment

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

Awesome! 🥳

@pengmai pengmai merged commit 6e8b80e into main Jun 14, 2023
16 checks passed
@pengmai pengmai deleted the jmp/fold-constant-insert-extract branch June 14, 2023 16:03
pengmai added a commit that referenced this pull request Jun 15, 2023
…act` indices (#161)

* Add verifiers and constant folders for quantum.extract and insert ops

* Add test for constant folding quantum.insert/extract

* Update changelog

* Update fold methods with new MLIR APIs
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

Successfully merging this pull request may close these issues.

None yet

3 participants