task4.ipynb (11700B)
1 { 2 "cells": [ 3 { 4 "cell_type": "code", 5 "execution_count": 2, 6 "metadata": {}, 7 "outputs": [], 8 "source": [ 9 "\n", 10 "import sympy as sp\n" 11 ] 12 }, 13 { 14 "cell_type": "code", 15 "execution_count": 3, 16 "metadata": {}, 17 "outputs": [], 18 "source": [ 19 "\n", 20 "x, y = sp.symbols(\"x y\")\n" 21 ] 22 }, 23 { 24 "cell_type": "code", 25 "execution_count": 4, 26 "metadata": {}, 27 "outputs": [], 28 "source": [ 29 "#Task1\n", 30 "def DA(x, y):\n", 31 " return sp.sqrt(1 - ( sp.cos(x/2)*sp.sin(x/2)*sp.exp(sp.I*y) + sp.cos(x/2)*sp.sin(x/2)*sp.exp(-1*sp.I*y))**2 )\n", 32 "\n", 33 "def DB(x, y):\n", 34 " return sp.sqrt(1 - ( -1*sp.I*sp.cos(x/2)*sp.sin(x/2)*sp.exp(sp.I*y) + sp.I*sp.cos(x/2)*sp.sin(x/2)*sp.exp(-1*sp.I*y))**2 )\n", 35 " " 36 ] 37 }, 38 { 39 "cell_type": "code", 40 "execution_count": 5, 41 "metadata": {}, 42 "outputs": [], 43 "source": [ 44 "from sympy.physics.quantum import TensorProduct as TeP\n", 45 "\n", 46 "def alice(d, m, state): \n", 47 "\n", 48 " w, p, q = sp.symbols(\"w, p, q\")\n", 49 "\n", 50 " ##########################################\n", 51 " if d==2:\n", 52 " B1 = [sp.Matrix([1, 0]), sp.Matrix([0, 1])]\n", 53 " B2 = [1/sp.sqrt(2)*sp.Matrix([1, 1]), 1/sp.sqrt(2)*sp.Matrix([1, -1])]\n", 54 " B3 = [1/sp.sqrt(2)* sp.Matrix([1, sp.I]), 1/sp.sqrt(2)*sp.Matrix([1, - sp.I])]\n", 55 "\n", 56 " Blist = [B1, B2, B3]\n", 57 " elif d==3:\n", 58 " B1 = [sp.Matrix([1, 0, 0]), sp.Matrix([0, 1, 0]), sp.Matrix([0,0,1 ]) ]\n", 59 " B2 = [1/sp.sqrt(3) * sp.Matrix([1, 1, 1]), 1/sp.sqrt(3) *sp.Matrix([1, w, w**2]), 1/sp.sqrt(3) * sp.Matrix([1 , w**2 ,w ]) ]\n", 60 " B3 = [1/sp.sqrt(3) * sp.Matrix([1, w, w]), 1/sp.sqrt(3) * sp.Matrix([1, w**2, 1 ]) , 1/sp.sqrt(3) *sp.Matrix([1, 1, w**2])]\n", 61 " B4 = [1/sp.sqrt(3) * sp.Matrix([1, w**2, w**2]), 1/sp.sqrt(3) * sp.Matrix([1, w, 1 ]) , 1/sp.sqrt(3) *sp.Matrix([1, 1, w])]\n", 62 "\n", 63 " Blist = [B1, B2, B3, B4]\n", 64 "\n", 65 " ##########################################\n", 66 " Mat = []\n", 67 " Matconj = []\n", 68 " B = []\n", 69 " for base in range(m):\n", 70 " B += Blist[base]\n", 71 "\n", 72 " for vector in B:\n", 73 " M = vector @ vector.H\n", 74 " M2 = TeP(M, M)\n", 75 " Mat.append(M2)\n", 76 "\n", 77 " for vector in B:\n", 78 " M = vector @ vector.H\n", 79 " M2 = TeP(M, sp.conjugate(M))\n", 80 " Matconj.append(M2)\n", 81 "\n", 82 "\n", 83 " \n", 84 "\n", 85 " if state == \"Bell\":\n", 86 " #aufgabe 3\n", 87 " if d == 2:\n", 88 " #here should be the bell state\n", 89 " phiplus = 1/(sp.sqrt(2))*sp.Matrix([1, 0, 0, 1])\n", 90 " \n", 91 " \n", 92 " rho_bell = phiplus @ phiplus.H\n", 93 " rho = rho_bell\n", 94 " #aufgabe 3\n", 95 " elif d == 3:\n", 96 "\n", 97 " ket0 = sp.Matrix([1, 0 ,0])\n", 98 " ket1 = sp.Matrix([0, 1 ,0])\n", 99 " ket2 = sp.Matrix([0, 0 ,1])\n", 100 "\n", 101 " bellvec = 1/sp.sqrt(3)* (TeP(ket0, ket0) + TeP(ket1, ket1) + TeP(ket2, ket2))\n", 102 " bell = bellvec @ bellvec.H\n", 103 "\n", 104 " rho_bell = sp.Identity(d**2) * 1/d**2*(1-p) + p* bell\n", 105 " rho = rho_bell\n", 106 "\n", 107 " elif state == \"Werner\":\n", 108 " P = sp.zeros(d**2, d**2) \n", 109 " for i in range(d):\n", 110 " for j in range(d):\n", 111 " b_1 = B1[j]\n", 112 " b_2 = B1[i]\n", 113 " P += TeP(b_1, b_2) @ TeP(b_2, b_1).H\n", 114 "\n", 115 " P_sym = sp.Identity(d**2) + P\n", 116 " P_asym = sp.Identity(d**2) - P\n", 117 " rho_wern = q * P_sym/(d*(d+1)) + (1- q)*(P_asym)/(d*(d-1))\n", 118 " rho = rho_wern\n", 119 "\n", 120 " \n", 121 " trace = 0\n", 122 " for matrix in Mat:\n", 123 " M = matrix @ rho\n", 124 " for i in range(d**2):\n", 125 " trace += M[i,i]\n", 126 " Unconj = trace.subs({w:sp.exp( 2 *sp.pi/d * sp.I )})\n", 127 "\n", 128 " traceconj = 0\n", 129 " for matrix in Matconj:\n", 130 " M = matrix @ rho\n", 131 " for i in range(d**2):\n", 132 " traceconj += M[i,i]\n", 133 " Conj = traceconj.subs({w: sp.exp( 2 *sp.pi/d * sp.I ) })\n", 134 "\n", 135 " return Unconj, Conj\n", 136 "\n" 137 ] 138 }, 139 { 140 "cell_type": "code", 141 "execution_count": 6, 142 "metadata": {}, 143 "outputs": [], 144 "source": [ 145 " w, p, q = sp.symbols(\"w, p, q\")" 146 ] 147 }, 148 { 149 "cell_type": "code", 150 "execution_count": 20, 151 "metadata": {}, 152 "outputs": [], 153 "source": [ 154 "#Aufgabe 3\n", 155 "state = \"Bell\"\n", 156 "d = 2\n", 157 "m = 2\n", 158 "Unconj, Conj = alice(d, m, state) " 159 ] 160 }, 161 { 162 "cell_type": "code", 163 "execution_count": 21, 164 "metadata": {}, 165 "outputs": [ 166 { 167 "data": { 168 "text/latex": [ 169 "$\\displaystyle 2$" 170 ], 171 "text/plain": [ 172 "2" 173 ] 174 }, 175 "execution_count": 21, 176 "metadata": {}, 177 "output_type": "execute_result" 178 } 179 ], 180 "source": [ 181 "Unconj" 182 ] 183 }, 184 { 185 "cell_type": "code", 186 "execution_count": 9, 187 "metadata": {}, 188 "outputs": [ 189 { 190 "data": { 191 "text/latex": [ 192 "$\\displaystyle 2$" 193 ], 194 "text/plain": [ 195 "2" 196 ] 197 }, 198 "execution_count": 9, 199 "metadata": {}, 200 "output_type": "execute_result" 201 } 202 ], 203 "source": [ 204 "Conj" 205 ] 206 }, 207 { 208 "cell_type": "code", 209 "execution_count": 10, 210 "metadata": {}, 211 "outputs": [ 212 { 213 "name": "stdout", 214 "output_type": "stream", 215 "text": [ 216 "d = 2 , m = 2 , State: Bell\n", 217 "For p = 0.0\n", 218 "Unconjugated = 2.00000000000000\n", 219 "Conjugated = 2.00000000000000\n", 220 "For p = 0.25\n", 221 "Unconjugated = 2.00000000000000\n", 222 "Conjugated = 2.00000000000000\n", 223 "For p = 0.5\n", 224 "Unconjugated = 2.00000000000000\n", 225 "Conjugated = 2.00000000000000\n", 226 "For p = 0.75\n", 227 "Unconjugated = 2.00000000000000\n", 228 "Conjugated = 2.00000000000000\n", 229 "For p = 1.0\n", 230 "Unconjugated = 2.00000000000000\n", 231 "Conjugated = 2.00000000000000\n" 232 ] 233 } 234 ], 235 "source": [ 236 "i = 0.0\n", 237 "print(\"d = \", d, \", m = \", m, \", State: \", state)\n", 238 "while i <= 1.0:\n", 239 " valun = sp.re(Unconj.subs({p:i, w:sp.exp(sp.I*2*sp.pi/d)}).evalf())\n", 240 " valcon = sp.re(Conj.subs({ p:i, w:sp.exp(sp.I*2*sp.pi/d)}).evalf())\n", 241 " print(\"For p = \", i)\n", 242 " print(\"Unconjugated = \", valun)\n", 243 " print(\"Conjugated = \", valcon)\n", 244 " i+=0.25" 245 ] 246 }, 247 { 248 "cell_type": "code", 249 "execution_count": 11, 250 "metadata": {}, 251 "outputs": [], 252 "source": [ 253 "state = \"Werner\"\n", 254 "d = 2\n", 255 "m = 3\n", 256 "Unconj, Conj = alice(d, m, state) " 257 ] 258 }, 259 { 260 "cell_type": "code", 261 "execution_count": 12, 262 "metadata": {}, 263 "outputs": [ 264 { 265 "data": { 266 "text/latex": [ 267 "$\\displaystyle 2 q$" 268 ], 269 "text/plain": [ 270 "2*q" 271 ] 272 }, 273 "execution_count": 12, 274 "metadata": {}, 275 "output_type": "execute_result" 276 } 277 ], 278 "source": [ 279 "Unconj" 280 ] 281 }, 282 { 283 "cell_type": "code", 284 "execution_count": 13, 285 "metadata": {}, 286 "outputs": [ 287 { 288 "data": { 289 "text/latex": [ 290 "$\\displaystyle \\frac{2 q}{3} + 1$" 291 ], 292 "text/plain": [ 293 "2*q/3 + 1" 294 ] 295 }, 296 "execution_count": 13, 297 "metadata": {}, 298 "output_type": "execute_result" 299 } 300 ], 301 "source": [ 302 "Conj" 303 ] 304 }, 305 { 306 "cell_type": "code", 307 "execution_count": 14, 308 "metadata": {}, 309 "outputs": [ 310 { 311 "name": "stdout", 312 "output_type": "stream", 313 "text": [ 314 "d = 2 , m = 3 , State: Werner\n", 315 "For p = 0.0\n", 316 "Unconjugated = 0\n", 317 "Conjugated = 1.00000000000000\n", 318 "For p = 0.25\n", 319 "Unconjugated = 0.500000000000000\n", 320 "Conjugated = 1.16666666666667\n", 321 "For p = 0.5\n", 322 "Unconjugated = 1.00000000000000\n", 323 "Conjugated = 1.33333333333333\n", 324 "For p = 0.75\n", 325 "Unconjugated = 1.50000000000000\n", 326 "Conjugated = 1.50000000000000\n", 327 "For p = 1.0\n", 328 "Unconjugated = 2.00000000000000\n", 329 "Conjugated = 1.66666666666667\n" 330 ] 331 } 332 ], 333 "source": [ 334 "#Aufgabe 4\n", 335 "i = 0.0\n", 336 "print(\"d = \", d, \", m = \", m, \", State: \", state)\n", 337 "while i <= 1.0:\n", 338 " valun = sp.re(Unconj.subs({q:i, w:sp.exp(sp.I*2*sp.pi/d)}).evalf())\n", 339 " valcon = sp.re(Conj.subs({ q:i, w:sp.exp(sp.I*2*sp.pi/d)}).evalf())\n", 340 " print(\"For p = \", i)\n", 341 " print(\"Unconjugated = \", valun)\n", 342 " print(\"Conjugated = \", valcon)\n", 343 " i+=0.25" 344 ] 345 }, 346 { 347 "cell_type": "code", 348 "execution_count": null, 349 "metadata": {}, 350 "outputs": [], 351 "source": [] 352 }, 353 { 354 "cell_type": "code", 355 "execution_count": null, 356 "metadata": {}, 357 "outputs": [], 358 "source": [] 359 }, 360 { 361 "cell_type": "code", 362 "execution_count": null, 363 "metadata": {}, 364 "outputs": [], 365 "source": [] 366 }, 367 { 368 "cell_type": "code", 369 "execution_count": null, 370 "metadata": {}, 371 "outputs": [], 372 "source": [] 373 }, 374 { 375 "cell_type": "code", 376 "execution_count": null, 377 "metadata": {}, 378 "outputs": [], 379 "source": [] 380 }, 381 { 382 "cell_type": "code", 383 "execution_count": null, 384 "metadata": {}, 385 "outputs": [], 386 "source": [] 387 }, 388 { 389 "cell_type": "code", 390 "execution_count": null, 391 "metadata": {}, 392 "outputs": [], 393 "source": [] 394 }, 395 { 396 "cell_type": "code", 397 "execution_count": null, 398 "metadata": {}, 399 "outputs": [], 400 "source": [] 401 }, 402 { 403 "cell_type": "code", 404 "execution_count": null, 405 "metadata": {}, 406 "outputs": [], 407 "source": [] 408 }, 409 { 410 "cell_type": "code", 411 "execution_count": null, 412 "metadata": {}, 413 "outputs": [], 414 "source": [] 415 }, 416 { 417 "cell_type": "code", 418 "execution_count": null, 419 "metadata": {}, 420 "outputs": [], 421 "source": [] 422 }, 423 { 424 "cell_type": "code", 425 "execution_count": null, 426 "metadata": {}, 427 "outputs": [], 428 "source": [] 429 }, 430 { 431 "cell_type": "code", 432 "execution_count": null, 433 "metadata": {}, 434 "outputs": [], 435 "source": [] 436 }, 437 { 438 "cell_type": "code", 439 "execution_count": null, 440 "metadata": {}, 441 "outputs": [], 442 "source": [] 443 }, 444 { 445 "cell_type": "code", 446 "execution_count": null, 447 "metadata": {}, 448 "outputs": [], 449 "source": [] 450 }, 451 { 452 "cell_type": "code", 453 "execution_count": null, 454 "metadata": {}, 455 "outputs": [], 456 "source": [] 457 }, 458 { 459 "cell_type": "code", 460 "execution_count": null, 461 "metadata": {}, 462 "outputs": [], 463 "source": [] 464 }, 465 { 466 "cell_type": "code", 467 "execution_count": null, 468 "metadata": {}, 469 "outputs": [], 470 "source": [] 471 } 472 ], 473 "metadata": { 474 "interpreter": { 475 "hash": "ee36a872144e01c68ec3aa3caf33536f3803d01a906cfaf7250c1aecc58053d7" 476 }, 477 "kernelspec": { 478 "display_name": "Python 3", 479 "language": "python", 480 "name": "python3" 481 }, 482 "language_info": { 483 "codemirror_mode": { 484 "name": "ipython", 485 "version": 3 486 }, 487 "file_extension": ".py", 488 "mimetype": "text/x-python", 489 "name": "python", 490 "nbconvert_exporter": "python", 491 "pygments_lexer": "ipython3", 492 "version": "3.9.5" 493 }, 494 "metadata": { 495 "interpreter": { 496 "hash": "56478dce9f9bc57d89b9e60ef5c051fa56e4b5d6ab8e261fa1a5710bdfcea7e7" 497 } 498 } 499 }, 500 "nbformat": 4, 501 "nbformat_minor": 2 502 }