|
83 | 83 | "\n", |
84 | 84 | "show(qprog) # Visualize the quantum program for analysis\n", |
85 | 85 | "\n", |
86 | | - "# Execute and print the results:\n", |
| 86 | + "# Execute and print the results\n", |
87 | 87 | "with ExecutionSession(qprog) as es:\n", |
88 | 88 | " res = es.sample()\n", |
89 | 89 | " display(res.dataframe)" |
|
168 | 168 | "\n", |
169 | 169 | "@qfunc\n", |
170 | 170 | "def main(x: Output[QNum[3, SIGNED, 0]]):\n", |
| 171 | + " allocate(x)\n", |
171 | 172 | " # TODO: Create GHZ state with QNum (gives 0 and -1)\n", |
172 | 173 | " # Hint: Is it any different from the previous main implementation?\n", |
173 | 174 | " pass\n", |
174 | 175 | "\n", |
175 | 176 | "\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)" |
177 | 184 | ], |
178 | 185 | "outputs": [], |
179 | 186 | "execution_count": null |
|
236 | 243 | " allocate(b)\n", |
237 | 244 | " # TODO: Put a and b in equal superposition\n", |
238 | 245 | "\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", |
240 | 248 | "\n", |
241 | 249 | " # Print out c's inferred size in qubits\n", |
242 | 250 | " print(f\"The size of c is {c.size}\")\n", |
243 | 251 | "\n", |
244 | 252 | "\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)" |
246 | 260 | ], |
247 | 261 | "outputs": [], |
248 | 262 | "execution_count": null |
|
288 | 302 | " # TODO: Put a and b in equal superposition\n", |
289 | 303 | "\n", |
290 | 304 | " # 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", |
292 | 306 | "\n", |
293 | 307 | " # Print out the numeric attributes of the inferred type\n", |
294 | 308 | " print(\"Numeric attributes of c:\")\n", |
|
297 | 311 | " )\n", |
298 | 312 | "\n", |
299 | 313 | "\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)" |
301 | 321 | ], |
302 | 322 | "outputs": [], |
303 | 323 | "execution_count": null |
|
345 | 365 | " # TODO : Flip the state of flag if x < 0.5\n", |
346 | 366 | "\n", |
347 | 367 | "\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)" |
349 | 375 | ], |
350 | 376 | "outputs": [], |
351 | 377 | "execution_count": null |
|
419 | 445 | " grover_operator(v)\n", |
420 | 446 | "\n", |
421 | 447 | "\n", |
422 | | - "# Synthesize the model, show, execute and print results\n", |
423 | 448 | "qprog = synthesize(main)\n", |
424 | | - "show(qprog)\n", |
| 449 | + "show(qprog) # Visualize the quantum program for analysis\n", |
425 | 450 | "\n", |
| 451 | + "# Execute and print the results\n", |
426 | 452 | "with ExecutionSession(qprog) as es:\n", |
427 | 453 | " res = es.sample()\n", |
428 | 454 | " display(res.dataframe)" |
|
863 | 889 | " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator_statevector\"),\n", |
864 | 890 | ")\n", |
865 | 891 | "\n", |
866 | | - "# Execute and print results:\n", |
| 892 | + "# Execute and print results\n", |
867 | 893 | "with ExecutionSession(qprog, preferences) as es:\n", |
868 | 894 | " res = es.sample()\n", |
869 | 895 | " print(\"Ex.6A Results:\")\n", |
|
0 commit comments