|
64 | 64 | },
|
65 | 65 | {
|
66 | 66 | "cell_type": "code",
|
67 |
| - "execution_count": 1, |
| 67 | + "execution_count": 2, |
68 | 68 | "source": [
|
69 | 69 | "from braket.circuits import Circuit, Observable, Gate, Noise\n",
|
70 | 70 | "from braket.devices import LocalSimulator\n",
|
|
86 | 86 | },
|
87 | 87 | {
|
88 | 88 | "cell_type": "code",
|
89 |
| - "execution_count": 2, |
| 89 | + "execution_count": 3, |
90 | 90 | "source": [
|
91 | 91 | "# enter the S3 bucket you created during onboarding (or any other bucket starting with \"amazon-braket-\") \n",
|
92 | 92 | "my_bucket = \"amazon-braket-Your-Bucket-Name\" # the name of the bucket\n",
|
|
107 | 107 | },
|
108 | 108 | {
|
109 | 109 | "cell_type": "code",
|
110 |
| - "execution_count": 3, |
| 110 | + "execution_count": 4, |
111 | 111 | "source": [
|
112 | 112 | "# build a simple circuit\n",
|
113 | 113 | "circ = Circuit().h(0).cnot(0,1)\n",
|
|
134 | 134 | "output_type": "stream",
|
135 | 135 | "name": "stdout",
|
136 | 136 | "text": [
|
137 |
| - "measurement results: Counter({'00': 418, '11': 385, '01': 102, '10': 95})\n" |
| 137 | + "measurement results: Counter({'00': 431, '11': 410, '01': 88, '10': 71})\n" |
138 | 138 | ]
|
139 | 139 | }
|
140 | 140 | ],
|
|
151 | 151 | },
|
152 | 152 | {
|
153 | 153 | "cell_type": "code",
|
154 |
| - "execution_count": 4, |
| 154 | + "execution_count": 5, |
155 | 155 | "source": [
|
156 | 156 | "def ghz_circuit(n_qubits: int) -> Circuit:\n",
|
157 | 157 | " \"\"\"\n",
|
|
189 | 189 | "output_type": "stream",
|
190 | 190 | "name": "stdout",
|
191 | 191 | "text": [
|
192 |
| - "measurement results: Counter({'0000000000000': 2, '0011000000001': 1, '0111110000000': 1, '1000010100000': 1, '1000001000000': 1, '1110111111110': 1, '1110000000011': 1, '0011001000000': 1, '0000001101011': 1})\n" |
| 192 | + "measurement results: Counter({'1111111111000': 1, '0000000000001': 1, '0000000011111': 1, '1111001000000': 1, '1011111111111': 1, '0000000000000': 1, '1111100000000': 1, '1110000001111': 1, '1111111000111': 1, '0010000000000': 1})\n" |
193 | 193 | ]
|
194 | 194 | }
|
195 | 195 | ],
|
|
245 | 245 | },
|
246 | 246 | {
|
247 | 247 | "cell_type": "code",
|
248 |
| - "execution_count": 5, |
| 248 | + "execution_count": 6, |
249 | 249 | "source": [
|
250 | 250 | "# define a bit flip noise channel with probability = 0.1\n",
|
251 | 251 | "noise = Noise.BitFlip(probability=0.1)\n",
|
|
284 | 284 | },
|
285 | 285 | {
|
286 | 286 | "cell_type": "code",
|
287 |
| - "execution_count": 6, |
| 287 | + "execution_count": 7, |
288 | 288 | "source": [
|
289 | 289 | "# define a phase flip noise channel\n",
|
290 | 290 | "noise = Noise.PhaseFlip(probability=0.1)\n",
|
|
317 | 317 | },
|
318 | 318 | {
|
319 | 319 | "cell_type": "code",
|
320 |
| - "execution_count": 7, |
| 320 | + "execution_count": 8, |
321 | 321 | "source": [
|
322 | 322 | "# creat an arbitrary 2-qubit Kraus matrix\n",
|
323 | 323 | "E0 = unitary_group.rvs(4) * np.sqrt(0.2) \n",
|
|
339 | 339 | },
|
340 | 340 | {
|
341 | 341 | "cell_type": "code",
|
342 |
| - "execution_count": 8, |
| 342 | + "execution_count": 9, |
343 | 343 | "source": [
|
344 | 344 | "K_invalid = [np.random.randn(2,2), np.random.randn(2,2)] \n",
|
345 | 345 | "\n",
|
|
377 | 377 | },
|
378 | 378 | {
|
379 | 379 | "cell_type": "code",
|
380 |
| - "execution_count": 9, |
| 380 | + "execution_count": 10, |
381 | 381 | "source": [
|
382 | 382 | "# apply depolarizing noise\n",
|
383 | 383 | "circ = Circuit().x(0).x(1).cnot(0,1).depolarizing(1, probability=0.2).x(0).two_qubit_dephasing(target1=0, target2=1, probability=0.1)\n",
|
|
438 | 438 | },
|
439 | 439 | {
|
440 | 440 | "cell_type": "code",
|
441 |
| - "execution_count": 10, |
| 441 | + "execution_count": 11, |
442 | 442 | "source": [
|
443 | 443 | "noise = Noise.PhaseDamping(gamma=0.1)\n",
|
444 | 444 | "\n",
|
|
491 | 491 | },
|
492 | 492 | {
|
493 | 493 | "cell_type": "code",
|
494 |
| - "execution_count": 11, |
| 494 | + "execution_count": 12, |
495 | 495 | "source": [
|
496 | 496 | "# the noise channel is applied to all the X gates in the circuit\n",
|
497 | 497 | "circ = Circuit().x(0).y(1).cnot(0,2).x(1).z(2)\n",
|
|
529 | 529 | },
|
530 | 530 | {
|
531 | 531 | "cell_type": "code",
|
532 |
| - "execution_count": 12, |
| 532 | + "execution_count": 13, |
533 | 533 | "source": [
|
534 | 534 | "U1=unitary_group.rvs(4)\n",
|
535 | 535 | "U2=unitary_group.rvs(4)\n",
|
|
568 | 568 | },
|
569 | 569 | {
|
570 | 570 | "cell_type": "code",
|
571 |
| - "execution_count": 13, |
| 571 | + "execution_count": 14, |
572 | 572 | "source": [
|
573 | 573 | "# the noise channel is applied to every gate on qubits 0 and 2\n",
|
574 | 574 | "circ = Circuit().x(0).y(1).cnot(0,2).x(1).z(2)\n",
|
|
606 | 606 | },
|
607 | 607 | {
|
608 | 608 | "cell_type": "code",
|
609 |
| - "execution_count": 14, |
| 609 | + "execution_count": 15, |
610 | 610 | "source": [
|
611 | 611 | "# the noise channel is applied to X gate on qubits 0\n",
|
612 | 612 | "circ = Circuit().x(0).y(1).cnot(0,2).x(0).x(1).z(2)\n",
|
|
644 | 644 | },
|
645 | 645 | {
|
646 | 646 | "cell_type": "code",
|
647 |
| - "execution_count": 15, |
| 647 | + "execution_count": 16, |
648 | 648 | "source": [
|
649 | 649 | "# define two noise channels\n",
|
650 | 650 | "noise1 = Noise.Depolarizing(probability=0.1)\n",
|
|
686 | 686 | },
|
687 | 687 | {
|
688 | 688 | "cell_type": "code",
|
689 |
| - "execution_count": 16, |
| 689 | + "execution_count": 17, |
690 | 690 | "source": [
|
691 | 691 | "# define a two-qubit noise channel\n",
|
692 | 692 | "noise = Noise.TwoQubitDephasing(probability=0.1)\n",
|
|
743 | 743 | },
|
744 | 744 | {
|
745 | 745 | "cell_type": "code",
|
746 |
| - "execution_count": 17, |
| 746 | + "execution_count": 18, |
747 | 747 | "source": [
|
748 | 748 | "# define a noise channel\n",
|
749 | 749 | "noise = Noise.Depolarizing(probability=0.1)\n",
|
|
784 | 784 | },
|
785 | 785 | {
|
786 | 786 | "cell_type": "code",
|
787 |
| - "execution_count": 18, |
| 787 | + "execution_count": 19, |
788 | 788 | "source": [
|
789 | 789 | "# define a two-qubit noise channel\n",
|
790 | 790 | "noise = Noise.TwoQubitDephasing(probability=0.1)\n",
|
|
839 | 839 | },
|
840 | 840 | {
|
841 | 841 | "cell_type": "code",
|
842 |
| - "execution_count": 19, |
| 842 | + "execution_count": 20, |
843 | 843 | "source": [
|
844 | 844 | "# define a noise channel\n",
|
845 | 845 | "noise = Noise.Depolarizing(probability=0.1)\n",
|
|
888 | 888 | },
|
889 | 889 | {
|
890 | 890 | "cell_type": "code",
|
891 |
| - "execution_count": 20, |
| 891 | + "execution_count": 21, |
892 | 892 | "source": [
|
893 | 893 | "# define a noise channel\n",
|
894 | 894 | "noise = Noise.PhaseFlip(probability=0.2)\n",
|
|
935 | 935 | },
|
936 | 936 | {
|
937 | 937 | "cell_type": "code",
|
938 |
| - "execution_count": 21, |
| 938 | + "execution_count": 22, |
939 | 939 | "source": [
|
940 | 940 | "# define the noise channel\n",
|
941 | 941 | "noise = Noise.AmplitudeDamping(gamma=0.1)\n",
|
|
951 | 951 | "circ.density_matrix(target=[0,1])\n",
|
952 | 952 | "print(circ)\n",
|
953 | 953 | "\n",
|
954 |
| - "# choose the noise simualtor, which is called \"braket_dm\"\n", |
| 954 | + "# choose the noise simulator, which is called \"braket_dm\"\n", |
955 | 955 | "device = LocalSimulator(\"braket_dm\")\n",
|
956 | 956 | "# run the circuit\n",
|
957 | 957 | "task = device.run(circ, shots=0)\n",
|
|
1004 | 1004 | },
|
1005 | 1005 | {
|
1006 | 1006 | "cell_type": "code",
|
1007 |
| - "execution_count": 22, |
| 1007 | + "execution_count": 23, |
1008 | 1008 | "source": [
|
1009 | 1009 | "# create a circuit\n",
|
1010 | 1010 | "circ = Circuit().x(0).y(1).cnot(0,2).x(1).z(2)\n",
|
|
1038 | 1038 | "\n",
|
1039 | 1039 | "T : | 0 | 1 | 2 | Result Types |\n",
|
1040 | 1040 | "- Probability is: \n",
|
1041 |
| - "[0.08 0.05 0. 0. 0.2 0.67 0. 0. ]\n", |
| 1041 | + "[0.11 0.08 0. 0. 0.12 0.69 0. 0. ]\n", |
1042 | 1042 | "- Expectation value <Z_0> is: \n",
|
1043 |
| - "-0.74\n" |
| 1043 | + "-0.62\n" |
1044 | 1044 | ]
|
1045 | 1045 | }
|
1046 | 1046 | ],
|
|
1058 | 1058 | "metadata": {
|
1059 | 1059 | "kernelspec": {
|
1060 | 1060 | "name": "python3",
|
1061 |
| - "display_name": "Python 3.7.6 64-bit ('base': conda)" |
| 1061 | + "display_name": "Python 3.7.10 64-bit ('Braket': conda)" |
1062 | 1062 | },
|
1063 | 1063 | "language_info": {
|
1064 | 1064 | "codemirror_mode": {
|
|
1070 | 1070 | "name": "python",
|
1071 | 1071 | "nbconvert_exporter": "python",
|
1072 | 1072 | "pygments_lexer": "ipython3",
|
1073 |
| - "version": "3.7.6" |
| 1073 | + "version": "3.7.10" |
1074 | 1074 | },
|
1075 | 1075 | "interpreter": {
|
1076 |
| - "hash": "0253d37730c9ef949b31486b4cff0d658c43b30ac02c14841de7d7631b67ad05" |
| 1076 | + "hash": "16295940b2ad1780f80ab35486298f56b74905bdf7e3032c7f9c97990fe8396d" |
1077 | 1077 | }
|
1078 | 1078 | },
|
1079 | 1079 | "nbformat": 4,
|
|
0 commit comments