Skip to content

Commit e526dfe

Browse files
remove backend.run
1 parent aa08d77 commit e526dfe

File tree

1 file changed

+33
-50
lines changed

1 file changed

+33
-50
lines changed

shor_algorithm.ipynb

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@
358358
},
359359
{
360360
"cell_type": "code",
361-
"execution_count": 14,
361+
"execution_count": 41,
362362
"id": "7719918a-28ee-407a-9159-dcf160205d46",
363363
"metadata": {
364364
"tags": []
@@ -369,17 +369,17 @@
369369
"output_type": "stream",
370370
"text": [
371371
" 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",
377377
".. ... ...\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",
383383
"\n",
384384
"[256 rows x 2 columns]\n"
385385
]
@@ -402,7 +402,7 @@
402402
},
403403
{
404404
"cell_type": "code",
405-
"execution_count": 15,
405+
"execution_count": 42,
406406
"id": "5bc94ef8-eec3-40eb-b8d6-04ffc82f10e0",
407407
"metadata": {
408408
"tags": []
@@ -413,17 +413,17 @@
413413
"output_type": "stream",
414414
"text": [
415415
" 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",
421421
".. ... ... ...\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",
427427
"\n",
428428
"[256 rows x 3 columns]\n"
429429
]
@@ -444,7 +444,7 @@
444444
},
445445
{
446446
"cell_type": "code",
447-
"execution_count": 20,
447+
"execution_count": 44,
448448
"id": "13184b4b-a0a8-41f1-b78d-8a0a0c8b5d63",
449449
"metadata": {
450450
"tags": []
@@ -463,7 +463,7 @@
463463
"1"
464464
]
465465
},
466-
"execution_count": 20,
466+
"execution_count": 44,
467467
"metadata": {},
468468
"output_type": "execute_result"
469469
}
@@ -479,7 +479,7 @@
479479
},
480480
{
481481
"cell_type": "code",
482-
"execution_count": 17,
482+
"execution_count": 47,
483483
"id": "20025ca7-71ed-4215-a8a4-a6d1ab5173a3",
484484
"metadata": {
485485
"tags": []
@@ -506,9 +506,12 @@
506506
" qc.measure(range(N_COUNT), range(N_COUNT))\n",
507507
" # Simulate Results\n",
508508
" #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",
512515
" print(\"Register Reading: \" + readings[0])\n",
513516
" phase = int(readings[0],2)/(2**N_COUNT)\n",
514517
" print(f\"Corresponding Phase: {phase}\")\n",
@@ -517,32 +520,12 @@
517520
},
518521
{
519522
"cell_type": "code",
520-
"execution_count": 21,
523+
"execution_count": null,
521524
"id": "e3307c70-8206-4d03-ae03-1831149fe68f",
522525
"metadata": {
523526
"tags": []
524527
},
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": [],
546529
"source": [
547530
"phase = qpe_amod15(a) # Phase = s/r\n",
548531
"Fraction(phase).limit_denominator(15)\n",

0 commit comments

Comments
 (0)