-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add transpiler pass for complementary control pattern simplification using Boolean algebra #15352
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
base: main
Are you sure you want to change the base?
Add transpiler pass for complementary control pattern simplification using Boolean algebra #15352
Conversation
|
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the following people are relevant to this code:
|
|
Mostafa Atallah seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
qiskit/transpiler/passes/optimization/control_pattern_simplification.py
Outdated
Show resolved
Hide resolved
|
Hi @alexanderivrii, @Cryoris, and @debasmita2102 I totally removed the sympy dependency please rereview the PR |
|
@Cryoris linters issue fixed |
Pull Request Test Coverage Report for Build 19681817322Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
I had a brief look at the PR (so no detailed feedback yet), honestly it's significantly more code than I expected. At this point I am wondering if it would be better to have this as a Qiskit-Community project and not a part of Qiskit itself, however I do want to look at the code in more detail and discuss with others before making a particular suggestion. I have a few high-level questions (in no particular order):
|
|
Hi @alexanderivrii, Thank you for the detailed review. Here are my responses: Complementary vs Subset Patterns: You're right that complementary patterns (Hamming distance 1) are a special case of subset patterns. I can consolidate these into a single detection method if preferred. Boolean Logic & Double Application: The patterns represent mutually exclusive control states—no quantum state can match multiple patterns simultaneously, so there's no risk of double gate application. Complexity: The typical use case involves 2-6 control qubits with 2-10 patterns (from quantum walk algorithms). The XOR Optimization: The CX trick is documented in:
SymPy Dependency: Completely removed—the implementation now uses pure bitwise operations. Unit Test: I will add a test based on your 3-controlled RXs example. Code Reduction: The current implementation (~1165 lines) can be reduced by ~30-40% by:
|
|
Thanks @Mostafa-Atallah2020 for the answers, and I will take a look the above paper and your code (but in a week or so, after Qiskit 2.3 release). One question that you did not answer: would you have been even able to use sympy to find patterns that differ at two or more positions? And a few more random questions, just by thinking about possible optimizations that one can perform.
Intuitively, the controls still form a complete partition.
Here the complement of the involved patterns is a single pattern |
|
Hi @alexanderivrii, Thank you for the suggestions. I've implemented both optimizations and added unit tests. Both the original SymPy-based version and the current bitwise implementation support all these optimizations. Example 1: Mixed Control Counts This simplifies to unconditional Result: 3 gates → 1 gate. Unit test: Example 2: Complement Optimization Patterns Result: 3 gates → 2 gates. Unit test: |
Summary
This PR adds a new transpiler pass
ControlPatternSimplificationthat optimizes multi-controlled gates with complementary control patterns using Boolean algebraic simplification.Note: This is an initial skeleton/draft PR. Full implementation will follow in subsequent commits.
Fixes #15348
Details and comments
Motivation
Multi-controlled gates with different control patterns can often be simplified when the patterns are complementary. For example, gates controlled on
'11'and'01'both require q0=1, so they can be combined into a single gate controlled only on q0.This pattern appears frequently in:
As demonstrated in #15348, the transpiler currently produces 31 gates for a case that could be optimized to just 5 gates (520% overhead).
Optimization Techniques
The pass will support four main optimization strategies:
Complementary patterns:
(q0 ∧ q1) ∨ (q0 ∧ ¬q1) = q0['11', '01']→ single control on q0Subset patterns:
(q0 ∧ q1 ∧ q2) ∨ (q0 ∧ q1 ∧ ¬q2) = (q0 ∧ q1)['111', '110']→ reduces control countXOR pairs: Patterns satisfying
q1 ⊕ q2 = 1['110', '101']→ CNOT-based optimizationComplete partitions: All control states covered
['00','01','10','11']→ unconditional gateExample Usage
Files Changed
qiskit/transpiler/passes/optimization/control_pattern_simplification.py- Main pass implementation (skeleton)qiskit/transpiler/passes/optimization/__init__.py- Export passqiskit/transpiler/passes/__init__.py- Documentation and importtest/python/transpiler/test_control_pattern_simplification.py- Test skeletonReferences
Next Steps