Basic programming for quantum machine learning with Qiskit and - - PowerPoint PPT Presentation

basic programming for quantum machine learning with
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Basic programming for quantum machine learning with Qiskit and PennyLane

NITheP Mini-school

Amira Abbas 08/09/2020

slide-2
SLIDE 2

Applications

Logistics Finance Material science The universe

slide-3
SLIDE 3

Quantum machine learning

Source: Maria Schuld and Francesco Petruccione. Supervised learning with quantum computers. Vol. 17. Springer, 2018.
slide-4
SLIDE 4

Quantum open source foundation

qosf.org

slide-5
SLIDE 5

Agenda

An introduction to variational circuits

slide-6
SLIDE 6

Agenda

A simple model An introduction to variational circuits

slide-7
SLIDE 7

Agenda

Circuit optimisation A simple model An introduction to variational circuits

slide-8
SLIDE 8

Agenda

Circuit optimisation Build the model with PennyLane A simple model An introduction to variational circuits

slide-9
SLIDE 9

Agenda

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

slide-10
SLIDE 10

f(x; θ)

slide-11
SLIDE 11

f(x; θ) θ

slide-12
SLIDE 12

|f(x; θ)⟩ θ

slide-13
SLIDE 13

Quantum models

slide-14
SLIDE 14

Quantum models

Deterministic quantum models Deutsch-Jozsa algorithm

y U |ψ⟩

slide-15
SLIDE 15

Quantum models

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(θ)

|ψ⟩ |ψ⟩

slide-16
SLIDE 16

Quantum machine learning

. . .

slide-17
SLIDE 17

Quantum machine learning

. . .

U(x; θ)

slide-18
SLIDE 18

Quantum machine learning

. . .

U(x; θ) |f(x; θ)⟩

slide-19
SLIDE 19

Quantum machine learning

. . .

U(x; θ) M |f(x; θ)⟩

slide-20
SLIDE 20

Quantum machine learning

̂ y

. . .

U(x; θ) M } |f(x; θ)⟩

slide-21
SLIDE 21

Variational circuits

slide-22
SLIDE 22

Success of variational models

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

slide-23
SLIDE 23

A simple example

|0⟩

Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html

slide-24
SLIDE 24

A simple example

|0⟩

Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html

|0⟩ = [ 1 0]

slide-25
SLIDE 25

A simple example

|0⟩

Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html

|0⟩ = [ 1 0]

slide-26
SLIDE 26

A simple example

|0⟩

Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html

|0⟩ = [ 1 0]

⟨σz⟩

slide-27
SLIDE 27

A simple example

|0⟩

Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html

|0⟩ = [ 1 0]

⟨σz⟩

σz = [ 1 0 −1]

slide-28
SLIDE 28

A simple example

|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:

slide-29
SLIDE 29

A simple example

|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:

slide-30
SLIDE 30

A simple example

|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:

slide-31
SLIDE 31

A simple example

|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]

slide-32
SLIDE 32

A simple example

|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]

slide-33
SLIDE 33

U(θ)

|0⟩⊗n

A simple example

slide-34
SLIDE 34

A simple example

|0⟩

Ry(θ2) Rx(θ1)

Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html

⟨σz⟩

slide-35
SLIDE 35

|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]

A simple example

Rx(θ1)

slide-36
SLIDE 36

|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:

A simple example

slide-37
SLIDE 37

|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 ∣ ψ⟩

A simple example

slide-38
SLIDE 38

|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:

A simple example

slide-39
SLIDE 39

|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:

A simple example

slide-40
SLIDE 40

|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?

A simple example

slide-41
SLIDE 41

U(θ)

|0⟩⊗n

A simple example

slide-42
SLIDE 42

U(θ)

̂ y

|0⟩⊗n

A simple example

slide-43
SLIDE 43

U(θ)

̂ y

cost

|0⟩⊗n

A simple example

slide-44
SLIDE 44

U(θ)

̂ y

cost update θ

|0⟩⊗n

A simple example

slide-45
SLIDE 45

Classical machine learning

f(θ)

̂ y

cost update θ

data

σ(f(θ))

slide-46
SLIDE 46

Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html

Define a cost function which we want to minimise:

A simple example

slide-47
SLIDE 47

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:

A simple example

slide-48
SLIDE 48

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)

A simple example

[ 1 0 −1] [ 1 0] = 1 [1 0]

Define a cost function which we want to minimise:

slide-49
SLIDE 49

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)

A simple example

[ 1 0 −1] [ 1 0] = 1 [1 0] [ 1 0 −1] [ 1] = − 1 [0 1]

Define a cost function which we want to minimise:

slide-50
SLIDE 50

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)

A simple example

Define a cost function which we want to minimise:

slide-51
SLIDE 51

Circuit optimisation

slide-52
SLIDE 52

Circuit optimisation

⟨ψ ∣ σz ∣ ψ⟩ = ⟨0 ∣ Rx(θ1)†Ry(θ2)†σz Ry(θ2)Rx(θ1) ∣ 0⟩ = cos(θ1) cos(θ2)

Define a cost function:

slide-53
SLIDE 53

Gradient-based methods

slide-54
SLIDE 54

Gradient descent

slide-55
SLIDE 55

Gradient descent

⃗ θ cost

slide-56
SLIDE 56

Gradient descent

⃗ θ cost θ1

slide-57
SLIDE 57

Gradient descent

⃗ θ cost θ1

slide-58
SLIDE 58

Gradient descent

⃗ θ cost θ1

slide-59
SLIDE 59

Gradient descent

⃗ θ cost θ1 θ* θ2

slide-60
SLIDE 60

Gradient-based methods

Source:Schuld, Maria, et al. "Circuit-centric quantum classifiers." Physical Review A 101.3 (2020): 032308.

U(θ)

̂ yθ

|0⟩⊗n

slide-61
SLIDE 61

Gradient-based methods

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(θ)

̂ yθ

|0⟩⊗n

slide-62
SLIDE 62

Software frameworks

https://qosf.org/learn_quantum/

slide-63
SLIDE 63

Jump to the code

slide-64
SLIDE 64

Next up

Encoding data into quantum states More sophisticated models Barren plateaus

slide-65
SLIDE 65

Thank you!

NITheP Mini-school

Amira Abbas @AmiraMorphism amyami187@gmail.com