##// END OF EJS Templates
Much improved nagivation for the notebook cells....
Much improved nagivation for the notebook cells. * Up/Down arrow now used to navigate cells. * For text cells, shift-enter renders, enter edits.

File last commit:

r4330:264b061c
r4334:c14e6511
Show More
grovers.ipynb
1 line | 1.9 KiB | text/plain | TextLexer
Brian Granger
Updating notebook examples, and notebook js/html.
r4330 {"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}]}