test: cover the control on a controlled swap through openqasm2 - #5263
Open
cleitonaugusto wants to merge 1 commit into
Open
test: cover the control on a controlled swap through openqasm2#5263cleitonaugusto wants to merge 1 commit into
cleitonaugusto wants to merge 1 commit into
Conversation
Regression test for NVIDIA#5192. A controlled swap currently lowers to three CNOTs between the targets, dropping the control, so the exported circuit swaps unconditionally while the simulator does not. The control is |0> on purpose. With the control set, a controlled swap and a plain swap agree, which is why SwapToCX.qke does not catch this: it only covers the uncontrolled case. Asserts that the control qubit appears in some gate rather than pinning a particular decomposition, so it does not constrain how the lowering is fixed. Fails on 0.15.1, passes once the control survives. Signed-off-by: Cleiton Augusto <augusto.cleiton@gmail.com>
cleitonaugusto
force-pushed
the
test-controlled-swap-keeps-control
branch
from
August 25, 2026 19:31
08a05d0 to
51312ac
Compare
Author
|
For whoever picks this up: this is the regression test for the bug that #5276 fixes, so the two go together. This one fails on 0.15.1 and passes once the control survives the lowering. They cover different layers on purpose. #5276 has a unit test on the decomposition pattern itself, which pins the wiring. This one goes through cudaq.translate to OpenQASM 2, so it also covers the path from the Python API down to the emitted text. No rush from my side, just flagging the connection so it is not reviewed as an unrelated change. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Regression test for #5192, which I reported: a controlled swap lowers to three CNOTs between the two targets, so the control is dropped and the exported OpenQASM 2 swaps unconditionally while the simulator does not.
This only adds the test. The lowering itself is still open, and there is a discussion on the issue about which form to use.
Two things about how it is written:
The control is
|0>on purpose. With the control set, a controlled swap and a plain swap agree, so a test with the control on passes either way. That is whytest/Transforms/DecompositionPatterns/SwapToCX.qkedoes not catch this: it only covers the uncontrolled swap.It asserts that the control qubit appears in some gate, rather than pinning a particular decomposition. Whether the fix emits a Fredkin, bails out for controlled swaps, or does something else, the control has to survive, and I did not want the test to constrain that choice.
Verified against 0.15.1 from
pip install cudaq: it fails there with the control absent, and the assertion prints the emitted body so the failure explains itself. Two unrelated tests in this file (test_translate_builder_qirandtest_translate_builder_with_params_qir) already fail for me on the released wheel, inkernel_builder.py, so I could not run the whole file green. The rest passes.