##// END OF EJS Templates
Updating notebook examples, and notebook js/html.
Brian Granger -
Show More
@@ -0,0 +1,1 b''
1 {"cells":[{"cell_type":"text","text":"<h1>SymPy: Open Source Symbolic Mathematics</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from __future__ import division\nfrom sympy import *\nx, y, z = symbols(\"x y z\")\nk, m, n = symbols(\"k m n\", integer=True)\nf, g, h = map(Function, 'fgh')","cell_type":"code","prompt_number":2},{"cell_type":"text","text":"<h2>Elementary operations</h2>"},{"code":"Rational(3,2)*pi + exp(I*x) / (x**2 + y)\n","cell_type":"code","prompt_number":3},{"code":"exp(I*x).subs(x,pi).evalf()\n","cell_type":"code","prompt_number":4},{"code":"e = x + 2*y","cell_type":"code","prompt_number":5},{"code":"srepr(e)","cell_type":"code","prompt_number":6},{"code":"exp(pi * sqrt(163)).evalf(50)","cell_type":"code","prompt_number":7},{"cell_type":"text","text":"<h2>Algebra<h2>"},{"code":"((x+y)**2 * (x+1)).expand()","cell_type":"code","prompt_number":8},{"code":"a = 1/x + (x*sin(x) - 1)/x\ndisplay(a)\nsimplify(a)","cell_type":"code","prompt_number":9},{"code":"solve(Eq(x**3 + 2*x**2 + 4*x + 8, 0), x)","cell_type":"code","prompt_number":10},{"code":"a, b = symbols('a b')\nSum(6*n**2 + 2**n, (n, a, b))","cell_type":"code","prompt_number":11},{"cell_type":"text","text":"<h2>Calculus</h2>"},{"code":"limit((sin(x)-x)/x**3, x, 0)","cell_type":"code","prompt_number":12},{"code":"(1/cos(x)).series(x, 0, 6)","cell_type":"code","prompt_number":13},{"code":"diff(cos(x**2)**2 / (1+x), x)","cell_type":"code","prompt_number":14},{"code":"integrate(x**2 * cos(x), (x, 0, pi/2))","cell_type":"code","prompt_number":16},{"code":"eqn = Eq(Derivative(f(x),x,x) + 9*f(x), 1)\ndisplay(eqn)\ndsolve(eqn, f(x))","cell_type":"code","prompt_number":17},{"code":"%notebook save sympy.ipynb","cell_type":"code","prompt_number":40},{"code":"%notebook load basic_quantum.ipynb","cell_type":"code","prompt_number":41}]} No newline at end of file
@@ -557,13 +557,19 b' Notebook.prototype.save_notebook = function (filename) {'
557 Notebook.prototype.load_notebook = function (filename) {
557 Notebook.prototype.load_notebook = function (filename) {
558 if (!this.test_filename(filename)) {return;}
558 if (!this.test_filename(filename)) {return;}
559 var that = this;
559 var that = this;
560 $.getJSON("/notebooks/" + filename,
560 // We do the call with settings so we can set cache to false.
561 function (data, status, xhr) {
561 var settings = {
562 that.fromJSON(data);
562 processData : false,
563 that.filename = filename;
563 cache : false,
564 that.kernel.restart();
564 type : "GET",
565 }
565 dataType : "json",
566 );
566 success : function (data, status, xhr) {
567 that.fromJSON(data);
568 that.filename = filename;
569 that.kernel.restart();
570 }
571 };
572 $.ajax("/notebooks/" + filename, settings);
567 }
573 }
568
574
569
575
@@ -13,6 +13,7 b''
13 <!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.11.custom.css" type="text/css" /> -->
13 <!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.11.custom.css" type="text/css" /> -->
14
14
15 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" charset="utf-8"></script>
15 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" charset="utf-8"></script>
16 <!-- <script type='text/javascript' src='static/mathjax/MathJax.js?config=TeX-AMS_HTML' charset='utf-8'></script> -->
16 <script type="text/javascript">
17 <script type="text/javascript">
17 if (typeof MathJax == 'undefined') {
18 if (typeof MathJax == 'undefined') {
18 console.log("Trying to load local copy of MathJax");
19 console.log("Trying to load local copy of MathJax");
@@ -1,1 +1,1 b''
1 {"cells":[{"cell_type":"text","text":"<h1>Basic Symbolic Quantum Mechanics</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":3},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":4},{"code":"phi, psi = Ket('phi'), Ket('psi')\nalpha, beta = symbols('alpha beta', complex=True)","cell_type":"code","prompt_number":5},{"code":"state = alpha*psi + beta*phi; state\n","cell_type":"code","prompt_number":6},{"code":"ip = Dagger(state)*state; ip\n","cell_type":"code","prompt_number":7},{"code":"qapply(expand(ip))\n","cell_type":"code","prompt_number":8},{"code":"A = Operator('A')\nB = Operator('B')\nC = Operator('C')","cell_type":"code","prompt_number":9},{"code":"A*B == B*A\n","cell_type":"code","prompt_number":10},{"code":"expand((A+B)**2)","cell_type":"code","prompt_number":11},{"code":"comm = Commutator(A,B); comm\n","cell_type":"code","prompt_number":12},{"code":"comm.doit()","cell_type":"code","prompt_number":13},{"code":"comm = Commutator(A*B,B+C); comm","cell_type":"code","prompt_number":14},{"code":"comm.expand(commutator=True)","cell_type":"code","prompt_number":15},{"code":"_.doit().expand()\n","cell_type":"code","prompt_number":16},{"code":"Dagger(_)","cell_type":"code","prompt_number":17},{"code":"%notebook save basic_quantum.ipynb","cell_type":"code","prompt_number":16}]} No newline at end of file
1 {"cells":[{"cell_type":"text","text":"<h1>Basic Symbolic Quantum Mechanics</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"cell_type":"text","text":"<h2>Bras and Kets</h2>"},{"code":"phi, psi = Ket('phi'), Ket('psi')\nalpha, beta = symbols('alpha beta', complex=True)","cell_type":"code","prompt_number":3},{"code":"state = alpha*psi + beta*phi; state\n","cell_type":"code","prompt_number":4},{"code":"ip = Dagger(state)*state; ip\n","cell_type":"code","prompt_number":5},{"code":"qapply(expand(ip))\n","cell_type":"code","prompt_number":6},{"cell_type":"text","text":"<h2>Operators</h2>"},{"code":"A = Operator('A')\nB = Operator('B')\nC = Operator('C')","cell_type":"code","prompt_number":7},{"code":"A*B == B*A\n","cell_type":"code","prompt_number":8},{"code":"expand((A+B)**2)","cell_type":"code","prompt_number":9},{"code":"comm = Commutator(A,B); comm\n","cell_type":"code","prompt_number":10},{"code":"comm.doit()","cell_type":"code","prompt_number":11},{"code":"comm = Commutator(A*B,B+C); comm","cell_type":"code","prompt_number":12},{"code":"comm.expand(commutator=True)","cell_type":"code","prompt_number":13},{"code":"_.doit().expand()\n","cell_type":"code","prompt_number":14},{"code":"Dagger(_)","cell_type":"code","prompt_number":15},{"code":"%notebook save basic_quantum.ipynb","cell_type":"code","prompt_number":16},{"code":"%notebook load quantum_computing.ipynb","cell_type":"code","prompt_number":19}]} No newline at end of file
@@ -1,1 +1,1 b''
1 {"cells":[{"cell_type":"text","text":"<h1>Gate Decomposition</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"code":"CY10 = CGate(1, Y(0)); CY10\n","cell_type":"code","prompt_number":3},{"code":"CY10.decompose()\n","cell_type":"code","prompt_number":4},{"code":"circuit_plot(CY10.decompose(), nqubits=2)","cell_type":"code","prompt_number":5},{"code":"CZ01 = CGate(0, Z(1)); CZ01\n","cell_type":"code","prompt_number":6},{"code":"CZ01.decompose()\n","cell_type":"code","prompt_number":7},{"code":"circuit_plot(CZ01.decompose(), nqubits=2)","cell_type":"code","prompt_number":8},{"code":"SWAP10 = SWAP(1, 0); SWAP10\n","cell_type":"code","prompt_number":9},{"code":"SWAP10.decompose()","cell_type":"code","prompt_number":10},{"code":"circuit_plot(SWAP10.decompose(), nqubits=2)","cell_type":"code","prompt_number":11},{"code":"gates = [CGate(1,Y(0)), CGate(0,Z(1)), SWAP(1, 0)]","cell_type":"code","prompt_number":12},{"code":"for g in gates:\n dg = g.decompose()\n display(Eq(g, dg))\n circuit_plot(g, nqubits=2)\n circuit_plot(dg, nqubits=2) ","cell_type":"code","prompt_number":16},{"code":"%notebook save decomposition.ipynb","cell_type":"code","prompt_number":30}]} No newline at end of file
1 {"cells":[{"cell_type":"text","text":"<h1>Gate Decomposition</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":2},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":3},{"cell_type":"text","text":"<h2>Example 1</h2>"},{"code":"CY10 = CGate(1, Y(0)); CY10\n","cell_type":"code","prompt_number":4},{"code":"CY10.decompose()\n","cell_type":"code","prompt_number":5},{"code":"circuit_plot(CY10.decompose(), nqubits=2)","cell_type":"code","prompt_number":6},{"cell_type":"text","text":"<h2>Example 2</h2>"},{"code":"CZ01 = CGate(0, Z(1)); CZ01\n","cell_type":"code","prompt_number":7},{"code":"CZ01.decompose()\n","cell_type":"code","prompt_number":8},{"code":"circuit_plot(CZ01.decompose(), nqubits=2)","cell_type":"code","prompt_number":9},{"cell_type":"text","text":"<h2>Example 3</h2>"},{"code":"SWAP10 = SWAP(1, 0); SWAP10\n","cell_type":"code","prompt_number":10},{"code":"SWAP10.decompose()","cell_type":"code","prompt_number":11},{"code":"circuit_plot(SWAP10.decompose(), nqubits=2)","cell_type":"code","prompt_number":12},{"cell_type":"text","text":"<h2>All together now</h2>"},{"code":"gates = [CGate(1,Y(0)), CGate(0,Z(1)), SWAP(1, 0)]","cell_type":"code","prompt_number":13},{"code":"for g in gates:\n dg = g.decompose()\n display(Eq(g, dg))\n circuit_plot(g, nqubits=2)\n circuit_plot(dg, nqubits=2) ","cell_type":"code","prompt_number":14},{"code":"%notebook save decompose.ipynb","cell_type":"code","prompt_number":30}]} No newline at end of file
@@ -1,1 +1,1 b''
1 {"cells":[{"cell_type":"text","text":"<h1>Dense Coding\n</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":2},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":3},{"code":"psi = Qubit('00')/sqrt(2) + Qubit('11')/sqrt(2); psi\n","cell_type":"code","prompt_number":4},{"code":"circuits = [H(1)*CNOT(1,0), H(1)*CNOT(1,0)*X(1), H(1)*CNOT(1,0)*Z(1), H(1)*CNOT(1,0)*Z(1)*X(1)]","cell_type":"code","prompt_number":20},{"code":"for circuit in circuits:\n circuit_plot(circuit, nqubits=2)\n display(Eq(circuit*psi,qapply(circuit*psi)))","cell_type":"code","prompt_number":21},{"code":"%notebook save dense_coding.ipynb","cell_type":"code","prompt_number":28}]} No newline at end of file
1 {"cells":[{"cell_type":"text","text":"<h1>Dense Coding\n</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"code":"psi = Qubit('00')/sqrt(2) + Qubit('11')/sqrt(2); psi\n","cell_type":"code","prompt_number":3},{"code":"circuits = [H(1)*CNOT(1,0), H(1)*CNOT(1,0)*X(1), H(1)*CNOT(1,0)*Z(1), H(1)*CNOT(1,0)*Z(1)*X(1)]","cell_type":"code","prompt_number":4},{"code":"for circuit in circuits:\n circuit_plot(circuit, nqubits=2)\n display(Eq(circuit*psi,qapply(circuit*psi)))","cell_type":"code","prompt_number":5},{"code":"%notebook save dense_coding.ipynb","cell_type":"code","prompt_number":28},{"code":"%notebook load teleportation.ipynb","cell_type":"code","prompt_number":181}]} No newline at end of file
@@ -1,1 +1,1 b''
1 {"cells":[{"cell_type":"text","text":"<h1>Grover's Algorithm</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"code":"nqubits = 3\n","cell_type":"code","prompt_number":4},{"code":"def black_box(qubits):\n return True if qubits == IntQubit(1, qubits.nqubits) else False\n","cell_type":"code","prompt_number":3},{"code":"psi = superposition_basis(nqubits); psi\n","cell_type":"code","prompt_number":5},{"code":"v = OracleGate(nqubits, black_box)\n","cell_type":"code","prompt_number":6},{"code":"iter1 = qapply(grover_iteration(psi, v)); iter1\n","cell_type":"code","prompt_number":7},{"code":"iter2 = qapply(grover_iteration(iter1, v)); iter2\n","cell_type":"code","prompt_number":8},{"code":"measure_all_oneshot(iter2)\n","cell_type":"code","prompt_number":12},{"code":"%notebook save grovers.ipynb","cell_type":"code","prompt_number":28}]} No newline at end of file
1 {"cells":[{"cell_type":"text","text":"<h1>Grover's Algorithm</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"code":"nqubits = 3\n","cell_type":"code","prompt_number":3},{"cell_type":"text","text":"Define a black box function that returns True if it is passed the state we are searching for."},{"code":"def black_box(qubits):\n return True if qubits == IntQubit(1, qubits.nqubits) else False\n","cell_type":"code","prompt_number":4},{"cell_type":"text","text":"Build a uniform superposition state to start the search."},{"code":"psi = superposition_basis(nqubits); psi\n","cell_type":"code","prompt_number":5},{"cell_type":"text","text":"Wrap that black box function in an oracle gate."},{"code":"v = OracleGate(nqubits, black_box)\n","cell_type":"code","prompt_number":6},{"cell_type":"text","text":"Perform two iterations of Grover's algorithm. Each iteration, the amplitude of the target state increases."},{"code":"iter1 = qapply(grover_iteration(psi, v)); iter1\n","cell_type":"code","prompt_number":7},{"code":"iter2 = qapply(grover_iteration(iter1, v)); iter2\n","cell_type":"code","prompt_number":8},{"cell_type":"text","text":"A single shot measurement is performed to retrieve the target state."},{"code":"measure_all_oneshot(iter2)\n","cell_type":"code","prompt_number":9},{"code":"%notebook save grovers.ipynb","cell_type":"code","prompt_number":28},{"code":"%notebook load qft.ipynb","cell_type":"code","prompt_number":63}]} No newline at end of file
@@ -1,1 +1,1 b''
1 {"cells":[{"cell_type":"text","text":"<h1>Quantum Error Correction</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"code":"M0 = Z(1)*X(2)*X(3)*Z(4); M0\n","cell_type":"code","prompt_number":3},{"code":"M1 = Z(2)*X(3)*X(4)*Z(0); M1\n","cell_type":"code","prompt_number":4},{"code":"M2 = Z(3)*X(4)*X(0)*Z(1); M2\n","cell_type":"code","prompt_number":5},{"code":"M3 = Z(4)*X(0)*X(1)*Z(2); M3\n","cell_type":"code","prompt_number":6},{"code":"gate_simp(Commutator(M0,M1).doit())\n","cell_type":"code","prompt_number":7},{"code":"for o in [M0,M1,M2,M3]:\n display(gate_simp(o*o))\n","cell_type":"code","prompt_number":8},{"code":"zero = Rational(1,4)*(1+M0)*(1+M1)*(1+M2)*(1+M3)*IntQubit(0, 5); zero\n","cell_type":"code","prompt_number":9},{"code":"qapply(4*zero)\n","cell_type":"code","prompt_number":10},{"code":"one = Rational(1,4)*(1+M0)*(1+M1)*(1+M2)*(1+M3)*IntQubit(2**5-1, 5); one\n","cell_type":"code","prompt_number":11},{"code":"qapply(4*one)\n","cell_type":"code","prompt_number":12},{"code":"encoding_circuit = H(3)*H(4)*CNOT(2,0)*CNOT(3,0)*CNOT(4,0)*H(1)*H(4)*\\\n CNOT(2,1)*CNOT(4,1)*H(2)*CNOT(3,2)*CNOT(4,2)*H(3)*\\\n H(4)*CNOT(4, 3)*Z(4)*H(4)*Z(4)\n","cell_type":"code","prompt_number":13},{"code":"circuit_plot(encoding_circuit, nqubits=5, scale=0.5)","cell_type":"code","prompt_number":14},{"code":"represent(4*encoding_circuit, nqubits=5)","cell_type":"code","prompt_number":16},{"code":"%notebook save qerror.ipynb","cell_type":"code","prompt_number":23},{"code":"","cell_type":"code","prompt_number":23}]} No newline at end of file
1 {"cells":[{"cell_type":"text","text":"<h1>Quantum Error Correction</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":2},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":3},{"cell_type":"text","text":"<h2>5 qubit code</h2>"},{"code":"M0 = Z(1)*X(2)*X(3)*Z(4); M0\n","cell_type":"code","prompt_number":4},{"code":"M1 = Z(2)*X(3)*X(4)*Z(0); M1\n","cell_type":"code","prompt_number":5},{"code":"M2 = Z(3)*X(4)*X(0)*Z(1); M2\n","cell_type":"code","prompt_number":6},{"code":"M3 = Z(4)*X(0)*X(1)*Z(2); M3\n","cell_type":"code","prompt_number":7},{"cell_type":"text","text":"These operators should mutually commute."},{"code":"gate_simp(Commutator(M0,M1).doit())\n","cell_type":"code","prompt_number":7},{"cell_type":"text","text":"And square to the identity."},{"code":"for o in [M0,M1,M2,M3]:\n display(gate_simp(o*o))\n","cell_type":"code","prompt_number":8},{"cell_type":"text","text":"<h2>Codewords</h2>"},{"code":"zero = Rational(1,4)*(1+M0)*(1+M1)*(1+M2)*(1+M3)*IntQubit(0, 5); zero\n","cell_type":"code","prompt_number":8},{"code":"qapply(4*zero)\n","cell_type":"code","prompt_number":9},{"code":"one = Rational(1,4)*(1+M0)*(1+M1)*(1+M2)*(1+M3)*IntQubit(2**5-1, 5); one\n","cell_type":"code","prompt_number":10},{"code":"qapply(4*one)\n","cell_type":"code","prompt_number":11},{"cell_type":"text","text":"<h2>The encoding circuit</h2>"},{"code":"encoding_circuit = H(3)*H(4)*CNOT(2,0)*CNOT(3,0)*CNOT(4,0)*H(1)*H(4)*\\\n CNOT(2,1)*CNOT(4,1)*H(2)*CNOT(3,2)*CNOT(4,2)*H(3)*\\\n H(4)*CNOT(4, 3)*Z(4)*H(4)*Z(4)\n","cell_type":"code","prompt_number":12},{"code":"circuit_plot(encoding_circuit, nqubits=5, scale=0.5)","cell_type":"code","prompt_number":13},{"code":"represent(4*encoding_circuit, nqubits=5)","cell_type":"code","prompt_number":14},{"code":"%notebook save qerror.ipynb","cell_type":"code","prompt_number":23},{"code":"%notebook load decompose.ipynb","cell_type":"code","prompt_number":23}]} No newline at end of file
@@ -1,1 +1,1 b''
1 {"cells":[{"cell_type":"text","text":"<h1>Teleportation</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"code":"fourier = QFT(0,3).decompose(); fourier\n","cell_type":"code","prompt_number":3},{"code":"circuit_plot(fourier, nqubits=3)","cell_type":"code","prompt_number":4},{"code":"m = represent(fourier, nqubits=3)","cell_type":"code","prompt_number":12},{"code":"m","cell_type":"code","prompt_number":13},{"code":"represent(Fourier(0,3), nqubits=3)*4/sqrt(2)\n","cell_type":"code","prompt_number":5},{"code":"state = (Qubit('000') + Qubit('010') + Qubit('100') + Qubit('110'))/sqrt(4); state\n","cell_type":"code","prompt_number":6},{"code":"qapply(fourier*state)\n","cell_type":"code","prompt_number":7},{"code":"%notebook save qft.ipynb","cell_type":"code","prompt_number":23}]} No newline at end of file
1 {"cells":[{"cell_type":"text","text":"<h1>Quantum Fourier Transform</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"cell_type":"text","text":"<h2>QFT Gate and Circuit</h2>"},{"cell_type":"text","text":"Build a 3 qubit QFT and decompose it into primitive gates."},{"code":"fourier = QFT(0,3).decompose(); fourier\n","cell_type":"code","prompt_number":3},{"code":"circuit_plot(fourier, nqubits=3)","cell_type":"code","prompt_number":4},{"cell_type":"text","text":"The QFT circuit can be represented in various symbolic forms."},{"code":"m = represent(fourier, nqubits=3)","cell_type":"code","prompt_number":5},{"code":"m","cell_type":"code","prompt_number":6},{"code":"represent(Fourier(0,3), nqubits=3)*4/sqrt(2)\n","cell_type":"code","prompt_number":7},{"cell_type":"text","text":"<h2>QFT in Action</h2>"},{"cell_type":"text","text":"Build a 3 qubit state to take the QFT of."},{"code":"state = (Qubit('000') + Qubit('010') + Qubit('100') + Qubit('110'))/sqrt(4); state\n","cell_type":"code","prompt_number":8},{"cell_type":"text","text":"Perform the QFT."},{"code":"qapply(fourier*state)\n","cell_type":"code","prompt_number":9},{"code":"%notebook save qft.ipynb","cell_type":"code","prompt_number":23},{"code":"%notebook load qerror.ipynb","cell_type":"code","prompt_number":207}]} No newline at end of file
@@ -1,1 +1,1 b''
1 {"cells":[{"cell_type":"text","text":"<h1>Symbolic Quantum Computing</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"code":"alpha, beta = symbols('alpha beta',real=True)","cell_type":"code","prompt_number":3},{"code":"psi = alpha*Qubit('00') + beta*Qubit('11'); psi\n","cell_type":"code","prompt_number":4},{"code":"Dagger(psi)\n","cell_type":"code","prompt_number":5},{"code":"qapply(Dagger(Qubit('00'))*psi)\n","cell_type":"code","prompt_number":6},{"code":"for state, prob in measure_all(psi):\n display(state)\n display(prob)\n","cell_type":"code","prompt_number":7},{"code":"represent(psi, nqubits=2)\n","cell_type":"code","prompt_number":8},{"code":"g = X(0); g\n","cell_type":"code","prompt_number":9},{"code":"represent(g, nqubits=2)\n","cell_type":"code","prompt_number":10},{"code":"c = H(0)*Qubit('00'); c\n","cell_type":"code","prompt_number":11},{"code":"qapply(c)\n","cell_type":"code","prompt_number":12},{"code":"for g1 in (Y,Z,H):\n for g2 in (Y,Z,H):\n e = Commutator(g1(0),g2(0))\n if g1 != g2:\n display(Eq(e,e.doit()))\n","cell_type":"code","prompt_number":13},{"code":"c = H(0)*X(1)*H(0)**2*CNOT(0,1)*X(1)**3*X(0)*Z(2)**2*S(3)**3; c\n","cell_type":"code","prompt_number":14},{"code":"circuit_plot(c, nqubits=4)","cell_type":"code","prompt_number":15},{"code":"gate_simp(c)\n","cell_type":"code","prompt_number":16},{"code":"circuit_plot(gate_simp(c),nqubits=5)","cell_type":"code","prompt_number":17},{"code":"%notebook save quantum_computing.ipynb","cell_type":"code","prompt_number":35}]} No newline at end of file
1 {"cells":[{"cell_type":"text","text":"<h1>Symbolic Quantum Computing</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"cell_type":"text","text":"<h2>Qubits</h2>"},{"code":"alpha, beta = symbols('alpha beta',real=True)","cell_type":"code","prompt_number":3},{"code":"psi = alpha*Qubit('00') + beta*Qubit('11'); psi\n","cell_type":"code","prompt_number":4},{"code":"Dagger(psi)\n","cell_type":"code","prompt_number":5},{"code":"qapply(Dagger(Qubit('00'))*psi)\n","cell_type":"code","prompt_number":6},{"cell_type":"text","text":"SymPy supports many different types of measurements."},{"code":"for state, prob in measure_all(psi):\n display(state)\n display(prob)\n","cell_type":"code","prompt_number":7},{"cell_type":"text","text":"Qubits can be represented in the computational basis."},{"code":"represent(psi)\n","cell_type":"code","prompt_number":8},{"cell_type":"text","text":"<h2>Gates</h2>"},{"code":"g = X(0); g\n","cell_type":"code","prompt_number":9},{"code":"represent(g, nqubits=2)\n","cell_type":"code","prompt_number":10},{"code":"c = H(0)*Qubit('00'); c\n","cell_type":"code","prompt_number":11},{"code":"qapply(c)\n","cell_type":"code","prompt_number":12},{"cell_type":"text","text":"<h2>Symbolic gate rules and circuit simplification</h2>"},{"code":"for g1 in (Y,Z,H):\n for g2 in (Y,Z,H):\n e = Commutator(g1(0),g2(0))\n if g1 != g2:\n display(Eq(e,e.doit()))\n","cell_type":"code","prompt_number":13},{"code":"c = H(0)*X(1)*H(0)**2*CNOT(0,1)*X(1)**3*X(0)*Z(1)**2; c\n","cell_type":"code","prompt_number":15},{"code":"circuit_plot(c, nqubits=2)","cell_type":"code","prompt_number":16},{"cell_type":"text","text":"This performs a commutator/anticommutator aware bubble sort algorithm to simplify a circuit."},{"code":"gate_simp(c)\n","cell_type":"code","prompt_number":17},{"code":"circuit_plot(gate_simp(c),nqubits=2)","cell_type":"code","prompt_number":18},{"code":"%notebook save quantum_computing.ipynb","cell_type":"code","prompt_number":35},{"code":"%notebook load grovers.ipynb","cell_type":"code","prompt_number":90}]} No newline at end of file
@@ -1,1 +1,1 b''
1 {"cells":[{"cell_type":"text","text":"<h1>Teleportation</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"code":"a,b = symbols('ab', real=True)\nstate = Qubit('000')*a + Qubit('001')*b; state","cell_type":"code","prompt_number":3},{"code":"entangle1_2 = CNOT(1,2)*HadamardGate(1); entangle1_2\n","cell_type":"code","prompt_number":4},{"code":"state = qapply(entangle1_2*state); state\n","cell_type":"code","prompt_number":5},{"code":"entangle0_1 = HadamardGate(0)*CNOT(0,1); entangle0_1\n","cell_type":"code","prompt_number":6},{"code":"circuit_plot(entangle0_1*entangle1_2, nqubits=3)\n","cell_type":"code","prompt_number":7},{"code":"state = qapply(entangle0_1*state); state\n","cell_type":"code","prompt_number":8},{"code":"result = measure_partial(state, (0,1))\n","cell_type":"code","prompt_number":10},{"code":"state = (result[2][0]*2).expand(); state","cell_type":"code","prompt_number":11},{"code":"state = qapply(XGate(2)*state); state\n","cell_type":"code","prompt_number":12},{"code":"%notebook save teleportation.ipynb","cell_type":"code","prompt_number":13},{"code":"","cell_type":"code","prompt_number":18}]} No newline at end of file
1 {"cells":[{"cell_type":"text","text":"<h1>Teleportation</h1>"},{"code":"%load_ext sympy_printing","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"code":"a,b = symbols('ab', real=True)\nstate = Qubit('000')*a + Qubit('001')*b; state","cell_type":"code","prompt_number":3},{"code":"entangle1_2 = CNOT(1,2)*HadamardGate(1); entangle1_2\n","cell_type":"code","prompt_number":4},{"code":"state = qapply(entangle1_2*state); state\n","cell_type":"code","prompt_number":5},{"code":"entangle0_1 = HadamardGate(0)*CNOT(0,1); entangle0_1\n","cell_type":"code","prompt_number":6},{"code":"circuit_plot(entangle0_1*entangle1_2, nqubits=3)\n","cell_type":"code","prompt_number":7},{"code":"state = qapply(entangle0_1*state); state\n","cell_type":"code","prompt_number":8},{"code":"result = measure_partial(state, (0,1))\n","cell_type":"code","prompt_number":10},{"code":"state = (result[2][0]*2).expand(); state","cell_type":"code","prompt_number":11},{"code":"state = qapply(XGate(2)*state); state\n","cell_type":"code","prompt_number":12},{"code":"%notebook save teleportation.ipynb","cell_type":"code","prompt_number":13},{"code":"%notebook load qft.ipynb","cell_type":"code","prompt_number":18}]} No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now