-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Adds BasisTanslator, UnrollCustomDefinitions to default levels. #4446
Adds BasisTanslator, UnrollCustomDefinitions to default levels. #4446
Conversation
36650e9
to
9d022a9
Compare
9d022a9
to
381ba6b
Compare
Ok I marked it as resolving those two issues (generalizing commutative cancellation seems like a separate issue) Can you add tests for rewriting some general circuits in terms of CZ and iSWAP? |
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.
I made 2 comments otherwise I'm good with this.
releasenotes/notes/add-basistranslator-to-default-levels-1c0de250f8ca4a59.yaml
Show resolved
Hide resolved
0f45556
to
1d2a89d
Compare
1d2a89d
to
b430cd0
Compare
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.
Since alternate basis are now supported by preset passmanagers, I think they should be supported by individual passes inside those passmanagers too - not just the two newly added passes. For example level 3 is supposed to do block collection and resynthesis to avoid redundant applications of 2-qubit gates. At the moment, however, I think this really just works for CNOTs.
Running this code:
from qiskit.circuit.library import QuantumVolume
from qiskit import transpile
qv_model = QuantumVolume(3, seed=3)
qv_iswap = transpile(qv_model, basis_gates=['iswap', 'u3'], optimization_level=3)
qv_iswap.draw('mpl', fold=100)
I get the circuit below, but all those iswap
chains of 6 should be reduced to at most 3 using the block collection/resynthesis passes.
This looks good. For 2-qubit gates I think this is doing a reasonable job, but for 1-qubit gates there are still inefficiencies. I fix this as part of #3658 from qiskit import *
qc = QuantumCircuit(2)
qc.cx(0, 1)
qc.cx(1, 0)
out = transpile(qc, basis_gates=['iswap', 'rx', 'rz'], optimization_level=3) |
Previous code mis-calculated the number of available free parameters from the gate signature, resulting in creation of gates like XGate(label=0.1). These would cause errors if the circuits containing these gates were drawn.
Updates BasisTranslator-Unroller compatability test test_basis_translator.TestUnrollerCompatibility.test_unroll_all_instructions to verify the generated circuit is equivalent (with snapshot, measure instructions removed) as the circuit transpiled by the BasisTranslator is no longer gate-for-gate equal with that of the Unroller.
5d8ab7e
to
9727571
Compare
4f8d2f8
to
be0e644
Compare
…it#4446) * Add Rz->RX,RY, U3->RX,RY, CX->RXX to StandardEquivalenceLibrary. Updates BasisTranslator-Unroller compatability test test_basis_translator.TestUnrollerCompatibility.test_unroll_all_instructions to verify the generated circuit is equivalent (with snapshot, measure instructions removed) as the circuit transpiled by the BasisTranslator is no longer gate-for-gate equal with that of the Unroller. * Fix free param calculation in standard gates to_matrix test. Previous code mis-calculated the number of available free parameters from the gate signature, resulting in creation of gates like XGate(label=0.1). These would cause errors if the circuits containing these gates were drawn. * Remove definition for C3XGate, C4XGate due to name conflict with MCXGate. * Add UnrollCustomDefinitions and BasisTranslator into default levels. * Add CX to CZ, to iSwap decompositions. * Support block collection for non-CX two-qubit gates. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Resolves #3146
Resolves #3086
Summary
Previous code mis-calculated the number of available free parameters
from the gate signature, resulting in creation of gates like
XGate(label=0.1). These would cause errors if the circuits containing
these gates were drawn.
Remove definition for C3XGate, C4XGate due to name conflict with MCXGate.
Add Rz->RX,RY, U3->RX,RY, CX->RXX to StandardEquivalenceLibrary.
Updates BasisTranslator-Unroller compatability test
test_basis_translator.TestUnrollerCompatibility.test_unroll_all_instructions
to verify the generated circuit is equivalent (with snapshot,
measure instructions removed) as the circuit transpiled by the
BasisTranslator is no longer gate-for-gate equal with that of the
Unroller.
on-hold for #4442 .Details and comments