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 Petruccione. Supervised learning with quantum computers . Vol. 17. Springer, 2018.
Quantum open source foundation qosf.org
Agenda An introduction to variational circuits
Agenda An introduction to variational circuits A simple model
Agenda An introduction to variational circuits A simple model Circuit optimisation
Agenda An introduction to variational circuits A simple model Circuit optimisation Build the model with PennyLane
Agenda An introduction to variational circuits A simple model Circuit optimisation Build the model with PennyLane Assume basic knowledge of quantum computing ! Previous mini-school: Daniel Park; Nielsen & Chuang - Quantum computation and quantum information
f ( x ; θ )
f ( x ; θ ) θ
| f ( x ; θ ) ⟩ θ
Quantum models
Quantum models Deterministic quantum models y | ψ ⟩ U Deutsch-Jozsa algorithm
Quantum models Deterministic quantum models y | ψ ⟩ U Deutsch-Jozsa algorithm Variational quantum models Variational quantum eigensolver Variational quantum classifier | ψ ⟩ ⟨ y ⟩ U ( θ ) Quantum support vector machines Quantum neural networks
Quantum machine learning . . .
Quantum machine learning U ( x ; θ ) . . .
Quantum machine learning U ( x ; θ ) . . . | f ( x ; θ ) ⟩
Quantum machine learning M U ( x ; θ ) . . . | f ( x ; θ ) ⟩
̂ M } Quantum machine learning y U ( x ; θ ) . . . | f ( x ; θ ) ⟩
Variational circuits
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
A simple example | 0 ⟩ Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ | 0 ⟩ = [ 0 ] 1 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ | 0 ⟩ = [ 0 ] 1 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ | 0 ⟩ = [ 0 ] 1 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ | 0 ⟩ = [ σ z = [ 0 ] 0 − 1 ] 1 1 0 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ | 0 ⟩ = [ σ z = [ 0 ] 0 − 1 ] 1 1 0 Calculating the expectation value: ⟨ 0 ∣ σ z ∣ 0 ⟩ Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ | 0 ⟩ = [ σ z = [ 0 ] 0 − 1 ] 1 1 0 0] [ − 1 ] [ 0 ] 1 0 1 Calculating the expectation value: ⟨ 0 ∣ σ z ∣ 0 ⟩ = [1 0 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ | 0 ⟩ = [ σ z = [ 0 ] 0 − 1 ] 1 1 0 0] [ − 1 ] [ 0 ] = 1 1 0 1 Calculating the expectation value: ⟨ 0 ∣ σ z ∣ 0 ⟩ = [1 0 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ X ⟨ σ z ⟩ X = [ | 0 ⟩ = [ σ z = [ 0 ] 0 ] 0 − 1 ] 0 1 1 1 0 1 Calculating the expectation value: ⟨ 1 ∣ σ z ∣ 1 ⟩ Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ X ⟨ σ z ⟩ X = [ | 0 ⟩ = [ σ z = [ 0 ] 0 ] 0 − 1 ] 0 1 1 1 0 1 1] [ − 1 ] [ 1 ] = − 1 1 0 0 Calculating the expectation value: ⟨ 1 ∣ σ z ∣ 1 ⟩ = [0 0 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⊗ n U ( θ )
A simple example | 0 ⟩ ⟨ σ z ⟩ R x ( θ 1 ) R y ( θ 2 ) Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ R x ( θ 1 ) R y ( θ 2 ) θ 1 θ 1 θ 2 θ 2 | 0 ⟩ = [ σ z = [ − i sin − sin cos cos 0 ] − 1 ] 1 0 1 2 2 2 2 R x ( θ 1 ) = R y ( θ 2 ) = θ 1 θ 1 θ 2 θ 2 0 − i sin cos sin cos 2 2 2 2 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ R x ( θ 1 ) R y ( θ 2 ) θ 1 θ 1 θ 2 θ 2 | 0 ⟩ = [ σ z = [ − i sin − sin cos cos 0 ] − 1 ] 1 0 1 2 2 2 2 R x ( θ 1 ) = R y ( θ 2 ) = θ 1 θ 1 θ 2 θ 2 0 − i sin cos sin cos 2 2 2 2 State after operations: | ψ ⟩ = R y ( θ 2 ) R x ( θ 1 ) | 0 ⟩ Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ R x ( θ 1 ) R y ( θ 2 ) θ 1 θ 1 θ 2 θ 2 | 0 ⟩ = [ σ z = [ − i sin − sin cos cos 0 ] − 1 ] 1 0 1 2 2 2 2 R x ( θ 1 ) = R y ( θ 2 ) = θ 1 θ 1 θ 2 θ 2 0 − i sin cos sin cos 2 2 2 2 State after operations: | ψ ⟩ = R y ( θ 2 ) R x ( θ 1 ) | 0 ⟩ Calculating the expectation value: ⟨ ψ ∣ σ z ∣ ψ ⟩ Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ R x ( θ 1 ) R y ( θ 2 ) θ 1 θ 1 θ 2 θ 2 | 0 ⟩ = [ σ z = [ − i sin − sin cos cos 0 ] − 1 ] 1 0 1 2 2 2 2 R x ( θ 1 ) = R y ( θ 2 ) = θ 1 θ 1 θ 2 θ 2 0 − i sin cos sin cos 2 2 2 2 State after operations: | ψ ⟩ = R y ( θ 2 ) R x ( θ 1 ) | 0 ⟩ Calculating the expectation value: ⟨ ψ ∣ σ z ∣ ψ ⟩ = ⟨ 0 ∣ R x ( θ 1 ) † Ry ( θ 2 ) † σ z R y ( θ 2 ) R x ( θ 1 ) ∣ 0 ⟩ Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ R x ( θ 1 ) R y ( θ 2 ) θ 1 θ 1 θ 2 θ 2 | 0 ⟩ = [ σ z = [ − i sin − sin cos cos 0 ] − 1 ] 1 0 1 2 2 2 2 R x ( θ 1 ) = R y ( θ 2 ) = θ 1 θ 1 θ 2 θ 2 0 − i sin cos sin cos 2 2 2 2 State after operations: | ψ ⟩ = R y ( θ 2 ) R x ( θ 1 ) | 0 ⟩ Calculating the expectation value: ⟨ ψ ∣ σ z ∣ ψ ⟩ = ⟨ 0 ∣ R x ( θ 1 ) † Ry ( θ 2 ) † σ z R y ( θ 2 ) R x ( θ 1 ) ∣ 0 ⟩ = cos( θ 1 ) cos( θ 2 ) Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⟨ σ z ⟩ R x ( θ 1 ) R y ( θ 2 ) θ 1 θ 1 θ 2 θ 2 | 0 ⟩ = [ σ z = [ − i sin − sin cos cos 0 ] − 1 ] 1 0 1 2 2 2 2 R x ( θ 1 ) = R y ( θ 2 ) = θ 1 θ 1 θ 2 θ 2 0 − i sin cos sin cos 2 2 2 2 State after operations: | ψ ⟩ = R y ( θ 2 ) R x ( θ 1 ) | 0 ⟩ Calculating the expectation value: ⟨ ψ ∣ σ z ∣ ψ ⟩ = ⟨ 0 ∣ R x ( θ 1 ) † Ry ( θ 2 ) † σ z R y ( θ 2 ) R x ( θ 1 ) ∣ 0 ⟩ = cos( θ 1 ) cos( θ 2 ) How do we choose the parameters? Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example | 0 ⟩ ⊗ n U ( θ )
̂ A simple example | 0 ⟩ ⊗ n y U ( θ )
̂ A simple example | 0 ⟩ ⊗ n y U ( θ ) cost
̂ A simple example | 0 ⟩ ⊗ n y U ( θ ) update θ cost
̂ Classical machine learning y σ ( f ( θ )) f ( θ ) data update θ cost
A simple example Define a cost function which we want to minimise: Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example Define a cost function which we want to minimise: ⟨ ψ ∣ σ z ∣ ψ ⟩ = ⟨ 0 ∣ R x ( θ 1 ) † Ry ( θ 2 ) † σ z R y ( θ 2 ) R x ( θ 1 ) ∣ 0 ⟩ = cos( θ 1 ) cos( θ 2 ) Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example Define a cost function which we want to minimise: ⟨ ψ ∣ σ z ∣ ψ ⟩ = ⟨ 0 ∣ R x ( θ 1 ) † Ry ( θ 2 ) † σ z R y ( θ 2 ) R x ( θ 1 ) ∣ 0 ⟩ = cos( θ 1 ) cos( θ 2 ) [ 0 − 1 ] [ 0 ] = 1 [1 0] 1 0 1 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example Define a cost function which we want to minimise: ⟨ ψ ∣ σ z ∣ ψ ⟩ = ⟨ 0 ∣ R x ( θ 1 ) † Ry ( θ 2 ) † σ z R y ( θ 2 ) R x ( θ 1 ) ∣ 0 ⟩ = cos( θ 1 ) cos( θ 2 ) [ 0 − 1 ] [ 0 ] = 1 [1 0] 1 0 1 [ 0 − 1 ] [ 1 ] = − 1 [0 1] 1 0 0 Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
A simple example Define a cost function which we want to minimise: ⟨ ψ ∣ σ z ∣ ψ ⟩ = ⟨ 0 ∣ R x ( θ 1 ) † Ry ( θ 2 ) † σ z R y ( θ 2 ) R x ( θ 1 ) ∣ 0 ⟩ = cos( θ 1 ) cos( θ 2 ) Source:https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html
Circuit optimisation
Circuit optimisation Define a cost function: ⟨ ψ ∣ σ z ∣ ψ ⟩ = ⟨ 0 ∣ R x ( θ 1 ) † Ry ( θ 2 ) † σ z R y ( θ 2 ) R x ( θ 1 ) ∣ 0 ⟩ = cos( θ 1 ) cos( θ 2 )
Gradient-based methods
Gradient descent
⃗ Gradient descent cost θ
⃗ Gradient descent cost θ 1 θ
⃗ Gradient descent cost θ 1 θ
⃗ Gradient descent cost θ 1 θ
⃗ Gradient descent cost θ * θ 1 θ 2 θ
̂ Gradient-based methods | 0 ⟩ ⊗ n y θ U ( θ ) Source:Schuld, Maria, et al. "Circuit-centric quantum classifiers." Physical Review A 101.3 (2020): 032308.
Recommend
More recommend