-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add gates.CNOT
as a native gate in gate decomposition
#1422
Conversation
for more information, see https://pre-commit.ci
gates.CNOT
as a native gategates.CNOT
as a native gate in gate decomposition
for more information, see https://pre-commit.ci
Examplecirc = Circuit(2)
circ.add(gates.H(0))
circ.add(gates.CNOT(0, 1))
circ.add(gates.SWAP(0, 1))
circ.add(gates.CZ(0, 1))
circ.add(gates.M(0, 1))
gate_list = [gates.GPI2, gates.RZ, gates.Z, gates.M, gates.CNOT]
native_gates = NativeGates(0).from_gatelist(gate_list)
custom_pipeline = Passes([Unroller(native_gates=native_gates)])
unrolled_circuit, _ = custom_pipeline(circ)
print(unrolled_circuit.draw(line_wrap=100)) Outputq0: ─Z─GPI2─o─o─X─o────────o────────M─
q1: ────────X─X─o─X─Z─GPI2─X─Z─GPI2─M─ |
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.
As said in the issue, the unroller should be entirely reviewed, since there are many more combinations that now are not accounted for.
In any case, they may also be unrealistic, and support is not needed in the short term.
For the time being, just fix the docstrings, and it should be ready to go.
for more information, see https://pre-commit.ci
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.
@csookim, you didn't have to ask again for a review: I already approved, and the modifications I asked were so minor that I trusted you on how to implement them :)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1422 +/- ##
=======================================
Coverage 99.94% 99.94%
=======================================
Files 78 78
Lines 11297 11304 +7
=======================================
+ Hits 11291 11298 +7
Misses 6 6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Indeed, if you leave it there it will edit the same comment, instead of adding a new one :) |
# No CZ, iSWAP gates in the native gate set | ||
# Decompose CNOT, CZ, SWAP gates into CNOT gates | ||
if native_gates & NativeGates.CNOT: | ||
return cnot_dec_temp(gate) |
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.
You can make this decomposition work for every gate by first decomposing into CZ and then decomposing CZ into CNOT. This is how it works for iSWAP decomposition (line 238-250).
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.
Yes, but it adds two H gates next to the CNOT and it requires optimization (fusion) of 1q gates. Since Paul will use simple circuits for testing, I only added basic decompositions. As @alecandido mentioned, it would be better to entirely review the unroller.
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.
It should be a realy easy check to remove two successive H gates, however if you need it only for simple applications it is fine
This covers issue #1421.
Checklist: