\subsubsection{\stid{4.06} ECP EZ: Fast, Effective, Parallel Error-bounded Exascale Lossy Compression for Scientific Data}

\paragraph{Overview}

Extreme scale simulations and experiments are generating more data than can be stored, communicated and analyzed. Current lossless compression methods suffer from low compression ratio and do not adequately address the limitations in storage bandwidth and storage space of projected Exascale systems. Existing lossy compressors, although enabling greater data reduction, are not covering the needs of many ECP applications.

The EZ project is extending and improving the SZ lossy compressor for structured and unstructured scientific datasets respecting user-set error controls. SZ offers an excellent compression ratio and compression time. Further work is essential, however, to improve our SZ lossy compressor for ECP scientific datasets, while ensuring that user-set error controls are respected. Specifically, we are maximizing the effectiveness of SZ's three core compression algorithms: prediction, quantization, and coding. The EZ project focuses on optimization of the compression quality, including improvement of compression ratio, memory cost minimization, parallelization, addition of more error controls, and integration of SZ into parallel I/O environments (PnetCDF, ADIOS, HDF5). Our goal is to produce a high-quality lossy compressor responding to the needs of ECP Exascale applications and experiment users. To this end, we are working with multiple ECP application teams, including ExaSky cosmology teams (HACC and Nyx), molecular dynamics simulations groups (EXAALT, QMCPACK), x-ray laser imaging experimentalists (ExaFEL), and computational chemists (NWChem-X) to optimize SZ for their applications and to harden SZ for production use.

\paragraph{Key Challenges}

There are several key challenges in the EZ project.
\begin{itemize}
\item One key challenge in designing an efficient compressor for HPC applications is the large
diversity of scientific simulation data, such as various dimensions, different scales, and dynamic data changes in both
space and time.
\item Another challenge is that the scientific data may have irregular characteristics. The simulation data may exhibit spiky changes in small local areas. For instance, all the key data in the HACC code are stored in six 1D arrays: three coordinate fields (xx, yy, zz) and three velocity fields (vx, vy, vz). It is hard to get a high compression ratio because of lack of correlations between adjacent particles in each array.
\item It is non-trivial to parallelize the lossy compressor SZ to get a high speed-up because of the relatively strong data dependencies in the data compression and decompression phase. The data prediction step, for example, relies on the neighboring data points for each data point, such that the entire compression/decompression has to be split into multiple blocks. How to perform the block-wise compression efficiently is an uneasy issue because block-wise prediction may degrade the prediction accuracy.
\item Integrating SZ into parallel I/O libraries (such as PnetCDF and HDF5) is non-trivial, because these I/O libraries are designed and implemented differently with various interfaces. We need to develop the integration codes based on the I/O libraries' interface with minimal cost.
\end{itemize}

\paragraph{Solution Strategy}

As for the first challenge, we keep a close communication with ECP application users to understand their specific demands on the lossy compression. For instance, we have a weekly meeting with ExaSky team to discuss the required error bounds and compression quality of cosmology simulation data. We also provide multiple types of error bounds (such as absolute error bound, PSNR, relative error bound) allowing users to control the errors in different ways.

As for the second challenge, we develop some particular compression techniques based on specific data features across different applications.

As for the third challenge, we split the entire dataset into multiple blocks based on the number of threads/ranks and conduct an adaptive prediction method to optimize the prediction accuracy dynamically.

We overcome the last challenge by understanding the principle of the I/O libraries (either reading the related documents or communicating with the I/O library developers closely).

\paragraph{Recent Progress}

