NMR Algorithm
The NMRHamiltonianAlgorithm
constructs quantum circuits for Hamiltonians containing XX, YY, and ZZ two-qubit interaction terms. This yields shallower circuits with fewer two-qubit gates than a CNOT-based decomposition, and avoids the SWAPs generated in a QSWAP-based decomposition. It uses the SpinInteraction
gate, which Qonvert can decompose more efficiently than the gate sequences produced by the CNOTAlgorithm
. This is particularly useful for simulating the second-order Trotterized time evolution of NMR Hamiltonians on devices with linear connectivity, since such Hamiltonians predominantly comprise XX, YY, and ZZ interactions.
The SpinInteraction
gate represents a generalized, anisotropic XYZ Heisenberg interaction between spins. It applies the following unitary to qubits t
and c
:
Example
Here is an example with a two-spin Hamiltonian:
hamiltonian = spins.PauliHamiltonian()
for i in range(number_spins):
for j in range(i + 1, number_spins):
for op in ["X", "Y", "Z"]:
hamiltonian.set(f"{i}{op}{j}{op}", 0.4)
PauliHamiltonian{
0X1X: 4e-1,
0Y1Y: 4e-1,
0Z1Z: 4e-1,
}
When using the NMRHamiltonianAlgorithm
to create the trotterized time evolution of the Hamiltonian we obtain the following circuit:
unitary = py_alqorithms.NMRHamiltonianAlgorithm(number_trotter_steps=1).order(1)
circuit = unitary.create_circuit(hamiltonian, 2.0)
This time-evolution circuit can then be compiled for a specific device (here containing RotateZ
, RotateX
, and CNOT
gates) using qonvert
, resulting in a circuit with 2 two-qubit gates:
With the CNOTAlgorithm
, on the other hand, we obtain the following time-evolution circuit:
unitary = py_alqorithms.CNOTAlgorithm(number_trotter_steps=1).order(1)
circuit = unitary.create_circuit(hamiltonian, 2.0)
Running the qonvert
compilation for the same device, we obtain a circuit with 6 two-qubit gates:
Limitations
While this algorithm is the best choice for these kinds of Hamiltonians, using it with a Hamiltonian with a term other than XX, YY or ZZ will result in an error.