Symbolic Quantum Computing
%load_ext sympyprinting
from sympy import sqrt, symbols, Rational
from sympy import expand, Eq, Symbol, simplify, exp, sin
from sympy.physics.quantum import *
from sympy.physics.quantum.qubit import *
from sympy.physics.quantum.gate import *
from sympy.physics.quantum.grover import *
from sympy.physics.quantum.qft import QFT, IQFT, Fourier
from sympy.physics.quantum.circuitplot import circuit_plot
Qubits
The state of a set of qubits (Two state systems) is the quantum state that is of interest in Quantum Computing.
alpha, beta = symbols('alpha beta',real=True)
psi = alpha*Qubit('00') + beta*Qubit('11'); psi
Dagger(psi)
qapply(Dagger(Qubit('00'))*psi)
SymPy supports many different types of measurements.
for state, prob in measure_all(psi):
display(state)
display(prob)
Qubits can be represented in the computational basis.
represent(psi)
Gates
Gate objects are the operators which act on a quantum state.
g = X(0); g
represent(g, nqubits=2)
c = H(0)*Qubit('00'); c
qapply(c)
for gate in [H,X,Y,Z,S,T]:
for state in [Qubit('0'),Qubit('1')]:
lhs = gate(0)*state
rhs = qapply(lhs)
display(Eq(lhs,rhs))
Symbolic gate rules and circuit simplification
for g1 in (Y,Z,H):
for g2 in (Y,Z,H):
e = Commutator(g1(0),g2(0))
if g1 != g2:
display(Eq(e,e.doit()))
c = H(0)*X(1)*H(0)**2*CNOT(0,1)*X(1)**3*X(0)*Z(1)**2; c
circuit_plot(c, nqubits=2)
This performs a commutator/anticommutator aware bubble sort algorithm to simplify a circuit.
gate_simp(c)
circuit_plot(gate_simp(c),nqubits=2)
%notebook save quantum_computing.ipynb
%notebook load grovers.ipynb