You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"<a href=\"https://colab.research.google.com/github/MonitSharma/Learn-Quantum-Machine-Learning/blob/main/Gaussian_Transformation.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
27
11
]
28
12
},
29
13
{
30
14
"cell_type": "markdown",
15
+
"metadata": {
16
+
"id": "Wo8gh7fA0CM9"
17
+
},
31
18
"source": [
32
19
"# Gaussian Transformation\n",
33
20
"\n",
34
21
"Here we'll learn about the basic principles of continuous variable (CV) photonic devices.\n",
35
22
"\n",
36
23
"\n",
37
24
"Read [this](https://strawberryfields.readthedocs.io/en/latest/) documentation to learn more on it."
38
-
],
39
-
"metadata": {
40
-
"id": "Wo8gh7fA0CM9"
41
-
}
25
+
]
42
26
},
43
27
{
44
28
"cell_type": "markdown",
29
+
"metadata": {
30
+
"id": "b2cDyZU00Uzh"
31
+
},
45
32
"source": [
46
33
"## The quantum circuit\n",
47
34
"----\n",
@@ -72,147 +59,147 @@
72
59
"\n",
73
60
"----\n",
74
61
"Our aim here is to optimize the circuit parameters $(\\alpha, \\phi)$ such that the mean photon number is equal to one. The rotating gate is actually a *passive transformation*, meaning that it does not change the energy of the system. The displacement gate is an *active transformation*, which modifies the energy of the photonic system."
75
-
],
76
-
"metadata": {
77
-
"id": "b2cDyZU00Uzh"
78
-
}
62
+
]
79
63
},
80
64
{
81
65
"cell_type": "markdown",
66
+
"metadata": {
67
+
"id": "v1rphGsv17TA"
68
+
},
82
69
"source": [
83
70
"## Constructing the QNode\n",
84
71
"\n",
85
72
"Import Pennylane and NumPy"
86
-
],
87
-
"metadata": {
88
-
"id": "v1rphGsv17TA"
89
-
}
73
+
]
90
74
},
91
75
{
92
76
"cell_type": "code",
93
-
"source": [
94
-
"import pennylane as qml\n",
95
-
"from pennylane import numpy as np"
96
-
],
77
+
"execution_count": 1,
97
78
"metadata": {
98
79
"id": "X5PQCKxW0fv1"
99
80
},
100
-
"execution_count": 2,
101
-
"outputs": []
81
+
"outputs": [],
82
+
"source": [
83
+
"import pennylane as qml\n",
84
+
"from pennylane import numpy as np"
85
+
]
102
86
},
103
87
{
104
88
"cell_type": "markdown",
105
-
"source": [
106
-
"Next, we instantiate a device which will be used to evaluate the circuit. Because our circuit contains only Gaussian operations, we can make use of the built-in `default.gaussian` device."
107
-
],
108
89
"metadata": {
109
90
"id": "fIqx_6Ve2D1Y"
110
-
}
91
+
},
92
+
"source": [
93
+
"Next, we instantiate a device which will be used to evaluate the circuit. Because our circuit contains only Gaussian operations, we can make use of the built-in `default.gaussian` device."
"After initializing the device, we can construct our quantum node. As before, we use the `qnode()` to convert our quantum function (encoded by the circuit above) into a quantum node running on the `default.gaussian` device."
127
-
],
128
109
"metadata": {
129
110
"id": "aRy5muAV2LHr"
130
-
}
111
+
},
112
+
"source": [
113
+
"After initializing the device, we can construct our quantum node. As before, we use the `qnode()` to convert our quantum function (encoded by the circuit above) into a quantum node running on the `default.gaussian` device."
"Notice that we have broken up the complex number $α$\n",
151
138
" into two real numbers `mag_alpha` and `phase_alpha`, which form a polar representation of $α$\n",
152
139
". This is so that the notion of a gradient is clear and well-defined."
153
-
],
154
-
"metadata": {
155
-
"id": "W2H_pYWr2TC5"
156
-
}
140
+
]
157
141
},
158
142
{
159
143
"cell_type": "markdown",
144
+
"metadata": {
145
+
"id": "G2SWZbav2ZcG"
146
+
},
160
147
"source": [
161
148
"## Optimization\n",
162
149
"\n",
163
150
"As in the [qubit rotation](https://colab.research.google.com/github/MonitSharma/Learn-Quantum-Machine-Learning/blob/main/Qubit_Rotation.ipynb) tutorial, let’s now use one of the built-in PennyLane optimizers in order to optimize the quantum circuit towards the desired output. We want the mean photon number to be exactly one, so we will use a squared-difference cost function:"
"When the gate parameters are near to zero, the gates are close to the identity transformation, which leaves the initial state largely unchanged. Since the initial state contains no photons, the mean photon number of the circuit output is approximately zero, and the cost is close to one.\n",
218
205
"\n",
@@ -224,44 +211,22 @@
224
211
"Now, let’s use the `GradientDescentOptimizer`, and update the circuit parameters over 100 optimization steps.\n",
"The optimization converges after about 20 steps to a cost function value of zero.\n",
297
284
"\n",
298
285
"We observe that the two angular parameters phase_alpha and phi do not change during the optimization. Only the magnitude of the complex displacement $|α|$ affects the mean photon number of the circuit.\n",
299
286
"\n",
300
287
"\n",
301
288
"Next we will learn how to utilize the extensive plugin ecosystem of Pennylane, build continuous variable quantum nodes."
0 commit comments