J.R. Johansson and P.D. Nation
For more information about QuTiP see http://qutip.org
import numpy as np
from qutip import (about, qeye, qpt, qpt_plot_combined, sigmax, sigmay, sigmaz,
spost, spre)
from qutip_qip.operations import (cnot, fredkin, iswap, phasegate, snot,
sqrtiswap, swap, toffoli)
%matplotlib inline
"""
Plot the process tomography matrices for some 1, 2, and 3-qubit qubit gates.
"""
gates = [
["C-NOT", cnot()],
["SWAP", swap()],
["$i$SWAP", iswap()],
[r"$\sqrt{i\mathrm{SWAP}}$", sqrtiswap()],
["S-NOT", snot()],
[r"$\pi/2$ phase gate", phasegate(np.pi / 2)],
["Toffoli", toffoli()],
["Fredkin", fredkin()],
]
def plt_qpt_gate(gate, figsize=(8, 6)):
name = gate[0]
U_psi = gate[1]
N = len(U_psi.dims[0]) # number of qubits
# create a superoperator for the density matrix
# transformation rho = U_psi * rho_0 * U_psi.dag()
U_rho = spre(U_psi) * spost(U_psi.dag())
# operator basis for the process tomography
op_basis = [[qeye(2), sigmax(), sigmay(), sigmaz()] for i in range(N)]
# labels for operator basis
op_label = [["$i$", "$x$", "$y$", "$z$"] for i in range(N)]
# calculate the chi matrix
chi = qpt(U_rho, op_basis)
# visualize the chi matrix
fig, ax = qpt_plot_combined(chi, op_label, name, figsize=figsize)
ax.set_title(name)
return fig, ax
plt_qpt_gate(gates[0]);
plt_qpt_gate(gates[1]);
plt_qpt_gate(gates[2]);
plt_qpt_gate(gates[3]);
plt_qpt_gate(gates[4]);
plt_qpt_gate(gates[5]);
fig, ax = plt_qpt_gate(gates[6], figsize=(16, 12))
ax.axis("tight");
fig, ax = plt_qpt_gate(gates[7], figsize=(16, 12))
ax.axis("tight");
about()
QuTiP: Quantum Toolbox in Python ================================ Copyright (c) QuTiP team 2011 and later. Current admin team: Alexander Pitchford, Nathan Shammah, Shahnawaz Ahmed, Neill Lambert, Eric Giguère, Boxi Li, Jake Lishman, Simon Cross and Asier Galicia. Board members: Daniel Burgarth, Robert Johansson, Anton F. Kockum, Franco Nori and Will Zeng. Original developers: R. J. Johansson & P. D. Nation. Previous lead developers: Chris Granade & A. Grimsmo. Currently developed through wide collaboration. See https://github.com/qutip for details. QuTiP Version: 5.1.0.dev0+50fc9b7 Numpy Version: 1.22.4 Scipy Version: 1.13.0 Cython Version: 3.0.10 Matplotlib Version: 3.5.2 Python Version: 3.10.4 Number of CPUs: 4 BLAS Info: Generic INTEL MKL Ext: False Platform Info: Linux (x86_64) Installation path: /usr/share/miniconda3/envs/test-environment/lib/python3.10/site-packages/qutip ================================================================================ Please cite QuTiP in your publication. ================================================================================ For your convenience a bibtex reference can be easily generated using `qutip.cite()`