Loading [Contrib]/a11y/accessibility-menu.js
##// END OF EJS Templates
Adding new notebook examples....
r4328:7877585c
Show More
quantum_computing.ipynb
1 line | 2.0 KiB | text/plain | TextLexer

Symbolic Quantum Computing

In [2]:
%load_ext sympy_printing
In [3]:
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
In [4]:
alpha, beta = symbols('alpha beta',real=True)
In [5]:
psi = alpha*Qubit('00') + beta*Qubit('11'); psi
In [6]:
Dagger(psi)
In [7]:
qapply(Dagger(Qubit('00'))*psi)
In [8]:
for state, prob in measure_all(psi):
    display(state)
    display(prob)
In [9]:
represent(psi, nqubits=2)
In [10]:
g = X(0); g
In [11]:
represent(g, nqubits=2)
In [12]:
c = H(0)*Qubit('00'); c
In [13]:
qapply(c)
In [14]:
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()))
In [24]:
c = H(0)*X(1)*H(0)**2*CNOT(0,1)*X(1)**3*X(0)*Z(2)**2*S(3)**3; c
In [25]:
circuit_plot(c, nqubits=4)
In [16]:
gate_simp(c)
In [23]:
circuit_plot(gate_simp(c),nqubits=5)
In [35]:
%notebook save quantum_computing.ipynb