|
175 | 175 | "Now import TensorFlow and the module dependencies:"
|
176 | 176 | ]
|
177 | 177 | },
|
178 |
| - { |
179 |
| - "cell_type": "code", |
180 |
| - "execution_count": 0, |
181 |
| - "metadata": { |
182 |
| - "colab": {}, |
183 |
| - "colab_type": "code", |
184 |
| - "id": "4Ql5PW-ACO0J" |
185 |
| - }, |
186 |
| - "outputs": [], |
187 |
| - "source": [ |
188 |
| - "# Update package resources to account for version changes.\n", |
189 |
| - "import importlib, pkg_resources\n", |
190 |
| - "importlib.reload(pkg_resources)" |
191 |
| - ] |
192 |
| - }, |
| 178 | + { |
| 179 | + "cell_type": "code", |
| 180 | + "execution_count": 0, |
| 181 | + "metadata": { |
| 182 | + "colab": {}, |
| 183 | + "colab_type": "code", |
| 184 | + "id": "4Ql5PW-ACO0J" |
| 185 | + }, |
| 186 | + "outputs": [], |
| 187 | + "source": [ |
| 188 | + "# Update package resources to account for version changes.\n", |
| 189 | + "import importlib, pkg_resources\n", |
| 190 | + "importlib.reload(pkg_resources)" |
| 191 | + ] |
| 192 | + }, |
193 | 193 | {
|
194 | 194 | "cell_type": "code",
|
195 | 195 | "execution_count": 1,
|
|
312 | 312 | " params = np.asarray(params).reshape((n_layers + 1, n_qubits, 3))\n",
|
313 | 313 | " \n",
|
314 | 314 | " # Sympy symbols for encoding angles\n",
|
315 |
| - " inputs = sympy.symbols(f'x(0:{n_qubits})'+f'(0:{n_layers})')\n", |
| 315 | + " inputs = sympy.symbols(f'x(0:{n_layers})'+f'_(0:{n_qubits})')\n", |
316 | 316 | " inputs = np.asarray(inputs).reshape((n_layers, n_qubits))\n",
|
317 | 317 | " \n",
|
318 | 318 | " # Define circuit\n",
|
|
361 | 361 | {
|
362 | 362 | "data": {
|
363 | 363 | "image/svg+xml": [
|
364 |
| - "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1009.1524609375002\" height=\"150.0\"><line x1=\"34.7588671875\" x2=\"979.1524609375002\" y1=\"25.0\" y2=\"25.0\" stroke=\"#1967d2\" stroke-width=\"1\" /><line x1=\"34.7588671875\" x2=\"979.1524609375002\" y1=\"75.0\" y2=\"75.0\" stroke=\"#1967d2\" stroke-width=\"1\" /><line x1=\"34.7588671875\" x2=\"979.1524609375002\" y1=\"125.0\" y2=\"125.0\" stroke=\"#1967d2\" stroke-width=\"1\" /><line x1=\"404.74449218750004\" x2=\"404.74449218750004\" y1=\"25.0\" y2=\"75.0\" stroke=\"black\" stroke-width=\"3\" /><line x1=\"464.74449218750004\" x2=\"464.74449218750004\" y1=\"75.0\" y2=\"125.0\" stroke=\"black\" stroke-width=\"3\" /><line x1=\"524.7444921875001\" x2=\"524.7444921875001\" y1=\"25.0\" y2=\"125.0\" stroke=\"black\" stroke-width=\"3\" /><rect x=\"10.0\" y=\"5.0\" width=\"49.517734375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"0\" /><text x=\"34.7588671875\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">(0, 0): </text><rect x=\"10.0\" y=\"55.0\" width=\"49.517734375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"0\" /><text x=\"34.7588671875\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">(0, 1): </text><rect x=\"10.0\" y=\"105.0\" width=\"49.517734375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"0\" /><text x=\"34.7588671875\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">(0, 2): </text><rect x=\"79.517734375\" y=\"5.0\" width=\"82.31109375000001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"120.67328125\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta0)</text><rect x=\"79.517734375\" y=\"55.0\" width=\"82.31109375000001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"120.67328125\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta3)</text><rect x=\"79.517734375\" y=\"105.0\" width=\"82.31109375000001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"120.67328125\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta6)</text><rect x=\"181.82882812500003\" y=\"5.0\" width=\"81.54109375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"222.59937500000004\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta1)</text><rect x=\"181.82882812500003\" y=\"55.0\" width=\"81.54109375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"222.59937500000004\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta4)</text><rect x=\"181.82882812500003\" y=\"105.0\" width=\"81.54109375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"222.59937500000004\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta7)</text><rect x=\"283.36992187500005\" y=\"5.0\" width=\"81.37457031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"324.0572070312501\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta2)</text><rect x=\"283.36992187500005\" y=\"55.0\" width=\"81.37457031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"324.0572070312501\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta5)</text><rect x=\"283.36992187500005\" y=\"105.0\" width=\"81.37457031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"324.0572070312501\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta8)</text><circle cx=\"404.74449218750004\" cy=\"25.0\" r=\"10.0\" /><circle cx=\"404.74449218750004\" cy=\"75.0\" r=\"10.0\" /><circle cx=\"464.74449218750004\" cy=\"75.0\" r=\"10.0\" /><circle cx=\"464.74449218750004\" cy=\"125.0\" r=\"10.0\" /><circle cx=\"524.7444921875001\" cy=\"25.0\" r=\"10.0\" /><circle cx=\"524.7444921875001\" cy=\"125.0\" r=\"10.0\" /><rect x=\"564.7444921875001\" y=\"5.0\" width=\"62.45953125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"595.9742578125001\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(x00)</text><rect x=\"564.7444921875001\" y=\"55.0\" width=\"62.45953125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"595.9742578125001\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(x10)</text><rect x=\"564.7444921875001\" y=\"105.0\" width=\"62.45953125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"595.9742578125001\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(x20)</text><rect x=\"647.2040234375002\" y=\"5.0\" width=\"91.21832031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"692.8131835937502\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta9)</text><rect x=\"647.2040234375002\" y=\"55.0\" width=\"91.21832031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"692.8131835937502\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta12)</text><rect x=\"647.2040234375002\" y=\"105.0\" width=\"91.21832031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"692.8131835937502\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta15)</text><rect x=\"758.4223437500002\" y=\"5.0\" width=\"90.4483203125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"803.6465039062502\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta10)</text><rect x=\"758.4223437500002\" y=\"55.0\" width=\"90.4483203125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"803.6465039062502\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta13)</text><rect x=\"758.4223437500002\" y=\"105.0\" width=\"90.4483203125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"803.6465039062502\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta16)</text><rect x=\"868.8706640625002\" y=\"5.0\" width=\"90.28179687500001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"914.0115625000002\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta11)</text><rect x=\"868.8706640625002\" y=\"55.0\" width=\"90.28179687500001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"914.0115625000002\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta14)</text><rect x=\"868.8706640625002\" y=\"105.0\" width=\"90.28179687500001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"914.0115625000002\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta17)</text></svg>" |
| 364 | + "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1009.1524609375002\" height=\"150.0\"><line x1=\"34.7588671875\" x2=\"979.1524609375002\" y1=\"25.0\" y2=\"25.0\" stroke=\"#1967d2\" stroke-width=\"1\" /><line x1=\"34.7588671875\" x2=\"979.1524609375002\" y1=\"75.0\" y2=\"75.0\" stroke=\"#1967d2\" stroke-width=\"1\" /><line x1=\"34.7588671875\" x2=\"979.1524609375002\" y1=\"125.0\" y2=\"125.0\" stroke=\"#1967d2\" stroke-width=\"1\" /><line x1=\"404.74449218750004\" x2=\"404.74449218750004\" y1=\"25.0\" y2=\"75.0\" stroke=\"black\" stroke-width=\"3\" /><line x1=\"464.74449218750004\" x2=\"464.74449218750004\" y1=\"75.0\" y2=\"125.0\" stroke=\"black\" stroke-width=\"3\" /><line x1=\"524.7444921875001\" x2=\"524.7444921875001\" y1=\"25.0\" y2=\"125.0\" stroke=\"black\" stroke-width=\"3\" /><rect x=\"10.0\" y=\"5.0\" width=\"49.517734375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"0\" /><text x=\"34.7588671875\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">(0, 0): </text><rect x=\"10.0\" y=\"55.0\" width=\"49.517734375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"0\" /><text x=\"34.7588671875\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">(0, 1): </text><rect x=\"10.0\" y=\"105.0\" width=\"49.517734375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"0\" /><text x=\"34.7588671875\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">(0, 2): </text><rect x=\"79.517734375\" y=\"5.0\" width=\"82.31109375000001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"120.67328125\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta0)</text><rect x=\"79.517734375\" y=\"55.0\" width=\"82.31109375000001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"120.67328125\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta3)</text><rect x=\"79.517734375\" y=\"105.0\" width=\"82.31109375000001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"120.67328125\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta6)</text><rect x=\"181.82882812500003\" y=\"5.0\" width=\"81.54109375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"222.59937500000004\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta1)</text><rect x=\"181.82882812500003\" y=\"55.0\" width=\"81.54109375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"222.59937500000004\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta4)</text><rect x=\"181.82882812500003\" y=\"105.0\" width=\"81.54109375\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"222.59937500000004\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta7)</text><rect x=\"283.36992187500005\" y=\"5.0\" width=\"81.37457031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"324.0572070312501\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta2)</text><rect x=\"283.36992187500005\" y=\"55.0\" width=\"81.37457031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"324.0572070312501\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta5)</text><rect x=\"283.36992187500005\" y=\"105.0\" width=\"81.37457031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"324.0572070312501\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta8)</text><circle cx=\"404.74449218750004\" cy=\"25.0\" r=\"10.0\" /><circle cx=\"404.74449218750004\" cy=\"75.0\" r=\"10.0\" /><circle cx=\"464.74449218750004\" cy=\"75.0\" r=\"10.0\" /><circle cx=\"464.74449218750004\" cy=\"125.0\" r=\"10.0\" /><circle cx=\"524.7444921875001\" cy=\"25.0\" r=\"10.0\" /><circle cx=\"524.7444921875001\" cy=\"125.0\" r=\"10.0\" /><rect x=\"564.7444921875001\" y=\"5.0\" width=\"62.45953125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"595.9742578125001\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(x0_0)</text><rect x=\"564.7444921875001\" y=\"55.0\" width=\"62.45953125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"595.9742578125001\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(x0_1)</text><rect x=\"564.7444921875001\" y=\"105.0\" width=\"62.45953125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"595.9742578125001\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(x0_2)</text><rect x=\"647.2040234375002\" y=\"5.0\" width=\"91.21832031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"692.8131835937502\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta9)</text><rect x=\"647.2040234375002\" y=\"55.0\" width=\"91.21832031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"692.8131835937502\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta12)</text><rect x=\"647.2040234375002\" y=\"105.0\" width=\"91.21832031250001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"692.8131835937502\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rx(theta15)</text><rect x=\"758.4223437500002\" y=\"5.0\" width=\"90.4483203125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"803.6465039062502\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta10)</text><rect x=\"758.4223437500002\" y=\"55.0\" width=\"90.4483203125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"803.6465039062502\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta13)</text><rect x=\"758.4223437500002\" y=\"105.0\" width=\"90.4483203125\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"803.6465039062502\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Ry(theta16)</text><rect x=\"868.8706640625002\" y=\"5.0\" width=\"90.28179687500001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"914.0115625000002\" y=\"25.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta11)</text><rect x=\"868.8706640625002\" y=\"55.0\" width=\"90.28179687500001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"914.0115625000002\" y=\"75.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta14)</text><rect x=\"868.8706640625002\" y=\"105.0\" width=\"90.28179687500001\" height=\"40\" stroke=\"black\" fill=\"white\" stroke-width=\"1\" /><text x=\"914.0115625000002\" y=\"125.0\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14px\" font-family=\"Arial\">Rz(theta17)</text></svg>" |
365 | 365 | ],
|
366 | 366 | "text/plain": [
|
367 | 367 | "<cirq.contrib.svg.svg.SVGCircuit at 0x7f3fbcc9e730>"
|
|
428 | 428 | " \n",
|
429 | 429 | " # Define explicit symbol order.\n",
|
430 | 430 | " symbols = [str(symb) for symb in theta_symbols + input_symbols]\n",
|
431 |
| - " self.indices = tf.constant([sorted(symbols).index(a) for a in symbols])\n", |
| 431 | + " self.indices = tf.constant([symbols.index(a) for a in sorted(symbols)])\n", |
432 | 432 | " \n",
|
433 | 433 | " self.activation = activation\n",
|
434 | 434 | " self.empty_circuit = tfq.convert_to_tensor([cirq.Circuit()])\n",
|
|
0 commit comments