Skip to content

Commit 1ab27e0

Browse files
Fix QRL tutorial (#634)
* QRL tutorial * QRL tutorial v2 * QRL tutorial v2.1 * QRL tutorial v2.1 * QRL tutorial v3 * QRL tutorial v3.1 * QRL tutorial v4.0 * QRL tutorial v4.1 * QRL tutorial v4.2 * QRL tutorial v4.3 * QRL tutorial v4.4 * Fix QRL tutorial Co-authored-by: MichaelBroughton <[email protected]>
1 parent 4c2f4ef commit 1ab27e0

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

docs/tutorials/quantum_reinforcement_learning.ipynb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,21 @@
175175
"Now import TensorFlow and the module dependencies:"
176176
]
177177
},
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+
},
193193
{
194194
"cell_type": "code",
195195
"execution_count": 1,
@@ -312,7 +312,7 @@
312312
" params = np.asarray(params).reshape((n_layers + 1, n_qubits, 3))\n",
313313
" \n",
314314
" # 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",
316316
" inputs = np.asarray(inputs).reshape((n_layers, n_qubits))\n",
317317
" \n",
318318
" # Define circuit\n",
@@ -361,7 +361,7 @@
361361
{
362362
"data": {
363363
"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>"
365365
],
366366
"text/plain": [
367367
"<cirq.contrib.svg.svg.SVGCircuit at 0x7f3fbcc9e730>"
@@ -428,7 +428,7 @@
428428
" \n",
429429
" # Define explicit symbol order.\n",
430430
" 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",
432432
" \n",
433433
" self.activation = activation\n",
434434
" self.empty_circuit = tfq.convert_to_tensor([cirq.Circuit()])\n",

0 commit comments

Comments
 (0)