|
358 | 358 | }, |
359 | 359 | { |
360 | 360 | "cell_type": "code", |
361 | | - "execution_count": 14, |
| 361 | + "execution_count": 41, |
362 | 362 | "id": "7719918a-28ee-407a-9159-dcf160205d46", |
363 | 363 | "metadata": { |
364 | 364 | "tags": [] |
|
369 | 369 | "output_type": "stream", |
370 | 370 | "text": [ |
371 | 371 | " Register Output Phase\n", |
372 | | - "0 00000000(bin) = 0(dec) 0/256 = 0.00\n", |
373 | | - "1 00000001(bin) = 1(dec) 1/256 = 0.00\n", |
374 | | - "2 00010000(bin) = 16(dec) 16/256 = 0.06\n", |
375 | | - "3 00010001(bin) = 17(dec) 17/256 = 0.07\n", |
376 | | - "4 00010010(bin) = 18(dec) 18/256 = 0.07\n", |
| 372 | + "0 11110010(bin) = 242(dec) 242/256 = 0.95\n", |
| 373 | + "1 10011001(bin) = 153(dec) 153/256 = 0.60\n", |
| 374 | + "2 11011011(bin) = 219(dec) 219/256 = 0.86\n", |
| 375 | + "3 01000101(bin) = 69(dec) 69/256 = 0.27\n", |
| 376 | + "4 10100001(bin) = 161(dec) 161/256 = 0.63\n", |
377 | 377 | ".. ... ...\n", |
378 | | - "251 11111011(bin) = 251(dec) 251/256 = 0.98\n", |
379 | | - "252 11111100(bin) = 252(dec) 252/256 = 0.98\n", |
380 | | - "253 11111101(bin) = 253(dec) 253/256 = 0.99\n", |
381 | | - "254 11111110(bin) = 254(dec) 254/256 = 0.99\n", |
382 | | - "255 11111111(bin) = 255(dec) 255/256 = 1.00\n", |
| 378 | + "251 01011001(bin) = 89(dec) 89/256 = 0.35\n", |
| 379 | + "252 01100101(bin) = 101(dec) 101/256 = 0.39\n", |
| 380 | + "253 01011100(bin) = 92(dec) 92/256 = 0.36\n", |
| 381 | + "254 01001101(bin) = 77(dec) 77/256 = 0.30\n", |
| 382 | + "255 00010001(bin) = 17(dec) 17/256 = 0.07\n", |
383 | 383 | "\n", |
384 | 384 | "[256 rows x 2 columns]\n" |
385 | 385 | ] |
|
402 | 402 | }, |
403 | 403 | { |
404 | 404 | "cell_type": "code", |
405 | | - "execution_count": 15, |
| 405 | + "execution_count": 42, |
406 | 406 | "id": "5bc94ef8-eec3-40eb-b8d6-04ffc82f10e0", |
407 | 407 | "metadata": { |
408 | 408 | "tags": [] |
|
413 | 413 | "output_type": "stream", |
414 | 414 | "text": [ |
415 | 415 | " Phase Fraction Guess for r\n", |
416 | | - "0 0.000000 0/1 1\n", |
417 | | - "1 0.003906 0/1 1\n", |
418 | | - "2 0.062500 1/15 15\n", |
419 | | - "3 0.066406 1/15 15\n", |
420 | | - "4 0.070312 1/14 14\n", |
| 416 | + "0 0.945312 14/15 15\n", |
| 417 | + "1 0.597656 3/5 5\n", |
| 418 | + "2 0.855469 6/7 7\n", |
| 419 | + "3 0.269531 4/15 15\n", |
| 420 | + "4 0.628906 5/8 8\n", |
421 | 421 | ".. ... ... ...\n", |
422 | | - "251 0.980469 1/1 1\n", |
423 | | - "252 0.984375 1/1 1\n", |
424 | | - "253 0.988281 1/1 1\n", |
425 | | - "254 0.992188 1/1 1\n", |
426 | | - "255 0.996094 1/1 1\n", |
| 422 | + "251 0.347656 5/14 14\n", |
| 423 | + "252 0.394531 2/5 5\n", |
| 424 | + "253 0.359375 5/14 14\n", |
| 425 | + "254 0.300781 3/10 10\n", |
| 426 | + "255 0.066406 1/15 15\n", |
427 | 427 | "\n", |
428 | 428 | "[256 rows x 3 columns]\n" |
429 | 429 | ] |
|
444 | 444 | }, |
445 | 445 | { |
446 | 446 | "cell_type": "code", |
447 | | - "execution_count": 20, |
| 447 | + "execution_count": 44, |
448 | 448 | "id": "13184b4b-a0a8-41f1-b78d-8a0a0c8b5d63", |
449 | 449 | "metadata": { |
450 | 450 | "tags": [] |
|
463 | 463 | "1" |
464 | 464 | ] |
465 | 465 | }, |
466 | | - "execution_count": 20, |
| 466 | + "execution_count": 44, |
467 | 467 | "metadata": {}, |
468 | 468 | "output_type": "execute_result" |
469 | 469 | } |
|
479 | 479 | }, |
480 | 480 | { |
481 | 481 | "cell_type": "code", |
482 | | - "execution_count": 17, |
| 482 | + "execution_count": 47, |
483 | 483 | "id": "20025ca7-71ed-4215-a8a4-a6d1ab5173a3", |
484 | 484 | "metadata": { |
485 | 485 | "tags": [] |
|
506 | 506 | " qc.measure(range(N_COUNT), range(N_COUNT))\n", |
507 | 507 | " # Simulate Results\n", |
508 | 508 | " #aer_sim = Aer.get_backend('aer_simulator')\n", |
509 | | - " # `memory=True` tells the backend to save each measurement in a list\n", |
510 | | - " job = backend.run(transpile(qc, backend), shots=1, memory=True)\n", |
511 | | - " readings = job.result().get_memory()\n", |
| 509 | + " # transpile the circuit\n", |
| 510 | + " t_qc = transpile(qc, backend)\n", |
| 511 | + " job = sampler.run([t_qc])\n", |
| 512 | + " result = job.result()\n", |
| 513 | + "\n", |
| 514 | + " readings = result.get_memory()\n", |
512 | 515 | " print(\"Register Reading: \" + readings[0])\n", |
513 | 516 | " phase = int(readings[0],2)/(2**N_COUNT)\n", |
514 | 517 | " print(f\"Corresponding Phase: {phase}\")\n", |
|
517 | 520 | }, |
518 | 521 | { |
519 | 522 | "cell_type": "code", |
520 | | - "execution_count": 21, |
| 523 | + "execution_count": null, |
521 | 524 | "id": "e3307c70-8206-4d03-ae03-1831149fe68f", |
522 | 525 | "metadata": { |
523 | 526 | "tags": [] |
524 | 527 | }, |
525 | | - "outputs": [ |
526 | | - { |
527 | | - "name": "stdout", |
528 | | - "output_type": "stream", |
529 | | - "text": [ |
530 | | - "Register Reading: 00101011\n", |
531 | | - "Corresponding Phase: 0.16796875\n" |
532 | | - ] |
533 | | - }, |
534 | | - { |
535 | | - "ename": "NameError", |
536 | | - "evalue": "name 'r' is not defined", |
537 | | - "output_type": "error", |
538 | | - "traceback": [ |
539 | | - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
540 | | - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", |
541 | | - "\u001b[0;32m/var/folders/4d/rp7dhwss6znf18sks0v304d80000gn/T/ipykernel_2675/2496551432.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mphase\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mqpe_amod15\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# Phase = s/r\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mFraction\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mphase\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlimit_denominator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m15\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mguesses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mgcd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgcd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mguesses\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
542 | | - "\u001b[0;31mNameError\u001b[0m: name 'r' is not defined" |
543 | | - ] |
544 | | - } |
545 | | - ], |
| 528 | + "outputs": [], |
546 | 529 | "source": [ |
547 | 530 | "phase = qpe_amod15(a) # Phase = s/r\n", |
548 | 531 | "Fraction(phase).limit_denominator(15)\n", |
|
0 commit comments