Lecture 1
Lecture 1
Programming
A programming-first approach
A great way to challenge yourself to think about computation in a totally new way
An experiment!
Course details
Online at: http://cs269q.stanford.edu
There will be one written problem sets, three programming projects, and
one final programming project.
Readings: posted online with the syllabus for each lecture. These are
critical.
Course Topics & Timeline
Introduction Low Level Noise & Hybrid Hardware & Hybrid Error Correction Other
Linear Algebra Programming Benchmarking Algorithms Compilation Algs & Error Corrected Topics
Quantum Quantum Ops VQE Simulation MBQC
(QML) Algorithms
Mechanics Instruction Sets QAOA Blind QC
Shor’s Factoring Algorithm
Classical Ctrl Optimization Grover’s Search Algorithm
Lecture 1 Lecture 20
Quantum Computing isn’t the answer to everything.
Transistor scaling
Source: https://www.anandtech.com/show/12693/intel-delays-mass-production-of-10-nm-cpus-to-2019
Classical computers have fundamental limits
Source: https://blog.openai.com/ai-and-compute/
And there’s more we want to do
For N qubits every time step (~100ns*) is an exponentially large 2N x 2N complex matrix multiplication
Crucial details:
- limited number of multiplications (hundreds to thousands) due to noise
- not arbitrary matrices (need to be easily constructed on a QC)
- small I/O, N-bits in and N-bits out
N qubits
OpenQuantum
Making quantum technologies useful sooner and for
more people
Image: Strangeworks
Quantum Hardware comes
in many forms
Photonic Quantum Computers Use Light
Image: Xanadu
Superconducting Qubits are Supercooled RF Circuits
Image: IBM
Images: Rigetti
Ion Trap Quantum Computers
Image: IonQ
Why build a quantum computer?
New power | New opportunity | Fundamental curiosity
Investments across academia, government, and industry are global and growing
Quantum computing reorients the relationship between physics and computer science.
Quantum computing reorients the relationship between physics and computer science.
Chip goes
here
CPU QPU
bits: qubits:
[0]...[N] 0...M
CPU QPU
bits: qubits:
[0]...[N] 0...M
CPU QPU
bits: qubits:
[0]...[N] 0...M
1. Send program
e.g.
X0
2. Prep
CNOT 0 1
Distribution
CPU QPU
bits: qubits:
qubits:
[0]...[N] 0...M
0...M
3. Sample
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
Probability of 0 Probability of 1
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
...
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
Probability of bitstring x
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
State (multi-unit) Bitstring Prob. Distribution (stochastic vector) Wavefunction (complex vector)
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
State (multi-unit) Bitstring Prob. Distribution (stochastic vector) Wavefunction (complex vector)
State (multi-unit) Bitstring Prob. Distribution (stochastic vector) Wavefunction (complex vector)
State (multi-unit) Bitstring Prob. Distribution (stochastic vector) Wavefunction (complex vector)
State (multi-unit) Bitstring Prob. Distribution (stochastic vector) Wavefunction (complex vector)
Component Ops Boolean Gates Tensor products of matrices Tensor products of matrices
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
State (multi-unit) Bitstring Prob. Distribution (stochastic vector) Wavefunction (complex vector)
Component Ops Boolean Gates Tensor products of matrices Tensor products of matrices
Sampling
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
State (multi-unit) Bitstring Prob. Distribution (stochastic vector) Wavefunction (complex vector)
Component Ops Boolean Gates Tensor products of matrices Tensor products of matrices
State (multi-unit) Bitstring Prob. Distribution (stochastic vector) Wavefunction (complex vector)
Component Ops Boolean Gates Tensor products of matrices Tensor products of matrices
𝛹 = [1, 0, 0, 0]
00 01 10 11
X 0 # “quantum NOT”
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
𝛹 = [1, 0, 0, 0]
00 01 10 11
X 0 # “quantum NOT”
Apply X instr to 0th qubit
𝛹 = [0, 1, 0, 0]
00 01 10 11
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
𝛹 = [1, 0, 0, 0]
00 01 10 11
X 0 # “quantum NOT”
𝛹 = [0, 1, 0, 0]
00 01 10 11
X 0
H 0 # Hadamard gate
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
𝛹 = [1, 0, 0, 0]
00 01 10 11
X 0 # “quantum NOT”
𝛹 = [0, 1, 0, 0]
00 01 10 11
X 0
H 0 # Hadamard gate
Apply H instr to 0th qubit
𝛹 = [1/√2, 1/√2, 0, 0]
00 01 10 11
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
𝛹 = [1, 0, 0, 0]
00 01 10 11
X 0 # “quantum NOT”
𝛹 = [0, 1, 0, 0]
00 01 10 11
X 0
H 0 # Hadamard gate
𝛹 = [1/√2, 1/√2, 0, 0]
00 01 10 11
CNOT 0 1
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
𝛹 = [1, 0, 0, 0]
00 01 10 11
X 0 # “quantum NOT”
𝛹 = [0, 1, 0, 0]
00 01 10 11
X 0
H 0 # Hadamard gate
𝛹 = [1/√2, 1/√2, 0, 0]
00 01 10 11
CNOT 0 1
Apply CNOT instr to 0 and 1 qubits
𝛹 = [1/√2, 0, 0, 1/√2]
00 01 10 11
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
𝛹 = [1, 0, 0, 0]
00 01 10 11
X 0 # “quantum NOT”
𝛹 = [0, 1, 0, 0]
00 01 10 11
X 0
H 0 # Hadamard gate
𝛹 = [1/√2, 1/√2, 0, 0]
00 01 10 11
CNOT 0 1
𝛹 = [1/√2, 0, 0, 1/√2]
00 01 10 11
X 0 # “quantum NOT”
X 0
H 0 # Hadamard gate
CNOT 0 1
𝛹 = [1/√2, 0, 0, 1/√2]
00 01 10 11
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
X 0 # “quantum NOT”
X 0
H 0 # Hadamard gate
CNOT 0 1
𝛹 = [1/√2, 0, 0, 1/√2]
00 01 10 11
# Move quantum data to classical data
# MEASURE <qubit register> [<bit register>]
MEASURE 0 [2]
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
X 0 # “quantum NOT”
X 0
H 0 # Hadamard gate
CNOT 0 1
𝛹 = [1/√2, 0, 0, 1/√2]
00 01 10 11
# Move quantum data to classical data
# MEASURE <qubit register> [<bit register>] 50-50 branch
MEASURE 0 [2]
𝛹 = [1, 0, 0, 0] 𝛹 = [0, 0, 0, 1]
00 01 10 11 00 01 10 11
Classical Bit
Register
0 0 0 0 ... 0 0 1 0 ...
[0] [1] [2] [3] [0] [1] [2] [3]
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
25%
1. Send program
e.g.
X0
2. Prep
CNOT 0 1
Distribution
CPU QPU
bits: qubits:
qubits:
[0]...[N] 0...M
0...M
3. Sample
The Quil Programming Model
Targets a Quantum Abstract Machine (QAM) with a syntax for representing state transitions
1. Hadamard on
qubit 3
Ψ1, C0, κ1
The Quil Programming Model
Targets a Quantum Abstract Machine (QAM) with a syntax for representing state transitions
1. Hadamard on Outcome 0
qubit 3
Ψ2, C0, κ2
Ψ1, C0, κ1
Outcome 1
Outcome 1
...
...
2. Measure qubit 3 Ψ3, C1, κ2
into bit #4
...
Pennylane
Main tools in this
course. All OSS
Apache v2 Pennylane
Control Pulse
PyQuil Computer program
QPU
0 1 0 1 0 1 1 0 0 0 1...
1
Readout
Qubit
operations
Image: Rigetti
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
0.000,000,000,000,000,000,000,1 %
0.1%
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
1. Send program
e.g.
X0
2. Prep
CNOT 0 1
Distribution
CPU QPU
bits: qubits:
qubits:
[0]...[N] 0...M
0...M
3. Sample
How do I program a quantum computer?
Hybrid Quantum Computers | Quantum Programming | Hybrid Programming | Hybrid Algorithms
1. Send program
e.g.
RX(𝛳) 2
2. Prep
4. Optimize
Distribution
choice of 𝛳
against some
CPU QPU
objective bits: qubits:
qubits:
[0]...[N] 0...M
0...M
3. Sample
Quantum Machine Learning
> Quantum neuron: an elementary building block for machine learning on A generative modeling approach for benchmarking and
quantum computers. (Cao et al. 2017) training shallow quantum circuits. (Benedetti et al. 2018)
e.g. Electronic Structure Hamiltonian e.g. Bravyi-Kitaev or Jordan-Wigner e.g. Unitary Coupled Cluster
Transform Variational Adiabatic Ansatz
e.g. DI-HYDROGEN
MEASURE TERM 1
CLASSICAL
PREPARE
MEASURE TERM 2 SUM OPTIMIZATION OF
QUANTUM
TERMS ANSATZ
STATE (𝞗)
…
PARAMETER:
MEASURE TERM N 𝞗
O'Malley, P. J. J., et al. (2015). Scalable Quantum Simulation of Molecular Energies. arXiv:1512.06860. McClean, J. R. et al. (2015). The theory of variational hybrid quantum-classical algorithms. arXiv:1509.04279.
Wecker, D., et al. (2015). Progress towards practical quantum variational algorithms. Physical Review A, 92(4), 042303. Peruzzo, A., et al. (2014). A variational eigenvalue solver on a photonic quantum processor. Nature communications, 5.
VQE Simulations on Quantum Hardware
Kandala et al.
1704.05018
Quantum Approximate Optimization Algorithm
[QAOA] Hybrid algorithm used for constraint satisfaction problems
Hadfield et al. 2017 [1709.03489] Otterbach et al. 2017 [1712.05771] Verdon et al. 2017 [1712.05304]
QAOA in Forest
In 19 lines of code
def qaoa_cost(params):
half = int(len(params)/2)
betas, gammas = params[:half], params[half:]
program = init_state_prog + qaoa_ansatz(betas, gammas)
return WavefunctionSimulator().expectation(prep_prog=program, pauli_terms=h_cost)
OpenFermion
Q1. Why program a quantum computer?
New power | New opportunity | Fundamental curiosity
Introduction Low Level Noise & Hybrid Hardware & Hybrid Error Correction Other
Linear Algebra Programming Benchmarking Algorithms Compilation Algs & Error Corrected Topics
Quantum Quantum Ops VQE Simulation MBQC
(QML) Algorithms
Mechanics Instruction Sets QAOA Blind QC
Shor’s Factoring Algorithm
Classical Ctrl Optimization Grover’s Search Algorithm
Lecture 1 Lecture 20
Actions for between now and the next
lecture:
1. Read the syllabus.
2. Read Mike & Ike Chapters 1 & 2. Especially review Sections 2.2, 2.3 & 2.6.