##// END OF EJS Templates
Minor changes to text_analysis notebook example.
Brian Granger -
Show More
@@ -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":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":"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},{"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}]} 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":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,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":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":"alpha, beta = symbols('alpha beta',real=True)","cell_type":"code","prompt_number":4},{"code":"psi = alpha*Qubit('00') + beta*Qubit('11'); psi\n","cell_type":"code","prompt_number":5},{"code":"Dagger(psi)\n","cell_type":"code","prompt_number":6},{"code":"qapply(Dagger(Qubit('00'))*psi)\n","cell_type":"code","prompt_number":7},{"code":"for state, prob in measure_all(psi):\n display(state)\n display(prob)\n","cell_type":"code","prompt_number":8},{"code":"represent(psi, nqubits=2)\n","cell_type":"code","prompt_number":9},{"code":"g = X(0); g\n","cell_type":"code","prompt_number":10},{"code":"represent(g, nqubits=2)\n","cell_type":"code","prompt_number":11},{"code":"c = H(0)*Qubit('00'); c\n","cell_type":"code","prompt_number":12},{"code":"qapply(c)\n","cell_type":"code","prompt_number":13},{"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":14},{"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":24},{"code":"circuit_plot(c, nqubits=4)","cell_type":"code","prompt_number":25},{"code":"gate_simp(c)\n","cell_type":"code","prompt_number":16},{"code":"circuit_plot(gate_simp(c),nqubits=5)","cell_type":"code","prompt_number":23},{"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},{"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
@@ -258,7 +258,8 b' def plot_graph(wgraph, pos=None):'
258 width = rescale_arr(np.array(width, dtype=float), 1, 15)
258 width = rescale_arr(np.array(width, dtype=float), 1, 15)
259
259
260 # Create figure
260 # Create figure
261 fig, ax = plt.subplots()
261 fig = plt.figure()
262 ax = fig.add_subplot(111)
262 fig.subplots_adjust(0,0,1)
263 fig.subplots_adjust(0,0,1)
263 nx.draw_networkx_nodes(wgraph, pos, node_size=sizes, node_color=degrees,
264 nx.draw_networkx_nodes(wgraph, pos, node_size=sizes, node_color=degrees,
264 alpha=0.8)
265 alpha=0.8)
@@ -289,7 +290,9 b' def plot_word_histogram(freqs, show=10, title=None):'
289 words = [i[0] for i in show_f]
290 words = [i[0] for i in show_f]
290 counts = [i[1] for i in show_f]
291 counts = [i[1] for i in show_f]
291
292
292 fig, ax = plt.subplots()
293 fig = plt.figure()
294 ax = fig.add_subplot(111)
295
293 if n_words<=20:
296 if n_words<=20:
294 # Only show bars and x labels for small histograms, they don't make
297 # Only show bars and x labels for small histograms, they don't make
295 # sense otherwise
298 # sense otherwise
General Comments 0
You need to be logged in to leave comments. Login now