I want to decompose a two-qubit unitary gate $U$, $$U = e^{-i \cdot \frac{t}{2} \cdot Z_1 \cdot Z_2}\,,$$ where $t$ is an angle.

I already know the right decomposition but Qiskit gives me an inefficent one. I want to know why. This is the code.

import numpy as np
from scipy.linalg import expm
from qiskit.compiler import transpile
from qiskit import QuantumCircuit, QuantumRegister
import qiskit.quantum_info as qi 

pauli_str = qi.Pauli('ZZ')

# define your matrix
A = np.array(pauli_str)
t = np.pi / 6

# expm is a matrix exponential 
U = expm(-1j * t * A)

# create a 1 qubit circuit
q1 = QuantumRegister(2, name='q')
circuit1 = QuantumCircuit(q1)

# apply a single-qubit unitary gate, this will do the decomposition
circuit1.unitary(U, [0, 1])

res1 = qi.Operator(circuit1)
print("\nFirst circuit:\n")

basis_gates=['id', 'rz', 'ry', 'rx', 'cx']
result = transpile(circuit1, basis_gates=basis_gates, optimization_level=3, seed_transpiler=1)

q2 = QuantumRegister(2, name='q')
circuit2 = QuantumCircuit(q2)
circuit2.cx(0, 1)
circuit2.rz(t*2, 1)
circuit2.cx(0, 1)

res2 = qi.Operator(circuit2)
print("\nSecond circuit:\n")

This is the result I getenter image description here

  • $\begingroup$ Just two ideas. Try to specify another basis gates set: CX, RZ, ID only. Note that native gates on IBM Quantum contains also square root of X. Secondly, you can play with optimization level and try to find out how this is related to efficiency of the decomposition. $\endgroup$ Feb 11 at 8:19


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.