##// END OF EJS Templates
Updating examples notebooks.
Updating examples notebooks.

File last commit:

r4337:0f16a103
r4337:0f16a103
Show More
density_matrix.ipynb
1 line | 1.8 KiB | text/plain | TextLexer

Symbolic Density Matrices

In [1]:
%load_ext sympyprinting
In [2]:
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.

In [3]:
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.

In [4]:
represent(state, nqubits=2)

Gate operators can be applied to density operators.

In [5]:
qapply(state.operate_on(HadamardGate(0)))

Von Neumann Entropy can be calculated.

In [6]:
state.entropy(nqubits=2)
In [7]:
Density([Qubit('00'),1]).entropy(nqubits=2)

We can also create symbolic states.

In [8]:
genState = Density([Ket('psi'),.5],[Ket('phi'),.5]); genState
In [16]:
%notebook save density_matrix.ipynb
In [19]:
%notebook load qerror.ipynb