Skip to content

Add CSWAP gate#1803

Draft
GabrielePalazzo wants to merge 1 commit intomasterfrom
cswap_qasm
Draft

Add CSWAP gate#1803
GabrielePalazzo wants to merge 1 commit intomasterfrom
cswap_qasm

Conversation

@GabrielePalazzo
Copy link
Contributor

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.

This draft aims to address #

In this PR I created a CSWAP gate.
While this automatically fixes the issue #1802, it feels just a copy-paste of the code in gates.py.
In alternative, the qasm parser can detect controlled gates and instantiate them.

@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 47.61905% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.43%. Comparing base (4815b7a) to head (7625bc7).

Files with missing lines Patch % Lines
src/qibo/gates/gates.py 44.44% 10 Missing ⚠️
src/qibo/backends/npmatrices.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1803      +/-   ##
==========================================
- Coverage   99.51%   99.43%   -0.09%     
==========================================
  Files          79       79              
  Lines       13274    13295      +21     
==========================================
+ Hits        13210    13220      +10     
- Misses         64       75      +11     
Flag Coverage Δ
unittests 99.43% <47.61%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@renatomello
Copy link
Contributor

renatomello commented Mar 12, 2026

I would suggest avoiding creating yet another gate that is controlled by default. This can be avoided by using the controlled_by method of the Gate class.

I am suggesting this because all gates that are controlled by default

GATES_CONTROLLED_BY_DEFAULT = [

already generate secondary issues as is, e.g. Transpilation issues, gate-counting issues. Since these gates would have to be refactored anyway, it would be better not to increase the number of gates controlled by default.

There are some rules to deal with edge cases in the _openqasm.py file.

def _qibo_gate_name(gate):

Oner rule for the CSWAP from qasm strings could be added there to be converted to a qibo SWAP with one control, and the import issue would be solved without having to create another gate class.

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.

2 participants