A quick introduction to quantum computing

Extensible, Efficient Quantum Algorithm Design for Humans. https://github.com/QuantumBFS/Yao.jl

classical circuits

Inverse Gate - X

In [13]:
using Yao, BitBasis
reg = product_state(3, 0b110)

function read(reg)
    "0b"*prod(copy(reg) |> measure |> first |> bitarray(nqubits(reg)) .|> Int .|> string)
end

reg |> read
Out[13]:
"0b011"
In [14]:
# |0> -----|X|-------
#
# |1> ---------------
#
# |1> ---------------

res = copy(reg) |> put(3, 1=>X) |> read
Out[14]:
"0b111"

XOR Gate - CNOT

In [6]:
# |0> -----|X|-------
#           |
# |1> ------.--------
#
# |1> ---------------

@show copy(reg) |> control(3, 2, 1=>X) |> read
@show copy(reg) |> control(3, 1, 2=>X) |> read;
(copy(reg) |> control(3, 2, 1 => X)) |> read = "0b111"
(copy(reg) |> control(3, 1, 2 => X)) |> read = "0b011"

NAND Gate - Toffoli

In [7]:
# |0> -----|X|-------
#           |
# |1> ------.--------
#           |
# |1> ------.--------

copy(reg) |> control(3, (2,3), 1=>X) |> read
Out[7]:
"0b111"

Cubic or Qubic?

What happens inside a quantum simulator

In [8]:
# one hot representation
statevec(reg)
Out[8]:
8-element Array{Complex{Float64},1}:
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 1.0 + 0.0im
 0.0 + 0.0im

A review of X gate in Hilbert space

In [9]:
mat(X)
Out[9]:
2×2 LuxurySparse.PermMatrix{Complex{Float64},Int64,Array{Complex{Float64},1},Array{Int64,1}}:
    0       1.0+0.0im
 1.0+0.0im     0     
In [10]:
statevec(copy(reg) |> put(3, 1=>X))
Out[10]:
8-element Array{Complex{Float64},1}:
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 1.0 + 0.0im

A quantum Gate

  • A classical gate is a permutation matrix
  • A quantum gate should be unitary (expect measure)
  • A quantum state lies on the unit ball of the hypercubic

One half of an X Gate

In [11]:
res = copy(reg) |> put(3, 1=>Rx(π/2))
statevec(res)
Out[11]:
8-element Array{Complex{Float64},1}:
                0.0 + 0.0im               
                0.0 + 0.0im               
                0.0 + 0.0im               
                0.0 + 0.0im               
                0.0 + 0.0im               
                0.0 + 0.0im               
 0.7071067811865476 + 0.0im               
                0.0 - 0.7071067811865475im

super-position

In [12]:
for i=1:10
    @show read(res)  # NOTE: our nature can not repeatedly read a register.
end
read(res) = "0b011"
read(res) = "0b011"
read(res) = "0b111"
read(res) = "0b011"
read(res) = "0b111"
read(res) = "0b111"
read(res) = "0b111"
read(res) = "0b011"
read(res) = "0b111"
read(res) = "0b011"

special topics

  • quantum circuit and renormalization group - MERA
In [ ]:

In [ ]: