basic_quantum.ipynb
401 lines
| 34.0 KiB
| text/plain
|
TextLexer
Basic Symbolic Quantum Mechanics
In [18]:
%load_ext sympyprinting
In [19]:
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 [20]:
phi, psi = Ket('phi'), Ket('psi')
alpha, beta = symbols('alpha beta', complex=True)
Create a superposition
In [21]:
state = alpha*psi + beta*phi; state
Out[21]:
Dagger the superposition and multiply the original
In [22]:
ip = Dagger(state)*state; ip
Out[22]:
Distribute
In [23]:
qapply(expand(ip))
Out[23]:
Operators
Create symbolic operators
In [24]:
A = Operator('A')
B = Operator('B')
C = Operator('C')
Test commutativity
In [25]:
A*B == B*A
Out[25]:
Distribute A+B squared
In [26]:
expand((A+B)**2)
Out[26]:
Create a commutator
In [27]:
comm = Commutator(A,B); comm
Out[27]:
Carry out the commutator
In [28]:
comm.doit()
Out[28]:
Create a more fancy commutator
In [29]:
comm = Commutator(A*B,B+C); comm
Out[29]:
Expand the commutator
In [30]:
comm.expand(commutator=True)
Out[30]:
Carry out and expand the commutators
In [31]:
_.doit().expand()
Out[31]:
Take the dagger
In [32]:
Dagger(_)
Out[32]: