\chapter{Particles and Waves}\label{c2}
A particle is a material body whose dimensions are insignificant in comparison
with the typical dimensions of its motion. A pebble can be considered to be a
particle when one considers its projectile motion but not so when one considers
its rotation. At a more extreme level, the earth is treated like a particle when
one studies it as a part of solar system but not when we study ocean currents.
A wave, on the other hand, is a periodic disturbance. In the case of material
waves the disturbance is felt in properties of the materials. For example, the
passage of a sound waves leads to periodic compressions and rarefactions in the
material. They are detected as changes in the pressure in the case of fluids and
internal stresses in the case of solids. Electromagnetic waves do not need
materials for their propagation and their passage is manifested in the periodic
variations in electric and magnetic field intensities at a point. Although this
distinction between particles and waves seems quite natural it is not so when
one observes nature beyond the human senses. Newton considered light to be
particulate and it took more than two centuries to suspect that it is probably
a wave. The interference experiments of Young could be explained only by
treating light as a wave. Maxwell predicted the existence of electromagnetic
waves and Hertz confirmed their existence. Maxwell also derived the speed of
electromagnetic waves and it was the same as the speed of light. As a result,
light was suspected to be an electromagnetic wave and was indeed shown to be so.
However, at the turn of the century other experiments were conducted whose
outcome could not be explained by assuming that light is a wave. We will
describe a few experiments in this chapter that demonstrate that what were
thought to be waves also behave like particles and \emph{vice versa}.

\section{Black body radiation}\label{c2s1}
Material bodies absorb and emit electromagnetic radiation. When they are in
thermal equilibrium the net absorption of radiation matches the net emission.
Most bodies do not absorb all radiation. They reflect or transmit it. Further,
their absorption depends on the angle of incidence. A black body is the one
that absorbs all radiation irrespective of its wavelength and angle of
incidence. If a blackbody is at thermal equilibrium then it should emit the
energy it absorbs. The emitted energy is called \emph{black body radiation}.
An approximately black body is a large cavity enclosed in an opaque material
and with a small hole for radiation to get in. It is only an approximation
because waves with wavelength greater than the hole's diameter will be
partially reflected. Further, a finite size cavity cannot hold radiation of all
wavelengths.

Since a black body absorbs radiation of all wavelengths it also emits radiation
of all wavelengths. If $U_\lambda$ is the amount of energy in the form of
radiation of wavelength $\lambda$ and if $V$ is it volume then
\begin{equation}\label{c2s1e1}
u_\lambda = \frac{U_\lambda}{V}
\end{equation}
is called the `spectral energy density'. The black body radiation experiment
consists in plotting $u_\lambda$ against $\lambda$. The results of the
experiment are shown in figure \ref{c2f1}.
\begin{figure}
\begin{center}
\includegraphics[scale=0.20]{bb}
\caption{Blackbody spectrum credit: Encyclopedia Britannica,\\
https://www.britannica.com/science/blackbody-radiation\#/media/1/68456/1374}
\label{c2f1}
\end{center}
\end{figure}

The plot shows that as temperature
rises the dominant wavelength decreases. It agrees with the observation that
hot bodies successively appear redish to bluish to white as their temperature
increases. Lord Rayleigh and Sir James Jeans first tried to understand the
black body spectrum assuming that radiation is in the form of electromagnetic
waves. Radiation is trapped inside a black body in the form of standing waves.
If we the black body is in the form a cube of length $L$ then radiation of
wavelength $\lambda$ will stay as a standing wave only if an integral number of
half wavelengths are accommodated in the extent $L$. If $n_x, n_y, n_z$ are the
number of half-wavelengths along the $x, y, z$ axes then
\begin{eqnarray}
n_x &=& \frac{L}{\lambda/2} = \frac{2L}{\lambda} \\
n_y &=& \frac{2L}{\lambda} \\
n_z &=& \frac{2L}{\lambda}
\end{eqnarray}
For a standing wave to form in an arbitrary direction we must have
\begin{equation}\label{c2s1e5}
n^2 = n_x^2 + n_y^2 + n_z^2 = \left(\frac{2L}{\lambda}\right)^2.
\end{equation}
In this equation we no longer require $n_x, n_y, n_z$ to be integers.
The number of waves with wavelengths between $\lambda$ and $\lambda + d\lambda$
is the number of points with positive coordinates $n_x, n_y, n_z$ in the region
between the first octant of the spheres with radii $n$ and $n + dn$. This number
is proportional to the volume of the region,
\[
\frac{1}{8} \times 4\pi n^2dn.
\]
Since there are two polarisations for each mode, the number of standing waves is
\begin{equation}\label{c2s1e6}
G(n)dn = \pi n^2 dn.
\end{equation}
From equation \eqref{c2s1e5} we have
\begin{equation}\label{c2s1e7}
n = \frac{2L}{\lambda} = \frac{2L}{c}\nu
\end{equation}
so that equation \eqref{c2s1e6} becomes
\begin{equation}\label{c2s1e8}
G(\nu)d\nu = \pi \cdot \frac{8L^3}{c^3}\nu^2d\nu.
\end{equation}
If $g(\nu)$ is the number of waves per unit volume, also called the density of
`states', then
\begin{equation}\label{c2s1e9}
g(\nu)d\nu = \frac{8\pi}{c^3}\nu^2 d\nu.
\end{equation}
Finally, in order to get the energy density, Rayleigh and Jeans used the
classical equipartition theorem that allocates an energy of $kT/2$ to each
degree of freedom. In the case of a single standing wave, there are two degrees
of freedom so that the energy of each mode is
\begin{equation}\label{c2s1e10}
U = kT,
\end{equation}
where $k = 1.38 \times 10^{-23}$ JK${}^{-1}$ is the Boltzmann constant and $T$
is the absolute temperature. The energy density is, therefore,
\begin{equation}\label{c2s1e11}
u(\nu)d\nu = \frac{8\pi kT}{c^3}\nu^2 d\nu.
\end{equation}
One can as well express the energy density $u$ as a function of wavelength and
write
\begin{equation}\label{c2s1e12}
u(\lambda)d\lambda = \frac{8\pi kT}{\lambda^4}d\lambda,
\end{equation}
where we have used the fact that $u(\nu)d\nu = -u(\lambda)d\lambda$ because of
the inverse relationship between $\nu$ and $\lambda$.
The experimentally observed energy density spectrum of a black body does not
follow these equations. In particular, when $\lambda \rightarrow 0$, or
equivalently, $\nu \rightarrow \infty$, $u$ blows up. This feature of the
function $u$ defined in \eqref{c2s1e10} and \eqref{c2s1e11} is called the
`ultraviolet catastrophe' and it was one of the first evidences to indicate
that certain experiments cannot be explained by classical physics.

Max Planck's correction to this formula lay in replacing the energy given by
equation \eqref{c2s1e10} with
\begin{equation}\label{c2s1e13}
U = \frac{h\nu}{\exp(\frac{h\nu}{kT}) - 1}
\end{equation}
where $h = 6.626 \times 10^{-34}$ Js is a universal constant, now called the
Planck's constant. The expression for energy density becomes
\begin{equation}\label{c2s1e14}
u(\nu)d\nu = \frac{8\pi h\nu^3}{c^3}\frac{d\nu}{\exp(\frac{h\nu}{kT}) - 1}.
\end{equation}
This is Planck's formula for black body radiation spectrum.

\subsection{Planck's expression for $U$}
There are many ways to derive Planck's expression in equation \eqref{c2s1e13}
for the energy of radiation. We will follow the one used originally by Planck
\cite{planck1901law}. It assumes
\begin{enumerate}
\item The relation between entropy $S$ and internal energy $U$
\begin{equation}\label{c2s1e15}
\left(\frac{\partial S}{\partial U}\right)_{V, N} = \frac{1}{T}.
\end{equation}
Here $T$ us the (absolute) temperature and $N$ is the number of particles.
\item The relation between entropy and the number of states in which a system
can be. If $\Omega$ is the number of states then
\begin{equation}\label{c2s1e16}
S = k\log\Omega
\end{equation}
where $k$ is Boltzmann constant.
\item Electromagnetic energy is transferred in the units of $h\nu$, where $\nu$
is the frequency of the radiation and $h$ is another universal constant, now
named after Planck.
\end{enumerate}
Of these assumptions, the first one is a result in thermodynamics, known since
the 1850s. The second one was proposed by Ludwig Boltzmann in the 1870s when he
laid the foundations of statistical mechanics while the last one was Planck's
contribution for which he was to receive a Nobel prize in Physics in 1918.

Let the black body cavity have an energy $U_0$ at the frequency $\nu$. If there
are $N$ modes of radiation, we want to find out the number of ways in which we
can  distribute the energy $U$ among them. The third assumption listed above
tells  that the energy $U$ is available as $P=U_0/(h\nu)$ packets, called quanta.
Therefore, the problem of distribution of energy $U_0$ among the radiation modes
is the same as counting the number of ways in which $P$ quanta can be
distributed among $N$ modes. This is an easy combinatorial problem whose
solution is
\begin{equation}\label{c2s1e17}
\Omega = \frac{(P + N - 1)!}{P!(N - 1)!}.
\end{equation}
Usually, the number $N$ is so large that $(N - 1)! \approx N!$ so that we can
as well write \eqref{c2s1e17} as
\begin{equation}\label{c2e1e18}
\Omega = \frac{(P + N)!}{P!N!}.
\end{equation}
so that
\[
\log\Omega = \log[(P + N)!] - \log P! - \log N!.
\]
When $n$ is large, we can approximate $\log n! \approx n\log n$ (this is called
Stirling's approximation. It is quite accurate even for $n = 10$) to get
\[
\log\Omega = (P + N)\log(P + N) - P\log P - N\log N
\]
so that the entropy of the electromagnetic radiation is
\begin{eqnarray*}
S &=& k\log\Omega \\
  &=& kN\left\{\left(1 + \frac{P}{N}\right)\log(P + N) - \frac{P}{N}
      \log P - \log N\right\} \\
 &=& kN\left\{\left(1 + \frac{P}{N}\right)\log(P+N) - \frac{P}{N}
     \left(\log\frac{P}{N} + \log N\right) - \log N\right\} \\
 &=& kN\left\{\left(1 + \frac{P}{N}\right)\left(\log(P+N)-\log N\right)
     - \frac{P}{N}\log\frac{P}{N}\right\} \\
 &=& kN\left\{\left(1 + \frac{P}{N}\right)\log\left(1+\frac{P}{N}\right)
     - \frac{P}{N}\log\frac{P}{N}\right\}
\end{eqnarray*}
Since $P$ was defined as $U_0/(h\nu)$, we can write
\[
\frac{U_0}{Nh\nu} = \frac{U}{h\nu}
\]
where
\begin{equation}\label{c2s1e19}
U = \frac{U_0}{N}
\end{equation}
is the average energy per mode. We now have
\begin{equation}\label{c2s1e20}
S = kN\left\{\left(1 + \frac{U}{h\nu}\right)\log\left(1+\frac{U}{h\nu}\right)
     - \frac{U}{h\nu}\log\frac{U}{h\nu}\right\}.
\end{equation}
From equations \eqref{c2s1e15} and \eqref{c2s1e19} one can readily show that
\begin{equation}\label{c2s1e21}
\frac{1}{T} = \frac{k}{h\nu}\left(1 + \frac{h\nu}{U}\right).
\end{equation}
This equation can be rearranged to get
\begin{equation}\label{c2s1e22}
U = \frac{h\nu}{\exp\left(\frac{h\nu}{kT}\right) - 1}
\end{equation}
which is identical with \eqref{c2s1e13}.

\subsection{Additional notes on Planck's derivation}
Planck deduced the relation $E = h\nu$ first on the basis of thermodynamic
arguments (section 2 of \cite{planck1901law}). Later on (sixth lecture in
\cite{planck2012eight}) he gave an explanation using the mathematical
properties of electromagnetic radiation. Chang \cite{chang2017physical} gives
an account of Planck's theory in modern terms.

Entropy is usually introduced as a quantity measuring the disorder in a system.
The molecules of a vapour have more freedom of movement than the molecules of a
liquid. As a result we say the vapour has more entropy than a liquid. What could
entropy mean in the case of radiation? Radiation is characterised by frequency
(or wavelength), phase and amplitude. The entropy of radiation consists in
random fluctuations of phase and amplitude.

Although Planck introduced the idea of a quantum of energy he did not consider it
as seriously as others like Einstein, Ehrenfest and Lorentz (preface of
\cite{planck2012eight}). In the remaining sections we will see how the idea
turned out to have a profound and far-reaching impact on physics.

\subsection{Problem set 1}
\begin{enumerate}
\item Physics is an experimental science. We should supplement the theoretical
development of black body radiation spectrum of \eqref{c2s1e14} with an
understanding of how it is measured. Refer to
\url{https://physicsopenlab.org/2015/12/04/black-body-emission/} for one way to
measure the spectrum.
\item When the voltage drops an incandescent bulb gives a reddish glow. When the
voltage reaches its normal level the bulb glows bright. Can you explain the
change in appearance based on your understanding of \eqref{c2s1e14}?
\item It is safer to use a touchless thermometer when a large number of people
have to be examined. Can you design a touchless thermometer using
\eqref{c2s1e14}?
\item Consider the function
\begin{equation}\label{c2e1e23}
B(\nu, T) = \frac{2h\nu^3}{c^2}\frac{1}{\exp\left(\frac{h\nu}{kT}\right) - 1}.
\end{equation}
Show that it reaches an extremum at a frequency $\nu_0$ such that
\begin{equation}\label{c2e1e24}
3 + \left(\frac{h\nu_0}{kT} - 3\right)\exp\left(\frac{h\nu_0}{kT}\right) = 0.
\end{equation}
If you measure the radiation spectrum of a body using the procedure outlined
in the first problem and read the frequency $\nu_0$ at which the spectral energy
density peaks then you can use equation \eqref{c2e1e24} to determine the
temperature.
\item If
\begin{equation}\label{c2e1e25}
x = \frac{h\nu_0}{kT}
\end{equation}
then equation \eqref{c2e1e24} can be written as $3 + (x - 3)e^x = 0$. You can
solve this equation using Newton's method to get $x \approx 2.821440$. Thus,
the relation between temperature of the black body and its peak frequency is
\begin{equation}\label{c2s1e26}
\frac{h\nu_0}{kT} \approx 2.821440.
\end{equation}
Using equation \eqref{c2s1e26} find the peak frequency when you measure the
radiation spectrum of
\begin{enumerate}
\item Sun whose surface temperature is approximately $6000$ K?
\item human body with temperature of $310$K? (Do you now see the usefulness
of infrared cameras?)
\end{enumerate}
On the other hand the peak frequency of the outer space is around $160$ GHz.
What is the space's temperature? (The ambient radiation in the outer space
is called the cosmic microwave background. Can you relate it to the relativistic
Doppler effect you studied in the previous chapter?)
\end{enumerate}

\section{Photoelectric effect and X-ray generation}\label{c2s2}
When light of suitable frequency is shone on a clean metal surface, the metal
emits electrons. This is called the photoelectric effect. Experiments reported
that
\begin{itemize}
\item The electrons are emitted only if the light exceeds a certain frequency
, called the threshold frequency, which is characteristic of the metal.
\item As long as the light exceeds the threshold frequency the energy of the
emitted electrons increases with frequency.
\item The number of electrons emitted is proportional to the intensity of light
if its frequency exceeds the threshold. If its frequency is below the threshold
the increasing intensity of light does not result in emission of electrons.
\item There is no lag between turning on the light and the emission of electrons.
\end{itemize}

None of these observations could be satisfactorily explained if one assumes that
light is a classical electromagnetic wave. A classical wave can transfer energy
to an electron in a continuous manner so that eventually the electron has enough
energy to free itself from the metal and escape.

Einstein used Planck's idea of an energy quantum to explain the experimental
facts mentioned above (see section 8 of \cite{einstein1905heuristic}). He
proposed that an electron in a metal has to overcome a certain energy barrier,
called the `work function' $\phi$ of the metal, before it can escape it. The
minimum frequency that the light must have for it to eject an electron is
\begin{equation}\label{c2s2e1}
h\nu_0 = \phi.
\end{equation}
If the light has a frequency $\nu > \nu_0$ then the energy $h\nu - \phi =
h(\nu - \nu_0)$ beyond the metal's work function is transferred to the
electron as its kinetic energy.

