Basic programming for quantum machine learning with Qiskit and PennyLane
NITheP Mini-school
Amira Abbas 08/09/2020
Basic programming for quantum machine learning with Qiskit and - - PowerPoint PPT Presentation
Basic programming for quantum machine learning with Qiskit and PennyLane NITheP Mini-school Amira Abbas 08/09/2020 Applications The universe Material science Finance Logistics Quantum machine learning Source: Maria Schuld and Francesco
NITheP Mini-school
Amira Abbas 08/09/2020
Logistics Finance Material science The universe
qosf.org
An introduction to variational circuits
A simple model An introduction to variational circuits
Circuit optimisation A simple model An introduction to variational circuits
Circuit optimisation Build the model with PennyLane A simple model An introduction to variational circuits
Circuit optimisation Build the model with PennyLane A simple model An introduction to variational circuits Assume basic knowledge of quantum computing ! Previous mini-school: Daniel Park; Nielsen & Chuang - Quantum computation and quantum information
Deterministic quantum models Deutsch-Jozsa algorithm
y U |ψ⟩
Deterministic quantum models Deutsch-Jozsa algorithm Variational quantum models Variational quantum eigensolver Variational quantum classifier Quantum support vector machines Quantum neural networks
y U
⟨y⟩
U(θ)
|ψ⟩ |ψ⟩
. . .
. . .
U(x; θ)
. . .
U(x; θ) |f(x; θ)⟩
. . .
U(x; θ) M |f(x; θ)⟩
̂ y
. . .
U(x; θ) M } |f(x; θ)⟩
Can run on near term quantum hardware Robust to noise Shows most promise in chemistry applications Can be used in many quantum machine learning models
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩ = [ 1 0]
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩ = [ 1 0]
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩ = [ 1 0]
⟨σz⟩
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩ = [ 1 0]
⟨σz⟩
σz = [ 1 0 −1]
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩ = [ 1 0]
⟨σz⟩
⟨0 ∣ σz ∣ 0⟩
σz = [ 1 0 −1]
Calculating the expectation value:
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩ = [ 1 0]
⟨σz⟩
⟨0 ∣ σz ∣ 0⟩ = [1 0] [ 1 −1] [ 1 0]
σz = [ 1 0 −1]
Calculating the expectation value:
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩ = [ 1 0]
⟨σz⟩
⟨0 ∣ σz ∣ 0⟩ = [1 0] [ 1 −1] [ 1 0] = 1
σz = [ 1 0 −1]
Calculating the expectation value:
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩ = [ 1 0]
⟨σz⟩
⟨1 ∣ σz ∣ 1⟩
σz = [ 1 0 −1]
Calculating the expectation value:
X
X = [ 1 1 0]
|0⟩
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
|0⟩ = [ 1 0]
⟨σz⟩
⟨1 ∣ σz ∣ 1⟩ = [0 1] [ 1 −1] [ 1] = − 1
σz = [ 1 0 −1]
Calculating the expectation value:
X
X = [ 1 1 0]
U(θ)
|0⟩⊗n
|0⟩
Ry(θ2) Rx(θ1)
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨σz⟩
|0⟩
Ry(θ2)
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨σz⟩
Rx(θ1) = cos
θ1 2
−i sin
θ1 2
−i sin
θ1 2
cos
θ1 2
Ry(θ2) = cos
θ2 2
−sin
θ2 2
sin
θ2 2
cos
θ2 2
|0⟩ = [ 1 0] σz = [ 1 −1]
Rx(θ1)
|0⟩
Ry(θ2) Rx(θ1)
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨σz⟩
Rx(θ1) = cos
θ1 2
−i sin
θ1 2
−i sin
θ1 2
cos
θ1 2
Ry(θ2) = cos
θ2 2
−sin
θ2 2
sin
θ2 2
cos
θ2 2
|0⟩ = [ 1 0] σz = [ 1 −1]
|ψ⟩ = Ry(θ2) Rx(θ1) |0⟩
State after operations:
|0⟩
Ry(θ2) Rx(θ1)
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨σz⟩
Rx(θ1) = cos
θ1 2
−i sin
θ1 2
−i sin
θ1 2
cos
θ1 2
Ry(θ2) = cos
θ2 2
−sin
θ2 2
sin
θ2 2
cos
θ2 2
|0⟩ = [ 1 0] σz = [ 1 −1]
|ψ⟩ = Ry(θ2) Rx(θ1) |0⟩
State after operations: Calculating the expectation value: ⟨ψ ∣ σz ∣ ψ⟩
|0⟩
Ry(θ2) Rx(θ1)
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨σz⟩
Rx(θ1) = cos
θ1 2
−i sin
θ1 2
−i sin
θ1 2
cos
θ1 2
Ry(θ2) = cos
θ2 2
−sin
θ2 2
sin
θ2 2
cos
θ2 2
|0⟩ = [ 1 0] σz = [ 1 −1]
Calculating the expectation value: ⟨ψ ∣ σz ∣ ψ⟩ = ⟨0 ∣ Rx(θ1)†Ry(θ2)†σz Ry(θ2)Rx(θ1) ∣ 0⟩
|ψ⟩ = Ry(θ2) Rx(θ1) |0⟩
State after operations:
|0⟩
Ry(θ2) Rx(θ1)
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨σz⟩
Rx(θ1) = cos
θ1 2
−i sin
θ1 2
−i sin
θ1 2
cos
θ1 2
Ry(θ2) = cos
θ2 2
−sin
θ2 2
sin
θ2 2
cos
θ2 2
|0⟩ = [ 1 0] σz = [ 1 −1]
Calculating the expectation value: ⟨ψ ∣ σz ∣ ψ⟩ = ⟨0 ∣ Rx(θ1)†Ry(θ2)†σz Ry(θ2)Rx(θ1) ∣ 0⟩ = cos(θ1) cos(θ2)
|ψ⟩ = Ry(θ2) Rx(θ1) |0⟩
State after operations:
|0⟩
Ry(θ2) Rx(θ1)
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨σz⟩
Rx(θ1) = cos
θ1 2
−i sin
θ1 2
−i sin
θ1 2
cos
θ1 2
Ry(θ2) = cos
θ2 2
−sin
θ2 2
sin
θ2 2
cos
θ2 2
|0⟩ = [ 1 0] σz = [ 1 −1]
Calculating the expectation value: ⟨ψ ∣ σz ∣ ψ⟩ = ⟨0 ∣ Rx(θ1)†Ry(θ2)†σz Ry(θ2)Rx(θ1) ∣ 0⟩ = cos(θ1) cos(θ2)
|ψ⟩ = Ry(θ2) Rx(θ1) |0⟩
State after operations: How do we choose the parameters?
U(θ)
|0⟩⊗n
U(θ)
|0⟩⊗n
U(θ)
cost
|0⟩⊗n
U(θ)
cost update θ
|0⟩⊗n
f(θ)
cost update θ
data
σ(f(θ))
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
Define a cost function which we want to minimise:
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨ψ ∣ σz ∣ ψ⟩ = ⟨0 ∣ Rx(θ1)†Ry(θ2)†σz Ry(θ2)Rx(θ1) ∣ 0⟩ = cos(θ1) cos(θ2)
Define a cost function which we want to minimise:
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨ψ ∣ σz ∣ ψ⟩ = ⟨0 ∣ Rx(θ1)†Ry(θ2)†σz Ry(θ2)Rx(θ1) ∣ 0⟩ = cos(θ1) cos(θ2)
[ 1 0 −1] [ 1 0] = 1 [1 0]
Define a cost function which we want to minimise:
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨ψ ∣ σz ∣ ψ⟩ = ⟨0 ∣ Rx(θ1)†Ry(θ2)†σz Ry(θ2)Rx(θ1) ∣ 0⟩ = cos(θ1) cos(θ2)
[ 1 0 −1] [ 1 0] = 1 [1 0] [ 1 0 −1] [ 1] = − 1 [0 1]
Define a cost function which we want to minimise:
Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
⟨ψ ∣ σz ∣ ψ⟩ = ⟨0 ∣ Rx(θ1)†Ry(θ2)†σz Ry(θ2)Rx(θ1) ∣ 0⟩ = cos(θ1) cos(θ2)
Define a cost function which we want to minimise:
⟨ψ ∣ σz ∣ ψ⟩ = ⟨0 ∣ Rx(θ1)†Ry(θ2)†σz Ry(θ2)Rx(θ1) ∣ 0⟩ = cos(θ1) cos(θ2)
Define a cost function:
⃗ θ cost
⃗ θ cost θ1
⃗ θ cost θ1
⃗ θ cost θ1
⃗ θ cost θ1 θ* θ2
Source:Schuld, Maria, et al. "Circuit-centric quantum classifiers." Physical Review A 101.3 (2020): 032308.
U(θ)
|0⟩⊗n
Source:Schuld, Maria, et al. "Circuit-centric quantum classifiers." Physical Review A 101.3 (2020): 032308.
U(θ + s) ̂ yθ+s |0⟩⊗n U(θ − s) ̂ yθ−s |0⟩⊗n
−
Gradient =
U(θ)
|0⟩⊗n
https://qosf.org/learn_quantum/
Encoding data into quantum states More sophisticated models Barren plateaus
NITheP Mini-school
Amira Abbas @AmiraMorphism amyami187@gmail.com