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

Create a finite state machine analysis pass to propagate Pauli basis states, and use it to disentangle CNOTs and SWAPs #1154

Merged
merged 38 commits into from
Dec 20, 2024

Conversation

paul0403
Copy link
Contributor

@paul0403 paul0403 commented Sep 24, 2024

Context:
In circuits that mostly involve the six Pauli eigenstates, the effect of gates can be described by a simple six-state finite state machine. This allows us to deduce their midcircuit state at compile time.

The knowledge of the snapshot midcircuit states can be useful when:

  • Deducing CNOT/Toffoli/SWAP/... effect and decouple them. We decouple CNOT and SWAP in this PR.
  • Replace complicated circuits whose results are |01+-LR> with standard preparation routines
  • Potentially more

Description of the Change:
Added an analysis for propagating simple states (and tests).
Also added CNOT and SWAP decomposition pass disentangle-CNOT, disentangle-SWAP (and tests).
Credit to Ritu Thombre for the work on the SWAP gates! #1297

Benefits:
More compile time circuit information for potential compile time transformation/optimization.

Possible Drawbacks:
This algorithm is from an external paper. We need to properly cite it.
https://arxiv.org/abs/2012.07711 (fig.5)

Related GitHub Issues: closes #1268

[sc-74649]
[sc-74650]

…states whenever possible.

The knowledge of the snapshot midcircuit states can be useful when:
  - Deducing CNOT effect and decouple them
  - Replace complicated circuits whose results are |01+-LR> with standard preparation routines
  - Potentially more
…other passes can query (this is done via the mlir analysis framework)

- add a transformation pass --disentangle-CNOT (with test)
- both passes are changed to function passes
@paul0403 paul0403 changed the title Create a finite state machine analysis pass to propagate Pauli basis states whenever possible Create a finite state machine analysis pass to propagate Pauli basis states, and use it to disentangle CNOTs Sep 25, 2024
@paul0403 paul0403 marked this pull request as ready for review September 26, 2024 15:02
@paul0403 paul0403 requested a review from a team September 26, 2024 17:24
@paul0403
Copy link
Contributor Author

paul0403 commented Sep 26, 2024

Note that this is a hackweek project and is not on any roadmaps, so it's not urgent

Edit (2024/12/20): this is a P2 item now

@paul0403 paul0403 added the enhancement New feature or request label Sep 26, 2024
@paul0403
Copy link
Contributor Author

paul0403 commented Nov 1, 2024

Adding do-not-merge label to freeze this branch for assessment

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.68%. Comparing base (48edd02) to head (e5401f4).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1154   +/-   ##
=======================================
  Coverage   96.68%   96.68%           
=======================================
  Files          75       75           
  Lines        8266     8266           
  Branches      867      867           
=======================================
  Hits         7992     7992           
  Misses        221      221           
  Partials       53       53           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@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.

Really nice work 💯 Nothing structural or major that needs changing, just some minor tweaks :)

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
mlir/test/Quantum/DisentangleCNOTTest.mlir Show resolved Hide resolved
mlir/test/Quantum/DisentangleCNOTTest.mlir Show resolved Hide resolved
mlir/test/Quantum/DisentangleCNOTTest.mlir Show resolved Hide resolved
mlir/lib/Quantum/Transforms/DisentangleCNOT.cpp Outdated Show resolved Hide resolved
@paul0403 paul0403 dismissed erick-xanadu’s stale review December 20, 2024 19:03

Addressed the comments, but Erick is on vacation : )

@paul0403 paul0403 changed the title Create a finite state machine analysis pass to propagate Pauli basis states, and use it to disentangle CNOTs Create a finite state machine analysis pass to propagate Pauli basis states, and use it to disentangle CNOTs and SWAPs Dec 20, 2024
@mehrdad2m mehrdad2m self-requested a review December 20, 2024 20:43
@paul0403 paul0403 merged commit 5a7362a into main Dec 20, 2024
43 checks passed
@paul0403 paul0403 deleted the qstate_mlir_interpreter_fsm branch December 20, 2024 20:49
mehrdad2m pushed a commit that referenced this pull request Jan 6, 2025
…states, and use it to disentangle CNOTs and SWAPs (#1154)

**Context:**
In circuits that mostly involve the six Pauli eigenstates, the effect of
gates can be described by a simple six-state finite state machine. This
allows us to deduce their midcircuit state at compile time.

The knowledge of the snapshot midcircuit states can be useful when:
- Deducing CNOT/Toffoli/SWAP/... effect and decouple them. We decouple
CNOT and SWAP in this PR.
- Replace complicated circuits whose results are |01+-LR> with standard
preparation routines
  - Potentially more

**Description of the Change:**
Added an analysis for propagating simple states (and tests).
Also added CNOT and SWAP decomposition pass `disentangle-CNOT`,
`disentangle-SWAP` (and tests).
Credit to [Ritu Thombre](https://github.com/ritu-thombre99) for the work
on the SWAP gates!

**Benefits:**
More compile time circuit information for potential compile time
transformation/optimization.

**Possible Drawbacks:**
This algorithm is from an external paper. We need to properly cite it. 
https://arxiv.org/abs/2012.07711 (fig.5)

**Related GitHub Issues:** closes #1268 

[sc-74649]
[sc-74650]

---------

Co-authored-by: Ritu Thombre <[email protected]>
Co-authored-by: Ritu Thombre <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement SWAP gate disentangling at compile time
4 participants