Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson
This notebooks demonstrates how a toffoli gate can be rewritten in terms of CNOT gates and single qubit gates, and verifies the equivalence of the two gate sequences by comparing their matrix representations. For more information about the toffoli decomposition, see Nielsen & Chuang, Sec. 4.3, p178.
Note: The circuit image visualizations require ImageMagick for display.
ImageMagick can be easily installed with the command conda install imagemagick
if you have conda installed.
Otherwise, please follow the installation instructions on the ImageMagick documentation.
from qutip import about
from qutip_qip.operations import gate_sequence_product
from qutip_qip.circuit import QubitCircuit
q = QubitCircuit(3, reverse_states=False)
q.add_gate("TOFFOLI", controls=[0, 2], targets=[1])
q.png
/home/runner/work/qutip-tutorials/qutip-tutorials/qutip-qip/src/qutip_qip/circuit/circuit_latex.py:95: UserWarning: Could not locate system 'pdfcrop': image output may have additional margins. warnings.warn(
U = gate_sequence_product(q.propagators())
U.tidyup()
q2 = q.resolve_gates()
q2.png
/home/runner/work/qutip-tutorials/qutip-tutorials/qutip-qip/src/qutip_qip/circuit/circuit_latex.py:95: UserWarning: Could not locate system 'pdfcrop': image output may have additional margins. warnings.warn(
U2 = gate_sequence_product(q2.propagators())
U2.tidyup()
U == U2
True
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: 4.7.1 Numpy Version: 1.22.4 Scipy Version: 1.8.1 Cython Version: 0.29.33 Matplotlib Version: 3.5.2 Python Version: 3.10.4 Number of CPUs: 2 BLAS Info: Generic OPENMP Installed: False INTEL MKL Ext: False Platform Info: Linux (x86_64) Installation path: /home/runner/work/qutip-tutorials/qutip-tutorials/qutip/qutip ================================================================================ Please cite QuTiP in your publication. ================================================================================ For your convenience a bibtex reference can be easily generated using `qutip.cite()`