sympy_quantum_computing.ipynb
409 lines
| 26.9 KiB
| text/plain
|
TextLexer
In [1]:
%load_ext sympyprinting
In [2]:
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
Bras and Kets
Create symbolic states
In [3]:
phi, psi = Ket('phi'), Ket('psi')
alpha, beta = symbols('alpha beta', complex=True)
Create a superposition
In [4]:
state = alpha*psi + beta*phi; state
Out[4]:
Dagger the superposition and multiply the original
In [5]:
ip = Dagger(state)*state; ip
Out[5]:
Distribute
In [6]:
qapply(expand(ip))
Out[6]:
Operators
Create symbolic operators
In [7]:
A = Operator('A')
B = Operator('B')
C = Operator('C')
Test commutativity
In [8]:
A*B == B*A
Out[8]:
Distribute A+B squared
In [9]:
expand((A+B)**2)
Out[9]:
Create a commutator
In [10]:
comm = Commutator(A,B); comm
Out[10]:
Carry out the commutator
In [11]:
comm.doit()
Out[11]:
Create a more fancy commutator
In [12]:
comm = Commutator(A*B,B+C); comm
Out[12]:
Expand the commutator
In [13]:
comm.expand(commutator=True)
Out[13]:
Carry out and expand the commutators
In [14]:
_.doit().expand()
Out[14]:
Take the dagger
In [15]:
Dagger(_)
Out[15]: