Symbolic Density Matrices
%load_ext sympyprinting
from sympy import sqrt, symbols, Rational, S
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
from sympy.physics.quantum.densityOp import *
Density Operators are used to represent systems which has both classical mixtures as well as quantum superpositions.
state = Density([Qubit('00'),0.5],[(Qubit('00')+Qubit('11'))/sqrt(2),0.5]); state
In addition to Dirac notation, code can represent the state as a matrix.
represent(state, nqubits=2)
Gate operators can be applied to density operators.
qapply(state.operate_on(HadamardGate(0)))
Von Neumann Entropy can be calculated.
state.entropy(nqubits=2)
Density([Qubit('00'),1]).entropy(nqubits=2)
We can also create symbolic states.
genState = Density([Ket('psi'),.5],[Ket('phi'),.5]); genState
%notebook save density_matrix.ipynb
%notebook load qerror.ipynb