%matplotlib inline
from IPython.display import display
from sympy import init_printing
init_printing(use_latex=True)
from sympy import sqrt, symbols, Rational
from sympy import expand, Eq, Symbol, simplify, exp, sin, srepr
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
alpha, beta = symbols('alpha beta', real=True)
psi = alpha*Qubit('00') + beta*Qubit('11'); psi
Dagger(psi)
qapply(Dagger(Qubit('00'))*psi)
for state, prob in measure_all(psi):
display(state)
display(prob)
Qubits can be represented in the computational basis.
represent(psi)
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))
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)
<sympy.physics.quantum.circuitplot.CircuitPlot at 0x110567940>