Skip to content
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 equivalences from CR<Pauli> to R<Paulis> #9507

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions qiskit/circuit/library/standard_gates/equivalence_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,33 @@
crx_to_srycx.append(inst, qargs, cargs)
_sel.add_equivalence(CRXGate(theta), crx_to_srycx)

# CRX in terms of one RXX
# ┌───┐ ┌────────────┐┌───┐
# q_0: ────■──── q_0: ───┤ H ├───┤0 ├┤ H ├
# ┌───┴───┐ ≡ ┌──┴───┴──┐│ Rxx(-ϴ/2) │└───┘
# q_1: ┤ Rx(ϴ) ├ q_1: ┤ Rx(ϴ/2) ├┤1 ├─────
# └───────┘ └─────────┘└────────────┘
theta = Parameter("theta")
crx_to_rxx = QuantumCircuit(2)
crx_to_rxx.h(0)
crx_to_rxx.rx(theta / 2, 1)
crx_to_rxx.rxx(-theta / 2, 0, 1)
crx_to_rxx.h(0)
_sel.add_equivalence(CRXGate(theta), crx_to_rxx)

# CRX to CRZ
#
# q_0: ────■──── q_0: ─────────■─────────
# ┌───┴───┐ ≡ ┌───┐┌───┴───┐┌───┐
# q_1: ┤ Rx(ϴ) ├ q_1: ┤ H ├┤ Rz(ϴ) ├┤ H ├
# └───────┘ └───┘└───────┘└───┘
theta = Parameter("theta")
crx_to_crz = QuantumCircuit(2)
crx_to_crz.h(1)
crx_to_crz.crz(theta, 0, 1)
crx_to_crz.h(1)
_sel.add_equivalence(CRXGate(theta), crx_to_crz)

# RXXGate
#
# ┌─────────┐ ┌───┐ ┌───┐
Expand All @@ -257,6 +284,20 @@
def_rxx.append(inst, qargs, cargs)
_sel.add_equivalence(RXXGate(theta), def_rxx)

# RXX to RZX
# ┌─────────┐ ┌───┐┌─────────┐┌───┐
# q_0: ┤0 ├ q_0: ┤ H ├┤0 ├┤ H ├
# │ Rxx(ϴ) │ ≡ └───┘│ Rzx(ϴ) │└───┘
# q_1: ┤1 ├ q_1: ─────┤1 ├─────
# └─────────┘ └─────────┘
theta = Parameter("theta")
rxx_to_rzx = QuantumCircuit(2)
rxx_to_rzx.h(0)
rxx_to_rzx.rzx(theta, 0, 1)
rxx_to_rzx.h(0)
_sel.add_equivalence(RXXGate(theta), rxx_to_rzx)
Comment on lines +287 to +298
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is correct then I don't like our naming convention for RZXGate - to me, that reads as a ZX bitstring interaction, i.e. the Z is on qubit 1. But whatever, even if it mattered what I thought, the ship's long since sailed.

Copy link
Contributor Author

@Cryoris Cryoris Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh I never know which order it is and just end up trying until it fits 😅 but I agree that RZX should implement e^{i theta * ZX} and in our tensor order that would be Z on q_1..

Copy link
Member

@jakelishman jakelishman Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the argument is that it implements what our documentation calls $Z \otimes X$, where I think there's some conflation of the general tensor product $\otimes$ with the Kronecker product ordering we use to make concrete matrix representations.

But anyway, the ship's sailed, and it's unrelated to this PR!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - Wikipedia explains:

the Kronecker product, sometimes denoted by $\otimes$

as opposed to:

the tensor product $V\otimes W$

I've never used \otimes to refer to the Kronecker product, and wasn't aware that was something people did - to me, it's always meant the arbitrary tensor product, which isn't tied to any particular representation of linear algebra.



# RXX to RZZ
q = QuantumRegister(2, "q")
theta = Parameter("theta")
Expand Down Expand Up @@ -321,6 +362,49 @@
def_cry.append(inst, qargs, cargs)
_sel.add_equivalence(CRYGate(theta), def_cry)

# CRY to CRZ
#
# q_0: ────■──── q_0: ───────────────■────────────────
# ┌───┴───┐ ≡ ┌─────────┐┌───┴───┐┌──────────┐
# q_1: ┤ Ry(ϴ) ├ q_1: ┤ Rx(π/2) ├┤ Rz(ϴ) ├┤ Rx(-π/2) ├
# └───────┘ └─────────┘└───────┘└──────────┘
theta = Parameter("theta")
cry_to_crz = QuantumCircuit(2)
cry_to_crz.rx(pi / 2, 1)
cry_to_crz.crz(theta, 0, 1)
cry_to_crz.rx(-pi / 2, 1)
_sel.add_equivalence(CRYGate(theta), cry_to_crz)

# CRY to CRZ
#
# q_0: ────■──── q_0: ────────────────────■─────────────────────
# ┌───┴───┐ ≡ ┌───┐┌─────────┐┌───┴───┐┌──────────┐┌───┐
# q_1: ┤ Ry(ϴ) ├ q_1: ┤ H ├┤ Rz(π/2) ├┤ Rx(ϴ) ├┤ Rz(-π/2) ├┤ H ├
# └───────┘ └───┘└─────────┘└───────┘└──────────┘└───┘
theta = Parameter("theta")
cry_to_crx = QuantumCircuit(2)
cry_to_crx.h(1)
cry_to_crx.rz(pi / 2, 1)
cry_to_crx.crx(theta, 0, 1)
cry_to_crx.rz(-pi / 2, 1)
cry_to_crx.h(1)
_sel.add_equivalence(CRYGate(theta), cry_to_crx)

