{"cells":[{"cell_type":"text","text":"

Symbolic Quantum Computing

"},{"code":"%load_ext sympyprinting","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":"

Qubits

"},{"cell_type":"text","text":"The state of a set of qubits (Two state systems) is the quantum state that is of interest in Quantum Computing."},{"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":"

Gates

"},{"cell_type":"text","text":"Gate objects are the operators which act on a quantum state."},{"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 gate in [H,X,Y,Z,S,T]:\n for state in [Qubit('0'),Qubit('1')]:\n lhs = gate(0)*state\n rhs = qapply(lhs)\n display(Eq(lhs,rhs))","cell_type":"code","prompt_number":13},{"cell_type":"text","text":"

Symbolic gate rules and circuit simplification

"},{"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(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}]}