Quantum Computing: The QuTiP Framework

How does QuTiP compare to Qiskit for Quantum Computing?
Published

December 28, 2021

In the last post I reviewed the Qiskit quantum computing framework. I mentioned that another framework I found is QuTiP and we will now review that (Johansson, Nation, and Nori 2012).

Johansson, J. R., P. D. Nation, and Franco Nori. 2012. “QuTiP: An Open-Source Python Framework for the Dynamics of Open Quantum Systems.” Computer Physics Communications 183 (8): 1760–72. https://doi.org/10.1016/j.cpc.2012.02.021.

Qobj

The QuTiP documentation starts with a description of the primitve Qobj which is > a data structure that is capable of encapsulating the properties of a quantum operator and ket/bra vectors.

Code
from qutip import Qobj

print(str(
    Qobj([[1], [2], [3]])
))
Quantum object: dims = [[3], [1]], shape = (3, 1), type = ket
Qobj data =
[[1.]
 [2.]
 [3.]]
Code
from qutip import Qobj

print(str(
    Qobj([[1, 2, 3]])
))
Quantum object: dims = [[1], [3]], shape = (1, 3), type = bra
Qobj data =
[[1. 2. 3.]]
Code
import numpy as np
from qutip import Qobj

print(str(
    Qobj(np.random.rand(4, 4))
))
Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False
Qobj data =
[[0.73741067 0.38012055 0.18891659 0.5947496 ]
 [0.73478544 0.50153262 0.97199214 0.17788035]
 [0.89417473 0.79639117 0.93951824 0.8901991 ]
 [0.83072986 0.06070965 0.76528419 0.41292235]]

This start reminds me of tensors which should be easier to work with than using the different x, y and z operations. The basic operations finishes with exactly that:

Code
from qutip import Qobj

print(str(
    Qobj([[1], [2], [3]]) * Qobj([[1, 2, 3]]) + 1
))
Quantum object: dims = [[3], [3]], shape = (3, 3), type = oper, isherm = True
Qobj data =
[[ 2.  2.  3.]
 [ 2.  5.  6.]
 [ 3.  6. 10.]]

I should be able to use my existing experience with tensors to work with this. Based on this start I’m quite hopeful.

Quantum Circuits

Implementing a program using pure matrix operations is fine. It’s not really what I am looking for in Quantum Computing as I could just as easily do that with tensor arithmetic.

QuTiP also has a quantum circuit mode which requires another dependency - qutip-qip (quantum information processing) (Li et al. 2021). I want to explore this to see how easy it is to use compared to the qiskit version. This is a separate package to reduce the overall maintenance burden of the qutip package, and so the documentation is separate. There is also a notebook showing some use of it.

Li, Boxi, Shahnawaz Ahmed, Sidhant Saraogi, Neill Lambert, Franco Nori, Alexander Pitchford, and Nathan Shammah. 2021. “Pulse-Level Noisy Quantum Circuits with QuTiP.” https://arxiv.org/abs/2105.09902.

To get this to work I had to install pdfcrop which, on ubuntu, requires sudo apt-get install texlive-extra-utils.

Code
from qutip_qip.circuit import QubitCircuit
from math import pi

qc = QubitCircuit(N=1, num_cbits=1, reverse_states=False)
qc.add_gate("RX", targets=[0], arg_value=pi/2, arg_label=r'\frac{\pi}{2}')
qc.add_measurement("M0", targets=[0], classical_store=0)
qc.svg
RuntimeError: pdflatex failed. Perhaps you do not have it installed, or you are missing the LaTeX package 'qcircuit'.The latex code is printed below. Please try to compile locally using pdflatex:

\documentclass{standalone}
\usepackage[braket]{qcircuit}
\renewcommand{\qswap}{*=<0em>{\times}}
\begin{document}
\Qcircuit @C=1cm @R=1cm {
 &  &  \gate{R_x(\frac{\pi}{2})}  &  \meter & \qw \\ 
 &  &  \qw  &  \qw \cwx[1]  & \qw \\ 
}
\end{document}

I’m fed up with this. I’ve spent about an hour trying to resolve this error and I am not interested in continuing.

Since I cannot usefully visualize the structure of the quantum circuit I cannot use this framework.