Skip to content

Commit fc93143

Browse files
authored
Merge pull request #20 from QuEraComputing/john/update-deps
2 parents c97dac6 + 2d97a74 commit fc93143

File tree

2 files changed

+168
-288
lines changed

2 files changed

+168
-288
lines changed

QRC Demo Aquila Submission.ipynb

Lines changed: 37 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": null,
66
"id": "d892ba92",
77
"metadata": {},
88
"outputs": [],
@@ -19,13 +19,13 @@
1919
},
2020
{
2121
"cell_type": "code",
22-
"execution_count": 2,
22+
"execution_count": null,
2323
"id": "5137b1fb",
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
2727
"import bloqade\n",
28-
"from bloqade.ir.location import Chain, start"
28+
"from bloqade.analog.ir import Chain, start"
2929
]
3030
},
3131
{
@@ -47,21 +47,10 @@
4747
},
4848
{
4949
"cell_type": "code",
50-
"execution_count": 3,
50+
"execution_count": null,
5151
"id": "fea12b36-2f1c-4538-8cec-c365091a7d6d",
5252
"metadata": {},
53-
"outputs": [
54-
{
55-
"name": "stdout",
56-
"output_type": "stream",
57-
"text": [
58-
"X_train: (60000, 28, 28)\n",
59-
"Y_train: (60000,)\n",
60-
"X_test: (10000, 28, 28)\n",
61-
"Y_test: (10000,)\n"
62-
]
63-
}
64-
],
53+
"outputs": [],
6554
"source": [
6655
"# Download the MNIST dataset and rescaling data\n",
6756
" \n",
@@ -79,23 +68,12 @@
7968
},
8069
{
8170
"cell_type": "code",
82-
"execution_count": 4,
71+
"execution_count": null,
8372
"id": "122d68ab-68f0-4d82-a0a1-3217d480bbba",
8473
"metadata": {
8574
"tags": []
8675
},
87-
"outputs": [
88-
{
89-
"data": {
90-
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGli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AIQoAhCgAEKIAQIgCAOFCPOa8devWlTcnT54sbw4ePFjerFixoryZSb9+/SpvxsbGypvJycnyhrnJSQGAEAUAQhQACFEAIEQBgBAFAEIUAAhRACBEAYAQBQBCFAAIUQAgXIhHK20ughsYGGj1rjaX261evbrVu+ayZ8+elTeDg4Plza1bt8ob5g8nBQBCFAAIUQAgRAGAEAUAQhQACFEAIEQBgBAFAEIUAAhRACBEAYBwId48s3z58vJmw4YN5c2VK1fKm/Xr15c3c93Tp0/LmwsXLrR6182bN8ubycnJVu/iz+WkAECIAgAhCgCEKAAQogBAiAIAIQoAhCgAEKIAQIgCACEKAIQoABCiAEC4JXUG9PX1lTfDw8Ot3rVly5byZs2aNa3eNZc9efKkvLl06VJ5c/fu3fLm69ev5Q3MFCcFAEIUAAhRACBEAYAQBQBCFAAIUQAgRAGAEAUAQhQACFEAIEQBgPijL8Tbvn17eXP69OnyZtu2beXNypUry5u57suXL612Q0ND5c25c+fKm8+fP5c3MN84KQAQogBAiAIAIQoAhCgAEKIAQIgCACEKAIQoABCiAECIAgAhCgDEH30hXn9//4xsZtLo6Gh5c+fOnfLm58+f5c2lS5fKm6ZpmvHx8VY7oM5JAYAQBQBCFAAIUQAgRAGAEAUAQhQACFEAIEQBgBAFAEIUAAhRACA63W63O6UHO53p/hYAptFUfu6dFAAIUQAgRAGAEAUAQhQACFEAIEQBgBAFAEIUAAhRACBEAYAQBQBCFAAIUQAgRAGAEAUAQhQACFEAIEQBgBAFAEIUAAhRACBEAYAQBQBCFAAIUQAgRAGAEAUAQhQACFEAIEQBgBAFAEIUAAhRACBEAYAQBQBCFAAIUQAgRAGA6Jnqg91udzq/A4A5wEkBgBAFAEIUAAhRACBEAYAQBQBCFAAIUQAgRAGA+DdFFDZD3G7ZOwAAAABJRU5ErkJggg==",
91-
"text/plain": [
92-
"<Figure size 640x480 with 1 Axes>"
93-
]
94-
},
95-
"metadata": {},
96-
"output_type": "display_data"
97-
}
98-
],
76+
"outputs": [],
9977
"source": [
10078
"# example of an training dataset image for '5'\n",
10179
"plt.imshow(train_X[0], cmap=plt.get_cmap('gray'), interpolation='None')\n",
@@ -118,42 +96,12 @@
11896
},
11997
{
12098
"cell_type": "code",
121-
"execution_count": 5,
99+
"execution_count": null,
122100
"id": "6cc2f07f-b04f-4e06-946f-1c7baef0a677",
123101
"metadata": {
124102
"scrolled": true
125103
},
126-
"outputs": [
127-
{
128-
"name": "stdout",
129-
"output_type": "stream",
130-
"text": [
131-
"Training set PCA: \n",
132-
" [[ 0.48601015 1.22617358 0.09613354 2.17944297 -0.10704576 0.9116717\n",
133-
" 0.91763033 0.62666468]\n",
134-
" [ 3.96752304 1.15630211 -2.33858651 1.80692626 -3.24421656 0.71353148\n",
135-
" -0.17655089 -0.41164546]\n",
136-
" [-0.2033318 -1.53793393 0.73925392 -2.04318175 -1.20266952 0.00719743\n",
137-
" -3.36881255 1.44545833]\n",
138-
" [-3.13383152 2.38116556 -1.07314212 -0.41520877 -0.00726755 -2.74374391\n",
139-
" -1.85769884 -0.2640067 ]\n",
140-
" [-1.50099977 -2.86487399 -0.06413234 0.94783341 0.38494646 -0.16952834\n",
141-
" -0.35947686 -1.59041131]] \n",
142-
"\n",
143-
"Test set PCA: \n",
144-
" [[ 0.48601015 1.22617358 0.09613354 2.17944297 -0.10704576 0.9116717\n",
145-
" 0.91763033 0.62666468]\n",
146-
" [ 3.96752304 1.15630211 -2.33858651 1.80692626 -3.24421656 0.71353148\n",
147-
" -0.17655089 -0.41164546]\n",
148-
" [-0.2033318 -1.53793393 0.73925392 -2.04318175 -1.20266952 0.00719743\n",
149-
" -3.36881255 1.44545833]\n",
150-
" [-3.13383152 2.38116556 -1.07314212 -0.41520877 -0.00726755 -2.74374391\n",
151-
" -1.85769884 -0.2640067 ]\n",
152-
" [-1.50099977 -2.86487399 -0.06413234 0.94783341 0.38494646 -0.16952834\n",
153-
" -0.35947686 -1.59041131]] \n"
154-
]
155-
}
156-
],
104+
"outputs": [],
157105
"source": [
158106
"# We first use PCA to downsample the data into 10-dimensional vectors\n",
159107
"dim_pca = 8\n",
@@ -187,7 +135,7 @@
187135
},
188136
{
189137
"cell_type": "code",
190-
"execution_count": 6,
138+
"execution_count": null,
191139
"id": "ed5a7bc3-9d38-4a86-bb7e-ad8be8eb481e",
192140
"metadata": {
193141
"scrolled": true
@@ -217,7 +165,7 @@
217165
},
218166
{
219167
"cell_type": "code",
220-
"execution_count": 7,
168+
"execution_count": null,
221169
"id": "e67796a3",
222170
"metadata": {},
223171
"outputs": [],
@@ -243,7 +191,7 @@
243191
},
244192
{
245193
"cell_type": "code",
246-
"execution_count": 8,
194+
"execution_count": null,
247195
"id": "3ffae4d8",
248196
"metadata": {},
249197
"outputs": [],
@@ -328,7 +276,7 @@
328276
},
329277
{
330278
"cell_type": "code",
331-
"execution_count": 9,
279+
"execution_count": null,
332280
"id": "ea54345e",
333281
"metadata": {},
334282
"outputs": [],
@@ -346,7 +294,7 @@
346294
},
347295
{
348296
"cell_type": "code",
349-
"execution_count": 10,
297+
"execution_count": null,
350298
"id": "43caeabb",
351299
"metadata": {},
352300
"outputs": [],
@@ -369,7 +317,7 @@
369317
},
370318
{
371319
"cell_type": "code",
372-
"execution_count": 11,
320+
"execution_count": null,
373321
"id": "ac5935be",
374322
"metadata": {},
375323
"outputs": [],
@@ -380,19 +328,10 @@
380328
},
381329
{
382330
"cell_type": "code",
383-
"execution_count": 12,
331+
"execution_count": null,
384332
"id": "067eac2e",
385333
"metadata": {},
386-
"outputs": [
387-
{
388-
"name": "stdout",
389-
"output_type": "stream",
390-
"text": [
391-
"(1000, 288)\n",
392-
"(200, 288)\n"
393-
]
394-
}
395-
],
334+
"outputs": [],
396335
"source": [
397336
"print(embeddings.shape)\n",
398337
"print(test_embeddings.shape)"
@@ -421,18 +360,10 @@
421360
},
422361
{
423362
"cell_type": "code",
424-
"execution_count": 13,
363+
"execution_count": null,
425364
"id": "fe750ec5",
426365
"metadata": {},
427-
"outputs": [
428-
{
429-
"name": "stdout",
430-
"output_type": "stream",
431-
"text": [
432-
"PCA test accuracy: 69.0 %\n"
433-
]
434-
}
435-
],
366+
"outputs": [],
436367
"source": [
437368
"#building a linear model\n",
438369
"model = tf.keras.Sequential([\n",
@@ -460,18 +391,10 @@
460391
},
461392
{
462393
"cell_type": "code",
463-
"execution_count": 14,
394+
"execution_count": null,
464395
"id": "74ffd5d9",
465396
"metadata": {},
466-
"outputs": [
467-
{
468-
"name": "stdout",
469-
"output_type": "stream",
470-
"text": [
471-
"QRC test accuracy: 83.0 %\n"
472-
]
473-
}
474-
],
397+
"outputs": [],
475398
"source": [
476399
"#building a linear model\n",
477400
"#we include regularization and tune epsilon parameter of the optimizer to better control training from QRC embeddings generated on finite number of samples\n",
@@ -502,18 +425,10 @@
502425
},
503426
{
504427
"cell_type": "code",
505-
"execution_count": 16,
428+
"execution_count": null,
506429
"id": "266a1d4f",
507430
"metadata": {},
508-
"outputs": [
509-
{
510-
"name": "stdout",
511-
"output_type": "stream",
512-
"text": [
513-
"4-layer NN test accuracy: 81.0 %\n"
514-
]
515-
}
516-
],
431+
"outputs": [],
517432
"source": [
518433
"model = tf.keras.Sequential([\n",
519434
" tf.keras.layers.Dense(50, activation='relu'),\n",
@@ -539,28 +454,10 @@
539454
},
540455
{
541456
"cell_type": "code",
542-
"execution_count": 15,
457+
"execution_count": null,
543458
"id": "5333d324",
544459
"metadata": {},
545-
"outputs": [
546-
{
547-
"name": "stderr",
548-
"output_type": "stream",
549-
"text": [
550-
"c:\\Users\\mkornjaca\\anaconda3\\envs\\blpy_June\\Lib\\site-packages\\sklearn\\svm\\_base.py:1235: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
551-
" warnings.warn(\n"
552-
]
553-
},
554-
{
555-
"name": "stdout",
556-
"output_type": "stream",
557-
"text": [
558-
"Linear SVM test accuracy: 70.0 %\n",
559-
"SVC test accuracy (rbf kernel): 89.0 %\n",
560-
"QRC test accuracy: 84.0 %\n"
561-
]
562-
}
563-
],
460+
"outputs": [],
564461
"source": [
565462
"#The same implemented with LinearSVC and SVC from sklearn.\n",
566463
"\n",
@@ -602,7 +499,7 @@
602499
},
603500
{
604501
"cell_type": "code",
605-
"execution_count": 19,
502+
"execution_count": null,
606503
"id": "ad2cec48",
607504
"metadata": {},
608505
"outputs": [],
@@ -625,7 +522,7 @@
625522
},
626523
{
627524
"cell_type": "code",
628-
"execution_count": 21,
525+
"execution_count": null,
629526
"id": "583b9878",
630527
"metadata": {},
631528
"outputs": [],
@@ -641,7 +538,7 @@
641538
" try:\n",
642539
" #task=build_task(QRC_parameters, xs[data,:]).parallelize(15).braket.aquila().run_async(shots=nshots, name = \"QRC_train_\"+str(data))\n",
643540
" task=build_task(QRC_parameters, xs[data,:]).parallelize(15).quera.mock().run_async(shots=nshots, name = \"QRC_train_\"+str(data))\n",
644-
" bloqade.save(\n",
541+
" bloqade.analog.save(\n",
645542
" task,\n",
646543
" path_to_tasks + \"/\" + \"qrc_train_\" + str(data) + \".json\", \n",
647544
" )\n",
@@ -655,7 +552,7 @@
655552
" try:\n",
656553
" #task=build_task(QRC_parameters, xs[data,:]).parallelize(15).braket.aquila().run_async(shots=nshots, name = \"QRC_test_\"+str(data))\n",
657554
" task=build_task(QRC_parameters, xs_test[data,:]).parallelize(15).quera.mock().run_async(shots=nshots, name = \"QRC_test_\"+str(data))\n",
658-
" bloqade.save(\n",
555+
" bloqade.analog.save(\n",
659556
" task,\n",
660557
" path_to_tasks + \"/\" + \"qrc_test_\" + str(data) + \".json\", \n",
661558
" )\n",
@@ -687,8 +584,8 @@
687584
"#Train task fetching\n",
688585
"for data in range(num_examples):\n",
689586
" try:\n",
690-
" task = bloqade.load(path_to_tasks + \"/\" + \"qrc_train_\" + str(data) + \".json\")\n",
691-
" bloqade.save(\n",
587+
" task = bloqade.analog.load(path_to_tasks + \"/\" + \"qrc_train_\" + str(data) + \".json\")\n",
588+
" bloqade.analog.save(\n",
692589
" task.fetch(),\n",
693590
" path_to_results + \"/\" + \"qrc_train_\" + str(data) + \".json\", \n",
694591
" )\n",
@@ -698,8 +595,8 @@
698595
"#Test task fetching\n",
699596
"for data in range(num_test_examples):\n",
700597
" try:\n",
701-
" task = bloqade.load(path_to_tasks + \"/\" + \"qrc_test_\" + str(data) + \".json\")\n",
702-
" bloqade.save(\n",
598+
" task = bloqade.analog.load(path_to_tasks + \"/\" + \"qrc_test_\" + str(data) + \".json\")\n",
599+
" bloqade.analog.save(\n",
703600
" task.fetch(),\n",
704601
" path_to_results + \"/\" + \"qrc_test_\" + str(data) + \".json\", \n",
705602
" )\n",
@@ -724,13 +621,13 @@
724621
"source": [
725622
"embeddings_Aquila=[]\n",
726623
"for data in range(num_examples):\n",
727-
" task_report = bloqade.load(path_to_results + \"/\" + \"qrc_train_\" + str(data) + \".json\").report()\n",
624+
" task_report = bloqade.analog.load(path_to_results + \"/\" + \"qrc_train_\" + str(data) + \".json\").report()\n",
728625
" embeddings.append(process_results(QRC_parameters,task_report))\n",
729626
"embeddings_Aquila=np.array(embeddings_Aquila)\n",
730627
"\n",
731628
"test_embeddings_Aquila=[]\n",
732629
"for data in range(num_test_examples):\n",
733-
" task_report = bloqade.load(path_to_results + \"/\" + \"qrc_test_\" + str(data) + \".json\").report()\n",
630+
" task_report = bloqade.analog.load(path_to_results + \"/\" + \"qrc_test_\" + str(data) + \".json\").report()\n",
734631
" test_embeddings_Aquila.append(process_results(QRC_parameters,task_report))\n",
735632
"test_embeddings_Aquila=np.array(test_embeddings_Aquila)\n"
736633
]
@@ -786,7 +683,7 @@
786683
],
787684
"metadata": {
788685
"kernelspec": {
789-
"display_name": "Python 3 (ipykernel)",
686+
"display_name": "QRC-tutorials",
790687
"language": "python",
791688
"name": "python3"
792689
},
@@ -800,7 +697,7 @@
800697
"name": "python",
801698
"nbconvert_exporter": "python",
802699
"pygments_lexer": "ipython3",
803-
"version": "3.12.4"
700+
"version": "3.12.1"
804701
}
805702
},
806703
"nbformat": 4,

0 commit comments

Comments
 (0)