# CRY to RZZ
#
# q_0: ────■──── q_0: ────────────────────────■───────────────────
# ┌───┴───┐ ≡ ┌─────┐┌─────────┐┌───┐ │ZZ(-ϴ/2) ┌───┐┌───┐
# q_1: ┤ Ry(ϴ) ├ q_1: ┤ Sdg ├┤ Rx(ϴ/2) ├┤ H ├─■─────────┤ H ├┤ S ├
# └───────┘ └─────┘└─────────┘└───┘ └───┘└───┘
cry_to_rzz = QuantumCircuit(2)
cry_to_rzz.sdg(1)
cry_to_rzz.rx(theta / 2, 1)
cry_to_rzz.h(1)
cry_to_rzz.rzz(-theta / 2, 0, 1)
cry_to_rzz.h(1)
cry_to_rzz.s(1)
_sel.add_equivalence(CRYGate(theta), cry_to_rzz)

# RYYGate
#
# ┌─────────┐ ┌─────────┐ ┌──────────┐
Expand Down Expand Up @@ -398,6 +482,44 @@
def_crz.append(inst, qargs, cargs)
_sel.add_equivalence(CRZGate(theta), def_crz)

# CRZ to CRY
#
# q_0: ────■──── q_0: ────────────────■───────────────
# ┌───┴───┐ ≡ ┌──────────┐┌───┴───┐┌─────────┐
# q_1: ┤ Rz(ϴ) ├ q_1: ┤ Rx(-π/2) ├┤ Ry(ϴ) ├┤ Rx(π/2) ├
# └───────┘ └──────────┘└───────┘└─────────┘
theta = Parameter("theta")
crz_to_cry = QuantumCircuit(2)
crz_to_cry.rx(-pi / 2, 1)
crz_to_cry.cry(theta, 0, 1)
crz_to_cry.rx(pi / 2, 1)
_sel.add_equivalence(CRZGate(theta), crz_to_cry)

# CRZ to CRX
#
# q_0: ────■──── q_0: ─────────■─────────
# ┌───┴───┐ ≡ ┌───┐┌───┴───┐┌───┐
# q_1: ┤ Rz(ϴ) ├ q_1: ┤ H ├┤ Rx(ϴ) ├┤ H ├
# └───────┘ └───┘└───────┘└───┘
theta = Parameter("theta")
crz_to_crx = QuantumCircuit(2)
crz_to_crx.h(1)
crz_to_crx.crx(theta, 0, 1)
crz_to_crx.h(1)
_sel.add_equivalence(CRZGate(theta), crz_to_crx)

# CRZ to RZZ
#
# q_0: ────■──── q_0: ────────────■────────
# ┌───┴───┐ ≡ ┌─────────┐ │ZZ(-ϴ/2)
# q_1: ┤ Rz(ϴ) ├ q_1: ┤ Rz(ϴ/2) ├─■────────
# └───────┘ └─────────┘
theta = Parameter("theta")
crz_to_rzz = QuantumCircuit(2)
crz_to_rzz.rz(theta / 2, 1)
crz_to_rzz.rzz(-theta / 2, 0, 1)
_sel.add_equivalence(CRZGate(theta), crz_to_rzz)

# RZZGate
#
# q_0: ─■───── q_0: ──■─────────────■──
Expand Down Expand Up @@ -429,6 +551,19 @@
rzz_to_rxx.append(inst, qargs, cargs)
_sel.add_equivalence(RZZGate(theta), rzz_to_rxx)

# RZZ to RZX
# ┌─────────┐
# q_0: ─■───── q_0: ─────┤0 ├─────
# │ZZ(ϴ) ≡ ┌───┐│ Rzx(ϴ) │┌───┐
# q_1: ─■───── q_1: ┤ H ├┤1 ├┤ H ├
# └───┘└─────────┘└───┘
theta = Parameter("theta")
rzz_to_rzx = QuantumCircuit(2)
rzz_to_rzx.h(1)
rzz_to_rzx.rzx(theta, 0, 1)
rzz_to_rzx.h(1)
_sel.add_equivalence(RZZGate(theta), rzz_to_rzx)

# RZZ to RYY
q = QuantumRegister(2, "q")
theta = Parameter("theta")
Expand Down
18 changes: 18 additions & 0 deletions releasenotes/notes/crx-equivalences-cc9e5c98bb73fd49.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
features:
- |
Equivalences between the controlled Pauli rotations and translations to two-Pauli rotations
are now available in the equivalence library for Qiskit standard gates. This allows,
for example, to translate a :class:`.CRZGate` to a :class:`.RZZGate` plus :class:`.RZGate`
or a :class:`.CRYGate` to a single :class:`.RZXGate` plus single qubit gates::

from qiskit.circuit import QuantumCircuit
from qiskit.compiler import transpile

angle = 0.123
circuit = QuantumCircuit(2)
circuit.cry(angle, 0, 1)

basis = ["id", "sx", "x", "rz", "rzx"]
transpiled = transpile(circuit, basis_gates=basis)
print(transpiled.draw())