SZ has been released as an open source on GitHub (http://github.com/disheng222/SZ). Figure \ref{fig:sz-principle} (a) demonstrates the core step (data prediction and linear-scaling quantization) in SZ lossy compression using a 2D dataset. Our customized improved compression techniques for different datasets mainly focus on various prediction methods based on data features.
Figure \ref{fig:sz-principle} (b) demonstrates the visual quality of decompressed data for ExaSky-NYX VX field. We can see that SZ has a pretty high visual quality even with a high compression ratio up to 156:1.

\begin{figure}[htb]
\centering
\includegraphics[width=2.8in]{projects/2.3.4-DataViz/2.3.4.06-EZ/sz-illu.png}
\includegraphics[width=3.2in]{projects/2.3.4-DataViz/2.3.4.06-EZ/Visual-quality-NYX-SZ.png}
	\caption{\label{fig:sz-principle}Illustration of data prediction in SZ and visual quality of decompressed data for ExaSky-NYX VX field}
\end{figure}

We have improved the compression quality for some ECP applications significantly. For instance, we develop PaSTRI code that can significantly improve the compression ratio for GAMESS two-electron integral datasets by leveraging the potential scaled repeated patterns. We also implemented effective compression method supporting point-wise relative error bounds for the ExaSky project and studied its lossy compression quality with multiple resolutions. Experiments with point-wise relative error bound based compression shows that our solution leads to 31\%-210\% higher compression ratio than other lossy compressors do.

We developed the multi-thread OpenMP version for SZ and evaluate the parallel compression performance, as presented in Figure \ref{fig:openmpperformance} (a). It is observed that the compression can obtain a speed-up of 250+ and the overall performance using lossy compression+I/O can be improved 15X compared with the data I/O without lossy compressor.
we can observe that the OpenMP version of SZ obtains about 6:1$\sim$16:1 performance gain when using 8$\sim$64 threads to do the compression/decompression in parallel. Decompression has higher performance gain than compression as the number of cores grow because it does not need to construct the Huffman tree.

We completed the integration of SZ into three popular I/O libraries (PnetCDF, ADIOS, and HDF5). Figure \ref{fig:openmpperformance} (b) and (c) present the performance evaluation using PnetCDF integrated with SZ.

\begin{figure}[htb]
\centering
\includegraphics[width=2.8in]{projects/2.3.4-DataViz/2.3.4.06-EZ/openmp-perf-SZ.jpg}
\includegraphics[width=3.5in]{projects/2.3.4-DataViz/2.3.4.06-EZ/pNetCDF-perf-SZ.jpg}
\caption{Performance evaluation of SZ with OpenMP and PnetCDF}
\label{fig:openmpperformance}
\end{figure}

\paragraph{Next Steps} Our next efforts are:

\textbf{Improve compression ratio by leveraging the smoothness of the data in the time dimension.} (1) Explore techniques for compression in time dimension; (2) Integration of compression in time dimension. (3) Test and performance evaluation on available CORAL systems

%\textbf{Support advanced error controls allowing the user to specify relative error bounds and to control the error distribution.} We will write a report describing the integration of additional error controls (relative error bound and control of error distribution) in SZ.


\chapter{Multistage and iterative methods for the efficient and automatic construction of master equation models}
\label{chapter:automatic-construction-of-master-equation}


\chapter{Dynamics of superfluid systems}
\label{ch:dynamics}

A superfluid is a state of matter that acts like a classical fluid withoug viscosity.
This means that once a superfluid is set in motion, there is no retarding force to keep it from flowing.
There are a few known systems in which superfluidity can exist, such as $^4$He (sometimes called Helium II when in its superfluid phase)~\cite{Allen1938}, neutron stars~\cite{Migdal1960} or BEC systems~\cite{Einstein1925, Anderson1995}.
As stated, we will focus on BEC systems, but it is important to note that any results shown for superfluid vortex dynamics may have applications beyond cold, atomic physics.

Though there are many interesting differences between classical fluids and superfluids, we will focus here on vortex dynamics.
By rotating a fluid, it is possible to create a vortex around the axis of rotation; however, because of the viscosity of a classical fluid, the vortex will begin to shrink and eventually disappear without constant driving.
In a superfluid, this is not necessarily the case.

In addition, due to the quantization of angular momentum in quantum mechanics, the vorticity in a superfluid is also quantized with the circulation defined as~\cite{Pethick2002},
\begin{equation}
\Gamma = \oint\mathbf{v} \cdot d \mathbf{l} = 2\pi \frac{\ell \hbar}{m},
\label{Eq:phase}
\end{equation}
where $\ell$ is an integer value known as the phase winding.
In this case, the velocity is
\begin{equation}
v = \frac{\hbar}{m}\mathbf{\nabla}\phi,
\end{equation}
where $m$ is the mass of the atomic species.
Because the energy $E \propto \ell^2$, as a superfluid is spun faster, a vortex will not grow or shrink in size, but multiple vortices will spawn instead~\cite{Pethick2002}.
In other words, it is energetically favorable for two vortices of smaller angular mementum to form instead of a single vortex with a large amuont of angular momentum.
Large amounts of angular momentum will therefore lead to many vortices, which will arrange themselves in a triangular lattice structure known as an Abrikosov lattice~\cite{Abrikosov1957, Fetter2001}.
This behaviour is identical to that of Type II superconductors under the effects of a magnetic field.

Vortices in superfluid systems are also peculiar in their behaviour when compared to classical vortices.
Superfluid vortices must either end at the end of the condensate or reconnect in the form of vortex rings or other, more complicated vortex structures~\cite{Reichl2013}.
Because the circulation around superfluid vortices is quantized, when two vortices approach each other with different velocity fields, they may reconnect into smaller, more energetically favorable vortex structures.
During this reconnection, the abrupt change in energy will create a sound wave at the reconnection site~\cite{Feynman1955}.

Three dimensional vortex structures have been notoriously difficult to generate in an experimental laboratory... ADD MORE FROM VORTEX STATES PAPER!!!

\section{Methods for vortex generation in superfluid BEC systems}

\subsection{Phase imprinting}
\subsection{Artificial magnetic fields}
\label{sec:gauge}

BECs are typically weakly interacting and composed of neutral atoms, which do not have charge that is directly affected by electric and magnetic fields; however, artificially magnetic fields can still play a crucial role in many cold atomic systems.
For example, artificial magnetic fields can lead to the generation of vortices in BEC systems~\cite{Lin2009}.
Since we desire to generate vortex rings with artificial magnetic fields, a detailed introduction, similar to that given by Dalibard in~\cite{Dalibard2015}, will be presented below.

From classical electrodynamics, we define can the magnetic field as
\begin{equation}
\mathbf{B} = \nabla \times \mathbf{A},
\end{equation}
where $\mathbf{A}$ is known as a vector potential and has no classical physical interpretation.
Thus, it can be be defined somewhat arbitrarily.
For example, if we have a uniform magnetic field in the $\hat z$ direction, $\mathbf{B} = B \hat z$, we may choose from many different options, such as the symmetric gauge
\begin{equation}
\mathbf{A}(r) = \frac{B}{2}(x \hat y - y \hat x),
\end{equation}
or the Landau gauge
\begin{equation}
\begin{split}
\mathbf{A}(r) &= Bx \hat y, \\
\mathbf{A}(r) &= By \hat x.
\end{split}
\end{equation}

Even though $\mathbf{A}$ has no \textit{classical} ramifications, in the \textit{quantum} realm, it can have physical implications.
The most famous example of this is the Aharonov-Bohm effect~\cite{Aharonov1959}.
Imagine a solenoid extending infinitely in the $\hat z$ direction, with an of electric current circulating through to create a static magnetic field through the center of the solenoid, but not on the exterior.
As mentioned above, this magnetic field could correspond to a few different gauge choices.
If we send a charged particle from one point on the exterior of the solenoid to an identical point on the other side of the solenoid by avoiding the solenoid, no matter what path we choose to send the particle along, there would be no significant difference between the different chosen paths.
This is obvious because the magnetic field is negligible on the exterior of the solenoid.
If we instead imagine sending a quantum particle around the solenoid, we could imagine a phase associated with a non-zero $\mathbf{A}$ given by
\begin{equation}
\phi = \frac{q}{\hbar}\int_P \mathbf{A} \cdot d\mathbf{r},
\end{equation}
where $q$ is the charge of the particle and $P$ is the chosen path.
If we connect the two paths, then we could imagine a change in phase related to the magnetic flux $\Phi_B = \mathbf{B}\eta$, where $\eta$ is the area within the object.
That phase difference would be
\begin{equation}
\Delta\phi = \frac{q\Phi_B}{\hbar}.
\end{equation}

The Aharonov--Bohm effect is a simple example with huge consequences: gauge fields matter in quantum mechanics.
In the following, we will discuss how to use this consequence to our advantage by first rotating our system to generate vortices, and then generating vortices again by using geometric gauge fields.

\subsubsection{Artificial Magnetic Fields With Rotation}
\label{sec:rot}

Even with an appropriate gauge field, to create rotation we still must somehow provide angular momentum to our cold atomic system.
Imagine a charged particle in a magnetic field undergoing gyromotion through the Lorentz force law, $F=q\mathbf{v} \times \mathbf{B}$.
By applying the appropriate transformation, the Hamiltonian for this system becomes
\begin{equation}
\hat H = \frac{(\hat{\mathbf{p}} - q \mathbf{A}(\hat{\mathbf{r}}))^2}{2m} + V_0(\hat{\mathbf{r}}),
\label{eqn:lorentz}
\end{equation}
where $q$ is the charge of the particle and $\hat p$ is its momentum.
Now, let us consider the same law, except with artificial magnetic fields created for cold, atomic systems.

As mentioned before, cold atoms are neutral and because of this, we must find ways to simulate the effects of magnetic fields instead of using magnetic fields themselves.
Imagine a plane rotating with an angular velocity $\Omega$ around the $z$-axis ($\mathbf{\Omega} = \Omega \hat z$).
In this case, the Coriolis force is defined as
\begin{equation}
\mathbf{F}_{\text{Coriolis}} = 2m \mathbf{v} \times \mathbf{\Omega},
\end{equation}
which is formally similar to the Lorentz force law.
By applying the transformation $\hat H = \hat H_0 - \Omega \hat L_z$, where $\hat L_z = x\partial_y - y\partial_x$, we find~\cite{Bhat2008}
\begin{equation}
\begin{split}
\hat H &= -\frac{\hbar^2}{2m}\nabla^2 + \frac 1 2 m \omega^2(x^2 + y^2) - \frac{\hbar \Omega}{i}(x\partial_y - y\partial_x) \\
 &= \frac{1}{2m}\left(\frac{\hbar}{i}\nabla - m(\mathbf{\Omega} \times \mathbf{r})\right)^2 + \frac m 2 \left( \omega^2 - \Omega^2 \right)r^2 \\
 &= \frac{(\hat{\mathbf{p}}-m\mathbf{A}(\mathbf{r}))^2}{2m}+ V_0(\mathbf{r}),
\end{split}
\end{equation}
where $\omega$ is the trapping frequency for a symmetric two-dimensional harmonic trap, $\mathbf{A} \equiv \mathbf{\Omega} \times \mathbf{r}$, and $V_0 = m/2 \left( \omega^2 - \Omega^2 \right)r^2$.
The final form is similar to that of Equation~\eqref{eqn:lorentz} for the Lorentz force law and coincide with an effective magnetic field according to $2 \mathbf \Omega \rightarrow \mathbf B$.
In this way, we may recreate the rotation expected from the Lorentz force law in a cold atomic system with an artificial magnetic field~\cite{Peshkin1989, Madison2000, Abo-Shaeer2001}.

With this method of generating vortices, the potential term $V_0$ becomes negative when $\Omega > \omega$, which allows particles to exit the trap, and there have been experiments rotating a BEC up to this limit~\cite{Schweikhard2004}.
In 2009, Lin~\textit{et~al.} showed that it was possible to generate vortices with geometric gauge fields instead, which can circumvent this limitation~\cite{Lin2009}.
We will now discuss how to generate vortices in BEC systems with geometric gauge fields instead of rotation.

\subsubsection{Geometric Gauge Fields}
\label{sec:geom}

In the following, we will discuss the adiabatic motion of free atoms undergoing geometric phase transformations through the Berry phase.
For this, we assume that our system has an external parameter $\lambda$ such that
\begin{equation}
\hat H(\lambda) \ket{\psi_n(\lambda)} = E_n(\lambda)\ket{\psi_n(\lambda)},
\end{equation}
where the set of eigenstates $\left\{ \ket{\psi_n(\lambda)} \right\}$ allow us to define the time evolution of our system such that
\begin{equation}
\ket{\psi(t)} = \sum_n c_n(t) \ket{\psi_n(\lambda(t))},
\end{equation}
and we consider $\lambda$ to evolve slowly with time. If we consider the system to begin with
\begin{equation}
c_l(0) = 1,
\qquad
c_n(0) = 0,
\qquad
\text{for all } n\neq l
\end{equation}
the state of the system is proportional to $\ket{\psi_l(\lambda(t))}$.
In this case, $c_l(t)$ is determined by the equation
\begin{equation}
i \hbar \dot{c}_l =  [E_l(t) - \dot{\lambda} \cdot \mathbf{A}_l(\lambda)]c_l,
\label{Bcnx-1}
\end{equation}
where
\begin{equation}
\mathbf{A}_l(\lambda) = i \hbar \braket{\psi_l|\nabla\psi_l}.
\label{eqn:Bcnx}
\end{equation}
This quantity is called the Berry connection, which is considered a vector potential, such that we can define a new artificial magnetic field, the Berry curvature as
\begin{equation}
\mathbf{B}_l = \mathbf{\nabla} \times \mathbf{A}_l.
\label{eqn:BC}
\end{equation}

Now imagine that the $\lambda$ parameter follows the closed contour $C$ such that $\lambda(T) = \lambda(0)$.
By integrating Equation~\eqref{Bcnx-1} above, we find
\begin{equation}
c_l(t) = e^{i \Phi_{\text{dyn}}(t)}e^{i\Phi_{\text B}(T)}c_l(0),
\label{eqn:c}
\end{equation}
where
\begin{equation}
\begin{split}
\Phi_{\text{dyn}}(T) &= - \frac{1}{\hbar}\int_0^TE_l(t)dt \\
\Phi_{\text{Berry}} (T)&= \frac{1}{\hbar} \int_0 ^T \dot{\lambda} \cdot \mathbf{A}_l(\lambda)dt = \frac{1}{\hbar}\oint\mathbf{A}_l(\lambda) \cdot d\lambda
\end{split}
\end{equation}
In this case $\Phi_{\text{Berry}}$ is called the Berry phase and it only depends on the motion path of $\lambda$.
It should be mentioned that both of the exponential terms in Equation~\eqref{eqn:c} are gauge invariant and thus remain unchanged when $\ket{\psi_n(\lambda)}$ is multiplied by a phase factor.
This phase allows us to transfer angular momentum into our BEC and generate a vortex geometry like those formed in the 2009 experiment by Lin~\textit{et~al.}~\cite{Lin2009}.
A method to generate these gauge fields in an experimentally realizable way will be described in Section~\ref{sec:evanescent}, but for now let us discuss the possible dynamics of similar in three dimensional systems.

%-------------------------------------------------------------------------------
\section{Vortex ring dynamics in BEC systems}
\label{sec:vortex}

As mentioned in Section~\ref{sec:intro}, in BEC systems with large amounts of angular momentum and a single axis of rotation, the vortices will create a two-dimensional Abrikosov lattice.
This regular structure is a direct consequence of the quantization of angular momentum in quantum mechanics.
There are many interesting features to vortices in superfluid systems, many of which follow from classical fluid dynamic theory~\ref{Fetter2009}, which is a well-studied field and covered in many texts~\cite{Faber1995, Kundu2012, Tritton1988, Landau1987}
Here, we discuss the dynamics of vortex rings in BEC systems.

In a three dimensional BEC and other superfluid systems, vortices can be described as as a system of freely-moving, current-carrying wires located along the axis of rotation.
In this way, it is possible to model such systems using the Biot-Savart law ~\cite{Schwarz1985}
\begin{equation}
    \boldsymbol{v}_s(\boldsymbol{r},t) = \frac{\kappa}{4\pi}\int\frac{|s_1-\boldsymbol{r}|\times ds_1}{|s_1-\boldsymbol{r}|^3},
\label{eqn:BS}
\end{equation}
where $\kappa = \hbar / m$ is the circulation.
This method of modelling a superfluid system has been called the ``vortex filament model,'' and allows us to attain an intuitive understanding for the motion of vortices in a superfluid system; however, it falls short in several areas, such as sound wave propagation and vortex reconnections~\cite{Zuccher2012}.
In electrodynamics, current can only flow within a closed loop or between two conductors.
Similarly, when a vortex filament is generated by injecting angular momentum into a superfluid system, it must either end at the edges of the superfluid or reconnect with other vortices.

Imagine providing a superfluid with an angular momentum of $\hbar k$.
In this case, a single vortex will be generated along the axis of rotation.
If another vortex is generated, we would expect it to change the dynamics of the superfluid and move our initial vortex.
If the new vortex has an angular momentum of $+\hbar k$, the two vortices will be repelled from each other, and if the new vortex has an angular momentum of  $-\hbar k$, it will be called an ``antivortex'' and the pair will be attracted to each other, eventually annihilating on contact.
If we rotate the condensate with integer multiples of $\hbar k$ angular momentum, we can generate many vortices, all rotating in the same direction and repelling off each other, creating the Abrikosov lattice structure from their mutual repulsion~\cite{Fetter2010}.

ADD FIGURE

By modifying our axis of rotation, we may imagine more complex vortex topologies to be created.
For example, imagine the toroidal velocity field shown in Figure~\ref{fig:V_R}, which will lead to  vortex filaments generating a ring instead of a single line.
This vortex ring structure is common in large, three dimensional modelling of fluid systems and is a direct consequence of the required connections of vortex lines.
In other words, the stability of vortex rings is ensured by Kelvin's theorem~\cite{Donnelly1991}, which means that unstable excitations may decay into vortex rings~\cite{Anderson2001}.
Now, we will discuss the dynamics of these rings.

We will begin our discussion of vortex rings with the thin-core approximation in inviscid fluids, as described by Barenghi and Donnelly~\cite{Barenghi2009}.
If we imagine a thin vortex ring of radius $R\gg a$, where a is the core radius, and  with circulation $\Gamma$ moving in an inviscid fluid with density $\rho$, the kinetic energy of the ring is given by
\begin{equation}
    E = \frac 1 2 \rho \Gamma^2R\left[\ln\left(\frac{8R}{a}\right)-\alpha\right],
\end{equation}
where $\alpha$ is a parameter determined by the system, and different
values of $\alpha$ correspond to different core models for vortex motion.
For example, it is 1.615 for the GPE~\cite{Roberts1971}.
This equation follows from the Biot-Savart law (Equation~\eqref{eqn:BS}) above.
The momentum of the system is given by
\begin{equation}
    p = \rho \Gamma \pi R^2,
\end{equation}
and the self-induced velocity is~\cite{Roberts1970}
\begin{equation}
    v = \frac{\partial E}{\partial p} = \left(\frac{\Gamma}{4 \pi R}\left[\ln(\frac{8R}{a})-\beta\right]\right),
\end{equation}
with $\beta = \alpha - 1$ under constant pressure, and $\beta = \alpha - 3/2$ under constant volume.
This method of vortex ring analysis has been extended to rings with finite, but small values of the core radius~\cite{Fraenkel1970, Fraenkel1972}.
%\tbc{These equations come from the Biot-Savart law above.
%If we consider a filament that is infinitesimally thin, we find an energy $E = \rho \Gamma^2 R/2$ and a velocity of $v = \Gamma / 4 \pi R$.}

If we imagine a single vortex ring, we can define a vortex bubble as its region of influence within the surrounding fluid.
If we take a two-dimensional slice of this ring as shown in Figure~\ref{fig:V_B}, we may represent the vortex bubble as the region influenced by two infinitely long, parallel vortex filaments with opposite vorticity.
There is an interesting analog to vortex rings and current-carrying loops in the theory of electromagnetism.
With a current-carrying wire, a dipolar magnetic field will be created and there is a well-defined spherical region in space where the loop's field overrides any external field.
In this way, the current density within the wire is related to the vorticity of a vortex loop at its core and the wire's magnetic field is related to the fluid velocity, $v$~\cite{Fetter1966}.

ADD FIGURE

In the case of multiple interacting vortex rings, we can expect to find many similar features in superfluids to what has been found previously in classical, viscous fluids.
If two vortex rings are generated in the same plane and in close proximity, it could be possible for the two velocity fields to interact, causing one ring to expand and slow down while the other contracts and speeds up.
Under the right conditions, the lagging ring can pass the forward ring through a process known as ``leapfrogging"~\cite{Sommerfield1950, Caplan2014}.

In addition to leapfrogging, vortex rings can interact through direct collisions~\cite{Shariff1992}.
In superfluid $^4$He, some of the earliest experiments on vortex collisions with vortex rings were performed by Schwarz in 1968~\cite{Schwarz1968}.
In the case of a head-on collision, two identical, moving vortex rings will first grow in size before dispersing into a series of smaller vortex rings around their common circumference~\cite{Lim1995}.
These smaller rings are created by vortex reconnection, which can occur any time vortex lines are facing anti-parallel directions.

Finally, we will briefly discuss vortex reconnections.
As predicted by Feynman in 1955, vortex reconnections in a superfluid lead to larger vortices continually reconnecting into smaller ones until the loops become small enough to decay from dissipation or from interactions with boundaries.~\cite{Feynman1955}.
These reconnections are thought to produce sound waves when vortices directly interact and Kelvin waves when vortices indirectly interact~\cite{Paoletti2011}.
When a vortex ring structure is not pinned by either gauge fields or rotation, it will evolve naturally by reconnecting into smaller and smaller vortex rings~\cite{Jackson1999}.
This means that we expect to see vortex reconnections in any sufficiently complicated vortex tangle~\cite{Barenghi2014}.
In addition, when simulations of vortex rings were performed by Jones and Roberts, they found that by computing vortex rings towards the limit of $R \rightarrow a$, they eventually found a solitary wave~\cite{Jones1982, Berloff2005}.


\section{Introduction}

\castro\ has three radiation solvers:
\begin{itemize}
\item {\tt SingleGroupSolver}: this solver does not have radiation
  pressre.  It is pure hydro plus radiation diffusion.  This is only
  applicable when the medium is optically thick and the pressure is small.

\item {\tt SGFLDSolver}: this is the gray flux-limited diffusion
  radiation hydrodymamics solver.  Here the radiation pressure is
  separate from the gas pressure, and both pressures participate in
  the Riemann solver.

\item {\tt MGFLDSolver}: this is the multigroup flux-limited diffusion
  radiation hydrodynamics solver.  As with the gray solver, radiation
  pressure contributes to the pressure in the Riemann solver.  Here a
  number of energy groups are used to represent the radiation field,
  and the opacity can be frequency-dependent.

\end{itemize}

The gray solver has a comoving frame mode and a mixed frame mode,
whereas the MG solver uses the comoving frame approach.  More details
about the formulation and algorithm can be found in the series of
\castro\ papers.

\section{Getting Started}

\subsection{Getting the Code}

The \castro\ radiation solver is part of the main \castro\ git repo,
so you already have all the \castro\ code and problem setups
to exercise radiation.  The only other requirement is a copy
of the \hypre\ library. \hypre\ provides the algebraic multigrid
solvers used by the implicit radiation update.  You can get
a copy at \url{https://computation.llnl.gov/casc/linear_solvers/sls_hypre.html}.  You will need to follow their installation instructions.

In addition to the environment variables you set for the main
\castro\ hydrodynamics problems, you also need to tell the code
where to find \hypre.  This is done via one of two variables:
\begin{itemize}
\item the environment variable {\tt HYPRE\_DIR} should
  point to the location of your Hypre installation
  (e.g., {\tt\seqsplit{/home/J.Doe/hypre}}) or
  can be set directly in
  {\tt\seqsplit{CastroRadiation/Exec/Make.Castro}}.
  This applies is you build with {\tt USE\_OMP=FALSE}

\item the variable {\tt HYPRE\_OMP\_DIR} should be set (either as an
  environment variable or in
  {\tt\seqsplit{Castro/Exec/Make.Castro}}) to the directory
  for openmp enabled Hypre (e.g.,
  {\tt\seqsplit{/home/J.Doe/hypre-omp}}) if you build with {\tt
    USE\_OMP=TRUE}
\end{itemize}

Now go to a ``run'' directory, say
{\tt\seqsplit{Castro/Exec/radiation\_tests/RadThermalWave}},
edit the file {\tt GNUmakefile}, and set
\begin{itemize}
\item {\tt COMP} = your favorite compiler suite (e.g., {\tt gnu}, {\tt pgi}, {\tt intel})
\item {\tt DIM}   = 1 or 2 or 3
\item \makevar{USE\_RAD} {\tt = TRUE}---this is important.  This tells the build system to
  compile in, and link the the radiation code.
\end{itemize}
Then type {\tt make} to generate an executable file.

\section{Microphysics: EOS, Network, and Opacity}

\subsection{EOS}

\castro\ provides several types of equation of state (EOS), including
gamma-law and Helmholtz.  To use the gamma-law EOS, set
\begin{verbatim}
EOS_DIR := gamma_law_general
\end{verbatim}
in the {\tt GNUmakefile}.

The original Helmholtz EOS for stellar interiors includes a radiation
contribution.  However, for radiation hydrodynamics calculations, the
radition contribution should be taken out of EOS because radiation has
been treated in other places.  To use Helmholtz EOS, we will use the
version in \microphysics, as with the pure hydrodynamics code, but
this will interpret the \ifdef{RADIATION} preprocessor variable and
disable the radiation portion of the EOS\footnote{at the moment, we
  don't have a way to allow for the EOS to provide radiation pressure
  if the \castro\ radiation is used solely for neutrinos, but this is
  something that could be added easily.}  If you have your own EOS, you
can put it in \microphysics.

\subsubsection{EOS Parameters}

The following parameters affect how the radiation solver used the EOS:
\begin{itemize}
  \item {\tt radiation.do\_real\_eos = 1}

    Usually you do not want to change this from the default.  Setting
    this to {\tt 0} is only for contrived tests that assume the
    specific heat is in the form of a power-law,
    \begin{equation}
      c_v = \mathrm{const}\ \rho^m T^{-n}
    \end{equation}

\end{itemize}

\subsection{Network}

The radiation solver uses the same networks as we saw for pure hydro,
so nothing needs to change here.  Again, if you are not modeling
reactions, then the {\tt general\_null} network can be used to define
the appropriate composition for your problem.

\subsection{Opacity}

By default, we assume that
\begin{equation}
  \kappa = \mathrm{const}\ \rho^{m} T^{-n} \nu^{p} , \label{eq:kappa}
\end{equation}
where $\kappa$ is either Planck or Rosseland mean absorption
coefficients, $\rho$ is density, $T$ is temperature, $\nu$ is
frequency, and $m$, $n$ and $p$ are constants.  For the gray solver,
$p = 0$.  If Equation~(\ref{eq:kappa}) is sufficient, set
\begin{verbatim}
Opacity_dir := null
\end{verbatim}
in {\tt GNUmakefile}.  Otherwise, put your own opacity in
{\tt\seqsplit{Castro/Microphysics/opacity}} and set
the input parameter, {\tt radiation.use\_opacity\_table\_module = 1} (see
\S~\ref{sec:opacpars}).

Some notes:
\begin{itemize}
\item Here, $\kappa$ has units of $\mathrm{cm}^{-1}$.  Some papers or
  texts may instead have an implicit density factor in $\kappa$,
  yielding units $\mathrm{cm}^2~\mathrm{g}^{-1}$.

\item \castro\ allows for two temperatures (different radiation and gas
  temperature, so $E_\mathrm{r} \ne a T_\mathrm{gas}^4$).
  Correspondingly,  \castro\ cares about both the Planck mean,
  $\kappa_P$, and Rosseland mean, $\kappa_R$, opacities---these have
  different weightings.

  If we set $\kappa_P \Delta x \gg 1$ ($\kappa_P$ is really large),
  then the two temperatures become the same.

  If we set $\kappa_P = \kappa_R$, then we can see how different the
  two temperature are.

  In an optically thick medium, we would not expect the two temperatures
  to be very different.

\end{itemize}

\subsubsection{Opacity Parameters}
\label{sec:opacpars}

The parameters describing the opacity include:
\begin{itemize}

\item {\tt radiation.use\_opacity\_table\_module = 0}

  For neutrino problems, this parameter is not ignored.  For photon
  problems, this determines whether the opacity module at {\tt
    Opacity\_dir} (which is set in {\tt GNUmakefile}) will be used to
  compute opacities.  If this is set to 1, the following parameters
  for opacities will be ignored.

\item For the Planck mean opacity of the form in Eq.~(\ref{eq:kappa}),
  the following parameters set the coefficient and exponents:
  \begin{itemize}
  \item {\tt radiation.const\_kappa\_p = -1.0}
  \item {\tt radiation.kappa\_p\_exp\_m = 0.0}
  \item {\tt radiation.kappa\_p\_exp\_n = 0.0}
  \item {\tt radiation.kappa\_p\_exp\_p = 0.0}
  \end{itemize}

\item For the Rosseland mean opacity of the form in Eq.~(\ref{eq:kappa}),
  the following parameters set the coefficient and exponents:
  \begin{itemize}
  \item {\tt radiation.const\_kappa\_r = -1.0}
  \item {\tt radiation.kappa\_r\_exp\_m = 0.0}
  \item {\tt radiation.kappa\_r\_exp\_n = 0.0}
  \item {\tt radiation.kappa\_r\_exp\_p = 0.0}
  \end{itemize}

\item For the scattering coefficient of the form in Eq.~(\ref{eq:kappa}),
  the following parameters set the coefficient and exponents:
  \begin{itemize}
  \item {\tt radiation.const\_scattering = 0.0}
  \item {\tt radiation.scattering\_exp\_m = 0.0}
  \item {\tt radiation.scattering\_exp\_n = 0.0}
  \item {\tt radiation.scattering\_exp\_p = 0.0}
  \end{itemize}

\item {\tt radiation.kappa\_r\_floor = 0.0}

  Floor for Rosseland mean.

\item{\tt radiation.do\_kappa\_stm\_emission = 0}

  If it is 1, correction for stimulated emission is applied to Planck mean as
  follows
  \begin{equation}
    \kappa = \mathrm{const}\ \rho^{m} T^{-n} \nu^{p}
    \left [1-\exp{\left (-\frac{h\nu}{k T} \right )} \right ].
  \end{equation}

\item {\tt radiation.surface\_average = 2}

 How the averaging of opacity is done from faces to center for
 the radiation solver.  {\tt 0} is arithmetic averaging, {\tt 1}
 is harmonic averaging, and {\tt 2} is a combination of the two.
 This is implemented in {\tt RAD\_?D.F} in {\tt kavg}.

\end{itemize}

\noindent Note that the unit for opacities is $\mathrm{cm}^{-1}$.  For
the gray solver, the total opacity in the diffusion coefficient is the sum
of {\tt kappa\_r} and {\tt scattering}, whereas for the MG solver,
there are two possibilities.  If {\tt const\_kappa\_r} is greater than
0, then the total opacity is set by {\tt kappa\_r} alone, otherwise
the total opacity is the sum of {\tt kappa\_p} and {\tt scattering}.

\section{Radiation Solver Physics}

In this section, we list some radiation related parameters that you
can set in an {\tt inputs} file.  Here are some important parameters:
\begin{itemize}
\item {\tt radiation.SolverType}:

  Set it to {\tt 5} for the gray solver, and {\tt 6} for the MG solver.

\item {\tt castro.do\_hydro}

  Usually you want to set it to {\tt 1}.  If it is set to {\tt 0},
  hydro will be turned off, and the calculation will only solve
  radiation diffusion equation.

\item {\tt castro.do\_radiation}

  If it is {\tt 0}, the calculation will be pure hydro.
\end{itemize}

Below are more parameters.  For each parameter, the default value is
on the right-hand side of the equal sign.

\subsection{Verbosity and I/O}
\label{sec:bothpar}

\begin{itemize}
\item {\tt radiation.v = 0}

  Verbosity

\item {\tt radiation.verbose = 0}

  Verbosity

\item {\tt radiation.plot\_lambda = 0}

  If {\tt 1}, save flux limiter in plotfiles.

\item {\tt radiation.plot\_kappa\_p = 0}

  If {\tt 1}, save Planck mean opacity in plotfiles.

\item {\tt radiation.plot\_kappa\_r = 0}

  If {\tt 1}, save Rosseland mean opacity in plotfiles.

\item {\tt radiation.plot\_lab\_Er = 0}

  If {\tt 1}, save lab frame radiation energy density in plotfiles.
  This flag is ignored when the mixed-frame gray solver is used.

\item {\tt radiation.plot\_com\_flux = 0}

  If {\tt 1}, save comoving frame radiation flux in plotfiles.

\item {\tt radiation.plot\_lab\_flux = 0}

  If {\tt 1}, save lab frame radiation flux in plotfiles.

\end{itemize}

\subsection{Flux Limiter and Closure}

\label{sec:fluxlimiter}

\begin{itemize}

\item {\tt radiation.limiter = 2}

  Possible values are:
  \begin{itemize}
  \item {\tt ~0}: No flux limiter

  \item {\tt ~2}: Approximate limiter of Levermore \& Pomraning

  \item {\tt 12}: Bruenn's limiter

  \item {\tt 22}: Larsen's square root limiter

  \item {\tt 32}: Minerbo's limiter
  \end{itemize}

\item {\tt radiation.closure = 3}

  Possible values are:
  \begin{itemize}
  \item {\tt 0}: $f = \lambda$, where $f$ is the scalar Eddington factor
    and $\lambda$ is the flux limiter.

  \item {\tt 1}: $f = \frac{1}{3}$
  \item {\tt 2}: $f = 1 - 2 \lambda$
  \item {\tt 3}: $f = \lambda + (\lambda R)^2$, where $R$ is the radiation
    Knudsen number.
  \item {\tt 4}: $f = \frac{1}{3} + \frac{2}{3} (\frac{F}{cE})^2$, where
      $F$ is the radiation flux, $E$ is the radiation energy density,
      and $c$ is the speed of light.
  \end{itemize}
\end{itemize}

Note the behavior of the radiative flux in the optically thin and
optically thick limits.  The flux limiter, $\lambda = \lambda(R)$,
where
\begin{equation}
  R = \frac{|\nabla E_r^{(0)}|}{\chi_R E_r^{(0)}}
\end{equation}
Regardless of the limiter chosen, when we are optically thick,
$\chi_R \rightarrow \infty$, $R \rightarrow 0$, and $\lambda \rightarrow 1/3$.
The radiative flux then becomes
\begin{equation}
  F_r^{(0)} = -\frac{c\lambda}{\chi_R} \nabla E_r^{(0)} \rightarrow
  \frac{1}{3} \frac{c}{\chi_R} \nabla E_r^{(0)}
\end{equation}
And when we are optically thin, $\chi_R \rightarrow 0$, $R \rightarrow \infty$,
and $\lambda \rightarrow 1/R = \chi_R E_r^{(0)}/{|\nabla E_r^{0}|}$, and
the radiative flux then becomes
\begin{equation}
  F_r^{(0)} = -\frac{c\lambda}{\chi_R} \nabla E_r^{(0)} \rightarrow
  -\frac{c}{\chi_R}\frac{\chi_R E_r^{(0)}}{|\nabla E_r^{0}|}
    \nabla E_r^{(0)} = -c E_r^{0}
\end{equation}
See Krumholz et al.\ 2007 for some discussion on this.
\subsection{Boundary Conditions}

\castro\ needs to know about the boundary conditions for both
the hydrodynamics and radiation portions of the evolution.

\subsubsection{Hydrodynamics Evolution}

For the hydrodynamics portion of the solve, the boundary conditions
for the normal hydrodynamic state values will be set by the problem's
{\tt hypfill} routine (which typically just calls {\tt filcc} to handle
the usual hydrodynamics boundary types: outflow, symmetry, etc.).

A corresponding {\tt radfill} routine needs to be written to fill the
ghost cells for the radiation energy density during the hydrodynamics
evolution.  Again, this usually will just default to calling {\tt
  filcc}.

Note: if any of the hydrodynamic boundary conditions types are set
to {\tt Inflow}, then you will need to ensure that the {\tt radfill}
routine explicitly handles the boundary condition implementation
for the radiation energy density in that case---the {\tt filcc}
routine will not do a hydrodynamic {\tt Inflow} boundary.

\subsubsection{Radiation Evolution}

The following parameters are for radiation boundary in the diffusion
equation. They do not affect hydrodynamic boundaries.
\begin{itemize}
\item {\tt radiation.lo\_bc}

  This sets the action to take at the lower edge of the domain in
  each coordinate direction.  Possible values are:
  \begin{itemize}

  \item {\tt 101} {\em Dirchlet}:

    Specify the radiation energy density on the boundary.
    For gray radiation, this could be $E_r = a T^4$.

    For multigroup radiation,  \castro\ stores the energy density as
    $\mathrm{erg}~\mathrm{cm}^{-3}$, so the total radiation energy
    can be found by simply summing over the groups.  So if you want
    to set the radiation BCs using the Planck function, you simply
    multiply by the group width---see {\tt Exec/radiation\_tests/RadSphere/Tools/radbc.f90}
    for an example.

  \item {\tt 102} {\em Neumann}:

    Here, you specify the radiation flux on the boundary.  For gray
    radiation, this is the expression given in the gray \castro\ paper
    (Eq. 7, 8),
    \begin{equation}
      F_r = - \frac{c\lambda}{\kappa_R} \nabla E_r
    \end{equation}
    where $\lambda$ is the flux limiter.

    Note that if your boundary represents an incoming flux through
    a vacuum (like stellar irradiation), then $\kappa \rightarrow 0$, leaving
    \begin{equation}
      F_r = -c E_r
    \end{equation}
    (see \S~\ref{sec:fluxlimiter}) in that case.

  \item {\tt 104} {\em Marshak} (vacuum):

    Here, you specify the incident flux and the outside is a vacuum.
    This differs from the Neumann condition because there is also a
    flux coming from inside, for the net flux across the boundary is
    different than the incident flux.

  \item {\tt 105} {\em Sanchez-Pomraning}:

    This is a modified form of the Marshak boundary condition that works with FLD.
    This is like the Marshak condition, but $\lambda = 1/3$ is not assumed inside
    the boundary (optical thickness).

  \end{itemize}

\item {\tt radiation.hi\_bc}

  See {\tt radiation.lo\_bc}.

\item {\tt radiation.lo\_bcflag = 0 0 0}

  If it is 0, {\tt bcval} is used for that dimension, otherwise
  subroutine {\tt rbndry} in {\tt RadBndry\_1d.f90} is called to set
  boundary conditions.

\item {\tt radiation.hi\_bcflag = 0 0 0}

  See {\tt radiation.lo\_bcflag}

\item {\tt radiation.lo\_bcval = 0.0 0.0 0.0}

  The actual value to impose for the boundary condition type set by
  {\tt radiation.lo\_bc}.  This parameter is interpreted differently
  depending on the boundary condition:
  \begin{itemize}
    \item Dirchlet: Dirichlet value of rad energy density
    \item Neumann:  inward flux of rad energy
    \item Marshak:  incident flux
    \item Sanchez-Pomraning: incident flux
  \end{itemize}

\item {\tt radiation.hi\_bcval = 0.0 0.0 0.0}

  See {\tt radiation.lo\_bcval}
\end{itemize}

\subsection{Convergence}

For the gray solver, there is only one iteration in the scheme,
whereas for the MG solver, there are two iterations with an inner
iteration embedded inside an outer iteration.  In the following, the
iteration in the gray solver will also be referred as the outer
iteration for convenience.  The parameters for the inner iteration are
irrelevant to the gray solver.

\begin{description}
\item[radiation.maxiter = 50] \hfill \\
  Maximal number of outer iteration steps.
\item[radiation.miniter = 1] \hfill \\
  Minimal number of outer iteration steps.
\item[radiation.reltol = 1.e-6] \hfill \\
  Relative tolerance for the outer iteration.
\item[radiation.abstol = 0.0] \hfill \\
  Absolute tolerance for the outer iteration.
\item[radiation.maxInIter = 30] \hfill \\
  Maximal number of inner iteration steps.
\item[radiation.minInIter = 1] \hfill \\
  Minimal number of inner iteration steps.
\item[radiation.relInTol = 1.e-4] \hfill \\
  Relative tolerance for the inner iteration.
\item[radiation.absInTol = 0.0] \hfill \\
  Absolute tolerance for the inner iteration.
\item[radiation.convergence\_check\_type = 0] \hfill \\
  For the MG solver only.  This specifiy the way of checking the
  convergence of an outer iteration.  Possible values are
  \begin{itemize}
    \item 0: Check $T$, $Y_e$, and the residues of the equations for
      $\rho e$ and $\rho Y_e$
    \item 1: Check $\rho e$
    \item 2: Check the residues of the equations for $\rho e$ and $\rho Y_e$
    \item 3: Check $T$ and $Y_e$
  \end{itemize}
\end{description}

\subsection{Parameters for Gray Solver}
\label{sec:graypar}

\begin{description}
\item[radiation.comoving = 1] \hfill \\
  Do we use the comoving frame approach?
\item[radiation.Er\_Lorentz\_term = 1] \hfill \\
  If the mixed-frame approach is taken, this parameter decides whether
  Lorentz transformation terms are retained.
\item[radiation.delta\_temp = 1.0] \hfill \\
  This is used in computing numerical derivativas with respect to $T$.
  So it should be a small number compared with $T$, but not too small.
\item[radiation.update\_limiter = 1000] \hfill \\
  Stop updating flux limiter after {\tt update\_limiter} iteration steps.
\item[radiation.update\_planck = 1000] \hfill \\
  Stop updating Planck mean opacity after {\tt update\_planck} iteration steps.
\item[radiation.update\_rosseland = 1000] \hfill \\
  Stop updating Rosseland mean opacity after {\tt update\_rosseland} iteration steps.
\end{description}

\subsection{Grouping in the MG Solver}

We provide two methods of setting up groups based upon logarithmic
spacing.  In both methods, you must provide:
\begin{description}
\item[radiation.nGroups] \hfill \\
  Number of groups.
\item[radiation.lowestGroupHz] \hfill \\
  Frequency of the lower bound for the first group.
\end{description}

In addition, if the parameter {\tt groupGrowFactor} is provided, then
the first method will be used, otherwise the second method will be
used.  In the first way, you must also provide {\tt firstGroupWidthHz}
(the width of the first group).  The width of other groups is set to
be {\tt groupGrowFactor} times the width of its immediately preceding
group.  In the second way, you must provide {\tt highestGroupHz} as
the upper bound of the last group.  It should be noted that {\tt
  lowestGroupHz} can be 0 in the first method, but not the second
method.  However, when we compute the group-integrated Planck
function, the lower bound for the first group and the upper bound for
the last group are assumed to be 0 and $\infty$, respectively.

\subsection{Parameters for MG Solver}
\label{sec:mgpar}

\begin{description}
\item[radiation.delta\_e\_rat\_dt\_tol = 100.0] \hfill \\
  Maximally allowed relative change in $e$ during one time step.
\item[radiation.delta\_T\_rat\_dt\_tol = 100.0] \hfill \\
  Maximally allowed relative change in $T$ during one time step.
\item[radiation.delta\_Ye\_dt\_tol = 100.0] \hfill \\
  Maximally allowed absolute change in $Y_e$ during one tim estep.
\item[radiation.fspace\_advection\_type = 2] \hfill \\
  Possible value is 1 or 2.  The latter is better.
\item[radiation.integrate\_Planck = 1] \hfill \\
  If 1, integrate Planck function for each group.  For the first
  group, the lower bound in the integration is assumed to be 0 no
  matter what the grouping is.  For the last group, the upper bound in
  the integration is assumed to be $\infty$.
\item[radiation.matter\_update\_type = 0] \hfill \\
  How to update matter.  0 is proabaly the best.
\item[radiation.accelerate = 2] \hfill \\
  The inner iteration of the MG solver usually requires an
  acceleration scheme.  Choices are
  \begin{itemize}
    \item 0: No acceleration
    \item 1: Local acceleration
    \item 2: Gray acceleration
  \end{itemize}
\item[radiation.skipAccelAllowed = 0] \hfill \\
  If it is set to 1, skip acceleration if it does not help.
\item[radiation.n\_bisect = 1000] \hfill \\
  Do bisection for the outer iteration after {\tt n\_bisec} iteration steps.
\item[radiation.use\_dkdT = 1] \hfill \\
  If it is 1, $\frac{\partial \kappa}{\partial T}$ is retained in the
  Jacobi matrix for the outer (Newton) iteration.
\item[radiation.update\_opacity = 1000] \hfill \\
  Stop updating opacities after {\tt update\_opacity} outer iteration steps.
\item[radiation.inner\_update\_limiter = 0] \hfill \\
  Stop updating flux limiter after {\tt inner\_update\_limiter} inner
  iteration steps.  If it is 0, the limiter is lagged by one outer
  iteration.  If it is -1, the limiter is lagged by one time step.  If
  the inner iteration has difficulty in converging, setting this
  parameter it to -1 can help.  Since the flux limiter is only a
  kludge, it is justified to lag it.
\end{description}

\subsection{Linear System Solver}
\label{sec:hypre}

There are a number of choices for the linear system solver.  The
performance of the solvers usually depends on problems and the
computer.  So it is worth trying a few solvers to find out which one
is best for your problem and computer.

\begin{description}
\item \runparam{radsolve.level\_solver\_flag}: the linear solver
  in \hypre\ to use.  The available choices are:
  \begin{itemize}
    \item {\tt 0}: SMG
    \item {\tt 1}: PFMG  ($\ge$ 2-d only)
    \item {\tt 100}: AMG using ParCSR ObjectType
    \item {\tt 102}: GMRES using ParCSR ObjectType
    \item {\tt 103}: GMRES using SStruct ObjectType
    \item {\tt 104}: GMRES using AMG as preconditioner
    \item {\tt 109}: GMRES using Struct SMG/PFMG as preconditioner
    \item {\tt 150}: AMG using ParCSR ObjectType
    \item {\tt 1002}: PCG using ParCSR ObjectType
    \item {\tt 1003}: PCG using SStruct ObjectType
  \end{itemize}

  As a general rule, the SMG is the most stable solver, but is usually
  the slowest.  The asymmetry in the linear system comes from the
  adaptive mesh, so the PFMG should be your first choice.  Note: in
  you cannot use PFMG.

  Setting this to 109 (GMRES using Struct SMG/PFMG as preconditioner)
  should work reasonably well for most problems.

\item \runparam{radsolve.maxiter} (default: {\tt 40}):
  Maximal number of iteration in Hypre.

\item \runparam{radsolve.reltol} (default: {\tt 1.e-10}):
  Relative tolerance in Hypre

\item \runparam{radsolve.abstol} (default: {\tt 0}):
  Absolute tolerance in Hypre

\item \runparam{radsolve.v} (default: {\tt 0}):
  Verbosity

\item \runparam{radsolve.verbos} (default: {\tt 0}):
  Verbosity

\item \runparam{habec.verbose} (default: {\tt 0}):
  Verbosity for {\tt level\_solver\_flag} $<$ 100

\item \runparam{hmabec.verbose} (default: {\tt 0}):
  Verbosity for {\tt level\_solver\_flag} $>=$ 100
\end{description}

\section{Output}

\subsection{Gray Solver}

For the gray radiation solver, the radiation energy density is stored in plotfiles
as {\tt rad}.  Note that this quantity has units of $\mathrm{erg~cm^{-3}}$, which
is different that the specify internal energy of the gas $\mathrm{erg~g^{-1}}$.


% This file is part of the causal-kepler project
% Copyright 2013, 2014 the authors.

% # to-do
% - write causal description

\documentclass[12pt, preprint]{aastex}

\newcommand{\notenglish}[1]{\textit{#1}}
\newcommand{\sic}{\notenglish{sic}}
\newcommand{\project}[1]{\textsl{#1}}
\newcommand{\Kepler}{\project{Kepler}}
\newcommand{\name}{CPM}
\newcommand{\set}[1]{\mathcal{#1}}
\newcommand{\given}{\,|\,}
\newcommand{\todo}[1]{\textbf{#1}}

\begin{document}

\title{%
  Self-calibration of time-domain imaging for exoplanet science, informed by causal structure%
  \\ or \\
  A data-driven, pixel-level model to improve the precision of \Kepler\ photometry%
  \\ or \\
  Exploiting causal structure to create a data-driven self-calibration of \Kepler\ imaging%
}
\author{%
  Dun~Wang\altaffilmark{\ref{CCPP}},
  Dan~Foreman-Mackey\altaffilmark{\ref{CCPP}},
  David~W.~Hogg\altaffilmark{\ref{CCPP},\ref{CDS},\ref{MPIA},\ref{email}},
  Bernhard~Sch\"olkopf\altaffilmark{\ref{MPIIS}},
  others%
}
\newcounter{address}
\setcounter{address}{1}
\altaffiltext{\theaddress}{\stepcounter{address}\label{CCPP}%
  Center for Cosmology and Particle Physics, Department of Physics, New York University}
\altaffiltext{\theaddress}{\stepcounter{address}\label{CDS}%
  Center for Data Science, New York University}
\altaffiltext{\theaddress}{\stepcounter{address}\label{MPIA}%
  Max-Planck-Institut f\"ur Astronomie, Heidelberg, Germany}
\altaffiltext{\theaddress}{\stepcounter{address}\label{email}%
  To whom correspondence should be addressed; \texttt{<david.hogg@nyu.edu>}.}
%% \altaffiltext{\theaddress}{\stepcounter{address}\label{Ames}%
%%   NASA Ames Research Center}
%% \altaffiltext{\theaddress}{\stepcounter{address}\label{Courant}%
%%   Courant Institute of Mathematical Sciences, New York University}
\altaffiltext{\theaddress}{\stepcounter{address}\label{MPIIS}%
  Max-Planck-Institut f\"ur Intelligente Systeme, T\"ubingen}
%% \altaffiltext{\theaddress}{\stepcounter{address}\label{Oxford}%
%%   Department of Physics, Oxford University}
%% \altaffiltext{\theaddress}{\stepcounter{address}\label{CfA}%
%%   Harvard--Smithsonian Center for Astrophysics}
%% \altaffiltext{\theaddress}{\stepcounter{address}\label{UCL}%
%%   Department of Physics and Astronomy, University College London}
%% \altaffiltext{\theaddress}{\stepcounter{address}\label{CMU}%
%%   McWilliams Center for Cosmology, Carnegie Mellon University}
%% \altaffiltext{\theaddress}{\stepcounter{address}\label{Caltech}%
%%   Department of Astronomy, California Institute of Technology}
%% \altaffiltext{\theaddress}{\stepcounter{address}\label{Columbia}%
%%   Department of Astronomy, Columbia University}

\begin{abstract}
The precision of \Kepler\ photometry for exoplanet science---the most
precise photometric measurements of stars ever made---appears to be
limited by unknown or untracked variations in spacecraft pointing and
temperature, and unmodeled stellar variability.
Here we present \name,
  a data-driven model of these variations in \Kepler\ data (or really of their impact on the photometry).
Importantly (and uniquely),
  \name\ works at the pixel level (not the photometric measurement level);
  it can capture more fine-grained information about the variation of the spacecraft
  (especially regarding pointing and point-spread function)
  than is available in the pixel-summed photometry.
\name\ is extreme in that it has enormous flexibility and it only uses data (and meta-data) to predict data:
\name\ provides a prediction for each readout pixel built from a linear combination of the readouts
  from very large numbers of nearby pixels (plus some spacecraft information);
  the choice of nearby pixels is guided by ideas from causal inference.
\name\ avoids over-fitting by employing a train-and-test formalism
  designed to ensure that transit-like photometric events and short-timescale stellar variability
  cannot be captured or distorted by the model;
  it is designed to remove spacecraft-induced variability but not intrinsic stellar variability.
We show that \name\ outperforms the \Kepler\ Presearch (\sic) Data Conditioning method on a set of example stars.
We release open-source code that provides \name\ output for any star in the existing \Kepler\ Archive,
  and we discuss applications for other missions,
  including any possible \Kepler\ two-wheel mission.
\end{abstract}

\section{Ultra-precise photometry}

The photometric measurements of stars made by the \Kepler\ Satellite are precise enough
  to permit discovery of exoplanet transits with depths smaller than $10^{-4}$.
This precision results from great spacecraft stability,
  supplemented by various methods for removing small residual spacecraft-induced and stellar-variability trends in the brightnesses,
  either filtering the data (with things like median filters; \todo{citations})
  or fitting the data with flexible models (like polynomials or splines or Gaussian Processes; \todo{citations}).
When employed in the service of exoplanet search and characterization,
  these methods are usually agnostic about whether photometric variations originate in the spacecraft or in the star itself;
  that is, they obliterate intrinsic stellar variability along with spacecraft issues.

In general, there are many reasons for apparent photometric variability in a \Kepler\ source.
There is intrinsic stellar variability,
  which is of interest to some and a nuisance to others.
There is also variability of overlapping fainter stars;
  that is, confusion noise combined with variability of the confusing sources.
There are small changes in spacecraft pointing,
  which leads to slightly different illumination of the focal-plane pixels,
  and thus different sensitivity to errors (problems) in the device flat-field or sensitivity map.
There are also \emph{intra-pixel} sensitivity variations that can contribute (\todo{cite white paper; Spitzer results}).
There are small changes in spacecraft temperature,
  which lead to point-spread function (PSF) and differential (across the focal plane) pointing changes.
These also lead to changes in pixel and intra-pixel illumination.
Stellar proper motion, geometric parallaxes, and differential stellar aberration as the spacecraft orbits all do more of the same.
There is electronic cross-talk between detectors and charge-transfer inefficiency;
  these can effectively transfer variability from one source to another.
There are additional electronics effects like ``rolling bands'' that put additional features into lightcurves.
There are also probably changes to the detector sensitivity with temperature and time,
  possibly illimunation-history effects,
  and possibly sources of variability not yet considered.
The remarkable thing about \Kepler\ is that it is trying to measure stars at a level of precision
  much higher than ever previously attempted;
  new effects really \emph{must} appear at some point.
In \figurename~\ref{fig:pixelpatch}, we show the pixel-level variability in the \Kepler\ data
  near one bright star that shows minimal intrinsic variability;
  this figure highlights the spacecraft-induced effects.

We propose and advise dealing with these variations in \Kepler\ light-curves by \emph{modeling} them.
In this context, a model is (at least) a parameterized function that can predict data, given parameter settings,
  and an objective function that can be optimized or sampled to choose or set those parameters.
Ideally the objective function is probabilistic, or has a probabilistic justification,
  as with a likelihood or a posterior pdf.
The model can be a physical model (of the spacecraft PSF, pointing, temperature, and so on)
  or it can be a flexible, effective model that has no direct interpretation in terms of physical spacecraft parameters.
In principle a physical model will do a better job,
  because it necessarily embodies more prior information,
  but it requires research and intuition about dominant effects,
  and this research and intuition is often wrong or incomplete.
The model we propose here is in the non-physical, effective category.
The \Kepler\ community is familiar with these kinds of models;
  to our knowledge, \emph{all} successful light-curve ``de-trending'' methods
  are flexible, effective models.

One such method---one that is designed to describe or model spacecraft-induced problems
  but \emph{not} interfere with measurements of stellar variability---%
  is the \Kepler\ Presearch (\sic) Data Conditioning (PDC) method (\todo{citation}).
The PDC ``de-trends'' the \Kepler\ lightcurves by fitting them with a small set of basis lightcurves
  generated from a principal components analysis (PCA) of filtered lightcurves.
That is, it uses data to predict data,
  regularizing the fit (and avoiding over-fitting) by filtering and restricting the dimensionality (through PCA).
The method proposed here, \name, is very similar in spirit to the PDC.
The main differences are
  (1)~that \name\ works in the pixel domain, not the lightcurve domain, so it has access to more fine-grained information,
  (2)~that \name\ has far more freedom (far more parameters) than the PDC
  but it strictly avoids over-fitting the lightcurves on exoplanet-transit time-scales
  through strong regularization and a train-and-test framework, and
  (3)~that when \name\ fits a star, there is no possibility of any contribution of the star itself to the fit basis vectors.
The two methods (\name\ and PDC) are similar however,
  in that they both make the assumption that whatever spacecraft effects are imprinting variability on a stellar lightcurve
  must also be imprinting similar or related variability on other lightcurves.
They also assume that the relationships can be captured with linear models.
By going to the pixel level (unlike the PDC, which works at the photometry level),
  \name\ makes it easier for the model to capture variability
  that is coming through variations in the centroids and point-spread function
  from spacecraft pointing, roll, and temperature.

Before we start, a few reminders about the \Kepler\ data are in order:
The satellite always observes precisely the same field, at fixed pointing (as closely as possible).
Only a few percent of the 80 million pixels in the focal plane are telemetered down
  to Earth from each 30-min exposure;
  the telemetered pixels are associated with \Kepler\ target stars chosen for study by the \Kepler\ Team.
The satellite is rolled by 90~deg every 90-ish days (to satisfy Solar-Angle constraints).
The focal plane contains many CCDs;
  this plus the 90-deg rotations means that each star is at a particular location
  on a particular CCD for 90-ish-day contiguous periods of time.
The PSF varies strongly across the field and is badly sampled.
The stars span a huge range in brightness;
  some of \Kepler's most important targets even saturate the device and bleed charge.
The stellar photometry returned by the \Kepler\ SAP and PDC pipelines is based on
  straight, \emph{unweighted} sums of pixels in small patches centered on the stellar centroid.
We will return to this latter point at the end;
  this kind of photometry cannot be optimal;
  it must be possible to do a better job with the photometric measurements.
That's beyond the scope of this project but a place for a valuable intervention on the \Kepler\ data.

The scope of this project is an intervention---\name---that makes the \Kepler\ photometry more precise.
We describe the method and deliver all the relevant code in a public, open-source repository.
We also provide an interface to the \Kepler\ data that delivers improved ``\name\ photometry''
  for every \Kepler\ target.

\section{Data-driven models}

The first general idea about data-driven modeling of the kind used here
  is that each data point or data source is going to be
  \emph{predicted} with or using a parameterized mathematical function of \emph{other data}.
That is, given a choice of some \emph{target} \Kepler\ data,
  we are going to find parameters of a function that takes as input some of the other \Kepler\ data,
  and provides as output predictions of the target data.
The simplest models are \emph{linear models},
  in which predictions for the target data are built from linear combinations of the other data,
  and in which the objective functions are quadratic in the prediction residual.
Examples of quadratic objective functions include Gaussian likelihoods, mean-squared-error, and chi-square statistics.
These models are simple,
  not just because they are easy to express and compute,
  but because optimization is convex:
There is only one optimum for the objective function.

The point of these models is to be \emph{flexible},
  so the usual approach is to make the input data set very large,
  and the number of parameters large,
  often as large as---or larger than---the target data available.
Such fits require \emph{regularization} to break degeneracies
  and control ill-constrained parameters.
These regularizations do for optimizations what priors do for posterior probability inferences;
  they express the desired behavior of the fit in the absence of data
  or along directions in parameter space in which the data are not constraining.
General regularizations or priors will break the convexity of linear models;
  if convexity is to be maintained, these regularizations also have to be quadratic,
  or else one of a small number of other known forms (one of which is L1-regularization).
Given these considerations, it makes sense to try to build our pixel-level model
  using a linear model with a quadratic objective function and a quadratic regularization;
  this is what \name\ will be.

The second general idea about data-driven modeling is the investigator's beliefs
  about the causal processes that generate the data
  are crucial in restricting the kinds of data that can be used as input to the model.
That is, different assumptions about the physical properties of the data
  and the data-taking system
  lead to different structures for the data-driven model.
For example, in the case of \Kepler\ data,
  if we believe that different stars in the \Kepler\ field vary independently
  (that is, are not physically synchronized in any way),
  then the only reason that one star might show variability that is strongly \emph{predictive}
  (useful for prediction) of another star's variability
  is that both stars are being observed by the same device or spacecraft.
That is, one star's pixels can be used to predict another star's pixels
  inasmuch as spacecraft issues imprint on both stars in related ways;
  they share a common cause.
For another example, if we think the spacecraft is being affected by
  processes that take place over time-scales longer than a single read-out
  (for example, thermal processes),
  then it would be sensible to model the data at time $t$ using not just simultaneous data,
  but also data from a range of times around $t$.
For another example, if an investigator doesn't care about preserving stellar variability,
  and just wants to detect exoplanet transits (say),
  pixels from the target star can be used to predict pixels from the target star,
  provided they are at large-enough time lags that they don't overlap (in time)
  the signals of interest.
That is, if the model is designed to fit not just spacecraft variability
  but also intrinsic stellar variability,
  the predictive model will be permitted to use as input pixels that \emph{do} overlap the target star.
In what follows, we are only going to use input data that do not overlap that target star pixels.
These models ought to remove spacecraft variability but not intrinsic stellar variability.

The third general idea is that we need to control for over-fitting.
That is, once you have a flexible-enough model you can in principle fit \emph{anything},
  whether it was caused by the spacecraft, intrinsic stellar variability, or a transiting exoplanet.
How do you prevent a very flexible model from taking small noise-induced fluctuations in all the input data
  and carefully combining them linearly into detailed models for every nook and cranny in the target data?
In most projects in astrophysics, over-fitting is controlled for by limiting model freedom.
The model is restricted in the number of parameters
  (as in ``you can't have more parameters than data points'')
  or by limiting the dimensionality
  (as in principal components analysis)
  or by applying strong priors
  (as with smoothness priors, that effectively reduce freedom without explicitly reducing the number of parameters).
In each case, the restriction on model freedom is controlled by some \emph{hyper-parameter}
  (such as the number of inputs, or number of principal components, or the strength of the smoothness prior).
The hyper-parameters can be set or tested with tools like cross-validation,
  the fully marginalized likelihood (Bayes factor or evidence),
  chi-squared statistical criteria,
  or intuition or heuristics.
Here we take a different and more general approach, which is to use a train-and-test framework.

In this framework, the data used to \emph{train} the model%
  ---meaning set the values of the parameters of the model---%
  are disjoint from the \emph{test} data
  ---meaning the data that are being predicted (the target data).
Because we are extremely concerned with detecting Earth-analog exoplanet transits,
  which take about ten hours,
  we adopt an extreme version of the train-and-test framework,
  in which the training data are always separated from the test data by at least ten hours.
That is, when we are using the model to predict a particular pixel in the target data taken at time $t$,
  we use parameters obtained by an optimization that makes use of only data
  that comes either at times prior to $t-\Delta t$ or after $t+\Delta t$,
  where $\Delta t$ is a tunable parameter but which we will set to roughly $12$~h.
This ensures that no information about any exoplanet transit itself
  can be entering into the prediction of the pixels contributing to the stellar photometry.
In general, if there is a scientific goal of preserving intrinsic stellar variability,
  or transit signals,
  on time-scales of $\tau$,
  the parameter optimization ought to be based on training data taken with a time-exclusion zone of half-width $\Delta t > \tau$.

In addition, each training data set within which we set the parameters (by optimization) has a finite total time extent $t_{\max}\approx 90$\,d.
The train-and-test framework, which includes data out to time $t_{\max}$ but excludes data within $\Delta t$ of the test data,
  effectively assumes that the signals worth preserving have time-scales less than $\Delta t$ but don't recur on time-scales
  shorter than $t_{\max}$.
Those assumptions are good for our purposes but not necessarily ideal for all users:
Short-period exoplanets and certain kinds of stellar variability
  could be wiped out by a model with these settings of the training-data regime.

The fourth general idea involved in this kind of data-driven modeling is that the models aren't \emph{interpretable}.
This means, in particular, that although the model might do a good job of \emph{predicting} the target pixels,
  using a linear (or more complex) combination of the input pixel data,
  it won't deliver anything that can be unambiguously interpreted as the \emph{flux} of the star in question,
  or any other signal we care about.
The data-driven model \emph{effectively} describes the pointing, point-spread function, and flat-field
  of the telescope and camera,
  plus the variability of every star and every exoplanet transit,
  but it does so without ever \emph{explicitly} creating any of those objects.
We have to make some kind of heuristic or interpretive move to extract from the data-driven model the quanitites of interest.

In the context of this project, the quantities of interest are the light-curves
  (photometry as a function of time or apparent flux as a function of time)
  for every star.
What we get, for every star, from the data-driven model, is a train-and-test prediction
  for the brightness of every pixel in the patch of the detector relevant to the star,
  along with the residual, or the difference between the measured read-out pixel value and the prediction (data minus prediction).
What will be called the ``\name\ photometry'' in what follows is constructed from what will be called the ``\name\ pixels''.
The \name\ photometry is constructed from the \name\ pixels
  just as the \Kepler\ official SAP photometry is constructed from the \Kepler\ Target Pixel Files;
  that is, by summing pre-defined sets of pixels (with unit weights; see above and below for criticism of this).
The \name\ pixels are constructed from the data-driven model predictions by taking,
  for each pixel in each contiguous data segment (see below),
  the \emph{mean} predicted pixel value (mean over time),
  and adding to it the residuals (data minus prediction) away from the data-driven model prediction.
These \name\ pixels are ``calibrated'' pixels,
  in that the data-driven model has been used to fit out all the variability it can,
  subject to the restrictions imposed by its finite freedom and the train-and-test specification.
The signal---in which exoplanet transits will be found---is fundamentally the observed residual away from this prediction,
  but it has to be added back into the mean prediction to have the right ``baseline'' or zero level.
In short, \name\ will produce prediction pixels, residual pixels, \name\ pixels (mean prediction plus residual),
  and aperture-based \name\ photometry analogous to the SAP photometry.

Finally, the fifth general idea is that there is no objective \emph{ground truth} against which we can tell
  that any particular data-driven model is better or worse than any other.
This problem is a problem for \name, and for the \Kepler\ PDC, and any other data-driven calibration models.
One might think that the ``best'' model is the one that predicts data with lowest variance;
  this would be true if all models adhered to the same train-and-test framework, which they don't.
Besides, a model that can predict not just the spacecraft-induced variability,
  but also variability caused by exoplanet transits of interest,
  will effectively over-fit and distort the most important information in the light-curves.
That is, what is considered best for modeling the data depends on the objectives of the user.
For us, who are interested (in the long term) in finding and characterizing Earth analogs,
  the ``best'' data-driven model is the one that produces the most success in finding and characterizing Earth analogs!
What we will show in what follows is that the \name\ photometry does not distort
  artificial exoplanet transit signals injected into real \Kepler\ pixel-level data.
We can also show that it produces stellar light-curves that look sensible for known variable stars.
We cannot yet show that it is optimal for our long-term goals,
  nor can we show that it produces pixelss or light-curves that are more accurately calibrated;
  we will only show promising properties of the \name\ outputs.
In the end, the value of the \name\ will be demonstrated by the scientific projects it enables.

\section{\name\ specification and hyper-parameters}

Each individual \Kepler\ target star is, for each quarter (each 90-ish-day period),
  on a particular CCD on the \Kepler\ focal plane.
Associated with each target star is some set of pixels,
  located in a small contiguous patch more-or-less centered on the target star,
  and telemetered down once for every 30-min exposure.
(Here we are ignoring all short-cadence data that is taken in a different mode with shorter exposures.)
That is, each telemetered pixel in each CCD is associated with a particular \Kepler\ target star.

Let's consider a particular pixel $m$ in the focal plane in one particular quarter.
In that quarter, the spacecraft delivers $N\sim 4000$ measurements $I_{mn}$
  of the intensity falling in that pixel at the $N$ times $t_n$ at which exposures were taken during the quarter.
(For intensity measurements $I_{mn}$ here we are using pixels from the Target Pixel Files.)
We want to build a prediction for the intensity $I_{mn}$ in pixel $m$ at each time $t_n$
  using the intensities $I_{m'n}$ of other pixels $m'$.
The question is:  What other pixels to choose?
There are many possible qualitatively and quantitatively different choices here.
Somewhat arbitrarily,
  we choose all the pixels $m'$ associated with the $Q=5$ stars on the same CCD in the same quarter
  that are closest in magnitude
  (\Kepler\ magnitude as reported in the \Kepler\ Input Catalog)
  to the target star associated with pixel $m$.
This set of pixels%
  ---from the $Q$ stars on the same CCD---%
  is the \emph{pixel set} $\set{M}_m$ associated with pixel $m$.
Note that because the set $\set{M}_m$ is of pixels associated with \emph{different} stars
  than the star associated with pixel $m$,
  the pixel $m$ will not be in the set $\set{M}_m$,
  and nor will any of pixel $m$'s close neighbors.
That is, there will be no (or almost no) overlap in stellar illumination of pixel $m$
  and the pixels $m'\in\set{M}_m$.

When we are predicting the measurement $I_{mn}$ from pixel $m$ at a particular time $t_n$,
  we are going to use a train-and-test framework in which not only do we not use
  data at time $t_n$ in optimizing the parameters of the regression or fit,
  but we don't even use any times $t$ such that $|t-t_n| < \Delta t$,
  where $\Delta t\sim 12$\,h.
That is, we train (optimize fit parameters) using the \emph{time set} $\set{N}_n$ of time
  indices $n'$ such that for all $n'\in\set{N}_n$,
  $t_{n'}$ is in the same quarter as $t_n$,
  and $|t_{n'} - t_n|>\Delta t$.
The time set of indices $\set{N}_n$ therefore does not overlap the time point $t_n$,
  nor any of its neighbors in a time window of half-width $\Delta_t$.

\todo{DFM: Do we want a schematic figure or cartoon which illustrates all of this?}

In addition to the other data (from pixels $m'\in\set{M}_m$ and taken at time points $n'\in\set{N}_n$)
  used to make each prediction, we will use also some \emph{meta-data};
  these include the time itself $t_n$,
  the sine and cosine of the parallactic angle $\theta(t_n)$,
  and the dot product $\hat{n}\cdot v(t_n)$ of the spacecraft velocity $v(t_n)$
  with the direction $\hat{n}$ towards the \Kepler\ field center.
These additional meta-data variables permit the data-driven model
  to capture easily variations induced in the data
  by proper motions, parallaxes, and stellar aberration.
Symbolically, we will denote these $K=4$ pieces of meta-data $d_{kn}$.

As mentioned above, in the context of this project,
  a model is something that can predict data given settings of some parameters,
  and an objective function that can be used to find best values for those parameters.
We prefer to work in a probabilistic mode in which the objective function can be justified
  in terms of a likelihood (probability for the data given the model)
  or a posterior probability density function (likelihood times a prior pdf).
The \name\ treats each \Kepler\ data point $I_{mn}$ as being
  predictable from a linear combination of data points $I_{m'n}$,
  where $m'$ is from the set of non-overlapping pixels $m'\in\set{M}_m$.
\begin{eqnarray}
I_{mn}         &=& I^{\ast}_{mn} + e_{mn}
\\
I^{\ast}_{mn}  &=& \sum_{m'\in\set{M}_m} a_{mnm'}\,I_{m'n} + \sum_{k=1}^{K} b_{mnk}\,d_{kn}
\quad,
\end{eqnarray}
where $I^{\ast}_{mn}$ is the prediction (by the model) for data point $I_{mn}$,
  $e_{mn}$ is a noise contribution or residual away from the prediction,
  and the $a_{mnm'}$ and $b_{mnk}$ are the parameters (linear coefficients of the prediction).
The parameters $a_{mnm'}$ and $b_{mnk}$ have indices $m$ because
  they are different for every pixel $m$,
  and they will even be different for every time step $n$;
  that is, there will be a separate best-fit value for the parameters for every $I_{mn}$.
If we presume that the residuals away from the prediction are normally distributed with zero mean
  and known variance,
  likelihood optimization reduces to chi-squared minimization.
We add to the standard chi-squared definition a regularization term
  (equivalent to multiplying the likelihood by a Gaussian prior pdf)
  that penalizes large absolute values for the the coefficients $a_{mnm'}$:
\begin{eqnarray}
\chi^2_{mn}    &=& \sum_{n'\in\set{N}_n} \frac{[I_{mn'} - I^{\ast}_{mnn'}]^2}{\sigma^2_{mn'}}
                 + \sum_{m'\in\set{M}_m} \frac{a_{mnm'}^2}{\Sigma^2}
\\
I^{\ast}_{mnn'} &=& \sum_{m'\in\set{M}_m} a_{mnm'}\,I_{m'n'} + \sum_{k=1}^{K} b_{mnk}\,d_{kn'}
\quad,
\end{eqnarray}
where the $\sigma^2_{mn'}$ are the (presumed known) individual-pixel noise variances,
  and $\Sigma^2$ sets the strength of the regularization (or width of the prior pdf).
Although the variances $\sigma^2_{mn'}$ are in principle different for every time step $n'$,
  for nearly-constant stars in good data, there is not much variation;
  in what follows, we treat these uncertainties as fixed at
  \todo{DFM: some mean value (we can't ignore this,
   because it ``plays off against'' the regularization)}
The regularization variance $\Sigma^2$ we set to 0.3 (\todo{DFM TAKE NOTE; that's about 10 for the parameter you usually use.})
  because we expect almost all the coefficients $a_{mnm'}$ to be less than unity in magnitude.
We do not regularize the meta-data coefficients $b_{mnk}$,
  because we want the model to make use of the (easily interpretable) meta-data coefficients as much as possible.

The train-and-test idea comes into the objective function $\chi^2_{mn}$:
When we are computing the objective function $\chi^2_{mn}$,
  we are using only time points $n'\in\set{N}_n$ that don't overlap the target (or test) time point $n$.
We train the model---that is, set the parameters $a_{mnm'}$ and $b_{mnk}$---%
  by choosing the full set of parameters that jointly minimize the objective function $\chi^2_{mn}$.
Fortunately, given the form of the model,
  this minimization is just a linear solve (linear operation on the data).
Importantly however, and perhaps surprisingly, the objective function $\chi^2_{mn}$ is \emph{different}
  for every target data point (pixel value to be predicted) $I_{mn}$;
  we have to do an \emph{independent optimization} (or really linear solve)
  of the parameters for every pixel value we want to predict.
That is, every pixel datum $I_{mn}$ we predict will have
  \emph{different} settings of the parameters $a_{mnm'}$ and $b_{mnk}$.
Since there are of order $10^{6}$ total pixel values in the \Kepler\ Target Pixel Files for \emph{each \Kepler\ target},
  and of order $10^7$ data sources used as basis functions in the linear fitting,
  this represents one fuck of a lot of linear solves,
  and a lot of parameters to obtain and record.

For this reason---\emph{so many solves}---%
  we do \todo{some crazy clever stuff} to make this work fast;
  \todo{DFM implementation notes here}.

Once we have obtained the parameters $a_{mnm'}$ corresponding to a particular data point $I_{mn}$,
  we can make a \emph{prediction} $I^{\ast}_{mnn}$ for the intensity at that pixel.
By construction of our objective function, this is truly a prediction,
  in the sense that the optimization (or solve) that produced the parameters
  (and thus the prediction)
  did not make use of $I_{mn}$ itself,
  or even any of the pixel values that are nearby in angle or time
  (as described above).
In addition to the predicted pixel value $I^{\ast}_{mnn}$,
  we can also construct a \emph{residual} $\delta_{mn}$ (data minus prediction),
  defined by
\begin{eqnarray}
\delta_{mn} &\equiv& I_{mn} - I^{\ast}_{mnn}
\quad .
\end{eqnarray}

In some sense, it is this residual that contains the exoplanet transit signals we seek.
That is, a transit creates a negative residual away from the prediction.
So far, however, the model is a model of \emph{pixels},
  and we need to obtain from this model \emph{photometric measurements} of stars.
In order to construct stellar photometry measurements out of the residual pixels $\delta_{mn}$,
  we add into each pixel residual $\delta_{mn}$ the \emph{mean predicted intensity} $\bar{I}^{\ast}_m$
\begin{eqnarray}
\bar{I}^{\ast}_m &=& \frac{1}{N_m}\,\sum_n I^{\ast}_{mnn}
\quad ,
\end{eqnarray}
where $N_m$ is the number of time steps in the quarter,
  and the sum is over those time steps.
\todo{DFM: Should we use mean or median here?}
We construct what we will call ``the \name\ pixels'' $J_{mn}$,
  which are the residuals plus the mean, or
\begin{eqnarray}
J_{mn} &=& \delta_{mn} + \bar{I}^{\ast}_m
\quad .
\end{eqnarray}
That is, we treat each pixel as differing from constant intensity
  only inasmuch as it has residuals away from the model prediction.

Our new stellar flux estimates,
  what we will call the ``\name\ photometry'',
  is constructed from the \name\ pixels
  in precisely the same way as the official \Kepler\ SAP photometry
  is constructed from the Target Pixel Files.
That is, we perform a weighted sum of \name\ pixels $J_{mn}$ with weights $w_m$,
  all of which are either zero or unity,
  and we adopt precisely the same weight assignments as are adopted in the SAP photometry;
  in equations, the flux estimate $S_n$ at time $t_n$ of the target star is given by
\begin{eqnarray}
S_n = \frac{1}{M}\,\sum_m w_m\,J_{mn}
\quad ,
\end{eqnarray}
where the sum is over the $M$ pixels that are associated with the target star.
As we have noted above and below, these photometric estimators are not optimal for any purpose,
  but improving them is beyond the scope of this project.

Some---or probably most---of the variations of the pixel intensities
  are being caused by small changes to stellar positions relative to the detector,
  in turn caused by pointing drifts, parallaxes, proper motions, aberration, and temperature changes.
The \name\ pixels, being constructed from a mean prediction plus residuals,
  represent some kind of mean image, averaged over these positional changes.
  that is, the image constructed from the \name\ pixels would have a broader
  point-spread function than any individual time-step,
  and does not necessarily represent any true astronomical scene.
This is another consequence of the point, discussed above,
  that data-driven models do not in general provide interpretable results.
This uninterpretability creates a small problem,
  which is that the optimization by which the \Kepler\ team chose the pixel weights $w_m$
  cannot be precisely appropriate for the \name\ pixels,
  even if it \emph{is} appropriate for the \Kepler\ Target Pixel Files.
That is, there could be a small sacrifice at this step in photometric estimator quality.
This motivates future work on photometric estimation.
That said, we don't expect this effect to be large,
  because the positional drifts involved are orders of magnitude smaller than a pixel.

\todo{DFM: What does the interface look like?  What are the run times and so on?}

\section{Examples and results}

For each example, give the code and show the output and provide some discussion.

We need a metric for comparing outputs.
For now lets try plotting the power spectrum of the SAP, PDC, and \name\ photometry for each star.

So DWH is imagining multi-panel plots: SAP, PDC, and \name\ vs time,
  plus a power-spectrum plot vs frequency.

Cases ought to include
\begin{itemize}
\item a bright, non-variable G star with an Earth injection,
\item a significant variable like that shown in the white paper, and
\item a star with a bad quarter or where \Kepler\ sucked it.
\end{itemize}

Then we want to show some kind of scatter plot, which is some variance estimate from us,
  vs the same estimate from the PDC,
  to show that we always or usually win.
This variance estimate should be something like the power in the residuals at frequencies
  corresponding to 30-hour periods or maybe 50-hour periods or something like that.

\section{Discussion}

Return to the SAP photometry ``unweighted sum'' issue here.

Didn't do anything about short-cadence data; suck it up.

Lots of quantitative and qualitative choices that ought to be explored.
These include what and what and what and what?
How \emph{ought we} make all these choices?

Not the least of these is linearity; deep learning and so on.

The potential for autoregressive models.  Cite the white paper.

The weakest point is construction of photometry from the model plus residuals;
  interesting whether the output of the model can be interrogated
  to provide value for those building physical models.

\acknowledgements
It is a pleasure to thank the whole \Kepler\ Team
  for designing, delivering, and operating a great facility,
  and for making all of the data public, in all its rawest forms, through the MAST interface.
We are also pleased to thank
  Ruth~Angus (Oxford),
  Tom~Barclay (Ames),
  Bekki~Dawson (Berkeley),
  Rob~Fergus (NYU),
  Stefan~Harmeling (Dusseldorf),
  Michael~Hirsch (UCL),
  Dustin~Lang (CMU),
  Benjamin~T.~Montet (Caltech),
  David~Schiminovich (Columbia),
  and
  Jake Vanderplas (UW)
for valuable discussions, input, encouragement, and advice.
This project was partially supported by
  NSF grant IIS-1124794,
  NASA grant NNX12AI50G.
  the Moore Foundation,
  and
  the Sloan Foundation.
This research made use of the NASA Astrophysics Data System.

\todo{White-paper Authors:  Feel free to contribute to this paper and move from the ack list to the author list.}

\clearpage
\begin{figure}
~ % DFM: replace this ~ with a figure
\caption{A patch of \Kepler\ pixels from the Target Pixel Files
  from \todo{XXX quarter}, centered on \todo{YYY target}.
  In the top panel, each box represents a pixel.
  Within each box is shown the light-curve of that pixel over the quarter.
  In the bottom panel, the SAP photometry for this target is shown;
  the SAP photometry is based on a straight sum of the pixels marked with darker borders.
  Note that every pixel varies substantially but the total SAP photometry is better than any individual pixel.
  Note also that the pixel variations are strongly inter-related.\label{fig:pixelpatch}}
\end{figure}

\clearpage
\begin{figure}
~ % DFM: replace this ~ with a figure
\caption{One quarter of photometric data for star \todo{KIC XXX}.
  The top panel shows the \Kepler\ SAP photometry;
    the vertical axis is \todo{something like median-divided brightness}
    and the horizontal axis is \todo{something like KBJD}.
  The next panel shows the \Kepler\ PDC photometry.
  The next shows the \name\ photometry.
  The bottom panel shows the power spectra of the three lightcurves.\label{fig:example1}}
\end{figure}

\end{document}


\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{amssymb, amsmath, amsthm, enumitem, physics}
\usepackage[margin=0.75in]{geometry} % set page margins automatically
\usepackage{tcolorbox, bm}
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{pdfpages}
\usepackage{qtree}

\newtcolorbox{mybox}[3][]
{
  colframe = cyan,
  colback  = white,
  coltitle = #2!20!black,
  title    = {#3},
  #1,
}

\pagestyle{fancy}

\newcommand{\pr}{\mathbb{P}}
\newcommand{\suml}{\sum\limits}
\newcommand{\intl}{\int\limits}
\renewcommand{\d}{\text{d}}
\begin{document}

\lhead{}
\rhead{}

\paragraph*{Terminology: }
\begin{itemize}
  \item Scene: a specific time step $t$ and its corresponding state $s_t$ (within an episode)
  \item Episode: Full sequence of scenes
  \item Memory: a 4-tuple ($s_t, a_t, r_t, s_{t+1}$)
  \item Trajectory: synonymous with episode. I.e., a trajectory is a sequence of memories that reaches a terminal state or some $t_{max}$.
\end{itemize}

\hrule

\paragraph{System overview:}

Actor-Critic

\begin{itemize}
  \item Critic $\mathcal{C}$ is learning a value $V_\theta (s)$ that critiques the actor. The critic $\mathcal{C}$ uses attention to train on trajectories from prior experiences. This would happen through self-supervised ``leave one out'' predictions in simialar fashion to the BERT / GPT-2 text generation tasks.
  \item TD-error is computed from $V_\theta (s)$:
    \begin{gather*}
      E_{TD} = r_t + \gamma V_\theta(s_{t+1}) - V_\theta(s_t) \\
      R_t = \suml_{k=0}^\infty \gamma^k r_{t+k}
    \end{gather*}

  \item Actor $\mathcal{A}$ (an MLP or something) acts based on sampled actions from a policy. The state $s_t$ and weights $\bm{\theta}$ are taken in by the actor $\mathcal{A}$ to output a probability distribution of actions $\pi_\theta (s_t)$. Sample from that probability distribution to select an action $a_t \sim \pi_\theta(s_t)$.
\end{itemize}

\begin{algorithm}[H]
\SetAlgoLined
\caption{Attention assisted actor critic}

\For{\normalfont number of training episodes}{
  \While{\normalfont\text{not in terminal state }$(t<T)$ }{
		In state $s_t$, select action $a_t$ from the policy $\pi$: $a_t \sim \pi_{\theta}(s_t)$ \\
    Perform action $a_t$ to retrieve $s_{t+1}, r_t$. \\
    Store the memory $(s_t, a_t, s_{t+1}, r_t)$ to the replay buffer. \\
    \eIf % If
      {\normalfont\text{terminal state}}%, then
      {Compute discounted rewards vector $\bm{R}$ with discount factor $\gamma$:
        $ \bm{R} = \suml_{t=0}^{T}
        \gamma^t r_t \hat{e_t} $ \\
      Save the trajectory sequence $\bm{\tau} = [M_0, \cdots, M_{T}]$ \\
      break}
    % else
      (){$s_t \leftarrow s_{t+1}$ \\
      $t \leftarrow t+1 $}
    }

	\textbf{Method 1 (Contrastive):} Train critic with contrastive learning in order to update the policy.  \\
  Use attention in masked training task similar to BERT (Zhu et al., 2020).   \\
  Train by minimizing loss $\mathcal{L} = \mathcal{L}_{\text{RL}} + \lambda \mathcal{L}_{\text{ct}}$, where: \\
  $\bm{K} = (k_1, \ldots, k_T)$: Set of keys encoded from non-makes set $S$. I.e.,
  $k_i = \text{Enc}_{\theta_k}(s_i),  \forall s_i\in S$.

  \begin{align*}
    &\mathcal{L}_{\text{ct}}
      = \suml_{i=1}^{T} -M_i
        \log \frac{\exp(q_i\cdot k_i / \omega)}{\suml_{j=1}^T
        \exp(q_i\cdot k_j / \omega)} ,
        \quad \omega\text{ is a hyperparameter} \\
    &\mathcal{L}_{\text{RL}} =  \ldots
  \end{align*}

  \textbf{Method 2 (Value estimates):}
  Compute $\bm{V} = [V_\theta(s_0), \ldots, V_\theta(s_T)]$ with states from the trajectory $\tau$.
}

The gradient-based updates can use any standard gradient-based learning rule.
\end{algorithm}

Non-synthetic environments to try out: Robotic arm manipulation, Open AI Gym.
\begin{itemize}
  \item
\end{itemize}

Deep Self-Supervised Bidirectional Episodic D Attention Actor-Critic

Deep Episodic D$\ldots$ Attention Actor Critic Self-Supervised

$D E A D A_cSS$

Stochastic Grad student descent

\paragraph{Attention:}

Self-supervised ``leave one out" training on trajectory inputs. This is similar to how BERT / GPT-2 do self-supervised training on sentences to build context for words. We would do this with trajectories to build context on memories, where the attention mechanism predicts

- Hidden layer embeddings are able to learn context-dependent information.

Training the attention part:

Input time ($t$): 0 1 2 3 \_ 5 6 7 8

For predicting t=4, we could input $s_4$, $a_4$, and predicts $s_5$

What's missing at $t=4$: $s_4, a_4$

Predicts $mathcal{R}$  -> expected reward $\gamma r_{4-8}$

\paragraph*{RL agent (live)}:

Then, when we give at seq like below:
Input time($t$): 0 1 2 3 4 \_

Right, we're in $s_4$ and want to pick $a_4$ and it would be helpful to know $r_4$ and $s_5$.

$Q_{att}(s_t, a)$: attention-value of state-action pair

$pi(s_t)$ = $max_a [Q(s_4, a) + Q_{att}(s_4, a)]$

----

Generate N trajectories, where N is a hyperparameter.

Attention trains on those trajectories in self-supervised setting to predict the expected reward?

Query is a seq. Tryign to figure out which keys you're most similar to. I'll give you a query (seq of tokens) and you'll tell me which keys most similar. Based on the similar b/w q and k,  $\to$ matrix products ($W_q$ $W_k$) attention project q's onto k's $\to$ Similarity metric is learned. Simulateneously, importance vector is learned.

\end{document}


\subsection{The TMS}

The following predicates are used to access the tms information
associated with \pfc\ facts.

\gloss{justification(+P,-J)\\
	justification(+P,-Js)}

\prolog{justification(P,J)} is true if one of the justifications for
fact P is J, where J is a list of \pfc\ facts and rules which taken
together deduce P.  Backtracking into this predicate can produce
additional justifications.  If the fact was added by the user, then
one of the justifications will be the list \prolog{[user]}.
\prolog{justifications(P,Js)} is provided for convenience.  It binds
\prolog{Js} to a list of all justifications returned by
\prolog(justification/2).

\gloss{base(+P,-Ps)}

\gloss{assumptions(+P,-Ps)}

\gloss{pfcChild(+P,-Q)\\
	pfcChildren(+P,-Qs)}

\gloss{pfcDescendant(+P,-Q)\\
	pfcDescendants(+P,-Qs)}