Processing math: 38%

Quantum logic gates for a single qubit, interactively

Drag and drop quantum gates to see how they act on a qubit.

Published

April 10, 2021

DOI

Quantum computers use quantum physics to perform computation. They use phenomena such as superposition and entanglement that make it possible to use more powerful algorithms than in classical computing . In classical computing, we use the electric signal as the carrier of information. In quantum, we use various implementations, including the polarization of light, the spin of ions, and the states of superconductors.

Qubit

In classical computing, the basic unit is a bit - 0 or 1. In quantum computing, the basic unit is a qubit. Instead of just two values, we have a vector with two components. In this article, we explore what a single qubit is, and what are the quantum computing operations:

|0=[10]|1=[01] In general, a qubit can be any superposition of |0 and |1 - that is

|ψ=α|0+β|1

where α and β are complex numbers, that is numbers z=x+iy, were x and y are real numbers and i is an imaginary unit i2=1. Here are a few common states:

|+=|0+|12|=|0|12

|\!\circlearrowleft \rangle=\frac{|0\rangle+i|1\rangle}{\sqrt{2}} \hspace{1cm} |\!\circlearrowright\rangle=\frac{|0\rangle-i|1\rangle}{\sqrt{2}}

If complex numbers are new to you - don’t worry. First, many interesting quantum states, operators, and phenomena can be described without complex numbers. Second, complex numbers are important and fun on their own.

Operations on a qubit

Instead of classic logic gates, we use quantum logic gates. How do they work? These are 2 \times 2 matrices, changing the state via matrix-vector multiplication

|\psi_{new}\rangle = M |\psi\rangle or showing all complex parametrs: \begin{bmatrix} \alpha_{new} \\ \beta_{new} \end{bmatrix} = \begin{bmatrix} m_{00} & m_{01}\\ m_{01} & m_{11} \end{bmatrix} \begin{bmatrix} \alpha \\ \beta \end{bmatrix}

Let us pick a state and a quantum gate!

1. Pick a state

1.00 exp(0.00i) | 0

amplitude qubit

polar polarTau cartesian color
01 +- +i-i

2. Pick a gate

Identity
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase

3. Check the result

1.00 exp(0.00i) | 0

amplitude qubit

polar polarTau cartesian color
01 +- +i-i

Quantum gates

Only identity (I) and negation (X) are the same in classical and quantum computing. All other gates are specific to quantum computing. For example, Hadamard gate (H), while having only real numbers, is enough to show the difference between |+\rangle and |-\rangle states (check it!). Another interesting gate is the square root of negation (\sqrt{X} or \sqrt{NOT}). If we apply it twice, we get a negation. Don’t worry - later in this post, you will be able to compose gates. So, what are the most typical gates?

I (Id, 𝟙, identity)
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
X (Pauli-X, NOT)
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
Y (Pauli-Y)
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
Z (Pauli-Z, 1/2 phase shiift)
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
H (Hadamard gate)
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
S (1/4 phase shift)
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
T (1/8 phase shift)
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase
√X (square root of NOT)
input 0 1 qubit output 0 1
change basis
01 +- +i-i
Amplitude Phase

Quantum circuits

Quantum gates can be composed. In a conventional matrix notation, we read from right to left. That is, X \;H \; Z \; |0\rangle means that we start with state |0\rangle, then apply Z gate, then H, then X. I It is a historic notation that is going to stay here. While in quantum circuits, we use a typical left to right notation, for the sake of this visualization, we use the matrix notation.

You can interact with various sequences of gates in the section below. Drag the gate you want to apply to the selected gate area. To delete a gate from that area, drag it to the trash area. You can pick any input state from the gauges. It uses a general parametrization of:

|\psi\rangle = \cos\left(\tfrac{\theta}{2}\right) \; |0\rangle + e^{i\phi} \; \sin\left(\tfrac{\theta}{2}\right) \; |1\rangle

If you want to avoid complex values, use \phi=0 (for positive values) or \phi=\pi (for negative values).

Observe how the state changes according to the applied gates. In BraKetVue, we use colors to denote phase of complex numbers and for an implementation for QuTiP.

Pick any state and compose a circuit

θ = 0.5 π
φ = 1 π

|ψ⟩ = 0.707 |0⟩ + ( -0.707 ) |1⟩

Available gates
Selected gates
|ψ⟩
Trash 🗑
step value state
0 Initial state
0.71 exp(0.00i) | 0 0.71 exp(3.14i) | 1
1 H gate
1.00 exp(6.28i) | 1
2 X gate
1.00 exp(6.28i) | 0
amplitude qubit
view base change
polar polarTau cartesian color
01 +- +i-i

Remarks

This post is a part of the quantum computing series by Quantum Flytrap. We wrote it using Distill for R Markdown - a style based on the Distill journal. This article uses:

These libraries are open source (MIT), as well as this post (CC-BY). The source to this post is here. We believe in an open, contributive culture.

Stay tuned for our next posts! The easiest way to do so is to follow our Twitter account.

Footnotes

    References

    Migdał, Piotr. 2014a. “QuTiP Example: Qubism Visualizations.” 2014. https://nbviewer.jupyter.org/github/qutip/qutip-notebooks/blob/master/examples/qubism-and-schmidt-plots.ipynb.

    ———. 2014b. “Symmetries and Self-Similarity of Many-Body Wavefunctions, Chapter 3.” PhD thesis, ICFO – The Institute of Photonic Sciences. https://arxiv.org/abs/1412.6796.

    Nielsen, Michael A., and Isaac L. C. Chuang. 2000. Quantum Computation and Quantum Information. Cambridge University Press.

    Petrisor, Emilia. 2019. “Visualizing Complex-Valued Functions with Matplotlib and Mayavi: Domain Coloring Method.” 2019. https://nbviewer.jupyter.org/github/empet/Math/blob/master/DomainColoring.ipynb.

    Reuse

    Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".