Skip to content

Commit b20f595

Browse files
Update CS and CSdg in the equivalence library (Qiskit#14001)
* update CS and CSdg in the equivalence library * add release notes * update release notes following review * fix misprint * add back original equivalences * update releasde notes * Update releasenotes/notes/update-cs-csdg-in-equivalence-library-c1e70d3246f4aa6d.yaml Co-authored-by: Alexander Ivrii <[email protected]> --------- Co-authored-by: Alexander Ivrii <[email protected]>
1 parent 9dcc668 commit b20f595

File tree

2 files changed

+66
-27
lines changed

2 files changed

+66
-27
lines changed

qiskit/circuit/library/standard_gates/equivalence_library.py

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -807,33 +807,6 @@ def _cnot_rxx_decompose(plus_ry: bool = True, plus_rxx: bool = True):
807807
def_sdg.append(U1Gate(-pi / 2), [q[0]], [])
808808
_sel.add_equivalence(SdgGate(), def_sdg)
809809

810-
# CSGate
811-
#
812-
# q_0: ──■── q_0: ───────■────────
813-
# ┌─┴─┐ ┌───┐┌─┴──┐┌───┐
814-
# q_1: ┤ S ├ = q_1: ┤ H ├┤ Sx ├┤ H ├
815-
# └───┘ └───┘└────┘└───┘
816-
q = QuantumRegister(2, "q")
817-
def_cs = QuantumCircuit(q)
818-
def_cs.append(HGate(), [q[1]], [])
819-
def_cs.append(CSXGate(), [q[0], q[1]], [])
820-
def_cs.append(HGate(), [q[1]], [])
821-
_sel.add_equivalence(CSGate(), def_cs)
822-
823-
# CSdgGate
824-
#
825-
# q_0: ───■─── q_0: ───────■────■────────
826-
# ┌──┴──┐ ┌───┐┌─┴─┐┌─┴──┐┌───┐
827-
# q_1: ┤ Sdg ├ = q_1: ┤ H ├┤ X ├┤ Sx ├┤ H ├
828-
# └─────┘ └───┘└───┘└────┘└───┘
829-
q = QuantumRegister(2, "q")
830-
def_csdg = QuantumCircuit(q)
831-
def_csdg.append(HGate(), [q[1]], [])
832-
def_csdg.append(CXGate(), [q[0], q[1]], [])
833-
def_csdg.append(CSXGate(), [q[0], q[1]], [])
834-
def_csdg.append(HGate(), [q[1]], [])
835-
_sel.add_equivalence(CSdgGate(), def_csdg)
836-
837810
# SdgGate
838811
#
839812
# ┌─────┐ ┌───┐┌───┐
@@ -877,6 +850,65 @@ def _cnot_rxx_decompose(plus_ry: bool = True, plus_rxx: bool = True):
877850
def_sdg.append(inst, qargs, cargs)
878851
_sel.add_equivalence(SdgGate(), def_sdg)
879852

853+
# CSGate
854+
#
855+
# ┌───┐
856+
# q_0: ──■── q_0: ┤ T ├──■───────────■──
857+
# ┌─┴─┐ ├───┤┌─┴─┐┌─────┐┌─┴─┐
858+
# q_1: ┤ S ├ = q_1: ┤ T ├┤ X ├┤ Tdg ├┤ X ├
859+
# └───┘ └───┘└───┘└─────┘└───┘
860+
q = QuantumRegister(2, "q")
861+
def_cs = QuantumCircuit(q)
862+
def_cs.append(TGate(), [q[0]], [])
863+
def_cs.append(TGate(), [q[1]], [])
864+
def_cs.append(CXGate(), [q[0], q[1]], [])
865+
def_cs.append(TdgGate(), [q[1]], [])
866+
def_cs.append(CXGate(), [q[0], q[1]], [])
867+
_sel.add_equivalence(CSGate(), def_cs)
868+
869+
# CSGate
870+
#
871+
# q_0: ──■── q_0: ───────■────────
872+
# ┌─┴─┐ ┌───┐┌─┴──┐┌───┐
873+
# q_1: ┤ S ├ = q_1: ┤ H ├┤ Sx ├┤ H ├
874+
# └───┘ └───┘└────┘└───┘
875+
q = QuantumRegister(2, "q")
876+
def_cs_csx = QuantumCircuit(q)
877+
def_cs_csx.append(HGate(), [q[1]], [])
878+
def_cs_csx.append(CSXGate(), [q[0], q[1]], [])
879+
def_cs_csx.append(HGate(), [q[1]], [])
880+
_sel.add_equivalence(CSGate(), def_cs_csx)
881+
882+
# CSdgGate
883+
#
884+
# ┌─────┐
885+
# q_0: ───■─── q_0: ──■─────────■──┤ Tdg ├
886+
# ┌──┴──┐ ┌─┴─┐┌───┐┌─┴─┐├─────┤
887+
# q_1: ┤ Sdg ├ = q_1: ┤ X ├┤ T ├┤ X ├┤ Tdg ├
888+
# └─────┘ └───┘└───┘└───┘└─────┘
889+
q = QuantumRegister(2, "q")
890+
def_csdg = QuantumCircuit(q)
891+
def_csdg.append(CXGate(), [q[0], q[1]], [])
892+
def_csdg.append(TGate(), [q[1]], [])
893+
def_csdg.append(CXGate(), [q[0], q[1]], [])
894+
def_csdg.append(TdgGate(), [q[0]], [])
895+
def_csdg.append(TdgGate(), [q[1]], [])
896+
_sel.add_equivalence(CSdgGate(), def_csdg)
897+
898+
# CSdgGate
899+
#
900+
# q_0: ───■─── q_0: ───────■────■────────
901+
# ┌──┴──┐ ┌───┐┌─┴─┐┌─┴──┐┌───┐
902+
# q_1: ┤ Sdg ├ = q_1: ┤ H ├┤ X ├┤ Sx ├┤ H ├
903+
# └─────┘ └───┘└───┘└────┘└───┘
904+
q = QuantumRegister(2, "q")
905+
def_csdg_csx = QuantumCircuit(q)
906+
def_csdg_csx.append(HGate(), [q[1]], [])
907+
def_csdg_csx.append(CXGate(), [q[0], q[1]], [])
908+
def_csdg_csx.append(CSXGate(), [q[0], q[1]], [])
909+
def_csdg_csx.append(HGate(), [q[1]], [])
910+
_sel.add_equivalence(CSdgGate(), def_csdg_csx)
911+
880912
# SwapGate
881913
# ┌───┐
882914
# q_0: ─X─ q_0: ──■──┤ X ├──■──
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features_synthesis:
3+
- |
4+
The standard equivalence library has additional equivalences for :class:`.CSGate` and :class:`.CSdgGate`.
5+
When transpiling to the `["cx", "u"]` basis set, the :class:`.BasisTranslator` transpiler pass now uses
6+
2 :class:`.CXGate` gates instead of 3 for :class:`.CSdgGate`, and in addition reduces the number of single-qubit
7+
gates in both cases.

0 commit comments

Comments
 (0)