Professional Documents
Culture Documents
Undergraduate Quantum Mechanics: A Numerical Approach Using Qutip
Undergraduate Quantum Mechanics: A Numerical Approach Using Qutip
I. INTRODUCTION
between these topics.
Quantum mechanics has undergone substantial ped- Photon polarization states are represented by vectors
agogical evolution in response to Physics Education in an 2-dimensional space. Starting with small vectors
Research (PER) results and advances in laboratory and matrices allows simultaneous calculation by-hand
technology.1 The development of a specialized framework and via computer. In the context of teaching, this is
for computational calculation in quantum mechanics pro- useful for verification during the orientation phase and
vides a valuable addition that we encourage instructors to catch numerical errors while students learn a new sys-
to add to their courses. Our goal is to present several tem. Later, students develop their own habits of verifica-
ways computational techniques can be added to existing tion and learn ways to check their work for larger Hilbert
courses in quantum mechanics. A distinct advantage of spaces.
this approach is that the computational framework in- Python is an object-oriented language which for our
cludes research-grade tools that enable advanced prob- purposes means that quantum states are represented by
lem solving for senior undergraduates and even graduate an object. Other pre-defeined functions can operate on
students. these objects, and we can define our own operations as
We note that this approach may be most natural for discussed below. The most fundamental object in QuTiP
courses that emphasize matrix mechanics early in the is the Qobj. Instances of Qobj have many useful prop-
course as vector and matrix methods are the most nat- erties. Primarily, they are a matrix (or vector) imple-
ural representations in numerical work. The order of mented efficiently in Python. The features most relevant
the specific examples presented here follows the textbook to this work are the indication of their status as either
Quantum Mechanics: Theory and Experiment by Mark bra or ket, and whether they are Hermitian operators
Beck1 which starts with photon polarization states and or not. We will not make much use of the other prop-
spin states then moves to one-dimensional potentials and erties, and for the most part, these properties are used
time dependent states. Many courses follow a similar internally for type-checking and other verification. Sev-
progression, and the tools we describe are useful in other eral important functions create frequently-used quantum
contexts as well. Even a course starting with wave me- objects. One of the most fundamental functions creates
chanics can make use of these examples once spin states basis vectors. The function basis takes a dimension, N ,
and matrix methods are introduced. and an index as its arguments. For two-state systems,
We present results using a specific computational N = 2 and we have two basis vectors: basis(2,0) and
framework called QuTiP (the Quantum Toolbox in 1
basis(2,1) which represent the column vectors and
Python). The QuTiP computational framework was re- 0
leased in 2011 with additional versions and updates in 0
respectively.6 We demonstrate these and many other
the years following.2,3 The examples here have been de- 1
veloped using version 4.2. In addition to QuTiP, we rec- features in the following sections.
ommend using Jupyter notebooks which provide an inter- Before presenting sample code, it is important to
active python computing environment.4,5 The notebook note that while a stock python environment is quite
interface allows instructors to create interactive lessons functional, it does not include some features we use
and for students to document their work in-place. throughout the following examples. To add these fea-
tures, we import from the qutip, numpy, and matplotlib
packages:7–9
II. PHOTON POLARIZATION STATES
Listing 1. Module imports used for code samples presented.
Our first example system uses photon polarization from qutip import *
states in parallel with the text and associated experi- from numpy import sqrt, pi, array, sin, cos, arange
ments presented by Beck.1 Given the similarity of the ma- import matplotlib.pyplot as plt
trix representation of all two-state systems, users benefit %matplotlib inline
2
The last line is only useful in a Jupyter Notebooks, it of a polarization state by a given angle. Defined as
enables inline figures.
For a two-level system, the basis states themselves can cos θ − sin θ
R̂p (θ) = , (3)
serve as horizontal (|Hi) and vertical (|V i) polarization sin θ cos θ
states or as spin-up (| + zi) and spin-down (| − zi). For
the rotation matrix implementation is given in Listing 4.
now, we use polarization states. In parallel with the no-
We use a short python function to create the matrix for
tation of Beck1 , we can define three pairs of polarization
a given angle theta. The function returns a Qobj that
states via code shown in Listing 2. Note, these are all
has been processed with the .tidyup() which removes
written in the HV basis; a point we make as it is impor-
any very small elements from the returned Qobj. This
tant to be aware of the basis any time a vector or matrix
is often useful as numerical artifacts from the finite pre-
is used to represent a quantum state.10
cision of the computer may accumulate if operators are
Listing 2. Definitions of basis states for the three standard used repeatedly.11
photon polarizations represented in the HV-basis.
Listing 4. 2x2 polarization rotation operator.
H = basis(2,0)
V = basis(2,1) def Rp(theta):
P45 = 1/sqrt(2)*(H + V) M = [[cos(theta),-sin(theta)],
M45 = 1/sqrt(2)*(H - V) [sin(theta),cos(theta)]]
R = 1/sqrt(2)*(H - 1j*V) return Qobj(M).tidyup()
L = 1/sqrt(2)*(H + 1j*V)
The photon states are also a good place to practice
Photon polarization states are a particularly good matrix operations such as change-of-basis. QuTiP han-
starting point in the pedagogical sense as students can dles matrix operations in a straightforward way making
relate their understanding to observations from optics it easy to perform transformation operations. As an ex-
experiments and the vector nature of polarization. With ample, we define the similarity transform used to change
these states defined, we can explore basic matrix me- from one basis to another (Listing 5). This is another ex-
chanics. Inner products such as hH|V i are computed by ample of a python function written to generate a matrix.
converting the ket |Hi into the bra hH| using the dag- In this case, we generate the matrix that transforms a
ger .dag() method which is defined for all instances of state from one basis to another. As inputs, the function
Qobj. As we would expect for orthogonal vectors, the takes four vectors: the two old basis vectors and the two
inner product hH|V i = 0. In QuTiP/python, H.dag()*V new basis vectors. Looking inside the function, we see an
returns 0. example of an outer product: new1.dag() * old1. The
We make futher use of the .dag() method to create .dag() again method converts a ket to a bra in order
projection operators: to carry out inner products such as: hnew1 |old1 i. The
last two lines of the function extract the value of each of
P̂H = |HihH| (1) the four inner products a,b,c,d and assemble them into
P̂V = |V ihV |, (2) a Qobj matrix. The full output of this function is the
matrix
which can be used to project a state into either horizion-
. hnew1 |old1 i hnew1 |old2 i
tal or vertical polarization. In this way, they represent S̄ = . (4)
hnew2 |old1 i hnew2 |old2 i
physical operation of passing light through a polarizer.
The QuTiP implementation of these projection operators
is given in Listing 3. As a simple calculation example, Listing 5. Definitions of basis states for the three standard
one can calculate P̂V |ψ+45 i which represents the photon photon polarizations represented in the HV-basis.
state that would result from passing light polarized at def sim_transform(old1, old2, new1, new2):
+45◦ through a vertical polarizer. The computational ’’’
representation is as simple as declaring psi = P45 and Form the similarity transform from one
0 basis to another.
operating on psi with Pv: Pv*psi yields , as
0.707 ’’’
expected.
# Calculate the relevant inner products:
Listing 3. Projection operators for horizontal and vertical a = new1.dag()*old1
polarization. b = new1.dag()*old2
c = new2.dag()*old1
Ph = H*H.dag() d = new2.dag()*old2
Pv = V*V.dag()
# extract values from these Qobj inner
Another example of a simple matrix operation that is # product results, reshape to 2 by 2, and
readily implemented in QuTiP is the polarization rota- # form a new Qobj matrix:
tion matrix. This operator corresponds to the rotation s = [i.data[0,0] for i in [a,b,c,d]]
3
return Qobj(array(s).reshape(2,2)) and y. To drive the point home, we find that | + zi and
|+yi are not orthogonal (as one may expect when think-
As we show, QuTiP can be used to construct many op- ing strictly of the cartesian unit vectors). Nonetheless,
erators that are typically developed and used by hand. pz.dag()*py confirms the correct result is 0.707 ( √12 ).13 .
While the 2x2 cases are straightforward, we find that
once users are familiar with the Qobj and the various Listing 7. The spin-1/2 projection operators are readily de-
methods provided by QuTiP, they can readily extend fined in terms of the Pauli matrices.
the size of the Hilbert space to scale their work to more Sx = 1/2.0*sigmax()
complex problems. In the following sections, we describe Sy = 1/2.0*sigmay()
several such examples; additional intermediate and ad- Sz = 1/2.0*sigmaz()
vanced examples are available via the QuTiP website and
documentation.12 Similar to the spin-1/2 basis states, the Pauli matri-
ces are available in QuTiP: sigmax, sigmay, and sigmaz.
The three spin operators are given in Listing 7 where we
III. SPIN-1/2 take ~ = 1, a step that should made quite clear in the
classroom! With these objects defined, it is straightfor-
At the level shown thus far, QuTiP can serve as a ward to construct a Hamiltonian that corresponds to an
matrix-mechanics calculator, used to compute vector and external magnetic field; a system with rich dynamics that
matrix calculations in a way that follows Dirac notation can still be computed by hand for comparison. Listing 8
and respects the algebra of quantum states. While such demonstrates the creation of a Hamiltonian that corre-
a use is welcome in the teaching setting, QuTiP provides sponds to a magnetic field oriented in the +z direction:
users with much more. Here, we demonstrate one of the
H = −µ · B = −γSz B,
QuTiP equation solvers. We also transition to spin-1/2
system and define the six relevant states as in Listing 6. with the B-field taken as a classical field, the Hamiltonian
Note, the same QuTiP function basis(...) is used again operator is:
here because spin-1/2 states are also represented by 2-
element column vectors just as polarization states were Ĥz = −ΩŜz . (5)
in Section II.
Listing 8. Code to represent the Hamiltonian for a single spin
Listing 6. The spin-1/2 system states in the z-basis using a
in a magnetic field oriented in the +z direction.
variable naming convention where “p” indicates “+” and “m”
indicates “-” and the three coordinate directions are given by omega = 5
the second letter in each variable name (i.e. mx is | − xi ). We Hz = -omega*Sz
note that these are all kets as defined here.
pz = basis(2,0) # i.e. the column vector (1,0) First, we point out the visual similarity between Eq. 5
mz = basis(2,1) # i.e. the column vector (0,1) and the python code to construct the same Hamiltonian
px = 1/sqrt(2)*(pz + mz) Hz=-omega*Sz. This similarity demonstrates QuTiP’s
mx = 1/sqrt(2)*(pz - mz) ease-of-use and illustrates the readable nature of the rel-
py = 1/sqrt(2)*(pz + 1j*mz) evant code. Next, the evolution of spin-1/2 particles sub-
my = 1/sqrt(2)*(pz - 1j*mz) ject to Eqn. 5 is calculated by setting an initial state for
the system, and allowing the system to evolve according
The spin-1/2 states are written in the basis where to the time-dependent Schrödinger equation. The solver
basis(2,0) creates the vector we use to represent spin- used in this case is sesolve() which takes at least four
up along the z-axis: arguments: the Hamiltonian (Hz), the initial state, an ar-
ray of time values at which the system state is calculated,
. 1 and one or more operators, the time-dependent expecta-
| + zi = .
0 tion value of each operator will be returned in the solver
results. A minimal example is given in Listing 9.
The declaration of this and the other spin states is given
in Listing 6. Listing 9. Solving for the time-evolution of a spin-1/2 sys-
In contrast to photon polarization states, where the tem subject to an external magnetic field oriented in the +z
orthogonality of |Hi and |V i is not surprising, it is im- direction and initially in the state | + xi.
portant to verify the orthogonality of the spin-1/2 states. t = arange(0,4*pi/omega,0.05)
The idea that the | + zi state is orthogonal to the | − zi expect_ops = [Sx,Sy,Sz]
state may be quite counterintuitive given the names spin- psi0 = px
up and spin-down: “up” and “down” are classically anti- result = sesolve(Hz, psi0, t, expect_ops)
parallel rather than orthogonal. Fortunately, vector cal-
culation by hand and via mz.dag()*pz confirm the z The result from running the sesolve() is stored in
states are orthogonal. This is easily generalized for x the variable result, a specialized object defined within
4
|3i
∆p ∆c
γc
γp
Ωc
Ωp
|2i
γ
|1i
FIG. 6. Atomic energy levels in EIT. The three atomic states
are designated |1i, |2i, and |3i. In EIT, |2i is a meta-stable
state such that the coherence between |1i and |2i is long-lived.
Excited state |3i undergoes spontaneous emission decay to |1i
and |2i with rates γp and γc respectively.
FIG. 5. The Wigner function for a sum of two coherent states
with α = ±2 ∓ 2i. Blue values are positive, red are negative.
One example of a more advanced application of QuTiP
is the study of Electromagnetically-Induced Trans-
in quantum optics.15 The Wigner function is analogous parency (EIT). A minimal example of an EIT system
to a phase-space distribution for classical systems. The is presented here for completeness, further details can
quantum version stretches this interpretation with the be found in other recent literature. We follow the theo-
possibility of containing negative values.16 Quantum in- retical treatment used by Erickson18 and Fleischhauer19 .
terference effects are the source of such values as we show The most relevant features of this system are captured in
here. The QuTiP method wigner(psi,x,y) computes the interaction Hamiltonian which describes the coupling
the Wigner function for state psi over coordinate arrays between two classical beams of light (the probe and cou-
x and y, or the plot_wigner(psi) function handles plot- pling fields) and a quantum-mechanical three-level atom.
ting and coordinate generation automatically. Listing 14 The Hamiltonian, after several standard approximations,
gives a simple example that generates Fig. 5. The state is given as:20
visualized here is a sum of two coherent states with dif-
ferent values of α = ±2 ∓ 2i. Note that python defines 0
0 Ω
p
the complex constant i as 1j and a general complex value H̃EIT
~
= − 0 2(∆p − ∆c ) Ωc (6)
such as 2i as 2j. The blue values in Fig. 5 are positive 2 Ω Ωc 2∆p
p
and the red values are negative. The fringes in the re-
gion between the two gaussian portions are a signature We point out that Refs. 18 and 19 differ in their sign
of quantum interference that has no classical analogy in convention for the field detunings ∆p and ∆c . We follow
phase space. These superpositions of coherent states are the definition in Ref. 18 where ∆p = ωp − (ω3 − ω1 ) and
known as Schrödinger cat states and have a variety of ∆c = ωc − (ω3 − ω2 ) with bare-atom energies En = ~ωn .
applications.17 For the example here, we set several parameters for the
system. Of the parameters included in the Hamiltonian,
Listing 14. Plotting the Wigner function
we set the coupling field detuning ∆c = 0, probe-field
plot_wigner(coherent(25,-2+2j)+coherent(25,2-2j)) Rabi frequency Ωp = 0.01, and the coupling-field Rabi
frequency Ωc = 1.0. Additionally, we define units such
that the relevant decay rates from the excited state: γp =
γc = 1 and the ground state coherence decay rate γ =
V. ADVANCED TOPICS 0.05. These parameters are defined in python as shown
in Listing 15.
QuTiP gives students the ability to extend the funda-
mental explorations presented above and tackle problems Listing 15. EIT parameters
that are closer to the cutting edge. All of the methods, gamma_p = 1 # decay rate on probe transition
techniques, and quantum objects that they have learned gamma_c = 1 # decay rate on coupling transition
7
The remaining parameter is the probe-field detuning Finally, we can plot the real and imaginary parts of
(∆p ). For this, we define a list of values in order to solve the resulting χ values to demonstrate two key features of
for the steady state of the system for each value of ∆p . an EIT system: transparency near resonance, and steep
Using the linspace function again, we create a list of normal dispersion. The solid (orange) curve in Fig. 7
values deltalist as well as an empty list that will hold shows the absorption which is nearly zero on resonance
the results as shown in Listing 18 (∆p = 0). This absorption dip indicates a frequency
range that experiences transparency. To confirm this,
Listing 18. EIT probe detunings one can re-run the simulation with a weak coupling field
# create list of delta_p values (Ωc ≤ 0.1). For such conditions, a single resonance ab-
deltalist = np.linspace(-3,3,200) sorption peak results, and at ∆p = 0 the absorption is
high instead of low (as expected for a resonant field).
# empty list to save results
chi = [] # susceptibility Listing 20. Graphing EIT results, shown in Fig. 7
plt.plot(deltalist,np.real(chi),label="Index n")
While the full details are beyond the scope of this pa- plt.plot(deltalist,np.imag(chi),label="Absorption")
per, the electric susceptibility associated with the probe plt.legend()
8
plt.xlabel("$\Delta_p$") rotates a qubit around the Y axis, and the RX gate ro-
plt.yticks([]) tates a qubit around the X axis. The amount of rotation
is specified in the add_gate— method, as are the target
The second notable feature of EIT is a region of strong qubit, and a label for the gate (which will appear in the
normal dispersion (refractive index increases with fre- figure generated by QuTiP).
quency). Such dispersion is known to cause low group
velocity for pulses of resonant light.21 Normal dispersion
Listing 21. A 2-qubit circuit with RX and RY gates.
is evident near resonance in the dashed (blue) curve of
Fig. 7. N=2
qc = QubitCircuit(N)
qc.add_gate("RY", 0, arg_value=pi/2,
VI. SUGGESTED PROBLEMS arg_label=r"\pi/2")
qc.add_gate("RX", 1, arg_value=pi/2,
As a full-featured software package, QuTiP offers many arg_label=r"\pi/2")
qc.png
opportunities for extended work. Many in-depth exam-
ples already exist as part of the documentation, but we
suggest a few starting points here that are more consis- Finally, we compute the full propagator (the ma-
tent with advanced undergraduate work. trix product that represents the full sequence of gates).
This is done in two steps, first, generate a list of
the propagators U_list and then calling the function
A. Computing and gates gate_sequence_product to compute the product:
U_list = qc.propagators()
Quantum computing is moving from the realm of fun-
U1 = gate_sequence_product(U_list)
damental physics toward engineering applications. Com-
panies like IBM and Intel have teams devoted to building
quantum computers. While currently far from market- To apply this circuit to a specific system, we prepare
ready, there is rapid development in the number of qubits an initial state, in this case two ground-state qubits, and
per system. act on the initial state with the gate sequence product:
In this brief introduction, we will demonstrate the fea-
tures of quantum gates that connect single-spin evolution initial = tensor(basis(N,0),basis(N,0))
to qubit gates and basic computational methods in the final = U1*initial
context of tools available in the QuTiP package.
Quantum circuits consist of a set of qubits, represented We can explore the effect of these gates on each indi-
by horizontal lines, not unlike a music staff. Each qubit vidual qubit. To do this, we use the Bloch representation
evolves in time by following it’s line to the right. Along again, and generate a Bloch vector for the initial and final
this trajectory, gates may act on one or more qubits re- spins (before and after application of the gate).
sulting in changes to the state of each individual qubit,
and therefore changes to the state of the system as a
whole. There are similarities to electronic circuits here, Listing 22. Bloch sphere representation of Ry gate
but there are also several key differences. One is that
before = Bloch()
this system, as a fundamentally quantum system, is not after = Bloch()
deterministic (unlike a basic battery, wire, bulb circuit). before.add_states(initial.ptrace(0)) # look at only
This is the primary advantage of quantum computing: qubit 0 with the ptrace
many simultaneous parallel computations using a finite after.add_states(final.ptrace(0))
set of states. before.show()
In this section, we present basic examples of quan- after.show()
tum circuits, using the QuTiP tools, with suggestions
for taking the topic further. The first step is to cre-
ate an object that represents the quantum circuit. This Listing 23. Bloch sphere representation of Rx gate
object’s methods will allow us to assemble a complete
circuit and perform calculations for the entire system. before = Bloch()
The add_gate method takes several arguments: gate, after = Bloch()
targets, controls, arg_value, and arg_label. Not before.add_states(initial.ptrace(1)) # look at only
all gates require controls, so these can be left as None qubit 1 with the ptrace
or skipped by using named arguments as shown in the after.add_states(final.ptrace(1))
second add_gate in Listing 21. before.show()
We will start with two simple gates, in fact we have after.show()
seen these in a different context earlier. The RY gate
9
print("before: C=",concurrence(initial))
print("after: C=",concurrence(final))
"fwhm": 0.2,
"on": -1.0,
"off": 9.0
},
"rabi_freq_t_func": "ramp_onoff"
}
]
},
"t_min": -2.0,
"t_max": 10.0,
"t_steps": 120,
"z_min": -0.2,
"z_max": 1.2,
"z_steps": 140,
"z_steps_inner": 10,
"num_density_z_func": "square",
"num_density_z_args": {
"on": 0.0,
"off": 1.0,
FIG. 10. Three-level lambda system with no coupling field.
"ampl": 1.0
Pulse absorption is complete.
},
"interaction_strengths": [100.0, 100.0],
"method": "mesolve"
}
"""
∗
dawes@pacificu.edu encouraging students to identify decimal representations
1
M. Beck, Quantum Mechanics: Theory and Experiment of numerical factors common to vector projection such as
(Oxford University Press, 2012). 0.707.
2 14
J. Johansson, P. Nation, and F. Nori, Computer Physics For more information, see qutip.org/docs/latest/
Communications 183, 1760 (2012). guide/guide-bloch.html.
3 15
J. Johansson, P. Nation, and F. Nori, Computer Physics U. Leonhardt, P. Knight, and A. Miller, Measuring the
Communications 184, 1234 (2013). Quantum State of Light, Cambridge Studies in Modern
4
T. Kluyver, B. Ragan-Kelley, F. Pérez, B. Granger, Optics (Cambridge University Press, 1997).
16
M. Bussonnier, J. Frederic, K. Kelley, J. Hamrick, Negative values in the Wigner function justify the descrip-
J. Grout, S. Corlay, P. Ivanov, D. Avila, S. Abdalla, and tion as a pseudo-probability distribution.
17
C. Willing, in Positioning and Power in Academic Publish- C. C. Gerry and P. L. Knight, American Journal of Physics
ing: Players, Agents and Agendas, edited by F. Loizides 65, 964 (1997), https://doi.org/10.1119/1.18698.
18
and B. Schmidt (IOS Press, 2016) pp. 87 – 90. W. W. Erickson, “Electromagnetically induced trans-
5
“jupyter.org,” . parency,” (2012).
6 19
Python is zero-indexed so the first element in an array or M. Fleischhauer, A. Imamoglu, and J. P. Marangos, Rev.
list has an index value of 0. Mod. Phys. 77, 633 (2005).
7 20
T. E. Oliphant, Guide to NumPy, 2nd ed. (CreateSpace The tilde indicates this operator has undergone unitary
Independent Publishing Platform, USA, 2015). transformation into a corotating frame as described in
8
E. Jones, T. Oliphant, P. Peterson, et al., “SciPy: Open Ref. 18.
21
source scientific tools for Python,” (2001–), [Online; ac- R. W. Boyd and D. J. Gauthier (Elsevier, 2002) pp. 497 –
cessed ¡today¿]. 530.
9 22
J. D. Hunter, Computing In Science & Engineering 9, 90 W. K. Wootters, Phys. Rev. Lett. 80, 2245 (1998).
23
(2007). T. Ogden, Resonant Pulse Propagation in Dense Atomic
10
Work is underway to add basis information to Qobj. Vapours, Ph.D. thesis, Durham University (2016).
11 24
Such artifacts can be seen by calculating cos(pi/2) which While not written in Java, this file format has become a
evaluates to 1e-17 rather than 0. The .tidyup() method common standard as it is both easy to read (by humans)
rounds such values back to zero. and simple to parse in software.
12 25
www.qutip.org. See Supplemental Materials for more details on using this
13
At this point, we call out another benefit of including nu- example.
merical work in a quantum mechanics class, and that is