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

File last commit:

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

Symbolic Quantum Computing

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

Qubits

The state of a set of qubits (Two state systems) is the quantum state that is of interest in Quantum Computing.

In [3]:
alpha, beta = symbols('alpha beta',real=True)
In [4]:
psi = alpha*Qubit('00') + beta*Qubit('11'); psi
In [5]:
Dagger(psi)
In [6]:
qapply(Dagger(Qubit('00'))*psi)

SymPy supports many different types of measurements.

In [7]:
for state, prob in measure_all(psi):
    display(state)
    display(prob)

Qubits can be represented in the computational basis.

In [8]:
represent(psi)

Gates

Gate objects are the operators which act on a quantum state.

In [9]:
g = X(0); g
In [10]:
represent(g, nqubits=2)
In [11]:
c = H(0)*Qubit('00'); c
In [12]:
qapply(c)
In [13]:
for gate in [H,X,Y,Z,S,T]:
    for state in [Qubit('0'),Qubit('1')]:
        lhs = gate(0)*state
        rhs = qapply(lhs)
        display(Eq(lhs,rhs))

Symbolic gate rules and circuit simplification

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 [15]:
c = H(0)*X(1)*H(0)**2*CNOT(0,1)*X(1)**3*X(0)*Z(1)**2; c
In [16]:
circuit_plot(c, nqubits=2)

This performs a commutator/anticommutator aware bubble sort algorithm to simplify a circuit.

In [17]:
gate_simp(c)
In [18]:
circuit_plot(gate_simp(c),nqubits=2)
In [35]:
%notebook save quantum_computing.ipynb
In [90]:
%notebook load grovers.ipynb