# How to implement the XY Heisenberg interaction using IBMQ and Qiskit?

A possible way to implement the 2 qubit Heisenberg XYZ model using a Quantum computer is to decompose the Hamiltonian as follows: $$H_{XYZ} = H_{XY} + H_{YZ} + H_{XZ}$$. In this case, these operators commute so we can apply the trotter formula to get the unitary evolution $$U = e^{-iH_{XY}t}e^{-iH_{XZ}t}e^{-iH_{YZ}t}$$

Further, using appropriate rotations on the single qubits, $$H_{XZ}$$ and $$H_{YZ}$$ can be expressed using single qubit gates and $$H_{XY}$$, meaning that the evolution $$U$$ should be able to be simulated using only single qubit rotations and the XY interaction ($$H_{XY} = \sigma_1^X\sigma_2^X + \sigma_1^Y\sigma_2^Y$$)

Given this, how can the XY interaction be implemented in IBMQ/Qiskit? Preferably it would be good to be able to do this without the use of an ancillary qubit.

First, let's use the fact that $$\sigma^X_1 \sigma^X_2$$ and $$\sigma^Y_1 \sigma^Y_2$$ commute. This means

$$e^{-i H_{XY} t} = e^{-i ~\sigma^X_1 \sigma^X_2~ t} ~ e^{-i ~\sigma^Y_1 \sigma^Y_2~ t}$$

Using appropriate single qubit rotations, $$e^{-i ~\sigma^Y_1 \sigma^Y_2~ t}$$ can be expressed using $$e^{-i ~\sigma^X_1 \sigma^X_2~ t}$$. So now we've reduced the problem to simply implementing $$e^{-i ~\sigma^X_1 \sigma^X_2~ t}$$.

To do this, the important relation to note is that,

$${CX}_{j,k} ~ e^{-i~\sigma^X_j~t} ~ {CX}_{j,k} = e^{-i ~\sigma^X_j \sigma^X_k~t}$$.

So all you need is a couple of cnots, and an appropriate single qubit rotation $$e^{-i~\sigma^X_j~t}$$ implemented on their control qubit. In Qiskit code, here's a two qubit circuit that would implement this (here I named the qubits as $$0$$ and $$1$$ instead of $$1$$ and $$2$$, to reflect the Python indexing convention)

    qc = QuantumCircuit(2)
qc.cx(0,1)
qc.rx(t,0)
qc.cx(0,1)


Following this method would mean using 12 cnots to implement the whole Hamiltonian, which is quite a lot given the fidelities of current devices. Fancier methods are doubtless possible.

Using the fact that $$\sigma_1^X\sigma_2^X$$ and $$\sigma_1^Y\sigma_2^Y$$ commute, you can split the term into a product of two rotations.

$$e^{t\cdot\sigma_1^X\sigma_2^X}$$ can be understood as rotation along the $$\{||00\rangle, |11\rangle \}$$ basis. There are inbuilt gates to perform this rotation which decompose into the gates that James above has answered. For example, RXX, RYY gate can be used for what you desired:

t = 1.0
circuit = QuantumCircuit(2)
circuit.rxx(t, 0, 1)
circuit.ryy(t, 0, 1)


You can use the Trotterization of higher orders to achieve a more accurate approximation at a cost of gate complexity for any general Hamiltonian Simulation without any extra ancilla qubits.

If you want to perform arbitrarily rotations for any number of qubits, then you can use PauliEvolutionGate (Refer to my question)