Skip to content

Commit fc1be70

Browse files
committed
Add boilerplate code to exercises
1 parent af63dae commit fc1be70

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

tutorials/workshops/algo_design_QCE_tutorial/algo_design_QCE_tutorial_part_I.ipynb

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"\n",
8484
"show(qprog) # Visualize the quantum program for analysis\n",
8585
"\n",
86-
"# Execute and print the results:\n",
86+
"# Execute and print the results\n",
8787
"with ExecutionSession(qprog) as es:\n",
8888
" res = es.sample()\n",
8989
" display(res.dataframe)"
@@ -168,12 +168,19 @@
168168
"\n",
169169
"@qfunc\n",
170170
"def main(x: Output[QNum[3, SIGNED, 0]]):\n",
171+
" allocate(x)\n",
171172
" # TODO: Create GHZ state with QNum (gives 0 and -1)\n",
172173
" # Hint: Is it any different from the previous main implementation?\n",
173174
" pass\n",
174175
"\n",
175176
"\n",
176-
"# TODO: Synthesize the model, show, execute and print results"
177+
"qprog = synthesize(main)\n",
178+
"show(qprog) # Visualize the quantum program for analysis\n",
179+
"\n",
180+
"# Execute and print the results\n",
181+
"with ExecutionSession(qprog) as es:\n",
182+
" res = es.sample()\n",
183+
" display(res.dataframe)"
177184
],
178185
"outputs": [],
179186
"execution_count": null
@@ -236,13 +243,20 @@
236243
" allocate(b)\n",
237244
" # TODO: Put a and b in equal superposition\n",
238245
"\n",
239-
" # TODO:Assign the value of 3*a + b to c\n",
246+
" # TODO: Assign the value of 3*a + b to c\n",
247+
" allocate(1, c) # Placeholder - replace with actual assignment\n",
240248
"\n",
241249
" # Print out c's inferred size in qubits\n",
242250
" print(f\"The size of c is {c.size}\")\n",
243251
"\n",
244252
"\n",
245-
"# TODO: Synthesize the model, show, execute and print results"
253+
"qprog = synthesize(main)\n",
254+
"show(qprog) # Visualize the quantum program for analysis\n",
255+
"\n",
256+
"# Execute and print the results\n",
257+
"with ExecutionSession(qprog) as es:\n",
258+
" res = es.sample()\n",
259+
" display(res.dataframe)"
246260
],
247261
"outputs": [],
248262
"execution_count": null
@@ -288,7 +302,7 @@
288302
" # TODO: Put a and b in equal superposition\n",
289303
"\n",
290304
" # TODO: Assign the value of 3*a + b to c\n",
291-
" # Hint: Is it any different from the previous main implementation?\n",
305+
" allocate(1, c) # Placeholder - replace with actual assignment\n",
292306
"\n",
293307
" # Print out the numeric attributes of the inferred type\n",
294308
" print(\"Numeric attributes of c:\")\n",
@@ -297,7 +311,13 @@
297311
" )\n",
298312
"\n",
299313
"\n",
300-
"# TODO: Synthesize the model, show, execute and print results"
314+
"qprog = synthesize(main)\n",
315+
"show(qprog) # Visualize the quantum program for analysis\n",
316+
"\n",
317+
"# Execute and print the results\n",
318+
"with ExecutionSession(qprog) as es:\n",
319+
" res = es.sample()\n",
320+
" display(res.dataframe)"
301321
],
302322
"outputs": [],
303323
"execution_count": null
@@ -345,7 +365,13 @@
345365
" # TODO : Flip the state of flag if x < 0.5\n",
346366
"\n",
347367
"\n",
348-
"# TODO: Synthesize the model, show, execute and print results"
368+
"qprog = synthesize(main)\n",
369+
"show(qprog) # Visualize the quantum program for analysis\n",
370+
"\n",
371+
"# Execute and print the results\n",
372+
"with ExecutionSession(qprog) as es:\n",
373+
" res = es.sample()\n",
374+
" display(res.dataframe)"
349375
],
350376
"outputs": [],
351377
"execution_count": null
@@ -419,10 +445,10 @@
419445
" grover_operator(v)\n",
420446
"\n",
421447
"\n",
422-
"# Synthesize the model, show, execute and print results\n",
423448
"qprog = synthesize(main)\n",
424-
"show(qprog)\n",
449+
"show(qprog) # Visualize the quantum program for analysis\n",
425450
"\n",
451+
"# Execute and print the results\n",
426452
"with ExecutionSession(qprog) as es:\n",
427453
" res = es.sample()\n",
428454
" display(res.dataframe)"
@@ -863,7 +889,7 @@
863889
" backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator_statevector\"),\n",
864890
")\n",
865891
"\n",
866-
"# Execute and print results:\n",
892+
"# Execute and print results\n",
867893
"with ExecutionSession(qprog, preferences) as es:\n",
868894
" res = es.sample()\n",
869895
" print(\"Ex.6A Results:\")\n",

0 commit comments

Comments
 (0)