MATLAB_Braket_QC_Workshop_Slides
MATLAB_Braket_QC_Workshop_Slides
Hands-on
Quantum Machine Learning
Workshop
Exercise 1
Set up the environment: Simulate in MATLAB and Execute on a QPU via Amazon Braket
Exercise 2
Introduction to Quantum Computing: (a practical guide to) Superposition and Entanglement
Exercise 3
Load Data on qubits
Exercise 4
Quantum Neural Network
2
Exercise 1
Set up the environment
3
Set up MATLAB
Get MATLAB
4
Set up AWS Braket Run Quantum Circuit on Hardware Using AWS
• The account credentials (AWS Access Key and AWS Secret Access Key) are only available to download just
after they are created.
• If your AWS account is managed through your organization, then you might need to contact your administrator
for the recommended way to retrieve credentials.
2. Set environment variables.
• Create a file named awsConfig.env that contains all necessary environment variables. At a minimum, you
must specify values for
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
4. Device Availability
• To see a list of available quantum devices:
Select Devices from the navigation menu in Braket after you log in to your AWS account.
5
AWS Promotional Credit Mechanisms
• AWS Partner Innovation Sandbox Credit, 3x monthly est. usage for new product building
• For small scale Braket trial plays, reach out to Xiaofan Yang ([email protected]) to claim
$25 credit codes, and redeem Your credit at AWS Credits
6
Simulate in MATLAB and Execute on a QPU via AWS
7
Try it:
Ex1_MATLAB_Braket_Setup
8
Exercise 2
Introduction to Quantum Computing
9
(a practical guide to) Superposition and Entanglement
We don't fully understand gravity, but we create simple models to represent it.
Superposition
[ [] ]
1
0
0
1 Entanglement NOBODY
REALLY
Knows!
[]
1
[ 10 ] ⨂ [ ]
[ ] [ ]
1 0
= 0
0 0 0
0 0 0
[]
1 0
0
0 1
[ 10 ] ⨂ [ ]
0
1
=
1
0
0 o Linear algebra is the mathematical framework for QC.
[ ]⨂ [ ]
0
1
1
0
=
0
1 o You don’t need to understand QC to use it!
0
[] [ ] [ ]
0 0 0
[ ]⨂ [ ]
0
1
0
1
=
0
0
0
0
0
1
1 0
1
10
Superposition
Types of Quantum Gates
11
Entanglement
Types of Quantum Gates
12
Entanglement
Types of Quantum Gates
13
Entanglement
Types of Quantum Gates
14
Entanglement
Types of Quantum Gates
15
Try it:
Ex2_Introduction_to_Quantum_Computing
16
Exercise 2
Load Data on Qubits
17
How to encode [x,y] data onto qubits?
¿ 0⟩
projection of onto the z-axis.
¿ 1⟩
is the parameter that determines the amplitudes of the basis states and
, and therefore can be used to encode [x,y] data.
18
How to encode [x,y] data onto qubits?
𝜃
Learn more:
Types of Quantum Gates
19
How to encode [x,y] data onto qubits?
𝜃𝑥 𝜃𝑦
20
How to encode an image onto qubits?
n = log2(256) = 8
Total number of qubits (for 2D
image)
= 2 * n = 16
[256,
256]
Learn more:
initGate:
returns a quantum.gate.CompositeGate object that initializes the target qubits to the specified state
qftGate:
applies the quantum Fourier transform (QFT) to the target
qubits
21
Try it:
Ex3_Load_2D_Data_on_Qubits
22
Exercise 4
Quantum Neural Networks
23
Data and task
Data: Set of randomly generated [x,y] pairs in (0,1)
x y Label
0.377414 0.99035 Yellow Task: Label the [x,y] pairs as Yellow or Blue based on their
0.221571 0.778238 Yellow coordinates, based on this logical condition:
0.704114 0.448232 Yellow
0.376998 0.057799 Blue
0.558292 0.783025 Blue
0.766507 0.902925 Blue
0.901688 0.78743 Blue
0.399439 0.57052 Yellow
0.812268 0.563872 Blue
0.089578 0.697184 Yellow
0.366913 0.741243 Yellow
0.20732 0.340848 Blue
0.35204 0.924936 Yellow
0.960943 0.763501 Blue
24
Network Architecture: Where does QC plug-in?
25
Try the NN without QC
Pr
Change only one line (#22) in the example to run a simple NN ac
tic
Original QNN e
Simple NN
Learn
more:
List of Deep Learning Layers
o The XOR problem is a non-linearly separable problem, but it is not ‘very’ hard at 2D.
o This 2D problem can be effectively solved using a NN with at least one hidden layer.
26
Complexity and high dimensional data
This mapping function resembles the “exclusive or ” XOR function.
a b XOR(a,b)
0 0 0
1 1 0
0 1 1
1 0 1
o Such simple logical operation can be executed quickly without any NN, let alone QC.
o AI is beneficial for problems with many features and complex relationship between
features and labels which are not easily captured by simple rules.
The purpose of this simple QNN example is to practice how to encode classical data onto
qubits and how to add a quantum computing layer to a classical neural network.
27
Advantages of Quantum NN to Classical NN
28
Input data into the network
30
Parameterized Quantum Circuit (PQC) layer
31
Fully connected layer
32
Softmax layer
33
Classification layer
34
Parameterized Quantum Circuit (PQC) Layer
35
Encode [x,y] data onto qubits
𝜃𝑥 𝜃𝑦
36
Building the quantum circuit: How does learning happen?
37
Building the quantum circuit: Single qubit operations
38
Next step in building the quantum circuit
⟨ 𝑍 1 ⟩ =𝑐𝑜𝑠 𝜃 1
Analogous to linear transformation
in classical network and does not
gain any quantum advantage.
⟨ 𝑍 2 ⟩ =𝑐𝑜𝑠 𝜃 2
39
Building the quantum circuit: Two qubit operation
40
Building the quantum circuit: Measurement
Z = - 0.1441
x=1.8073;
y=0.9085;
gates = [rxGate(1,x); rxGate(2,y);cxGate(1,2)];
c = quantumCircuit(gates);
plot(c);
S = simulate(c,"00")
S.Amplitudes
histogram(S)
Z = probability(S,2,"0") - probability(S,2,"1")
41
Train Network
42
Results
43
Try it:
Ex4_Quantum_Neural_Networks
44
Please Let Us Know How We Can Help You
45
Guided Evaluations & Technical Engagements
46
Thank You
Contact
Xiaofan Yang
[email protected]