-
Notifications
You must be signed in to change notification settings - Fork 447
Keep the control when decomposing a controlled swap #5276
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f5ff99a
Keep the control when decomposing a controlled swap
VaggelisGian e8bcab6
Update DecomposeCCXToCZ selection expectation
VaggelisGian 149c3b0
Cover the controlled-swap rewrite end to end
VaggelisGian 42d24ab
Use quake gate names in the controlled swap comment
VaggelisGian 6f8d484
Negate the toffoli control instead of wrapping the swap
VaggelisGian c280277
Thread the control and target wires through the final cnot
VaggelisGian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
cudaq/test/Transforms/DecompositionPatterns/SwapToCXControlled.qke
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // ========================================================================== // | ||
| // Copyright (c) 2022 - 2026 NVIDIA Corporation & Affiliates. // | ||
| // All rights reserved. // | ||
| // // | ||
| // This source code and the accompanying materials are made available under // | ||
| // the terms of the Apache License 2.0 which accompanies this distribution. // | ||
| // ========================================================================== // | ||
|
|
||
| // CircuitCheck is deliberately not used here: its UnitaryBuilder has no | ||
| // controlled multi-target path, so it miscomputes the unitary of a | ||
| // controlled swap on the reference side. | ||
|
|
||
| // RUN: cudaq-opt -pass-pipeline='builtin.module(decomposition{enable-patterns=SwapToCX})' %s | FileCheck %s | ||
|
|
||
| func.func @test_controlled(%qc: !quake.ref, %qa : !quake.ref, %qb : !quake.ref) { | ||
| quake.swap [%qc] %qa, %qb : (!quake.ref, !quake.ref, !quake.ref) -> () | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @test_controlled | ||
| // CHECK: quake.x {{\[}}%[[VAL_2:.*]]] %[[VAL_1:.*]] : (!quake.ref, !quake.ref) -> () | ||
| // CHECK: quake.x {{\[}}%[[VAL_0:.*]], %[[VAL_1]]] %[[VAL_2]] : (!quake.ref, !quake.ref, !quake.ref) -> () | ||
| // CHECK: quake.x {{\[}}%[[VAL_2]]] %[[VAL_1]] : (!quake.ref, !quake.ref) -> () | ||
| // CHECK: return | ||
| // CHECK: } | ||
|
|
||
| // A complemented control becomes a negated first control on the toffoli. | ||
| func.func @test_complemented(%qc: !quake.ref, %qa : !quake.ref, %qb : !quake.ref) { | ||
| quake.swap [%qc neg [true]] %qa, %qb : (!quake.ref, !quake.ref, !quake.ref) -> () | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @test_complemented( | ||
| // CHECK: quake.x {{\[}}%[[B_VAL:.*]]] %[[A_VAL:.*]] : (!quake.ref, !quake.ref) -> () | ||
| // CHECK-NEXT: quake.x {{\[}}%[[C_VAL:.*]], %[[A_VAL]] neg {{\[}}true, false{{\]}}{{\]}} %[[B_VAL]] : (!quake.ref, !quake.ref, !quake.ref) -> () | ||
| // CHECK-NEXT: quake.x {{\[}}%[[B_VAL]]] %[[A_VAL]] : (!quake.ref, !quake.ref) -> () | ||
| // CHECK: return | ||
| // CHECK: } | ||
|
|
||
| // The uncontrolled case must keep the plain three-CNOT lowering. | ||
| func.func @test_bare(%qa: !quake.ref, %qb : !quake.ref) { | ||
| quake.swap %qa, %qb : (!quake.ref, !quake.ref) -> () | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @test_bare | ||
| // CHECK: quake.x {{\[}}%[[VAL_1:.*]]] %[[VAL_0:.*]] : (!quake.ref, !quake.ref) -> () | ||
| // CHECK: quake.x {{\[}}%[[VAL_0]]] %[[VAL_1]] : (!quake.ref, !quake.ref) -> () | ||
| // CHECK: quake.x {{\[}}%[[VAL_1]]] %[[VAL_0]] : (!quake.ref, !quake.ref) -> () | ||
| // CHECK: return | ||
| // CHECK: } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please file an issue for tracking purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #5304 for the
CircuitCheckgap. The comment in the test file now points to it.Both comment suggestions are applied in 42d24ab.