#!/usr/bin/env python # coding: utf-8 # # Examples For `sympy.physics.quantum` Section # In[1]: get_ipython().run_line_magic('matplotlib', 'inline') from matplotlib import pyplot as plt # In[2]: from sympy.physics.quantum import Commutator, Dagger, Operator, Ket, qapply A = Operator('A') B = Operator('B') C = Operator('C') D = Operator('D') a = Ket('a') comm = Commutator(A, B) comm # In[3]: qapply(Dagger(comm*a)).doit() # In[4]: Commutator(C+B, A*D).expand(commutator=True) # In[5]: from sympy.physics.quantum.qubit import Qubit q = Qubit('0101') q # In[6]: q.flip(1) # In[7]: Dagger(q) # In[8]: ip = Dagger(q)*q ip # In[9]: ip.doit() # In[10]: from sympy.physics.quantum.qubit import Qubit, measure_all from sympy.physics.quantum.gate import H, X, Y, Z from sympy.physics.quantum.qapply import qapply c = H(0)*H(1)*Qubit('00') c # In[11]: q = qapply(c) measure_all(q) # In[12]: from sympy.physics.quantum.qft import QFT from sympy.physics.quantum.circuitplot import circuit_plot # In[13]: fourier = QFT(0,3).decompose() fourier # In[14]: circuit_plot(fourier, nqubits=3); plt.savefig('./images/circuitplot-qft.pdf', format='pdf')