\subsection{Problem set 2}
\begin{enumerate}
\item The (first) ionization energy of an atom is the energy needed to remove
an electron from its outermost shell. Caesium atom has an ionization energy of
$3.9$ eV. However the work function of Caesium metal is only $1.9$ eV. Why are
the two different? Why is the work function lower than the ionization energy?
\item Visible light's frequency ranges from $400$ to $800$ THz. If you want
to build a device to detect visible light using photoelectric effect, which
metals would you use? You can consult the Wikipedia for values of work function
(\url{https://en.wikipedia.org/wiki/Work_function#Work_functions_of_elements})
of common metals. Which metals can you use to detect red light? Which ones will
suffice if you are interested only in blue and violet?
\item You have probably studied thermionic emission in the context of vacuum
tube diode. In thermionic emission electrons are ejected from a metal surface
by heating the metal. Will the thermionic work function be different from the
photoelectric work function?
\end{enumerate}

In photoelectric effect, light transfers its energy to an electron giving it
enough energy to escape from a metal. The inverse process in which a fast moving
electron is stopped by a solid releasing its energy as light is also possible.
A sharp deceleration of an electron gives rise to `bremsstrahlung', the German
word for radiation as a result of stopping (applying brakes) a charged particle.
Figure \ref{c2f1} shows the X-ray spectrum of Rhodium metal downloaded from
Wikipedia (\url{https://commons.wikimedia.org/wiki/File:TubeSpectrum.jpg#/media/
File:TubeSpectrum.jpg}).The $x$-axis has the wavelength of X-rays in picometre
($1$ pm = $10^{-12}$ m) while the $y$-axis has a quantity proportional to the
intensity of the radiation. It is observed that the spectrum is largely smooth
except for two sharp peaks and that it abruptly drops at a certain minimum
wavelength. The smooth part of the spectrum is due to bremsstrahlung while the
sharp peaks are because of transition of electrons in Rhodium atoms from higher
energy levels to lower ones. We will understand these transitions better when we
study atomic structure in greater details in the chapters to follow.
\begin{figure}
\includegraphics[scale=0.5]{Tubespectrum}
\caption{X-ray spectrum of Rh downloaded from Wikipedia}\label{c2f2}
\end{figure}

\subsection{Problem set 3}
\begin{enumerate}
\item Figure \ref{c2f2} shows that there are no X-rays detected with a
wavelength lesser than a certain cut-off. What does the cut-off depend on? Is
it a characteristic of the metal or the fast moving electrons?
\item The cut-off wavelength is approximately $20$ pm. Can you estimate the
energy of the fast moving electrons?
\item How will the cut-off wavelength change when you use faster electrons?
\item When an electron is accelerated from rest by a potential difference
$V$ then it acquires an energy $eV$, where $e$ is the charge on the electron.
Suppose that this electron loses all its energy when it hits the metal in the
form of light of frequency $\nu_0$. Show that
\begin{equation}\label{c2s2e2}
\nu_0 = \frac{eV}{h}.
\end{equation}
Show that the corresponding wavelength is
\begin{equation}\label{c2s2e3}
\lambda_0 = \frac{hc}{eV}.
\end{equation}
The quantities $h, c$ and $e$ on the right hand side of \eqref{c2s2e3} are
universal constants. Use their values in SI units to derive
\begin{equation}\label{c2s2e4}
\lambda_0 = \frac{1.2398 \times 10^{-6}}{V}.
\end{equation}
Equation \eqref{c2s2e4} is called Duane-Hunt law. It was derived from empirical
data before the theory of X-ray production was understood.

Does \eqref{c2s2e4} help you answer the previous two questions better?
\end{enumerate}

\section{Compton effect}\label{c2s3}
Black body radiation spectrum and photoelectric effect can be explained by
assuming that electromagnetic waves transfer energy in discrete quanta. That
perhaps makes them strange kind of waves. But there is nothing in those
experiments to suggest that they are particles. Waves interfere, particles
collide and we can think of light as a stream of particles only when we can
make it collide with another particle. Compton's experiment involved the
interaction of light with an electron and its results can be explained by
treating light as a stream of particles, called photons. The particles have
and energy
\begin{equation}\label{c2s3e1}
E = h\nu,
\end{equation}
and their momentum is given by equation \eqref{c1s3e10} to be
\begin{equation}\label{c2s3e2}
p = \frac{E}{c}.
\end{equation}
Note that we still associate the term `frequency' for photons alluding to the
fact that they behave like particles and waves. Compton's experiment consisted
of shining light on electrons. If light is considered to be an electromagnetic
wave then the electron is exposed to an oscillating electric field as a result
of which it starts oscillating with the same frequency. An oscillating charge
also emits radiation so that the radiation observed after interaction with the
electron consists of the incident radiation and the emitted radiation. The
frequency of both radiations is the same although the scattered radiation is
polarised. Compton used radiation of a very high frequency in the form of X-rays
and gamma rays. He observed that the scattered radiation had a lower frequency,
or a higher wavelength. This observation could not be explained by the classical
theory. Compton, therefore, assumed that X-rays can be considered to be a
stream of particles of energy and momentum given by equations \eqref{c2s3e1}
and \eqref{c2s3e2}. He assumed that an electron at rest has zero momentum but
it has an energy $E = m_ec^2$, $m_e$ being the mass of the electron. The
collision between the X-ray photon and a stationary electron results in the
photon getting scattered by an angle $\theta$ and the electron recoiling at
an angle $\phi$ where the angles are measured with respect to the direction
along with the photons arrive. If we choose the $x$-axis to be along the
direction of the incident photons and if the origin is chosen to be the initial
position of the electron then $\phi$ and $\theta$ are the angles of the
final momenta of the photon and electron with the positive $x$-axis.

Let us put expressions for initial and final momenta of the electron and the
photon. The quantities after the collision are distingushed by a prime and those
related to the electron have a subscript `e'. Thus, the initial energy and
momenta are
\begin{eqnarray}
E &=& h\nu \label{c2s3e3} \\
\vec{p} &=& \frac{h\nu}{c}\hat{i} \label{c2s3e4} \\
E_e &=& m_ec^2 \label{c2s3e5} \\
\vec{p}_e &=& 0 \label{c2s3e6}
\end{eqnarray}
The corresponding quantities for the photon after the collision are
\begin{eqnarray}
E^\prime &=& \frac{h\nu^\prime}{c} \label{c2s3e7} \\
\pvec{p}^\prime &=& \frac{h\nu^\prime}{c}\cos\phi\hat{i} +
                   \frac{h\nu^\prime}{c}\cos\phi\hat{j} \label{c2s3e8}
\end{eqnarray}
If $p_e^\prime$ is the magnitude of the electron's momentum after collision then
\begin{equation}\label{c2s3e9}
\pvec{p}_e^\prime = p_e^\prime\cos\theta\hat{i} + p_e^\prime\sin\theta\hat{j}
\end{equation}
and
\begin{equation}\label{c2s3e10}
E_e^\prime = \sqrt{{p_e^\prime}^2c^2 + m_e^2c^4}.
\end{equation}

Since momentum is conserved,
\begin{eqnarray}
\frac{h\nu}{c} &=& \frac{h\nu^\prime}{c}\cos\phi + p_e^\prime\cos\theta
                   \label{c2s3e11} \\
0 &=& \frac{h\nu^\prime}{c}\sin\phi - p_e^\prime\sin\theta. \label{c2s3e12}
\end{eqnarray}
We can rearrange these as
\begin{eqnarray}
p_e^\prime c\cos\theta &=& h(\nu - \nu^\prime\cos\phi) \label{c2s3e13} \\
p_e^\prime c\sin\theta &=& h\nu^\prime\sin\phi. \label{c2s3e14}
\end{eqnarray}
Squaring and summing these
\begin{equation}\label{c2s3e15}
{p_e^\prime}^2c^2 = h^2(\nu^2 + {\nu^\prime}^2 - \nu\nu^\prime\cos\phi).
\end{equation}
Now let us consider energy conservation. After the collision, the electron
is no longer at rest. Let us assume that $T$ is its kinetic energy. It gets
it from the photon. Therefore,
\begin{equation}\label{c2s3e16}
T = h\nu - h\nu^\prime.
\end{equation}
The total energy of the electron after the collision is
\begin{equation}\label{c2s3e17}
E_e^\prime =  T + m_ec^2.
\end{equation}
From equations \eqref{c2s3e10} and \eqref{c2s3e17},
\[
T^2 + 2m_ec^2T + m_e^2c^4 = {p_e^\prime}^2c^2 + m_e^2c^4
\]
so that
\begin{equation}\label{c2s3e18}
{p_e^\prime}^2c^2 = T^2 + 2m_ec^2T.
\end{equation}
Substituting \eqref{c2s3e16} in the above equation we get
\begin{equation}\label{c2s3e19}
{p_e^\prime}^2c^2 = h^2(\nu^2 + {\nu^\prime}^2 - 2\nu\nu^\prime) +
                    2m_ec^2h(\nu - \nu^\prime).
\end{equation}
Finally, from equations \eqref{c2s3e15} and \eqref{c2s3e19} one get
\begin{equation}\label{c2s3e20}
\frac{m_e}{h}\left(\frac{c}{\nu^\prime} - \frac{c}{\nu}\right) = 1-\cos\phi.
\end{equation}
Since $c/\nu = \lambda$ and $c/\nu^\prime = \lambda^\prime$, we can as well
write \eqref{c2s3e20} as
\begin{equation}\label{c2s3e21}
\lambda^\prime - \lambda = \frac{h}{m_ec}(1 - \cos\phi).
\end{equation}
The expression on the right hand side of the above equation is called the
`Compton shift'. Observe that it depends on $\phi$ the angle at which one
observes the scattered photon.

\subsection{Problem set 4}
\begin{enumerate}
\item Mathematically it is clear that the Compton shift depends on the angle
of observation. Can you explain it solely on physical grounds?
\item Compton shift depends only on the angle of observation of the scattered
photon. The other terms are universal constants. In particular, the Compton
shift is independent of characteristics of the incident photon. Why did Compton
use X-rays when so many other choices of radiation were available?
\end{enumerate}

\subsection{About photons}
We used the term `photon' for the first time in this section. We used it to mean
a `light particle'. However, one should not imagine propagation of light as a
stream of particles of finite extent. Although it might have been the original
idea, the modern concept of photon is does not permit such a picture. A
pragmatic choice, at this stage, is just to assume that light can be associated
with an energy $E = h\nu$ and a momentum $p = E/c$ and conceptally one can
treat it as if it were a particle. To know more about why the idea of photon is
subtle and how physicists sometime get it wrong, refer to Willis Lamb's article
\cite{lamb1995anti} or a more extensive set of articles in
\cite{roychoudhurioptics}. The same caution applies to the `phonons', the
acoustic counterpart of photons, which we will study the specific heat of
solids.

\section{de Broglie waves}\label{c2s4}
Experimental evidence forced Max Planck, Albert Einstein and Arthur Compton to
propose and accept that idea that electromagnetic waves show particle-like
properties. The proposal was tortuous and the acceptance reluctant. If
waves can behave like particle, might particles behave like waves? There was
no experimental evidence to suspect this possibility in 1924 when the French
physicist Louis de Broglie proposed it. It was firmly in the realm of
speculation. However within a matter of three years the speculation was put to
rest by an experiment that demonstrated that electrons do get diffracted. In
this section, we will review de Broglie's ideas and describe the experiments
that proved them right.

We learnt in chapter \ref{c1} that photons of energy $E = h\nu$ have a momentum
\begin{equation}\label{c2s4e1}
p = \frac{E}{c} = \frac{h\nu}{c} = \frac{h}{\lambda}.
\end{equation}
de Broglie proposed that a particle with momentum $p$ has a wavelength
\begin{equation}\label{c2s4e2}
\lambda = \frac{h}{p}.
\end{equation}
Let us understand the profound implications of this mathematically innocuous
rearrangement of the terms of equation \eqref{c2s4e1}. We know that the momentum
of a particle of mass $m$ moving with a velocity $\vec{v}$ is
\begin{equation}\label{c2s4e3}
\vec{p} = \gamma m\vec{v},
\end{equation}
where
\begin{eqnarray*}
\gamma &=& \frac{1}{\sqrt{1 - \beta^2}} \\
\vec{\beta} &=& \frac{\vec{v}}{c}
\end{eqnarray*}
Therefore, the wavelength of the particle is
\begin{equation}\label{c2s4e4}
\lambda = \frac{h}{\gamma mv}.
\end{equation}
The energy of a body is $E = \gamma mc^2$. Therefore, its frequency is
\begin{equation}\label{c2s4e5}
\nu = \frac{E}{h} = \frac{\gamma mc^2}{h}
\end{equation}
and the velocity of its wave is
\begin{equation}\label{c2s4e6}
v_p = \nu\lambda = \frac{\gamma mc^2}{h}\frac{h}{\gamma mv} = \frac{c^2}{v}.
\end{equation}
We learnt in chapter \ref{c1} that material bodies always travel slower than
light. That is $v < c$. As a result, from equation \eqref{c2s4e6}, it is
evident that
\begin{equation}\label{c2s4e7}
v_p > c.
\end{equation}
The theory of relativity proposed that no information can travel faster than
light. So what kind of information is contained in a wave whose speed is given
by \eqref{c2s4e6}? To understand that, we need a brief interlude to refresh
our ideas about waves.

\subsection{The equation of a wave}
Any wave can be expressed with the equation
\begin{equation}\label{c2s4e8}
y = A\cos\left(2\pi\left(\frac{x}{\lambda} - \nu t\right)\right).
\end{equation}
The wave travels along the positive $x$ axis causing a displacement along the
$y$ axis. Its crest, or trough, or any other point with a fixed phase, travels
at a speed $v_p = \nu\lambda$. The subscript $p$ emphasizes that this is the
velocity of a point of a fixed phase. It is called the phase velocity. We saw
in equation \eqref{c2s4e7} that the phase velocity of de Broglie waves is
greater than the speed of light. Is there something else associated with a
wave whose velocity matches the velocity of the particle?

To do that, we introduce the angular frequency
\begin{equation}\label{c2s4e9}
\omega = 2\pi\nu
\end{equation}
and the wave number
\begin{equation}\label{c2s4e10}
k = \frac{2\pi}{\lambda}
\end{equation}
to rewrite the equation of wave motion as
\begin{equation}\label{c2s4e11}
y = A\cos(kx - \omega t)
\end{equation}
so that the phase velocity can also be written as
\begin{equation}\label{c2s4e12}
v_p = \frac{\omega}{k}.
\end{equation}

Now consider a superposition of two waves
\begin{eqnarray}
y_1 &=& A\cos(kx - \omega t) \label{c2s4e13} \\
y_2 &=& A\cos((k + \delta k)x - (\omega + \delta\omega)t). \label{c2s4e14}
\end{eqnarray}
The net displacement of any point on the $x$ axis is
\begin{equation}\label{c2s4e15}
y = y_1 + y_2 = A\left[\cos(kx-\omega t) +
  \cos((k + \delta k)x - (\omega + \delta\omega)t)\right].
\end{equation}
Using standard trignometric identities, one can write the above equation as
\begin{equation}\label{c2s4e16}
y = 2A\cos\left[\left(k+\frac{\delta k}{2}\right)x - \left(\omega +
\frac{\delta\omega}{2}\right)t\right]\cos\left(\frac{\delta k}{2}x -
\frac{\delta\omega}{2} t\right).
\end{equation}
Now assume that $\delta k \ll k$ and $\delta\omega \ll \omega$ so that $k +
\delta k/2 \approx k$ and $\omega + \delta\omega/2 \approx \omega$ and hence
\begin{equation}\label{c2s4e17}
y = 2A\cos\left(\frac{\delta k}{2}x - \frac{\delta\omega}{2}t\right)
    \cos(kx - \omega t)
\end{equation}
The superposition of the two waves \eqref{c2s4e13} and \eqref{c2s4e14} is thus
another wave with its amplitude modulated by the first cosine factor in
\eqref{c2s4e17}. The velocity of the modulation is
\begin{equation}\label{c2s4e18}
v_g = \frac{\delta\omega}{\delta k},
\end{equation}
which in the limit $\delta k \rightarrow 0, \delta\omega \rightarrow 0$ becomes
\begin{equation}\label{c2s4e19}
v_g = \frac{d\omega}{dk}.
\end{equation}
$v_g$ is called the group velocity of thewave $y$.

\subsection{Group velocity of de Broglie waves}
From equation \eqref{c2s4e4}
\begin{equation}\label{c2s4e20}
k = \frac{2\pi}{\lambda} = \frac{2\pi}{h}\gamma mv
\end{equation}
so that
\begin{equation}\label{c2s4e21}
\frac{dk}{dv} = \frac{2\pi}{h}\frac{m}{(1 - \beta^2)^{3/2}}.
\end{equation}
Likewise, from \eqref{c2s4e5}
\begin{equation}\label{c2s4e22}
\omega = 2\pi\nu = \frac{2\pi}{h}\gamma mc^2
\end{equation}
so that
\begin{equation}\label{c2s4e23}
\frac{d\omega}{dv} = \frac{2\pi}{h}\frac{mv}{(1 - \beta^2)^{3/2}}.
\end{equation}
From equations \eqref{c2s4e23} and \eqref{c2s4e21} we readily get
\begin{equation}\label{c2s4e24}
v_g = \frac{d\omega}{dk} = \frac{d\omega/dv}{dk/dv} = v.
\end{equation}
It is not the phase velocity but the group velocity of the de Broglie waves
that is physically significant. In fact, the group velocity is \emph{the}
velocity of the particle.

\subsection{Problem set 5}
\begin{enumerate}
\item Waves for which $\omega$ and $k$ have are proportional are called
non-dispersive waves. Show that for non-dispersive waves the group velocity is
identical with the phase velocity.
\item Are electromagnetic waves in vacuum dispersive or non-dispersive?
\item Derive equations \eqref{c2s4e21} and \eqref{c2s4e23}.
\item Mention the word `wave' and most people think of waves on water. Waves
in fluids are some of the most complicated waves one can come across. Read
the article \url{https://en.wikipedia.org/wiki/Dispersion_(water_waves)} for a
glimpse of their complexity and an understanding of what dispersion means.
\item The equation
\begin{equation}\label{c2s4e25}
y = A\cos(kx + \omega t)
\end{equation}
also represents a wave. What is the difference between the waves represented
by \eqref{c2s4e25} and \eqref{c2s4e8}?
\end{enumerate}

\section{Davisson-Germer experiment}\label{c2s5}
`Light travels in a straight line' is what everyone learns first in optics. If
this were strictly true then all objects would cast a sharp shadow. If you hold
your hand in front of a light source and observe its shadow on a wall you will
observe that there is a central dark shadow of your palm is surrounded by a
less darker outline of the palm. It happens because light rays bend as they go
past your palm. This phenomenon in which waves past a sharp edge bend is called
diffraction. Diffraction is a characteristic of waves.

Diffraction happens when light is made to pass through one or more narrow slits.
A grating is an optical instrument with a very large number of slits. It is
made by etching corrugations on a glass plate. Any regular, periodic arrangement
of a transparent material is a grating.

Visible light is diffracted by grating made of glass. Electromagnetic waves of
much shorter wavelengths like X-rays need gratings whose `slits' are far more
closely etched. It is hard to manufacture such grating but nature provides an
alternative in the form of crystals. When X-rays are shone on a crystal the
diffracted rays form a series of intensity peaks which depend on the geometry
and symmetry of the crystal. Observing a diffraction pattern of X-rays is not
surprising. Davisson and Germer observed a diffraction pattern when they
replaced X-rays with electrons giving the first evidence in support of de
Broglie's speculation that particles have wave-like features.

Electrons being charged particles interact strongly with the crystals. As a
result they undergo significant accelaration in the crystal. A change in their
momentum is accompanied with a change in their wavelength. It makes an analysis
of electron diffraction rather challenging. In modern times neutrons are used
in the place of electrons. They are neutral and do not interact with the crystal
as much as electrons do. They too result in a diffraction pattern further
corroborating de Broglie's hypothesis.

\subsection{Problem set 6}
\begin{enumerate}
\item The molecular weight of N$_2$ gas is $28$ g per mole. That is, $N_A$
number of N$_2$ molecules weigh $28$ g, where $N_A$ is the Avogadro number.
\begin{enumerate}
\item Find the mass of one N$_2$ molecule.
\item The root mean square speed of a gas molecule of mass $m$ at temperature
$T$ is
\begin{equation}
u = \sqrt{\frac{3kT}{m}}.
\end{equation}
Find the root mean square of a Nitrogen molecule at $300$ K. Hence compute its
mometum.
\item What is the de Broglie wavelength of the Nitrogen molecule? Compare it
with the typical mean free path which is of the order of $10^{-6}$ m.
\end{enumerate}

\item A typical cricket ball weighs $160$ g and typical fast bowler gives it a
speed of $130$ kmph. What is the ball's de Broglie wavelength after it
leaves the bowler.
\end{enumerate}

\section{Towards uncertainty relation}\label{c2s6}
We understand what waves are physically. Water waves are undulations on the
surface of water, sound waves are a succession of rarefactions and compressions
in air, electromagnetic waves are fluctuations of electric and magnetic fields
at a point. What are electrons waves? What undulates when an electron wave
passes by?

Electron waves, or de Broglie waves in general, are represented mathematically
by a wave function $\Psi$. It is a function of position $\vec{r}$ and time $t$.
In general, $\Psi$ is a complex valued function. That is, for a given $\vec{r}$
and $t$, $\Psi(\vec{r}, t)$ is a complex number. The quantity $|\Psi|^2 = \Psi
\Psi^\ast$ is a real quantity. It is proportional to the probability of finding
a particle at a point $\vec{r}$ and time $t$. This statement is not accurate
because the probability of finding a particle exactly at $\vec{r}$ and exactly
at time $t$ is always zero. The correct interpretation of $\Psi^2$ is that
it is the probability of finding the particle in a small volume $dV$ around
$\vec{r}$ between times $t$ and $t + dt$.

de Broglie waves are thus waves of a function $\Psi$ whose squared modulus has
is the probability density function of finding the particle in a neighbourhood
of a point and in an interval of time.

A probabilistic interpretation of $|\Psi|^2$ indicates that there is never a
certainty of finding a particle in a small enough region around a point
$\vec{r}$. The standard deviation of $|\Psi|^2$ at $\vec{r}$ is a measure of
uncertainty of finding the particle in the neighbourhood. If we restrict
ourselves to one dimension, that is if $\Psi$ is function of $x$ and $t$ then
the uncertainty of finding a particle in the neighbourhood of a point $x_0$ is
denoted by $\Delta x$.

Armed with this understanding of $\Psi$ let us consider a wave whose wavelength
is known precisely. If $\lambda$ is known then so is $k = 2\pi/\lambda$. Such
a wave looks like the one in figure \ref{c2f3}. Its squared modulus is shown in
figure \ref{c2f4}. How can one tell where the particle is? It seems like the
particle can be just about anywhere where $|\Psi|^2$ is not close to zero. The
uncertainty of finding it is fairly large.
\begin{figure}
\begin{center}
\includegraphics[scale=0.5]{one-wave}
\caption{A wave with precise $k$.}\label{c2f3}
\includegraphics[scale=0.5]{one-wave-sq}
\caption{Squared modulus of a wave with precise $k$.}\label{c2f4}
\end{center}
\end{figure}
Figures \ref{c2f5} and \ref{c2f6} show a plots for a wave formed by
superposition of two sinusoidal waves. Now we do not know the precise $k$, for
we have mixed two of them, but we get a slightly improved localisation of the
particle.
\begin{figure}
\begin{center}
\includegraphics[scale=0.5]{two-waves}
\caption{Superposition of two cosine waves.}\label{c2f5}
\includegraphics[scale=0.5]{two-waves-sq}
\caption{Squared modulus of superposition of waves.}\label{c2f6}
\end{center}
\end{figure}

If we repeat the exercise by mixing ten sinusoidal waves, we get the pair of
images \ref{c2f7} and \ref{c2f8}. We observe a much better knowledge of the
particle's position at the cost of losing information of $k$. We can now say
with a great confidence that the particle is likely to be in a small
neighbourhood of the origin.
\begin{figure}
\begin{center}
\includegraphics[scale=0.5]{ten-waves}
\caption{Superposition of ten cosine waves.}\label{c2f7}
\includegraphics[scale=0.5]{ten-waves-sq}
\caption{Squared modulus of superposition of ten waves.}\label{c2f8}
\end{center}
\end{figure}

These pictures indicate that there is always a trade-off in knowing $k$ and
knowing $x$. If you think this is just the mathematical property of sinusoids
you are absolutely correct. It is indeed a mathematical property that
\begin{equation}\label{c2s6e1}
\Delta x \Delta k \ge \frac{1}{2}.
\end{equation}
Physics connects momentum with $k$ through the equation
\begin{equation}\label{c2s6e2}
p = \frac{h}{\lambda} = \frac{h}{2\pi}k
\end{equation}
so that we can write equation \eqref{c2s6e1} as
\begin{equation}\label{c2s6e3}
\Delta x \Delta p \ge \frac{h}{4\pi}.
\end{equation}
This is the celebrated `Heisenberg uncertainty relation'. It tells us that
we cannot \emph{simultaneously} know the position and momentum of a particle.
We illustrate the uncertainty relation by considering a particle in one
dimension. As a result, its position and momentum had just one component.
However, in general, a particle will have three position components $(x, y, z)$
and three momentum components $(p_x, p_y, p_z)$. The complete set of uncertainty
relations is
\begin{eqnarray}
\Delta x \Delta p_x &\ge& \frac{h}{4\pi} \label{c2s6e4} \\
\Delta y \Delta p_y &\ge& \frac{h}{4\pi} \label{c2s6e5} \\
\Delta z \Delta p_z &\ge& \frac{h}{4\pi}. \label{c2s6e6}
\end{eqnarray}
However,
\begin{eqnarray}
\Delta x \Delta p_y &=& 0 \label{c2s6e7} \\
\Delta x \Delta p_z &=& 0 \label{c2s6e8} \\
\Delta y \Delta p_x &=& 0 \label{c2s6e9} \\
\Delta y \Delta p_z &=& 0 \label{c2s6e10} \\
\Delta z \Delta p_x &=& 0 \label{c2s6e11} \\
\Delta z \Delta p_y &=& 0 \label{c2s6e12}
\end{eqnarray}
Equations \eqref{c2s6e7} to \eqref{c2s6e12} guarantee that one can measure the
$x$ component of a particle and $p_y$ or $p_z$ components of its momentum with
arbitrary precision. Why is $\Delta x \Delta p_x \ge h/(4\pi)$ but $\Delta x
\Delta p_y = 0$? This question cannot be answered informally using the pictures
of superposed waves and their square modulii. The answer will be partly clear
when we study quantum mechanics later in this course.

\subsection{Problem set - 6}
\begin{enumerate}
\item An atom's size is of the order of $1$ A${}^\circ$. It means that the
uncertainty in the position of an electron in it is also of the same order.
What is the minimum uncertainty in momentum? What is the minimum uncertainty in
kinetic energy? (Assume that the electron moves at non-relativistic speed so
that its kinetic energy is $T = p^2/(2m_e)$, $m_e$ being the mass of the
electron.
\item Energy of nucleons (protons and neutrons) is of the order of $1$ MeV.
Can you estimate the size of the nucleus using the uncertainty relation?
\end{enumerate}


\documentclass{article}
\usepackage{amsmath,amsthm,amsfonts,microtype,amssymb}
\usepackage{enumitem}
\usepackage{parskip}
\usepackage{mathpazo}
\usepackage{tikz-cd}
\usepackage{geometry}
\geometry{top=1in}
\usepackage{float}
\usepackage{graphicx}

\usepackage{hyperref}
\hypersetup{%
  colorlinks=true,
  linkcolor=blue,
  filecolor=blue,
  urlcolor=blue,
  bookmarks=true,
  pdfpagemode=FullScreen,
}

\title{Homework 07 \\ Mayer--Vietoris Sequence}
\author{Algebraic Topology - Winter 2021}
\date{Due: \textbf{March 25, 2021, 11:59 pm}}

\begin{document}
\pagenumbering{gobble}
\maketitle

Using the Mayer--Vietoris sequence compute the singular homology with integer coefficients of the following spaces:
\begin{enumerate}
    \item $SX$ where $X$ is a \emph{path-connected} topological space,
    \item $S^1 \vee S^1$,
    \item $S^1 \times S^1$,
    \item $\mathbb{RP}^2$.
\end{enumerate}
You cannot assume that $H_1$ is the abelianization of $\pi_1$. You instead need to compute it explicitly using the long exact sequence.

\LaTeX ing long-exact sequences can get very tedious and time-consuming. Feel free to submit handwritten solutions for this homework.

\newpage
\section*{Suggested exercises for practice from Hatcher}

\begin{description}
\item[Pg. 157] 28, 29, 30, 31, 32, 35
\end{description}

\end{document}


The proposed autoscaling system scales a web application in response to change in throughput at fixed intervals, which we denote by reconfiguration intervals of 10 minutes. This system is able to provision the right amount and type of vm instances for minimizing the number of SLA violations while keeping the operational cost adapted to the customer requirements. Vertical and horizontal scaling actions can be applicable to satisfy the service demand. This architecture has the following key components:

\vspace{2mm}

\textbf{Predictor: } Inspired by~\cite{wolski_network_1999}, the Predictor component takes the monitoring data as input and uses different time-series analysis techniques to predict the future service demand for the next time interval. To provide accurate forecasting measures, this component utilizes the technique that exhibited the lowest cumulative error measure during the previous monitoring window. By doing so, the Predictor is able to adapt the predictions to the current type of workload. This component supports five distinct statistical models that fits four types of workload: \emph{(1)} \emph{Linear Regression} for linear trends~\cite{muppala_regression-based_2012}, \emph{(2)} \emph{Auto Regression Moving Average} (ARMA) for linear with small oscillations~\cite{roy_efficient_2011},\emph{(3)} \emph{Exponential Smoothing} for daily and seasonal~\cite{exponential_smoothing2010}, and \emph{(4)} \emph{Autoregression} and \emph{Vector Autoregression} for correlated trends~\cite{chandra_dynamic_2003,vector_autoregression_2006}.

\vspace{2mm}

\textbf{Profiler: } To choose a scaling plan, provisioning systems have to know the limitations of the different server configurations when running an application. The definition of profiles for each instance's type improves the accuracy of the scaling actions in heterogeneous cloud infrastructures. Thus, the Profiler component calculates the optimal throughput of each type of provisioned vm instance using profiling techniques.

% without any server instrumentation.

\vspace{2mm}

\textbf{Dynamic load balancer: } In order to adapt our system to the heterogeneity of requests and cloud resources, this component dynamically assign weights to the backend servers to proportionally distribute the incoming traffic based on the performance characteristics of each backend. As an example, a server with four cores is able to process a higher number of requests so its weight has to a be greater than a server with only one core.

\vspace{2mm}

\textbf{Scaler:} This component contains the central intelligence of our autoscaling system. As illustrated in Figure~\ref{autoScalingSys}, Scaler uses the Predictor and Profiler components to find the optimal provisioning strategy that fulfills a pre-established SLO (Service Level Objective). Furthermore, this component constantly analyzes the behavior of each provisioned vm triggering the Dynamic load balancer component when need it.

\begin{figure}[htb]
  \begin{center}
    \includegraphics[width=.85\linewidth]{images/monitoringSchema}
  \end{center}
\vspace{-5mm}
  \caption{Autoscaling system.}
  \label{autoScalingSys}
\end{figure}

%In the following we ..

%\subsection{Online profiling of allocated instances\label{profiling}}
\subsection{Online instance profiling\label{profiling}}

Regarding the resource heterogeneity of cloud infrastructures, a sensitivity analysis of the allocated resources is crucial to provide accurate scaling decisions. Accordingly, online profiling-based techniques~\cite{kaviani_profiling-as--service:_2011} have recently emerged as a solution to  estimate the resource's throughput under a certain workload. Traditionally, this technique replicates at runtime a server hosting an application, with a new server with profiling instrumentation that analyzes the performance behavior of a specific resource under a fixed percentage of the incoming traffic~\cite{jiangThesis,dejavu2012}. The use of fixed workloads to calculate the maximum throughput of a resource do not necessary imply the definition of more accurate profiles. A reason seems to be the lack of ideal performance isolation in cloud infrastructures which affects to the precision of the definitions, and consequently reduces the accuracy of the decisions. Furthermore, setting a profiling environment, in a heterogeneous cloud infrastructure, requires as many additional resources as number of available server configurations. Even though the use of online-profiling techniques is still under study, the configuration of a parallel environment and the heterogeneity of the cloud resources are the major drawbacks for its adoption. These techniques increase the operational cost and do not necessarily improve the accuracy of the scaling decisions.

%Even though the use of online-profiling techniques is still under study, the configuration of a parallel %environment and the limited accuracy of its scaling decisions are the major drawbacks for its %adoption.

As a consequence, we designed a novel online profiling technique that gives an estimation of the maximum throughput of each allocated instance's type without need for additional resources or parallel environments. To do that, the Profiler component use the provisioned resources for the analysis and estimation of the computing capacity of each available hardware configuration.

\begin{algorithm}
{\scriptsize
\SetAlgoLined
\SetInd{0mm}{2mm}
\KwData{ \\Service Level Objective, \emph{slo} \\ List of allocated instance types, \emph{inst\_types} \\ Compute units per \emph{inst\_type}, \emph{compute\_units$_{inst}$}}

\KwResult{Instances performance classification}

\While{ allocated instances to profile}{
\BlankLine
Collect profiling data of \emph{inst\_type}: \emph{req\_rate, cpu\_usage and resp\_time}\;

\While{ profiling data to smooth}{  \label{alg:smooth}
//Perform smoothing percentiles technique \;
\If{ \emph{resp\_time}$_i$ $>$ (slo * 0.25) and \emph{resp\_time}$_i$ $<=$ (slo * 0.75)}{
	\If{ \emph{req\_rate}$_i$ $>$ 0 and \emph{cpu\_usage}$_i$ $<$ 75}{
		\hspace{3mm} Add \emph{cpu\_usage$_i$} to cpu\_usage\_data\;
		\hspace{3mm} Add \emph{req\_rate$_i$} to req\_rate\_data\;
		\hspace{3mm} Add \emph{resp\_time$_i$} to resp\_time\_data\;
}
}
} \label{alg:endSmooth}
\BlankLine
Initialize instance capacity \emph{CPU speed$_{inst}$} to 0 \;
\uIf{ \emph{resp\_time\_data}, \emph{cpu\_usage\_data}, \emph{req\_rate\_data}  \textbf{not empty}}{
Calculate average of \emph{cpu\_usage\_data}, \emph{CPU$_{inst}$} \;
Calculate average of \emph{req\_rate\_data}, \emph{Num\_requests$_{inst}$} \;
\BlankLine
\emph{CPU speed$_{inst}$} = $\dfrac{\emph{CPU$_{inst}$} } {\emph{Num\_requests$_{inst}$} }$  \;
\BlankLine
Store instance computing capacity, \emph{CPU speed$_{inst}$} \;
}
\Else{
	Use historic value of \emph{CPU speed$_{inst}$} for \emph{inst\_type}\;
}
\BlankLine
Classify \emph{inst\_type} based on its computing capacity \;
\If{ CPU speed$_{inst}$ = 0 }{
Use \emph{compute\_units$_{inst}$} of \emph{inst\_type} to rank \emph{inst\_type} \;
}
\Else{
Use new value of \emph{CPU speed$_{inst}$} to rank \emph{inst\_type} \;
}
}
}
\caption{Instance profiling algorithm}
\label{profilingAlg}
\end{algorithm}

As detailed in Algorithm~\ref{profilingAlg}, once the Scaler component decides to trigger a scaling action, the Profiler component estimates the throughput of the allocated instances according the following steps:

\begin{enumerate}
\item Collect the latest hour of monitoring data from each instance's type. This profiling data contains information about monitoring metrics such as the request rate, cpu usage and response time, which provide enough feedback for the definition of instance profiles.

\item Perform a smoothing technique over the profiling data of each instance to remove the noise generated by traffic spikes. As pointed out in~\cite{gandhi_hybrid_2012}, when hosting web applications sudden changes in the workload, interference due to virtualization or OS activities may affect the precision of the profiling process. Hence, we decided to smooth the profiling data during the latest hour (or older if there is not enough data) to identify the performance capacity of one instance. In particular, the Profiler extracts the smoothed 75th and 25th percentiles from the response times below the SLO and 75th percentile from the cpu usage data-points. (See Lines \ref{alg:smooth}-\ref{alg:endSmooth}). This mechanism allows to identify the maximum ideal throughput of each instance while enforcing the performance requirements and avoiding CPU saturation. (based on the Amazon EC2 recommendation CPU usage < 75 )

As an example in Figure~\ref{fig:vm_performance}, we show the profiling data and percentiles for one "m1.small" (left) and one "c1.medium" (right) EC2 instance types during one hour. The gray areas represent the ranges of response times and cpu usage comprised by the percentiles. Red circles contain all data points that will be used to calculate the maximum ideal throughput of one instance. As we mentioned above, some data points are excluded as they identify periods of time on which resources suffered from under-utilization or over-utilization (denoted by white areas). Furthermore, as shown in Figure~\ref{fig:vm_performance} (left), a short number of data points are comprised between the percentiles for the "m1.small" instance. Its poor hardware configuration makes this type of instance more vulnerable to sudden changes in the workload.

%and three red circles highlight several data-points on which the performance of the instance was optimal while enforcing the %SLO.

%\begin{figure*}[htb]
%	\begin{minipage}[b]{0.5\linewidth}
%		\includegraphics[height=4.5cm]{images/vm_performance_resp_smallEC2Remark.pdf}		%\includegraphics[height=4.5cm]{images/vm_performance_cpu_smallEC2Remark.pdf}
%		\vspace{-4mm}
%	\end{minipage}
%	\hfill
%	\begin{minipage}[b]{0.5\linewidth}
%		\includegraphics[height=4.5cm]{images/vm_performance_resp_c1mediumRemark.pdf}		%\includegraphics[height=4.5cm]{images/vm_performance_cpu_c1mediumRemark.pdf}
%		\vspace{-4mm}
%	\end{minipage}
%\caption{Profiling data and percentiles of m1.small and c1.medium EC2 instances.}
%\label{fig:vm_performance}
%\end{figure*}

\begin{figure*}[htb]
	\begin{minipage}[b]{0.45\linewidth}
		\includegraphics[height=8.5cm]{images/idealSmallRemark.pdf}
		\vspace{-4mm}
	\end{minipage}
	\hfill
	\begin{minipage}[b]{0.45\linewidth}
		\includegraphics[height=8cm]{images/idealc1MediumRemark.pdf}
		\vspace{-4mm}
	\end{minipage}
\caption{Profiling data and percentiles of m1.small and c1.medium EC2 instances.}
\label{fig:vm_performance}
\end{figure*}

\item Classify the different instance types depending on its computing capacity. Using the profiling smoothed data of each instance type, the Profiler computes a factor, named \emph{CPU speed}, as the number of clocks required to process a request (clocks/request), where \emph{CPU$_{inst}$} represents the average of cpu usage and \emph{Num\_requests$_{inst}$} the average of request rate, as illustrated in the next Equation~\ref{cpu_speed}:

\begin{equation}\label{cpu_speed}
\begin{split}
CPU speed_{inst} = \dfrac{  CPU_{inst} } {Num\_requests_{inst} }
\end{split}
\end{equation}

The \emph{CPU speed$_{inst}$} factor gives an estimation of the ideal performance capacity of one instance when processing the current workload. Based on the value of this factor per-instance, the \emph{Profiler} classifies the different instances based on its computing capacity when running an application. The resulting classification gives an interesting feedback to the Scaler component, which is now able to identify the limitations of the instances, and consequently to choose an optimal scaling plan. Initially, there are not instance profiles due to the lack of monitoring data, thereby the Scaler uses the number of compute units per instance as a priori classification of their performance capacities. Note that, this work only consider the compute units, but memory or bandwidth can be also taken into account to classify the instances.

\end{enumerate}

This profiling process allows to define a profile per instance type, thus facilitating the selection of an appropriate scaling plan that satisfies the QoS requirements. As such, the accuracy of the scaling decisions can be improved independently of factors such as performance isolation in clouds or request heterogeneity.

\subsection{The scaling decision maker}

The Scaler component is the central governance of this autoscaling system, and thereby is the responsible of triggering any scaling decision.

%% Threshold fixed by the user

\subsubsection{Time-series smoothing}

When minimizing the SLA violations, a precise analysis of the monitoring data is crucial to improve the accuracy of the scaling decisions. It allows to identify the resource requirements from the current workload type. This analyisis has even more importance when hosting web applications (e.g. Wikipedia, Amazon) that need to provide high availability and performance to their clients. Moreover, the workload heterogeneity of this sites requires a meticulous analysis of every monitoring data-point to reduce at the maximum the number of SLO violations.

\begin{figure}[htb]
	\begin{minipage}[b]{0.49\linewidth}
		\includegraphics[width=4cm,height=3cm]{images/data2007/proxy_outputAvg.pdf}
		\vspace{-4mm}
	\end{minipage}
	\hfill
	\begin{minipage}[b]{0.49\linewidth}
		\includegraphics[width=4cm,height=3cm]{images/data2007/proxy_outputWMA.pdf}
		\vspace{-4mm}
	\end{minipage}
\caption{Response times for a trace: Average vs extended WMA.}
\label{fig:data_analysis}
\end{figure}

To obtain precise information (response times) that reflects the performance behavior of an application, we decided to extend a known smoothing technique called \emph{Weighted Moving Average} (WMA). This technique is widely used in resource provisioning systems instead of others such as the median, average or moving average. Using our extension of WMA, it first associated weights in an increasing order giving more importance to the latest monitoring data; and second it doubles the original weight value of each data-point that exceeds the performance requirements (response time). By doing so, the Scaler analyzes the monitoring data giving special importance to the data points on which SLO violations have occurred, and thereby being able to detect and avoid the maximum number of violations. As an example, Figure~\ref{fig:data_analysis} shows how several SLO violantions are omitted when analyzing the monitoring data using an average analytical method (left) than when using our version of WMA (right).

\subsubsection{Definition of a reactive threshold}

\fixme{Perhaps, you may want to omit this subsection, as it is more related to When to provision than How to provision ?}

Initially, the user defines several performance requirements that will be utilized by the Scaler to trigger scaling actions. As we mentioned, these QoS goals are previously specified in the Service Level Objective (SLO). In particual, when hosting web applications, these performance requirements are usually related to the maximum processing time needed to serve any request (response times). Regarding SLO fulfillment the majority of resource provisioning system aims to maintain the processing time as closer as possible to the performance requirements. However, this operation can become a problem, as provisioning systems are vulnerable to temporal traffic oscillations causing SLO violations.

Therefore, and based on the requirements, the Scaler defines a reactive threshold that will enable in advance to react against any traffic oscillation minimizing the number of SLO violations or period of time under-utilization of the provisioned resources. As shown in Figure~\ref{threshold}, this reactive threshold specifies one upper and lower boundaries creating two head-rooms between them and the performance requirements pre-defined by the user (for the response time). In the future, these two boundaries could be adjusted depending on the hardware configuration of each provisioned vm, as introduced in~\cite{beloglazov_adaptive_2010}.

\begin{figure}[htb]
  \begin{center}
    \includegraphics[width=.85\linewidth]{images/thresholdGraphic.jpg}
  \end{center}
\vspace{-5mm}
  \caption{Reactive threshold.}
  \label{threshold}
\end{figure}

\subsubsection{Vertical and horizontal scaling}

The \emph{Scaler} component supports two ways to add and remove resources to an application: vertical and horizontal scaling.
Horizontal scaling enables to create a cluster of virtual machines associated to one application whose size is dynamically adapted to the workload variations by adding or removing vmes to the cluster. This scaling technique is commonly supported for the majority of resource provisioning systems. In our system, vertical scaling enables to add or remove resources with high or less CPU or memory using \emph{service live migration}. Using this technique, the Scaler migrates the hosted service (web application) from one virtual machine to another with better hardware configuration. To reduce the degradations caused by this type of migration or by the booting time of the new machine, the Scaler checks the proper functioning of the new machine in order to release the older one.

Thus, the \emph{Scaler} evaluates whether the current performance behavior requires to trigger any of the following scaling actions:

\begin{itemize}

\item \textbf{Scale out or up:} Additional resources are provisioned if the performance behavior exceeds the upper boundary of the reactive threshold, and the \emph{Predictor} confirms that such traffic changes will remain at least during the next monitoring window (in our experiments 5min).

\item \textbf{Scale back or down:} Resources are released if the performance behavior exceeds the lower boundary of the reactive threshold, and the \emph{Predictor} confirms that such traffic changes will remain at least during the next monitoring window.

\end{itemize}

Note that, the \emph{Predictor} component will trigger short-term forecasts operations to minimize at the maximum the number of SLA violations, as well as to keep a high level of efficiency in the predictions.

%\begin{figure*}[htb]
%	\begin{minipage}[b]{0.3\linewidth}
%		\includegraphics[height=4.5cm]{images/prediction_conpaas_6min.eps}
%		\vspace{-4mm}
%	\end{minipage}
%	\hfill
%	\begin{minipage}[b]{0.3\linewidth}
%		\includegraphics[height=4.5cm]{images/prediction_conpaas_10min}
%		\vspace{-4mm}
%	\end{minipage}
%	\hfill
%	\begin{minipage}[b]{0.3\linewidth}
%		\includegraphics[height=4.5cm]{images/prediction_conpaas_30min}
%		\vspace{-4mm}
%	\end{minipage}
%\caption{ConPaaS Predictions, response times for 5min, 10min and 30min ahead.}
%\label{fig:vm_performance}
%\end{figure*}

\subsubsection{Scaling strategy decision-making}
The most important and challenging phase in a resource provisioning system is the selection of an appropriate scaling strategy (combination of resources) that satisfies the performance requirements with the lowest operational cost. This operation can become more laborious when running web applications, and therefore it has been barely addressed in the existing provisioning systems. Web applications are often a target of temporal traffic variations that may cause SLO violations having an impact in the user experience. Hence, the selection of an appropriate scaling plan becomes crucial to mitigate these penalties.

To overcome this challenging phase, the Scaler takes into consideration two aspects: resource heterogeneity and user experience. Cloud infrastructures are highly heterogeneous, offering a wide range of resource combinations. On the other hand, to boost the volume of customers, the user experience appears as a mandatory requirement in web applications contrary to budget cuts that may reduce the advantage over competitors.
Based on that, the Scaler computes the cost of all the possible resource combinations how the cost incurred by its SLO fulfillment degree and the infrastructure cost. The SLO fulfillment degree indicates the vulnerability of a strategy to experience SLO violations. To refine this search process according to the final goal and adapted to the customer preferences (user experience), the Scaler provides three classes of SLA agreements in function of the type of customer. These three classes of customers namely, gold, silver and bronze minimize the SLA violations with a different infrastructure cost. Accordingly, a gold customer pays more in order to get the best service at the cost of some extra over-provisioning. A silver customer gets good availability while a bronze customer obtains a reduced, but acceptable, SLA fulfillment but with very little over-provisioning.

Prior to any resource selection, the Scaler has to measure the requirements of the current workload. To do that, it has to compute its degree of complexity taken into account the total cpu usage and request rate served by the current scaling strategy. In Equation~\ref{workload_complexity}, the \emph{$Workload_{complex}$} factor represents the complexity of the incoming traffic and includes degradations caused by operative system activities, low network performance, vm sharing or request heterogeneity. These degradations are not detected by individually analyzing the request rate and cpu usage consumed by all the resources. Thus, the \emph{$Workload_{complex}$} is computed by using the sum of the cpu usage (denoted by \emph{$CPU\_usage_{i}$}) and the performance capacity of each allocated resource. The performance capacity is calculated as the average of the request rate served by each resource (denoted by $Num\_reqs_{i}$) and its ideal throughput (denoted by $CPU speed_{inst_{i}}$). By using the ideal throughput instead of calculating the current throughput, the Scaler is able to detect how much the current workload is affecting to the ideal performance of an instance.

{\scriptsize
\begin{equation}\label{workload_complexity}
\begin{split}
Workload_{complex}  = \dfrac{ \sum_{i=1}^N CPU\_usage_{i}  }  {  \sum_{i=1}^N \bigg(  Num\_reqs_{i}  * CPU speed_{inst_{i}}   \bigg)   }
\end{split}
\end{equation}
}

Additionally, the total cpu usage ($\sum_{i=1}^N CPU\_usage_{i} $) and request rate ($\sum_{i=1}^N  Num\_reqs_{i}$) can be calculated by the Predictor component to estimate the future service demand for the next monitoring windows (in our experiments 30min). This enables to select in advance a scaling strategy that will handle future variations in the workload, and thereby reducing the operational cost. As an example in Figure~\ref{fig:forecast}, the Predictor shows the forecast values for the resource requirements during the next 30min offering an acceptable level of accuracy.

\begin{figure}[htb]
  \begin{center}
    \includegraphics[height=5cm]{images/prediction_conpaas_30min}
  \end{center}
\vspace{-5mm}
  \caption{ConPaaS Predictor: prediction values for 30min ahead.}
  \label{fig:forecast}
\end{figure}

To decide which type of vm instances to release or add, the Scaler uses an optimal decision tree that calculates all the possible scaling strategies.  Figure~\ref{fig:scalingTree} shows three examples of scaling actions that propose three different resource combinations using EC2 instances. In the scaling decision tree, each node represents each type of vm instance offered by the cloud infrastructure. The branches define all the possible combination of resources. While the links indicate the percentage of CPU usage consumed to process the current workload when using a specific combination. Note that, CPU values provides enough feedback about the performance capacity, as it is a function of the request complexity  and number of served requests. To calculate the CPU usage consumed by each scaling strategy to process the current workload, Scaler uses the following formula~\ref{resource_combination}.

\begin{figure}[htb]
  \begin{center}
    \includegraphics[height=5cm]{images/scalingTree}
  \end{center}
\vspace{-5mm}
  \caption{Decision tree: scaling actions using EC2 instances.}
  \label{fig:scalingTree}
\end{figure}

%To calculate the different combinations of VM instances that enforce the performance requirements, we used the next

{\scriptsize
\begin{equation}\label{resource_combination}
\begin{split}
CPU_{strategy} = \dfrac{ \sum_{i=1}^n \bigg( \bigg( \dfrac{ Num\_reqs_{total} * Workload_{complex} }  {N}  \bigg) * CPU speed_{inst_{i}} \bigg) }  {N} \\
\\ {\small \textit{ If } CPU_{strategy} \leqslant CPU_{SLO} }
\end{split}
\end{equation}
}

Equation~\ref{resource_combination} defines how the workload will be distributed across the different instances taken into account their performance capacities.  Thus, the Scaler selects a strategy that uses \emph{N} resources to distribute the \emph{$Num\_reqs_{total}$} (total rate of served requests) with a complexity \emph{$Workload_{complex}$} across \emph{N} instances with an ideal throughput \emph{$CPUspeed_{inst}$}. Note that, the search of an optimal scaling strategy can represent a NP hard problem, so that Scaler limits the number of possible strategies by filtering them using a maximum CPU usage consumed by a strategy, where \emph{$CPU_{strategy} \leq CPU_{SLO}$}. \emph{$CPU_{SLO}$} can be calculated based on the Amazon EC2 recommendations with CPU values lower than 75\%, or based on the CPU values at which the application starts to experience SLO violations (or performance degradations). This assumption avoids to trigger new scaling actions in the next time interval saving costs. With the Equation~\ref{resource_combination} the Scaler is able to answer to the question \emph{"How many and which type of vm instances to provision?"}.

%is calculated using the Profiler component and will variate depending on the type of vm instance used in the strategy.

Once the Scaler obtains a list of filtered scaling strategies, they are classified based on their infrastructure cost and degree of SLO fulfillment, as defined in the Equation~\ref{strategy_cost}. The infrastructure cost specifies the price required to provision extra cloud resources. While the SLO fulfillment (\emph{slo\_fulfillment} in the Equation~\ref{strategy_cost}) represents its degree of vulnerability to violations. The \emph{slo\_fulfillment} cost is calculated given the percentage of \emph{$CPU_{strategy}$} and the \emph{$CPU_{SLO}$}, multiply by a SLO penalty (in \$)which is pre-established between the customer and provider. Obviously, higher values in the percentage of \emph{$CPU_{strategy}$} imply an increment in the probability of having SLO violations under traffic spikes, so the \emph{slo\_fulfillment} will increase as well. Therefore, according to the customer preferences, the Scaler will select one strategy with the lowest, highest or medium cost.

{\scriptsize
\begin{equation}\label{strategy_cost}
\begin{split}
infra\_cost = \sum_{i=1}^N \big( instance\_price_{i} \big) \\
slo\_fulfillment =  \bigg( \dfrac{ CPU_{strategy} } {CPU_{SLO}} \bigg) * SLO penalty \\
cost\_strategy = \dfrac{  slo\_fulfillment  } {infra\_cost}
\end{split}
\end{equation}
}

To decide which type of instance to release, the Scaler uses a conservative algorithm that releases the resources with the lowest utilization by analyzing their monitoring data. Similarly, a cost policy was also included for avoiding to choose wasteful scaling decisions. Considering the pricing model of cloud providers that charges users on a per-hour basis, the Scaler includes a cost policy that rejects strategies releasing vm instances which have been recently started ( 5min < time to the end of its hour < 20). Scaler releases resources which are closed to the hour are free under the cloud pricing model, and there is no gain from terminating them before this hour price boundary.

%A complete point of view of the whole scaling flow is shown in Figure~\ref{autoScalingFlow}.

%\begin{figure}[htb]
%  \begin{center}
 %   \includegraphics[width=\linewidth]{images/NewAutoScalingFlow}
%  \end{center}
%\vspace{-5mm}
%  \caption{Auto scaling flow.}
%  \label{autoScalingFlow}
%\end{figure}

\subsection{Dynamic load balancing weights: }

The problem we consider here is again the heterogeneity of cloud platforms.
Independently of its instance type, different virtual machines from the same cloud might have different performance
characteristics, even when their specifications from the cloud vendor are
the same~\cite{ec2Performance}. This issue can be addressed through various
load balancing techniques, like assigning weights to the backend servers or
taking into account the current number of connections that each server
handles. Furthermore, the performance behavior of the virtual servers may
also fluctuate, either due to changes in the application's usage
patterns, or due to changes related to the hosting of the virtual servers
(e.g., vm migration).

\begin{figure}[htb]
  \begin{center}
    \includegraphics[height=5cm]{images/load_balancing}
  \end{center}
\vspace{-5mm}
  \caption{Weighted load balancing flow.}
  \label{fig:load_balancing}
\end{figure}

In order to address these issues, the Scaler implemented a weighted
load balancing system in which the weights of the servers are
periodically re-adjusted automatically, based on the monitoring data.
This method assigns the same weight to each backend server at the
beginning of the process. As illustrated in Figure~\ref{fig:load_balancing}, the weights are then periodically
adjusted (in our experiments, using a monitoring window of $\sim$ 15min) proportionally
with the difference among the average cpu usage and request rate of the servers
during this time interval. By adding this technique to our autoscaling system,
the workload can be dynamically and proportionally distributed across the provisioned instances
depending on their performance capacities.

%we noticed a performance improvement when running the benchmarks, as discussed in the following.


%!TEX root=../mythesis.tex
% Chapter Template

\chapter{Late Interaction} % Main chapter title
\chaptermark{Late Interaction}  % replace the chapter name with its abbreviated form
\label{ch:late_interaction}

\section{Method}
\label{ch:late_interaction_method}
%
In this chapter, we present our next contribution designed specifically to tackle the long-standing decomposability gap problem described in~\sref{sec:open_book}.
%
Recall that in the original DPR architecture, the question $q$ and passage $p$ are encoded \emph{independently} at run time (see~\eqref{eq:dpr_encode}), which later gets multiplied to obtain the dot product as their similarity score.
%
By doing so, we effectively decompose the task of reading both $q$ and $p$ together to the task of extracting important information from each $q$ and $p$ to embedding vectors and later comparing them.
%
Our goal is to minimize the information loss caused by the extraction step.

\begin{figure}[!htbp]
	\centering
	\includegraphics[width=1.0\linewidth]{late_interaction/two_tower_late_interaction.pdf}
	\caption[Two-tower architecture of DPR retriever with the late interaction mechanism.]{
		%
		The two-tower architecture of the DPR retriever with the late interaction mechanism.
		%
		After the top-$n$ retrieval with the usual similarity scores $\text{sim}(q, p)$, where $n > k$, embedding vectors are fed to the feed-forward interaction layer to obtain the late interaction similarity scores $\text{sim}_L(q, p)$, after which the final set of ranked passages is returned.
	}
	\label{fig:two_tower}
\end{figure}

%
In this work, we propose to append a small parametric module after the information extraction step.
%
This component is designed to \emph{recover} necessary information from both the question and passage embeddings that will then be compared again for retrieval, thus called \emph{late interaction}.
%
\fref{fig:two_tower} presents an overview of our proposed method.
%
Specifically, suppose we have a question embedding vector $\mathbf{v}^{(q)}_{\texttt{[CLS]}} \in \mathbb{R}^d$ and a passage embedding vector $\mathbf{v}^{(p)}_{\texttt{[CLS]}} \in \mathbb{R}^d$ obtained from the question encoder and passage encoder, respectively, using~\eqref{eq:dpr_encode}.
%
We then allows simple interactions between the two vectors
%
\begin{equation}
\label{eq:late_concat}
\mathbf{v}^{(qp)}_{\texttt{[CLS]}} = [\mathbf{v}^{(q)}_{\texttt{[CLS]}}; \mathbf{v}^{(p)}_{\texttt{[CLS]}}; \mathbf{v}^{(q)}_{\texttt{[CLS]}} \odot \mathbf{v}^{(p)}_{\texttt{[CLS]}}; \mathbf{v}^{(q)}_{\texttt{[CLS]}} - \mathbf{v}^{(p)}_{\texttt{[CLS]}}] \in \mathbb{R}^{4d}
\end{equation}
where $[\cdot;\cdot]$ denotes vector concatenation and $\odot$ denotes the Hadamard product, which is a element-wise operation.
%
We obtain $\mathbf{v}^{(qp)}_{\texttt{[CLS]}}$, a vector containing information when the question representation is allowed to interact with the passage representation on the feature level via element-wise arithmetic operations.
%
This information-rich vector is then fed through a simple feed-forward (FFN) parametric module to obtain the final similarity score
\begin{equation}
\label{eq:late_sim}
\text{sim}_L(q, p) = \mathbf{m}_L^\intercal \mathbf{v}^{(qp)}_{\texttt{[CLS]}}  \in \mathbb{R}
\end{equation}
%
where $\mathbf{m}_L \in \mathbb{R}^{4d}$ is the weight vector of the FFN.

During training, we apply the same negative log-likehood objective function defined in Definition~\ref{def:nll} to the novel late interaction similarity scores
%
\begin{equation}
L_L(q_i, p^{+}_i, p^{-}_{i, 1}, p^{-}_{i, 2}, \ldots, p^{-}_{i, n}) = - \log \frac{e^{\text{sim}_L(q_i, p^{+}_i)}}{e^{\text{sim}_L(q_i, p^{+}_i)} + \sum_{j = 1}^{n} e^{\text{sim}_L(q_i, p^{-}_{i, j})}}
\end{equation}
%
The final objective function is then taken as sum of the two individual losses
\begin{equation}
L_{\text{late\_interaction}} = L(q_i, p^{+}_i, p^{-}_{i, 1}, p^{-}_{i, 2}, \ldots, p^{-}_{i, n}) + \lambda L_L(q_i, p^{+}_i, p^{-}_{i, 1}, p^{-}_{i, 2}, \ldots, p^{-}_{i, n})
\end{equation}
%
where $\lambda$ is the weight of the late interaction objective component.
%
In other words, we train the retriever model to minimize the losses with respect to both the usual similarity scores and late-interaction similarity scores, which can also be viewed as a multi-task training paradigm.

%
At test time, we use $\text{sim}(q, p)$ for our retrieval method and $\text{sim}_L(q, p)$ for our re-ranking method.
%
In particular, given at input query $q$, we first retrieve a set $\mathcal{C_F}\prime$ of top-$n$ highest-scoring passages from a pre-built FAISS index as described in~\sref{sec:dpr_training}, where $n > k$.
%
This means that we retrieve more passages than we need.
%
Afterwards, we feed the question feature embeddings $\mathbf{v}^{(q)}_{\texttt{[CLS]}}$ as well as the embeddings of each passage in $\mathcal{C_F}\prime$ to the late interaction module via~\eqref{eq:late_concat} and~\eqref{eq:late_sim} to obtain the late-interaction similarity scores with minimal additional computational cost.
%
These scores are then used to re-rank and filter the passages in $\mathcal{C_F}\prime$ to obtain the final set $\mathcal{C_F}$ of $k$ most relevant passages.

\section{Experimental Results}
\label{ch:late_interaction_results}

\begin{table*}[t!]
	\setlength\tabcolsep{5pt}
	\centering
	\small
	\begin{tabular}{ll|cccc}
		\toprule
		\textbf{Architecture} & \textbf{Loss function}
		& Top-1 & Top-5 & Top-20 & Top-100 \\
		\midrule
		\multirow{2}{*}{\shortstack{DPR \\(shared encoders)}} &
		DPR loss & \textbf{53.02} & \textbf{71.30} & \textbf{80.89} & \textbf{86.93} \\
		& DPR loss + late interaction loss & 51.66 & 69.42 & 79.64 & 86.15 \\
		\bottomrule
	\end{tabular}
	\caption[Top-$\{1, 5, 20, 100\}$ retrieval accuracy on the Natural Questions test set of the DPR retriever (shared encoders) with and without the late interaction module.]{
		%
		Top-$\{1, 5, 20, 100\}$ retrieval accuracy on the Natural Questions test set of the DPR retriever (shared encoders) with and without the late interaction module, calculated as the percentage of top-$k$ retrieved passages that contain the answer.
		%
		The proposed interaction component degrades the baseline DPR model performance by a sizable margin.
	}

	\label{tab:shared_encoders_results}
\end{table*}

%
We conduct an experiment on NQ following the experimental settings described in~\sref{sec:exp_setup} with a batch size of 24.
%
The baseline model is taken as the DPR retriever with parameter sharing introduced in~\cref{ch:shared_encoders}, and the hyperparameters are set to $\{n, \lambda\} = \{200, 1.0\}$.
%
\tref{tab:shared_encoders_results} presents the retrieval recall on the NQ test set.

%
We observe that the late interaction component brings about a marginal performance loss to the DPR retriever.
%
We believe there are several reasons that make designing a late interaction layer difficult.
%
First, the proposed interaction layer consists of a small parametric module with weights $\mathbf{m}_L \in \mathbb{R}^{4d}$, which might not be sufficient to fully capture such complex natural language interactions.
%
Second, our interaction layer makes use of only element-wise operations (\eqref{eq:late_concat}), therefore is incapable of modeling the complex cross-feature interactions between the question embeddings and passage embeddings.
%
Lastly, it is worth noting that we did not specifically tune the newly introduced hyperparameters $\{n, \lambda\}$ which can have a huge impact on the final model performance.
%
Nevertheless, a concurrent work of~\citet{khattab2020colbert} that shares a very similar idea to our proposed late interaction has shown that this mechanism is a valuable addon to the existing retriever to combat the problem of decomposability gap.
%
Therefore, we refer interested readers to~\cite{khattab2020colbert} for a complete work on this idea.


%\newpage
\subsubsection{\stid{3.13} CLOVER Sub-project SLATE}\label{subsubsect:slate}

\paragraph{Overview}

SLATE (Software for Linear Algebra Targeting Exascale)
provides fundamental dense linear algebra capabilities
to DOE and the HPC community at large.
To this end, SLATE provides
parallel basic linear algebra subprograms (BLAS), norms,
linear systems solvers, least square solvers,
singular value and eigenvalue solvers.

The ultimate objective of SLATE is to replace the
venerable Scalable Linear Algebra PACKage (ScaLAPACK) library,
which has become the industry standard for dense linear algebra operations
in distributed-memory environments.
After two decades of operation,
ScaLAPACK is past the end of its life cycle and overdue for a replacement,
as it can hardly be retrofitted to support GPUs,
which are an integral part of today's HPC hardware infrastructure.

Primarily, SLATE aims to extract the full performance potential and maximum
scalability from modern HPC machines with large numbers nodes,
large numbers of cores per node, and multiple GPUs per node.
For typical dense linear algebra workloads, this means getting close
to the theoretical roofline peak performance and scaling to the full size of
the machine.
This is accomplished in a portable manner by relying on standards
such as MPI and OpenMP.
%
% SLATE functionalities will first be delivered to the ECP applications
% that most urgently require SLATE capabilities
% (NWChem, GAMESS, EXAALT, QMCPACK, CANDLE, etc.)
% and to other software libraries
% that rely on underlying dense linear algebra services
% (STRUMPACK, SuperLU, etc.).
Figure~\ref{fig:slate-architecture} shows the role of SLATE
in the ECP software stack.

While the initial objective of SLATE is to serve as a successful,
drop-in replacement for ScaLAPACK with support for GPU accelerators,
the ultimate goal of SLATE is to deliver dense linear algebra capabilities
beyond the capabilities of ScaLAPACK.
This includes new features such as communication-avoiding
algorithms and randomization algorithms, as well as the potential to
support variable size tiles and block low-rank compressed tiles.

\begin{figure}[htb]
    \centering
    \includegraphics[width=0.75\textwidth]{projects/2.3.3-MathLibs/2.3.3.13-CLOVER/SLATE-architecture.jpg}
    \caption{\label{fig:slate-architecture}
    SLATE in the ECP software stack.}
\end{figure}

\paragraph{Key  Challenges}

\begin{enumerate}

\item
\textbf{Designing from the ground up:}
The SLATE project's primary challenge stems from the need to design the package
from the ground up, as no existing software package offers
a viable path forward for efficient support of GPUs
in a distributed-memory environment.

\item
\textbf{Facing harsh hardware realities:}
SLATE is being developed in a difficult hardware environment, where virtually
all the processing power is on the GPU side.
Achieving efficiency requires aggressive offload to GPU accelerators
and careful optimization of multiple bottlenecks, including
interconnect technology lagging behind the computing
capabilities of the GPUs.

\item
\textbf{Facing harsh software realities:}
SLATE is being developed using cutting-edge software technologies,
and relies on modern C++ features and recent extensions
to the OpenMP standard, many of which are not fully supported by compilers
and their runtime environments.
In terms of GPU acceleration, standardized solutions are still in flux.
% Also, while complete parallel programming frameworks exist, at this stage
% they have to be considered research prototypes.

\end{enumerate}

\paragraph{Solution Strategy}

\begin{enumerate}

\item
\textbf{Evolving design:}
Due to the inherent challenges of designing a software package
from the ground up, the SLATE project started
with a careful analysis of the existing and emerging
implementation technologies~\cite{abdelfattah2017roadmap},
and followed with a phase
of laying out the initial design~\cite{kurzak2017designing}.
Since then, the team has rolled out new computational routines
and performance improvements quarterly.
While we continue to refactor as needed to achieve high performance, the basic
design has solidified and been published~\cite{gates2019slate-design}.

\item
\textbf{Focus on GPUs:}
Efficient GPU acceleration is the primary focus of performance
engineering efforts in SLATE.
Where applicable, highly optimized vendor implementations of GPU operations
are used, such as the batched \texttt{gemm} routine.
Where necessary, custom GPU kernels are developed, as in the case of computing
matrix norms.
Care is taken to hide communication by overlapping it with GPU computations.

\item
\textbf{Community engagement:}
The SLATE team interacts on a regular basis with the OpenMP community,
represented in ECP by the SOLLVE project, and with the MPI community,
represented in ECP by the OMPI-X project and the Exascale MPI project.
The SLATE team also engages the vendor community through our contacts
at Cray, IBM, Intel, NVIDIA, AMD, and ARM.

\end{enumerate}

\paragraph{Recent Progress}

During 2020, the SLATE team expanded the Hermitian eigenvalue solver to
the generalized Hermitian problem of the forms $Ax = \lambda Bx$, $ABx =
\lambda x$, or $BAx = \lambda x$. These are of strong interest in
mechanics and chemistry applications, among others.
%
We also implemented the polar decomposition with the QDWH algorithm,
%
wrote a Users' Guide and Developers' Guide to document the public and
internal APIs,
%
and added native C and Fortran 2003 APIs that access SLATE's native
matrix types from outside C++.
%
Further work was done on performance enhancements, with notable gains
for BLAS (gemm, herk), norms, Cholesky and QR factorizations.
%
A new build system using CMake and Spack has been developed, in
collaboration with the NWChemEx project to help include BLAS++ and
LAPACK++ in their project.
%
All developments are documented in SLATE Working Notes
\footnote{\url{http://www.icl.utk.edu/publications/series/swans}.}

\paragraph{Next Steps}

\begin{enumerate}

\item
\textbf{Port to AMD and Intel platforms:}
Originally, SLATE was developed using NVIDIA CUDA and cuBLAS. We are now
abstracting the backend to run on AMD and Intel platforms. BLAS++ will
serve as a portability layer, with calls to NVIDIA cuBLAS, AMD rocBLAS,
or Intel oneMKL, as appropriate for the platform. CUDA kernels will be
ported to a combination of HIP, SYCL, and OpenMP offload.

\item
\textbf{Optimizing QR, eigenvalue, and singular value routines:}
These are fundamental routines used by many projects.
We have observed these routines that are not performing as well as expected.
In some cases, such as eigenvalues, we have already identified
improvements to be made to the algorithm, such as refactoring loops to improve
parallelism. In other cases, we will analyze traces to identify and
correct problems.

\item
\textbf{Implementing divide-and-conquer algorithm:}
For singular value and Hermitian eigenvalue problems, the divide-and-conquer
algorithm exhibits better performance and parallel scalability than the
traditional QR-iteration based algorithm currently used in SLATE.

\item
\textbf{Non-symmetric eigenvalue problem:}
Computing the non-symmetric eigenvalue problem is significantly more
computationally expensive than the Hermitian eigenvalue problem. Our
implementation will leverage the latest advances, such as aggressive early
deflation, to achieve high performance.

\end{enumerate}