text:
\section{Introduction}

Efficient strategies for vertical swimming under turbulence are important for many marine plankton species.
Many plankton species undergo daily vertical migration of up to tens of meters to greater depths and back~\cite{Park2001,Ringelberg2009,Smayda2010} to allow for efficient nutrition uptake, to avoid predators, and to adjust to tidal flows~\cite{Smayda2010,Schmitt2011,Katajisto1998,Hays1994}.
Many species adopt strategies leading to correlated and ballistic vertical migration along or against gravity~\cite{Schuech2014,Pundyak2017}.
Their horizontal dynamics, by contrast, is usually simply diffusive.
There are several simple passive gyrotactic mechanisms to achieve rapid vertical migration. Some organisms are bottom heavy, or display shape asymmetries.
In both cases, the resulting torques anti-align the organism with the direction of gravity.
Many plankton species also use active gyrotactic strategies. Some phytoplankton can adjust their shape to either align with or against gravity~\cite{Sengupta2017}. Species of protists and flagellates sense gravity using mechanosensitive ion channels to allow them to adjust their swimming direction with regards to gravity~\cite{Hemmersbach1999,Haeder2003,HemmersbachKrause1993}.
To our knowledge, there is no evidence that planktonic copepods sense gravity using ion channels.
It has been suggested that planktonic copepods instead can use setae distributed on their body and antennae to obtain information about their orientation relative to gravity~\cite{Strickler1973}, but this hypothesis has not been verified or discussed in detail.
The setae allow copepods to sense slip velocities as small as \SI{20}{\micro\metre\per\s} between themselves and the ambient fluid~\cite{Yen1992}. This is one order of magnitude smaller than their typical settling velocity in quiescent flow~\cite{Titelman2003}.
The setae also allow for measurement of additional hydromechanical signals such as the local strain rate and slip vorticity.
The strain rate is known to be important for predation and predator avoidance~\cite{Kioerboe1999predator}, but the detailed response of the copepod to different hydromechanical signals remains unclear.
Is it possible for copepods to use the information perceived by hydromechanical signals to achieve active gyrotaxis, and if so, what is the best swimming strategy for this?
The answers to these questions may provide a new perspective to understand the vertical migration taking place in different situations~\cite{Schmitt2011,Katajisto1998,Hays1994}.
The answers also have bearing on future applications of fabricated microswimmers.

It is not understood how microswimmers such as copepods navigate in the most efficient way in the turbulent ocean.
Due to their small size and the complexity of the flow, it is difficult to perform experimental investigations on the relationship between hydromechanical signals and navigation strategies such as vertical migration.
To anyway try to understand and explain the dynamics of plankton, a simplified model has been formulated, describing plankton as a point-like, bottom heavy, spheroidal particle that swim with a constant speed relative to the local fluid in their instantaneous direction~\cite{Durham2013,Lillo2014,Zhan2014,Gustavsson2016,Borgnino2018,Lovecchio2019}. Analyzing this model using direct numerical simulations (DNS) of turbulence and analytical approaches allows to discover the mechanisms that determine orientational statistics, clustering, preferential sampling, and vertical migration of plankton.
The gyrotactic torque resulting from the bottom-heaviness of the swimmer aligns it against gravity and give efficient upward vertical migration in the absence of turbulence.
But in the presence of turbulent velocity gradients, the model predicts that the upward vertical-migration velocity of copepods with parameters approximated from nature is only a fraction of the swimming speed, and upward migration may even fail due to gravitational settling~\cite{Qiu2020,Qiu2020a,Qiu2021}.
In addition, the model does not explain how some organisms swim downwards~\cite{Dodson1997,Ringelberg2009}.
Settling is too slow for copepods to migrate several metres to the depths at dawn, they must therefore use an active mechanism to descend more efficiently.

Due to the lack of experimental input, it is hard to formulate improved models where the swimmers can actively adjust their swimming behavior in response to external stimuli.
One approach is to use reinforcement learning to find good strategies, allowing to construct new models that can be compared to experiments.
Proof of concept studies have shown that reinforcement learning provides strategies for efficient vertical migration~\cite{Colabrese2017,Gustavsson2017,Alageshan2020,Qiu2020} and more general navigation tasks~\cite{Alageshan2020,Biferale2019,Schneider2019,Muinos2021,Gunnarson2021} for swimmers with different shapes and motilities in both two- and three-dimensional flows.
However, in these studies the swimmers had access to global information such as their absolute position or orientation.
Usually, the swimmers sense only local information, in their own frame of reference. As a consequence, vertical migration requires that external or hydrodynamic forces break the symmetry of the problem. For example, it was shown in Ref.~\cite{Qiu2021} that the symmetry breaking set by gravity allows the swimmer to infer its vertical orientation by sensing only local hydromechanical signals.
Using reinforcement learning, efficient steering protocols for upward navigation, based primarily on the local strain rate, were found in frozen (time-independent) two-dimensional flows.
The results illustrate that the swimmers can learn rapid vertical migration by mimicking slender swimmers that tend to preferentially sample upwelling regions in the flow~\cite{Gustavsson2016,Borgnino2018,Lovecchio2019,Cencini2019}.

The mechanism mentioned above is specific to two-dimensional flows. In this paper we therefore investigate vertical-migration strategies in three-dimensional flows. We use reinforcement learning to find candidate strategies. The best strategies found are similar to those found in the two-dimensional frozen flow~\cite{Qiu2021}, but it turns out that the slip velocity is the dominant signal, in contrast to the strain rate for the frozen two-dimensional flows.
The main result is a simple yet powerful strategy for vertical migration based on a single component of the slip velocity, summarized in Fig.~\ref{fig:mechanism}.
Let $\ve n$, $\ve p$ and $\ve q$ be an orthonormal coordinate system describing the orientation of a swimmer with $\ve n$ in its swimming direction and $\ve p$ in the direction perpendicular to $\ve n$ where the swimmer has most sensitive perception of flow disturbances. It could for instance be the direction of the antennae of a copepod, see Fig.~\ref{fig:mechanism}(a).
The symmetry breaking due to gravitational settling allows the swimmer to measure the $z$ component of $\ve p$ (assuming that gravity points in the negative $z$ direction) up to some resolution $p^{\rm th}_{z}$.
The strategy is to steer around its $\ve q$-axis with a positive angular velocity if $p_z>p^{\rm th}_{z}$ and with a negative angular velocity when $p_z<-p^{\rm th}_{z}$, both cases leading to the swimmer monotonously rotating towards larger $n_z$. Fig.~\ref{fig:mechanism}(b,c) illustrates this strategy for the case where the swimmer is unaffected by both fluid gradients and passive gyrotactic torque due to inhomogeneous mass distribution. Independent of the initial orientation, the swimmer can monotonously rotate towards larger $n_z$.
The strategy allows for both efficient migration upwards or downwards, not relying much on the physical characteristics of the swimmer in terms of shape, mass distribution and threshold value of the sensing.

In Section~\ref{sec:model}, we introduce the model for the microswimmers and our setup for reinforcement learning. In Section~\ref{sec:optimal}, we show results for the mechanism described above and compare it to swimmers using passive gyrotactics and refined active gyrotactic strategies relying on more flow signals. Conclusions and discussion of the results are presented in Section~\ref{sec:conclusions}.

\begin{figure}
\includegraphics[width=15.2cm]{Fig1.pdf}
\caption{\label{fig:mechanism}
(a) Orientation axes $\ve n$, $\ve p$ and $\ve q$ for a spheroidal swimmer in a fixed Cartesian frame of reference ($\hat{\ve x}$, $\hat{\ve y}$, $\hat{\ve z}$) with direction of gravity $\hat{\ve g}=-\hat{\ve z}$.
(b, c) Unit spheres illustrating the mechanism in Eq. (\ref{eq:optimal}) for active gyrotactic stability.
Starting with orientation $\ve n_0$, $\ve p_0$, and $\ve q$, the swimmer actively rotates around its $\ve q$-axis until $|p_z|\le p^{\rm th}_{z}$ (shaded region) with positive rotation if $p_{z,0}>0$ (b) and negative rotation if $p_{z,0}<0$ (c), leading to the final orientation $\ve n_{\rm f}$, $\ve p_{\rm f}$, and $\ve q$ with $n_{z,{\rm f}}\ge n_{z,0}$ in general.}
\end{figure}

\section{Model}
\label{sec:model}
We use a model similar to that in Ref.~\cite{Qiu2021}, but here we consider a three-dimensional flow.
We model the swimmer as a point particle with the shape of an elongated spheroid with aspect ratio $\lambda=a_{\parallel}/a_\perp$, where $a_\parallel$ is the axis length along the symmetry direction and $a_\perp$ is the transversal radius.
For typical microswimmers in the ocean, inertia of both the swimmer and the fluid can be neglected~\cite{Qiu2021}, leading to the following dynamics for the position $\ve x$, the symmetry direction $\ve n$, the transversal direction of the antennae $\ve p$, and the direction $\ve q$ perpendicular to the $\ve n$-$\ve p$ plane
\begin{subequations}
\label{eq:eqm}
\begin{align}
\label{eq:eqm_x}
\dot{\ve x}=\ve v
\,,\hspace{0.5cm}
\dot{\ve n}=\ve\omega\times\ve n
\,,\hspace{0.5cm}
\dot{\ve p}=\ve\omega\times\ve p
\,,\hspace{0.5cm}
\ve q=\ve n\times\ve p
\,.
\end{align}
Here $\ve v$ and $\ve\omega$ are translational and angular velocity, given by~\cite{Durham2013,Qiu2021}
\begin{align}
\label{eq:eqm_v}
\ve v&=\ve u(\ve x,t)+{\ve v^{(\rm g)}}+v^{({\rm s})}\ve n\,,\\
\ve\omega&=\ve\Omega(\ve x,t)+\Lambda\ve n\times(\ma S(\ve x,t)\ve n)+\frac{1}{2B}\ve n\times\hat{\ve z}+\ve\omega^{({\rm s})}\,.
\label{eq:eqm_omega}
\end{align}
\end{subequations}
The flow velocity $\ve u$, half the flow vorticity $\ve\Omega=\ve\nabla\times\ve u/2$ and the strain rate matrix $\ma S=(\ve\nabla\ve u+[\ve\nabla\ve u]^{\rm T})/2$ are evaluated at the instantaneous position of the swimmer. While $\ve u$ advects the swimmer's center of mass, the first two terms in $\ve\omega$ rotate it according to Jeffery's angular velocity for a spheroid with shape parameter $\Lambda=(\lambda^2-1)/(\lambda^2+1)$~\citep{Jef22}.

Assuming that the direction of gravity, $\hat{\ve g}$, points in the negative $\hat{\ve z}$ direction, the swimmer settles with an orientation-dependent velocity~\cite{Kim:2005}
\begin{align}
{\ve v^{(\rm g)}}=\left(v^{(\rm g)}_{\perp}-v^{(\rm g)}_{\parallel}\right)n_z\ve n-v^{(\rm g)}_{\perp}\hat{\ve z}\,.
\label{eq:settling}
\end{align}
Here $v^{(\rm g)}_{\parallel}$ and $v^{(\rm g)}_{\perp}$ are the velocities of a spheroidal particle settling in a quiescent flow with the symmetry axis parallel and perpendicular to gravity.
Assuming a bottom-heavy mass distribution, gravity also gives rise to a passive gyrotactic torque, turning the swimmer away from $\hat{\ve g}$ at the time scale $B$~\cite{Kessler1985}, leading to the third term in $\ve\omega$.

Finally, the last term in $\ve v$ corresponds to swimming with constant speed $v^{({\rm s})}$ in the instantaneous direction $\ve n$ and $\ve\omega^{({\rm s})}$  in $\ve\omega$ is an active angular velocity due to steering in response to measurements of the local environment.
We assume that $\omega^{({\rm s})}_p=\ve\omega^{({\rm s})}\cdot\ve p$ and $\omega^{({\rm s})}_q=\ve\omega^{({\rm s})}\cdot\ve q$ take either of the values $\{-\omega^{({\rm s})},0,\omega^{({\rm s})}\}$, whereas $\omega^{({\rm s})}_n=\ve\omega^{({\rm s})}\cdot\ve n$ remains zero.
Typical dimensional parameter values of copepods are shown in Table~\ref{tab:parameters}.

\subsection{Flow}
We use simulations of the dynamics (\ref{eq:eqm}) driven by a velocity field $\ve u$ obtained either by DNS or a statistical model for the flow velocity.
To make learning fast enough during training, we use frozen flow obtained by taking snapshots of the time-dependent flows in both the DNS and the statistical model. Later, when we evaluate the found strategies, we also consider the dynamics in time-dependent flows.
This approach of training in frozen flows only takes into account of spatial structure of the flow. We do not address the question of whether there exist even better strategies that exploit spatiotemporal structures in turbulence.

In our DNS we use the method of Ref.~\cite{Qiu2020a} to simulate incompressible homogeneous isotropic turbulence by numerical solution of Navier-Stokes equations
\begin{align}
\frac{\partial\ve u}{\partial t}+\ve u\cdot\ve\nabla\ve u=-\frac{\ve\nabla p^{(\rm f)}}{{\rho^{(\rm f)}}}+\nu\ve\nabla^2\ve u+\ve f\,,\hspace{0.5cm}\ve\nabla u=0
\label{eq:NS}
\end{align}
on a periodic domain.
Here $p^{(\rm f)}$, ${\rho^{(\rm f)}}$, and $\nu$ denote the pressure, density and kinematic viscosity of the fluid, respectively.
The turbulence is driven by an external force $\ve f$ with low wave number \cite{Machiels1997}. Eqs.~(\ref{eq:NS}) are solved by a pseudo-spectral method, and the $3/2$ rule is adopted to reduce the aliasing error on the nonlinear term. Time integration of both fluid and swimmer dynamics is performed using the explicit second-order Adam-Bashforth scheme~\cite{Rogallo1981}. Our simulations are carried out using $96^3$ grid points with Taylor scale Reynolds number ${\rm Re}=60$. The smallest resolved scale is about $1.78$ times smaller than the Kolmogorov scale, which lies within the accepted range to reach statistically reliable results~\cite{Pope2000}.

In the statistical model we use an incompressible Gaussian random velocity field on the form
\begin{equation}
    \ve{u}(\ve{x},t) = \frac{1}{\sqrt{6}}\nabla \times \ve{A}(\ve x,t)\,,
\label{eq:SM_u}
\end{equation}
where $\ve{A}$ is a three-dimensional vector potential with components being independent Gaussian random functions with zero mean and correlation function \cite{Gustavsson16review}
\begin{equation}
    \langle A_{i}(\ve x,\ve t)A_{j}(\ve x',\ve t')\rangle  = \delta_{ij}(\ellu^{\rm rms})^2\exp\Big[-\frac{|\ve{x'}-\ve{x}|^2}{2\ell^2}-\frac{|t-t'|}{\tau}\Big].
\label{eq:SM_A}
\end{equation}
Here $\langle\cdot\rangle$ denotes a steady-state ensemble average, $\ell$ and $\tau$ are characteristic length and time scales, and $u^{\rm rms}=\langle \ve{u}^2 \rangle^{1/2}$.
The statistical model shows the best agreement with simulations in turbulent flows if large but finite values of $\ku=u^{\rm rms}\tau/\ell$ is considered. In this limit,
the flow evaluated at the positions of Lagrangian tracer particles decorrelates on the time scale $\ell/u^{\rm rms}$ due to displacement, rather than the time scale $\tau$ due to temporal variations of the flow. The relevant time scale in the statistical model in the limit of large $\ku$ is thus proportional to the Kolmogorov time $\tau^{(\eta)}=\langle{\rm tr}(2\ma S^{\rm T}\ma S)\rangle^{-1/2}$, where $\ma S$ is the strain rate matrix. In the statistical model the Kolmogorov time evaluates to $\tau^{(\eta)}=\ell/(\sqrt{5}u^{\rm rms})$~\cite{Gustavsson16review}.

The root mean square velocity of turbulent fluctuations in the ocean, $u^{\rm rms}$, ranges from \SIrange{0.1}{100}{\milli\metre\per\s}~\cite{Yamazaki1996}.
The energy dissipation rate ranges from \SI{e-4}{\milli\metre\squared\per\s\cubed} in the deep sea, up to \SI{100}{\milli\metre\squared\per\s\cubed} in the upper ocean mixing layer~\cite{Yamazaki1996,Fuchs2016}.
For a kinematic viscosity of $\nu$ = \SI{1}{\milli\metre\squared\per\s}, the Kolmogorov time $\tau^{(\eta)}$ takes values between \SI{0.1}{\s} and~\SI{100}{\s}.

\begin{table}
	\begin{center}
	\begin{tabular}{llccc}\hline\hline
		&& range & used value & unit\\
				\hline
		Swimmer length  & $2a_\parallel$& 0.1-0.5& 0.2&\SI{}{\mm} \\
		Aspect ratio & $\lambda$ & 2.0-2.5& 2.0& \\
		Mass-density ratio & ${\rho^{(\rm p)}}/{\rho^{(\rm f)}}$& 1.005-1.019& 1.017& \\
		\multirow{2}*{Settling velocity} & $v^{(\rm g)}_{\parallel} $&\multirow{2}*{0.1-0.8}& 0.15 & \SI{}{\mm\per\s}\\
		~& $v^{(\rm g)}_{\perp} $&~& 0.13 & \SI{}{\mm\per\s}\\
		Swimming velocity& $v^{({\rm s})}$ & 0.33-3.76& 1.32 & \SI{}{\mm\per\s} \\
		Time scale of passive gyrotaxis & $B$& $\sim$ 10 & 5.0& \SI{}{\s}\\
		Swimming angular velocity & $\omega^{({\rm s})}$ & $<$ 20 & 1.14 & \SI{1}{\radian\per\s} \\
        Sensing threshold & ${\Delta u^{\rm th}}$ & $\ge$ 20 & 50 & \SI{}{\micro\metre\per\s}\\
				\hline\hline
	\end{tabular}
	\caption{Typical values of model parameters estimated from juvenile copepods in the ocean and experiments, taken from Ref.~\cite{Qiu2021}.
The length is obtained for small copepods \citep{Titelman2001,Titelman2003} and the aspect ratio is estimated from their length and width~\citep{Carlotti2007}.
The mass-density ratio is obtained using mass density of copepods, ${\rho^{(\rm p)}}$, from Ref.~\citep{Knutsen2001} and a sea-water density of ${\rho^{(\rm f)}} =$ \SI{1.025}{\gram\per\cm\cubed} obtained for \SI{3.5}{\percent} salinity at \SI{20}{\degreeCelsius}, \citep{millero1980new}.
The settling velocity is obtained using the Stokes settling velocity for spheroids~\citep{Kim:2005} with our used values for $a_\parallel$, $\lambda$ and ${\rho^{(\rm p)}}/{\rho^{(\rm f)}}$.
The swimming velocity is taken from the experiments in Ref.~\citep{Titelman2003}.
The gyrotactic reorientation time of copepods is largely unknown. The value $B$ $\sim$ \SI{10}{\s} is taken from the critical vorticity in experiments on juvenile copepods~\citep{Fields1997}. In our simulations we use a slightly shorter reorientation time, $B$ = \SI{5}{\s}.
The maximal swimming angular velocity was estimated from the experiments in \citep{jiang2004}. In our model we use a smaller value that represents the slow horizontal and vertical steering motion described in Ref.~\citep{Kabata1971}.
The minimal sensing threshold ${\Delta u^{\rm th}}\sim \SI{20}{\micro\metre\per\s}$ is obtained from the measurements in Ref.~\cite{Yen1992}.
Simulation parameters are taken as the used values.
    }
	\label{tab:parameters}
	\end{center}
\end{table}

\subsection{Sensing and actions}
\label{sec:sensing}
Small microorganisms equipped with setae can use them to measure velocity differences between their body and the surrounding fluid~\cite{Strickler1973,Yen1992}.
Experiments show that copepods respond in different ways depending on the magnitudes of strain rate $\ma S$, angular velocity differences $\Delta\ve\Omega$, and velocity differences $\Delta\ve u$ of the flow~\cite{Kioerboe1999hydrodynamic}, indicating that they can distinguish between these three signals while not swimming.
This ability could be a consequence of that different flow structures give rise to different bending patterns of the copepod's setae~\cite{VisserBook,Kioerboe1999hydrodynamic}.
The disturbance to the surrounding flow by swimming complicates measurements~\cite{VisserBook}.
However, copepods are able to distinguish external hydrodynamic signals from its own generated flow when feeding~\cite{hwang2001can}.
It is therefore plausible that copepods are able to distinguish external hydromechanical signals from its own flow during steady swimming by recognizing spatial and temporal flow structures~\cite{yen1996advertisement} using an array of densely distributed setae along its body and antennae~\cite{Fields2014}.
Copepods often show a directional bias in their ability to sense hydromechanical signals~\cite{Fields2010}.
We assume a microorganism that is better at detecting signals in the symmetry direction $\ve n$ and the directions of its antennae $\pm\ve p$ than in the direction $\ve q$.
Primarily, we therefore consider navigation using the signals $\ma S$, $\Delta\ve\Omega$ and $\Delta\ve u$, projected on the $\ve n$ and $\ve p$ directions in the local frame of the swimmer. For completeness we also discuss strategies including the $\ve q$ direction because, in principle, a generic swimmer, which is able to use its setae to measure the flow at enough independent positions and orientations, has enough information to distinguish signals along both directions $\ve p$ and $\ve q$.

To reduce the number of signals, we use Eqs.~(\ref{eq:eqm}) to express velocity and angular velocity differences in the local coordinate system $\ve n$, $\ve p$ and~$\ve q$
\begin{subequations}
\label{eq:projections}
\begin{align}
\label{eq:vn}
\Delta u_n&=u_n-v_n=v^{(\rm g)}_{\parallel} n_z-v^{({\rm s})}\,,\\
\label{eq:vp}
\Delta u_p&=u_p-v_p=v^{(\rm g)}_{\perp} p_z\,,\\
\label{eq:vq}
\Delta u_q&=u_q-v_q=v^{(\rm g)}_{\perp} q_z\,,\\
\label{eq:omegan}
\Delta\Omega_n&=\Omega_n-\omega_n=-\omega^{({\rm s})}_n\,,\\
\label{eq:omegap}
\Delta\Omega_p&=\Omega_p-\omega_p=\Lambda S_{nq}+\frac{1}{2B}q_z-\omega^{({\rm s})}_p\,,\\
\label{eq:omegaq}
\Delta\Omega_q&=\Omega_q-\omega_q=-\Lambda S_{np}-\frac{1}{2B}p_z-\omega^{({\rm s})}_q\,.
\end{align}
\end{subequations}
\noindent
Here subscripts $n$, $p$ or $q$ denote scalar product with the corresponding unit vector $\ve n$, $\ve p$ or $\ve q$.
First, according to Eq.~(\ref{eq:vn}), the magnitude $|\Delta u_n|\sim v^{({\rm s})}$ is much higher than our used sensing threshold in Table~\ref{tab:parameters}.
To avoid introducing additional arbitrary threshold values, we skip this signal.
Second, Eqs.~(\ref{eq:vp}) and (\ref{eq:vq}) show that the swimmer is able to directly measure the $z$-component of the $\ve p$ and $\ve q$ directions and we adopt these components as signals.
Third, Eq.~(\ref{eq:omegan}) shows that measurement of $\Delta\Omega_n$ does not provide any information. Moreover, Eqs.~(\ref{eq:omegap}) and (\ref{eq:omegaq}) show that $\Delta\Omega_p$, is given by the signals $S_{nq}$ and $q_z$, and $\Delta\Omega_q$ is given by $S_{np}$ and $p_z$. Therefore $\Delta\ve\Omega$ does not contribute with any independent information and we neglect it as a signal.
Fourth, we only consider the strain components that directly affect the dynamics in Eqs.~(\ref{eq:projections}), $S_{np}$ and $S_{nq}$. Other strain components may give relevant information due to flow correlations, but this is most likely secondary to the direct contributions of $S_{np}$ and $S_{nq}$.
Finally, in our model we have omitted higher-order derivatives and time dependence of the hydromechanical signals.

The aim is to use reinforcement learning to search for optimal or approximately optimal strategies for vertical migration by suitable steering (actions) based on hydromechanical signals (states).
In our model we use different sets of states obtained from combinations of discretized signals $p_z$, $q_z$, $S_{np}$, and $S_{nq}$.
Each signal $\sigma$ is discretized into three states separated by a threshold level ${\sigma^{\rm th}}$
\begin{align}
\mbox{states for signal $\sigma$}=\left\{
\begin{array}{ll}
\sigma^{(+)} & \mbox{if }\sigma>{\sigma^{\rm th}}\cr
\sigma^{(0)} & \mbox{if }|\sigma|<{\sigma^{\rm th}}\cr
\sigma^{(-)} & \mbox{if }\sigma<-{\sigma^{\rm th}}
\end{array}
\right.\,.
\label{eq:state_discretization}
\end{align}
For the velocity differences $\Delta u_p$ and $\Delta u_q$, we use a threshold ${\Delta u^{\rm th}}$ = \SI{50}{\micro\metre\per\s}, giving the threshold $p^{\rm th}_{z}={\Delta u^{\rm th}}/v^{(\rm g)}_{\perp}\approx 0.37$ for the $p_z$ and $q_z$ components with $v^{(\rm g)}_{\perp}$ from Table~\ref{tab:parameters}.
Estimating the corresponding gradients along the length of the swimmer, ${\Delta u^{\rm th}}/a_\parallel$~\cite{Kioerboe1999predator}, we obtain the threshold we use for angular velocity differences and strain rates, ${S^{\rm th}}$= \SI[per-mode=power]{0.5}{\per\s}.
We have chosen the threshold ${\Delta u^{\rm th}}$ to lie between the smallest velocity difference that copepods can physically sense, \SI{20}{\micro\metre\per\s}~\cite{Yen1992}, and the settling velocity $\sim$ \SI{150}{\micro\metre\per\s} in order to allow the copepod to sense its settling.
In experiments it is observed that different species of copepods make vigorous escape jumps in response to steady-flow strain rates of the order \SIrange[per-mode=power]{0.2}{20}{\per\s}~\cite{Kioerboe1999hydrodynamic,Kioerboe1999predator,Titelman2001,Buskey2002}.
Our threshold ${S^{\rm th}}$ is of this order of magnitude, indicating that it can be measured by copepods in nature.
We have confirmed that our results described in the next section are not sensitive to the exact values of the thresholds, as long as ${\Delta u^{\rm th}}$ is smaller than half the settling velocity.

We assume that the active angular velocity contribution, $\ve\omega^{({\rm s})}$ in Eq.~(\ref{eq:eqm_omega}), allows the swimmer to steer by rotating around the $\ve p$- and $\ve q$-axes with angular velocities $\omega^{({\rm s})}_p$ and $\omega^{({\rm s})}_q$ respectively.
We first consider a planar model, where the swimmer can measure signals in the $\ve n$-$\ve p$ plane: $p_z$ and $S_{np}$.
In this case we assume no steering around the $\ve p$-axis, $\omega^{({\rm s})}_p=0$, and the angular velocity $\omega^{({\rm s})}_q$ around the $\ve q$-axis takes three values, $\omega^{({\rm s})}_q =\{-\omega^{({\rm s})},0,+\omega^{({\rm s})}\}$.
This planar model is similar to the two-dimensional model considered in Ref.~\cite{Qiu2021}, but in that case $\ve q$ was fixed to the direction perpendicular to the flow plane, while $\ve q$ is free to rotate in the three-dimensional flow considered here.
We also consider a full three-dimensional model, where the swimmer in addition to the signals of the planar model has access to the signals $S_{nq}$ and $q_z$.
In addition to the three values of angular velocities around the $\ve q$-axis, the swimmer in the 3D model can also steer around the $\ve p$-axis with three levels $\omega^{({\rm s})}_p = \{-\omega^{({\rm s})},0,+\omega^{({\rm s})}\}$, giving in total $9$ different actions.

Copepods can acquire angular velocities up to \SI{20}{\radian\per\s} before a jump~\cite{jiang2004}. When cruising they steer with smaller angular velocities~\cite{Kabata1971}.
In our reinforcement learning we use $\omega^{({\rm s})}$ = \SI{1.14}{\radian\per\s}. We choose this value because it is of the order of the root-mean-square vorticity in our simulations during training, and it is much smaller than the hypothetical maximal angular velocity, $v^{({\rm s})}/a_\parallel \approx$ \SI{13}{\radian\per\s}, that would have been obtained if the swimmer were able to convert the full swimming propulsion into angular rotation. Our value $\omega^{({\rm s})}$ = \SI{1.14}{\radian\per\s} gives a large length–specific turning radius, $v^{({\rm s})}/(\omega^{({\rm s})} a_\parallel)\approx 12$, consistent with slow steering while cruising. We have confirmed that our results described in the next section are not sensitive to the exact value of $\omega^{({\rm s})}$, as long as it is not too small.

\subsection{Reinforcement Learning for vertical migration}

We adopt a one-step Q-learning algorithm~\cite{Watkins1992,Sutton1998,Mehlig2021} to train the swimmer to find efficient strategies for vertical migration.
The training is divided into a number of episodes.
In each episode, one precalculated frozen flow snapshot is randomly chosen. The swimmer starts with a random initial position and orientation and follows the dynamics~(\ref{eq:eqm}), first for an equilibration time $T^{\rm eq}$, and then for a predefined physical time of training, $T^{\rm train}$.
The initial equilibration is introduced to search for strategies that are efficient in the statistical steady state, not relying on the arbitrary uniform initial condition.
In the DNS at regularly distributed time steps $iT^{\rm meas}$ with $i=0,1,\dots,\lfloor(T^{\rm eq}+T^{\rm train})/T^{\rm meas}\rfloor$, the swimmer measures its current discrete state $s_i$, obtained by measurement of the signals described above, and is given a reward $r_i$.
In the statistical model a reward is instead given at any time step where the state changes.
Because the goal is vertical migration upwards, we use the velocity in the $z$ direction since the last state measurement as reward in the DNS, $r_i = (z_{i+1} - z_{i})/T^{\rm meas}$, and displacement, $r_i = z_{i+1} - z_i$, in the statistical model.
After the reward is given, the swimmer sets $\ve\omega^{({\rm s})}$ to action $a_i$.
During the equilibration, $T<T^{\rm eq}$, the action is chosen according to a greedy policy, $a_i={\rm arg\,max}_a Q(s_i,a)$ and the Q-table is kept constant. After the equilibration the action is chosen according to an $\varepsilon$-greedy policy
\begin{align}
\label{eq:policy}
a_i=\left\{
\begin{array}{ll}
\mbox{random action} & \mbox{with probability }\varepsilon\cr
{\rm arg\,max}_a Q(s_i,a) & \mbox{otherwise}
\end{array}
\right.\,,\hspace{0.5cm}
\mbox{where }
\varepsilon=\varepsilon_0\,{\rm max}\left(0,1-\frac{E}{E^{(\varepsilon)}}\right)\,.
\end{align}
Here $\varepsilon$ is an exploration rate that starts at $\varepsilon_0$ and decays linearly with the training episode number $E$ until it reaches zero at episode $E^{(\varepsilon)}$.
It allows the swimmer to explore different actions, preventing the learning to get stuck at local optima.
Normally, non-exploratory actions are chosen as the action giving the maximal value of the $Q$-table, $Q(s,a)$, for the current state.
Starting with a $Q$-table of uniform values, it is updated each time the agent is given a reward using the rule
\begin{equation}\label{qlearning}
Q(s_i,a_i) \leftarrow Q(s_i,a_i) + \alpha[r_i + \gamma \max_{a}Q(s_{i+1},a) - Q(s_i,a_i)]\,,\hspace{0.5cm}
\mbox{where }
\alpha=\alpha_0\frac{E^{(\alpha)}}{E^{(\alpha)}+E}\,.
\end{equation}
Here $\alpha$ is a learning rate, starting at $\alpha_0$ and decaying on the episode scale $E^{(\alpha)}$.
The discount factor $\gamma$, with $0\le\gamma<1$, sets an optimization time scale over $(1-\gamma)^{-1}$ state changes. It is introduced to prevent divergence of the values in the $Q$ table in the long run. We adopt a far-sighted optimization by setting $\gamma$ close to $1$.
At the end of each episode, the $Q$ table is kept for the next episode, continuing to be updated.
In the ideal case of infinitely many exploratory moves and if the system is Markovian, the entries of the $Q$-table approach the optimal values for the expectation values of the future discounted reward, $Q(s_i,a)=\langle\sum_{j=0}^\infty \gamma^j r_{i+j}\rangle$ for taking action $a$ in state $s_i$ following the policy~(\ref{eq:policy}). In most realistic situations, the process instead converges to an approximately optimal strategy.
Information about the parameters used in our different training cases are given in Appendix~\ref{appendix:learning_parameters}.

\section{Optimal swimming strategies}
\label{sec:optimal}

\subsection{Results from reinforcement learning}
\begin{table}[]
	\begin{tabular}{b{1.8cm}b{1.8cm}b{2.5cm}p{0.8cm}p{1.4cm}p{0.8cm}p{1.4cm}l}
	& & & \multicolumn{4}{c}{Performance $\langle v_z\rangle/\langle v_z\rangle_0$\vspace*{0.1cm}}\\
	Model & Actions & Signals & \multicolumn{2}{l}{Frozen DNS} & \multicolumn{2}{l}{Frozen statistical model} \\
	  \hline
    Naive & $-$ & $-$ &  0.30 & & 0.22 & \\
	  \hline
    Planar & $\omega^{({\rm s})}_q$ & $p_z$ & 0.58 & (0.58) & 0.73 & (0.73) & (Eq. (\ref{eq:optimal}))\\
	\hspace{0.45cm}" & \hspace{0.1cm}" & $S_{np}$ & 0.31 & & 0.22 & &\\
	\hspace{0.45cm}" & \hspace{0.1cm}"& $p_z$, $S_{np}$ & 0.58 & & 0.73 & & \\
	  \hline
    Full 3D & $\omega^{({\rm s})}_p$, $\omega^{({\rm s})}_q$ & $p_z$ & 0.58 & & 0.73 & & \\
	\hspace{0.45cm}"& \hspace{0.45cm}" & $q_z$ & 0.58 & & 0.73 & & \\
	\hspace{0.45cm}"& \hspace{0.45cm}"& $p_z$, $q_z$ & 0.64 & (0.66) & 0.94 & (0.94) & (Eq. (\ref{eq:optimal_two_signals})) \\
	\hspace{0.45cm}"& \hspace{0.45cm}"& $S_{np}$ & 0.32 & & 0.22 & & \\
	\hspace{0.45cm}"& \hspace{0.45cm}"& $S_{nq}$ & 0.34 & & 0.22 & & \\
	\hspace{0.45cm}"& \hspace{0.45cm}"& $S_{np}$, $S_{nq}$ & 0.31 & & 0.20 & & \\
	\hspace{0.45cm}"& \hspace{0.45cm}"& $p_z$, $S_{np}$ & 0.57 & & 0.73 & & \\
	\hspace{0.45cm}"& \hspace{0.45cm}"& $p_z$, $S_{nq}$ & 0.58 & & 0.73 & & \\
	\hspace{0.45cm}"& \hspace{0.45cm}"& $q_z$, $S_{np}$ & 0.57 & & 0.73 & & \\
	\hspace{0.45cm}"& \hspace{0.45cm}"& $q_z$, $S_{nq}$ & 0.58 & & 0.73 & & \\
	\hspace{0.45cm}"& \hspace{0.45cm}"& $p_z$, $q_z$, $S_{np}$, $S_{nq}$ & 0.64 & (0.68) & 0.94 & (0.94)  & (Eq. (\ref{eq:optimal_four_signals})) 	\end{tabular}
\caption{\label{tab:DNS_signal_comb}Average vertical velocity $\langle v_z\rangle$ normalized by the value in quiescent flows $\langle v_z\rangle_0$ [Eq.~(\ref{eq:vz0})] for different sets of discretized actions and states, see Section~\ref{sec:sensing}, with parameters from Table~\ref{tab:parameters}. Numbers show results obtained by evaluation of the best strategy found for each case using reinforcement learning in frozen DNS or statistical model flows. The numbers in parentheses show results for the strategies in Eqs.~(\ref{eq:optimal}), (\ref{eq:optimal_two_signals}) and (\ref{eq:optimal_four_signals}). Errors of the numerical values are of the order $\pm 0.01$.
}
\end{table}
We evaluate the performance of the strategies found in our reinforcement learning by running the same setup as in the training, but with a greedy action ($\varepsilon=0$) and we do not update the $Q$-table ($\alpha=0$). We average the vertical velocity over multiple episodes, each of time $T^{\rm train}$ sampled after the initial equilibration time $T^{\rm eq}$. Both $T^{\rm eq}$ and $T^{\rm train}$ are chosen much larger than the maximal time scale of the dynamics, so that steady state statistics is obtained.
The results of the best strategies found are summarized in Table~\ref{tab:DNS_signal_comb}.
The vertical velocity is normalized using the average
\begin{align}
\langle v_z\rangle_0=v^{({\rm s})} - v^{(\rm g)}_{\parallel}\,,
\label{eq:vz0}
\end{align}
obtained in the long-time limit if the ambient flow velocity $\ve u$ is put to zero in Eq.~(\ref{eq:eqm_v}).
Results for the naive model, obtained for a swimmer with zero active angular velocity, $\ve\omega^{({\rm s})}=0$, are given as a reference.

\begin{figure}
\includegraphics[width=15.5cm]{Fig2.pdf}
    \caption{Summary of strategies obtained by reinforcement learning for the cases of the planar model with single signal $p_z$ and full 3D model with joint signal $p_z$ and $q_z$. Results from the frozen DNS [(a) and (c)] and the statistical model [(b) and (d)]. Rows represent different states, the signs $-$, $0$, and $+$ represent the states $\sigma^{(-)}$, $\sigma^{(0)}$, and $\sigma^{(+)}$ in the discretized signal in Eq.~(\ref{eq:state_discretization}). Columns represent different actions, where the signs represent the values $-\omega^{({\rm s})}$, $0$, and $+\omega^{({\rm s})}$ respectively. The action selected in a given state for the best strategy found in our reinforcement learning is highlighted in red. In each panel the resulting strategies from 60 completed training sessions are summarized. Each numerical value gives the non-zero percentage of strategies choosing a certain action in a given state. The background is color coded according to this percentage from white (0\%) to blue (100\%).
    }
	\label{fig:Policy_planar_DNS}
\end{figure}

In the planar model the swimmer can steer around the $\ve q$-axis, $\ve\omega^{({\rm s})}=\omega^{({\rm s})}_q\ve q$, and it can sense combinations of two signals: the vertical component $p_z$ of the $\ve p$-axis and the strain component $S_{np}$.
The results in Table~\ref{tab:DNS_signal_comb} show that the signal $p_z$ is more important for upward vertical migration than $S_{np}$ in both the DNS and the statistical model.
The optimal strategy when using only $p_z$ as the signal is the same in the two flows, and it is highlighted using red frames in Fig.~\ref{fig:Policy_planar_DNS}(a,b).
Fig.~\ref{fig:mechanism} shows the mechanism explaining why this strategy is successful.
The optimal strategy when using only $S_{np}$ as the signal is on the same level as the naive strategy. The optimal strategy using both $p_z$ and $S_{np}$ performs approximately on the same level as the simpler strategy using only $p_z$ as the signal.

In the full 3D model, the swimmer can rotate around both the $\ve p$- and $\ve q$-axes, and all four relevant flow signals are considered.
Using a single signal $p_z$, the best strategy found for both the DNS and statistical model is the same as in the planar case, i.e. rotate around the $\ve q$-axis according to Fig.~\ref{fig:Policy_planar_DNS}(a), with no rotation around the $\ve p$-axis. Using $q_z$ as the signal, the equivalent strategy is found by rotating around $\ve p$ with no rotation around $\ve q$.
For two combined signals, the best strategies found in both DNS and statistical model are based on $p_z$ and $q_z$. They are highlighted using red frames in Fig.~\ref{fig:Policy_planar_DNS}(c,d).

The strategies based only on the strain signals perform on the level of the naive swimmer, with approximately half the vertical velocity compared to the strategies based on $p_z$ and $q_z$. Hybrid strategies between one strain component and either of $p_z$ or $q_z$ perform on the same level as the individual $p_z$ or $q_z$ signal.
Finally, in the case of four signals, $p_z$, $q_z$, $S_{np}$, and $S_{nq}$, the best strategies found are of the same order as the strategies based on $p_z$ and $q_z$ only.

Being a stochastic process, different training sessions often converge to different approximately optimal strategies. Therefore, we have run several training sessions for each case considered, and the results displayed in Table~\ref{tab:DNS_signal_comb} are based on the strategy with the best performance during training.
The cell colors in Fig.~\ref{fig:Policy_planar_DNS} summarize the resulting strategies from 60 training sessions for each case (a--d).
For a given state, an action with a white or light-blue cell are rarely chosen, while actions with blue color are selected in most of the resulting strategies.
We find that for a single signal in the planar model, most training sessions converge to the optimal strategy highlighted in red in Fig.~\ref{fig:Policy_planar_DNS} (a,b).
For two signals in the full 3D model, results are more scattered.
The reason is that many strategies have similar reward levels and it is therefore hard to find the global optimal strategy.
In the DNS the mean value of $\langle v_z\rangle/\langle v_z\rangle_0$ obtained in the 60 training sessions is $0.60$ and the median is $0.61$, both being close to the value $0.64$ for the best strategy found. The same holds for the statistical model where the mean value is $0.85$ and the median is 0.94, equal to the value for the best strategy found.
We conclude that although it is hard to find the global optimum, many quasi-optimal strategies have approximately the same performance.

The strategies discussed above are obtained in frozen flows. The flow is changed each episode to reduce bias towards specific frozen flows.
However, the flow statistics of the dynamics in a frozen flow is slightly different from the statistics in time fluctuating flows, or for swimmers with other parameter values.
In general, which strategy is optimal for a given task depends on both the model parameters and learning parameters, such as the choice of actions and states. There is no guarantee that a strategy found for one setup is also the best strategy for a different setup. For example, the optimal strategy found using a frozen flow is not necessarily the same as the optimal strategy in a time-dependent flow, and a flow in nature could have yet another optimal strategy.
We therefore try to identify generally valid strategies that are robust upon changing the details.
Using the trend that the best strategies in Fig.~\ref{fig:Policy_planar_DNS} tend to chose actions along the diagonals, we formulate strategies below in the planar model and full 3D model that have good performance for a large number of parameters and flows, including time-dependent flows.

\subsection{Planar model with a single signal}
Our reinforcement learning shows that for upward vertical navigation in the planar model using a single observable and the action to steer around the $\ve q$-axis, the most important signal is $p_z$, being proportional to the cosine of the angle between the transversal direction $\ve p$ and the direction of gravity $\hat{\ve g}=-\hat{\ve z}$.
The resulting optimal strategy, shown in Fig.~\ref{fig:Policy_planar_DNS}(a,b), can be written mathematically as $\ve\omega^{({\rm s})}=\omega^{({\rm s})}_p\ve p+\omega^{({\rm s})}_q\ve q$ with
\begin{align}
\omega^{({\rm s})}_p=0
\hspace{0.5cm}
\mbox{and}
\hspace{0.5cm}
\omega^{({\rm s})}_q=\omega^{({\rm s})}
\left\{
\begin{array}{ll}
1&\mbox{ if }p_z>p^{\rm th}_{z}\cr
-1&\mbox{ if }p_z<-p^{\rm th}_{z}\cr
0 & \mbox{ otherwise}
\end{array}
\right.\,.
\label{eq:optimal}
\end{align}
This strategy imposes an active gyrotactic stability on the orientational dynamics.
To understand the mechanism of Eq.~(\ref{eq:optimal}), we consider a simplified dynamics where passive gyrotaxis and flow gradients are neglected. In this limit, the angular velocity of the swimmer, Eq.~(\ref{eq:eqm_omega}), is solely determined by the active swimming contribution, $\ve\omega=\ve\omega^{({\rm s})}$, and the orientational dynamics of Eq.~(\ref{eq:eqm_x}) becomes
\begin{align}
\dot{\ve n}=\omega^{({\rm s})}_q\ve p
\,,\hspace{0.3cm}
\dot{\ve p}=-\omega^{({\rm s})}_q\ve n
\hspace{0.3cm}\mbox{and}\hspace{0.3cm}
\dot{\ve q}=0\,.
\label{eq:mechanism}
\end{align}
Assuming $\omega^{({\rm s})}>0$, the signature of $\omega^{({\rm s})}_q$ only depends on $p_z$ according to Eq.~(\ref{eq:optimal}).
If the initial value $p_{z,0}$ is smaller than the sensing threshold, $|p_{z,0}|\lep^{\rm th}_{z}$, the orientation remains unchanged. If instead $|p_{z,0}|>p^{\rm th}_{z}$, the active rotational swimming turns the swimmer around its $\ve q$-axis until $p_z$ reaches $p^{\rm th}_{z}$ for the case of positive $p_{z,0}$, or until it reaches $-p^{\rm th}_{z}$ for the case of negative $p_{z,0}$. The direction of the rotation following from Eq.~(\ref{eq:optimal}) is such that the $z$ component of $\ve n$ in Eq.~(\ref{eq:mechanism}) is rotated towards larger values, $\dot n_z=\omega^{({\rm s})}|p_z|\Theta(|p_z|-p^{\rm th}_{z})\ge 0$, where $\Theta$ is the Heaviside step function. Fig.~\ref{fig:mechanism}(b,c) illustrate this mechanism for the case $p^{\rm th}_{z}=0.37$.

To evaluate the average alignment $\langle n_z\rangle$ for the simplified dynamics (\ref{eq:mechanism}), we use the normalisation $n_z^2+p_z^2+q_z^2=1$.
If $|p_{z,0}|\le p^{\rm th}_{z}$, there is no rotation and the final value $n_{z,{\rm f}}$ is equal to the initial value $n_{z,0}$.
If $|p_{z,0}|> p^{\rm th}_{z}$, then $q_z$ remains constant, while $p_z$ is rotated until the threshold $\pmp^{\rm th}_{z}$.
Using the normalisation, the final value of $n_z$ must take the form $n_{z,{\rm f}}=\pm\sqrt{1-[p^{\rm th}_{z}]^2-q_{z,0}^2}$.
The sign choice in Eq.~(\ref{eq:optimal}) breaks symmetry, always giving the positive solution of $n_{z,{\rm f}}$, while the negative solution would be obtained by rotating in the opposite direction of Eq.~(\ref{eq:optimal}).
Averaging the positive solution $n_{z,{\rm f}}$ over initially uniformly distributed orientations, assuming $0\lep^{\rm th}_{z}\le 1$, gives (see Appendix \ref{appendix:alignment} for details)
\begin{align}
\label{eq:nz_planar}
\langle n_z\rangle=\frac{4}{3\pi}\frac{(1-[p^{\rm th}_{z}]^2)^{3/2}}{p^{\rm th}_{z}}{}_3F_2\left[\frac{1}{2},1,2;\frac{3}{2}, \frac{5}{2};1 - \frac{1}{[p^{\rm th}_{z}]^2}\right]\,.
\end{align}
Here ${}_3F_2$ is the generalized hypergeometric function.
This solution scales as $\langle n_z\rangle\sim\tfrac{\pi}{4}-\tfrac{2}{\pi}p^{\rm th}_{z}-\tfrac{\pi}{4}[p^{\rm th}_{z}]^2$ for small $p^{\rm th}_{z}$.
The limiting case of very high resolution of the signal, $p^{\rm th}_{z}\to 0$, results in large albeit not perfect alignment, $\langle n_z\rangle\to\tfrac{\pi}{4}\approx 0.8$.
As $p^{\rm th}_{z}$ approaches unity, the solution scales as $\langle n_z\rangle\sim \tfrac{8\sqrt{2}}{3\pi}(1-p^{\rm th}_{z})^{3/2}$. For $p^{\rm th}_{z}>1$, the swimmer cannot resolve $p_z$ and active alignment fails.
We conclude that Eq.~(\ref{eq:mechanism}) is a simple mechanism for active gyrotactic stability, leading to partial alignment against gravity in quiescent flows even without inhomogeneous mass distribution.

\begin{figure}
\includegraphics[width=17.5cm]{Fig3.pdf}
\caption{
\label{fig:velocity}
Numerical simulation results in the steady state for average alignment (a) and velocity (b,c) against the threshold of the flow signal, $p^{\rm th}_{z}={\Delta u^{\rm th}}/v^{(\rm g)}_{\perp}$ (a,b), and the dimensionless angular swimming velocity $\omega^{({\rm s})}\tau^{(\eta)}$ (c).
Velocities are normalized using $\langle v_z\rangle_0$ in Eq.~(\ref{eq:vz0}).
Symbols show results from simulations of Eqs.~(\ref{eq:eqm}) with smart planar steering [$\ve\omega^{({\rm s})}=\omega^{({\rm s})}_q\ve q$ using Eq.~(\ref{eq:optimal})] in the statistical model with $\ku=10$ (colored symbols) and DNS [hollow symbols in panels (a,b)].
Numerical results for the naive strategy ($\ve\omega^{({\rm s})}=0$) in the statistical model are shown as horizontal dashed green lines.
The shaded region corresponds to threshold levels below the minimal resolution limit $\Delta u$ = \SI{20}{\micro\metre\per\s}.
The dash-dotted line in panel (a) shows the theory for the simplified dynamics, Eq. (\ref{eq:nz_planar}).
Flow parameters $u^{\rm rms}$ = \SI{6.7}{\mm\per\s} and $\tau^{(\eta)}$ = \SI{1}{\s}. All swimmer parameters according to the used values in Table~\ref{tab:parameters}, except for parameter values stated in the figure.}
\end{figure}

Fig.~\ref{fig:velocity} shows simulation results for the full dynamics~(\ref{eq:eqm}) using the strategy (\ref{eq:optimal}) with parameters from Table~\ref{tab:parameters}. The data illustrates the sensitivity of the strategy to the choice of the dimensionless parameters $p^{\rm th}_{z}$, $\omega^{({\rm s})}\tau^{(\eta)}$ and $B/\tau^{(\eta)}$.
Fig.~\ref{fig:velocity}(a) shows the dependence of the average vertical alignment $\langle n_z\rangle$ on the signal threshold $p^{\rm th}_{z}$.
As expected, for $p^{\rm th}_{z}>1$ the alignment is equal to the naive case with no steering, $\omega^{({\rm s})}=0$. In this case there is a weak alignment due to the passive gyrotactic angular velocity in Eq.~(\ref{eq:eqm_omega}).
When $p^{\rm th}_{z}$ is reduced below unity, there is a sharp increase in $\langle n_z\rangle$ until $p^{\rm th}_{z}\approx 0.5$. For smaller values of $p^{\rm th}_{z}$, $\langle n_z\rangle$ is approximately constant around $0.8$. We conclude that the results are not sensitive to the value of $p^{\rm th}_{z}$, as long as it is smaller than $0.5$.
Our choice of $p^{\rm th}_{z}=0.37$ lies in the upper part of this range.
The dash-dotted curve in Fig.~\ref{fig:velocity}(a) shows the analytical evaluation for a quiescent flow, Eq.~(\ref{eq:nz_planar}).
It has the same trend as the numerical data, but predicts a somewhat smaller alignment. This is expected because the passive gyrotactic contribution in the numerical simulations adds to the alignment and the turbulent velocity gradients do not affect the alignment too much for the flow with $u^{\rm rms}$ = \SI{6.7}{\mm\per\s} and $\tau^{(\eta)}$ = \SI{1}{\s} in Fig.~\ref{fig:velocity}.
Fig.~\ref{fig:velocity}(b) shows that the same conclusion holds for the average vertical velocity $\langle v_z\rangle$.
Starting at the naive result for $p^{\rm th}_{z}>1$, $\langle v_z\rangle$ increases quickly until $p^{\rm th}_{z}\sim 0.5$, where a plateau is reached with velocity around $0.7\langle v_z\rangle_0$, with $\langle v_z\rangle_0$ given in Eq.~(\ref{eq:vz0}).
Hollow markers in Fig.~\ref{fig:velocity}(a,b) show results from our DNS. Since they qualitatively agree with the statistical model, we limit the analysis in what follows to the statistical model which is quicker to evaluate.

Fig.~\ref{fig:velocity}(c) shows the vertical velocity component for statistical model simulations against $\omega^{({\rm s})}\tau^{(\eta)}$ for different values of $B/\tau^{(\eta)}$.
The data reaches plateaus for $|\omega^{({\rm s})}|\tau^{(\eta)}>0.8$, meaning that the results are not sensitive to the choice of the dimensionless steering angular velocity if it is large enough.
For  $\tau^{(\eta)}$ = \SI{1}{\s}, the choice $\omega^{({\rm s})}\tau^{(\eta)}=1.14$ in Table~\ref{tab:parameters} lies well within the plateaus.
When $B/\tau^{(\eta)}\to\infty$ (brown,$\triangleleft$), the passive gyrotactic torque vanishes, and by solely using the active gyrotactic mechanism (\ref{eq:optimal}), the swimmer reaches an upward velocity of about $0.5\langle v_z\rangle_0$.
For negative values of $\omega^{({\rm s})}$, the active mechanism works in the opposite direction, giving alignment with gravity and a means to migrate downwards with a slightly larger speed due to the contribution from settling.
Adding passive gyrotaxis with reorientation time $B/\tau^{(\eta)}=5$ from Table~\ref{tab:parameters} gives an additive contribution of around $0.1\langle v_z\rangle_0$ for the full range of $\omega^{({\rm s})}\tau^{(\eta)}$ (red,$\circ$).
To modify the vertical velocity significantly, the reorientation time must be of the order of $\tau^{(\eta)}$ (green,$\star$) for the flow considered here.
Results for passive gyrotaxis is obtained along the line $\omega^{({\rm s})}=0$ in Fig.~\ref{fig:velocity}(c).
When $B/\tau^{(\eta)}>2$, the active gyrotactic stability is dominant, while for $B/\tau^{(\eta)}<2$ passive gyrotaxis is efficient for upward migration and the active mechanism only give a minor contribution.

In conclusion, our numerical simulations show that the good performance of the found strategy is not sensitive to the precise values of the parameters or the statistics of the flow used in training.
For the parameters considered in Fig.~\ref{fig:velocity}, vertical alignment due to passive and active gyrotactic reorientation result in high vertical velocities.
Both the average flow velocity $\langle u_z\rangle$ and the settling velocity ${\ve v^{(\rm g)}}$ in Eq.~(\ref{eq:eqm_v}) are at most of order $0.1\langle v_z\rangle_0$, which is small in comparison.
We discuss the relative contributions of the terms in Eq.~(\ref{eq:eqm_v}) in more detail below.
In what follows we consider the parameters in Table~\ref{tab:parameters}. For these, the active gyrotactic mechanism dominates over the passive one.

\subsection{Full 3D model}
In our 3D model the swimmer can steer around both $\ve q$ and $\ve p$, and respond to signals in both directions with the threshold values ${\Delta u^{\rm th}}$ for velocity differences and ${S^{\rm th}}$ for fluid gradients.
Our reinforcement learning shows that when only one signal is used, the dominant signal is still $p_z$ and the strategy (\ref{eq:optimal}) remains optimal. There also exists an equivalent strategy where $q_z$ is the signal and the agent steers around $\ve p$ instead of $\ve q$.
It gives rise to the same mechanism for aligning $\ve n$ against gravity as in Fig.~\ref{fig:mechanism}, but from rotations around the $\ve p$-axis with $q_z$ as signal.

For swimmers allowed to use two signals when navigating, the best strategies obtained from reinforcement learning use the combined signal of $p_z$ and $q_z$, see Table~\ref{tab:DNS_signal_comb}.
They are highlighted in Fig.~\ref{fig:Policy_planar_DNS}(c,d). A common trend in the DNS and the statistical model is that the best strategies frequently take actions along the diagonal.
It is therefore of interest to compare to the strategy of choosing actions along the diagonal in Fig.~\ref{fig:Policy_planar_DNS}(c,d).
This diagonal strategy is simply a superposition of the two single-signal strategies described above, which can be expressed mathematically as $\ve\omega^{({\rm s})}=\omega^{({\rm s})}_p\ve p+\omega^{({\rm s})}_q\ve q$ with
\begin{align}
\omega^{({\rm s})}_p=-\omega^{({\rm s})}
\left\{
\begin{array}{ll}
1&\mbox{ if }q_z>p^{\rm th}_{z}\cr
-1&\mbox{ if }q_z<-p^{\rm th}_{z}\cr
0 & \mbox{ otherwise}
\end{array}
\right.
\hspace{0.5cm}
\mbox{and}
\hspace{0.5cm}
\omega^{({\rm s})}_q=\omega^{({\rm s})}
\left\{
\begin{array}{ll}
1&\mbox{ if }p_z>p^{\rm th}_{z}\cr
-1&\mbox{ if }p_z<-p^{\rm th}_{z}\cr
0 & \mbox{ otherwise}
\end{array}
\right.\,.
\label{eq:optimal_two_signals}
\end{align}
Here $\omega^{({\rm s})}_q$ is identical to that in Eq.~(\ref{eq:optimal}) and $\omega^{({\rm s})}_p$ takes the same expression with $p_z$ replaced by $q_z$ and multiplied by a minus sign as a consequence of the relative handedness between the vectors $\ve n$, $\ve p$ and $\ve q$.
Corresponding to our simulations, we have chosen the same threshold level $p^{\rm th}_{z}$ for both $p_z$ and $q_z$, and that the swimmer turns around the axes $\ve p$ and $\ve q$ at the same angular rate $\omega^{({\rm s})}$.
We find that the performance of strategy (\ref{eq:optimal_two_signals}) is slightly better than the optimal policy obtained by reinforcement learning, see Table~\ref{tab:DNS_signal_comb}.
This is a consequence of the reinforcement learning getting stuck in local optima.
Although we cannot be certain that strategy~(\ref{eq:optimal_two_signals}) is the global optimal strategy for our flows, we expect it to be close to optimal and we analyze its dynamics below.

Strategy (\ref{eq:optimal_two_signals}) gives rise to terms that adds to the contributions of the two passive gyrotactic terms in $\omega_p=\Omega_p-\Delta\Omega_p$ and $\omega_q=\Omega_q-\Delta\Omega_q$ in Eqs.~(\ref{eq:omegap}) and (\ref{eq:omegaq}), and therefore strengthen the gyrotactic contribution.
Using the simplified dynamics (no flow gradients or passive gyrotaxis) used to derive Eq.~(\ref{eq:nz_planar}), the alignment in the present case becomes $\langle n_z\rangle\sim 1-(1+\tfrac{2}{\pi})[p^{\rm th}_{z}]^2$ for small $p^{\rm th}_{z}$ and $\langle n_z\rangle\sim \tfrac{16\sqrt{2}}{3\pi}(1-p^{\rm th}_{z})^{3/2}$ for $p^{\rm th}_{z}$ close to unity, see Appendix~\ref{appendix:alignment} for details.
In contrast to the case of a single signal, the present strategy allows for perfect alignment in quiescent flows if the threshold level is small enough. The alignment has a plateau for small $p^{\rm th}_{z}$ and decreases sharply to zero as $p^{\rm th}_{z}$ approaches unity, similar to Eq.~(\ref{eq:nz_planar}) shown as the dash-dotted line in Fig.~\ref{fig:velocity}(a).

\begin{figure}
\includegraphics[width=17.5cm]{Fig4.pdf}
\caption{
\label{fig:velocity_full}
Left column: Steady-state results from statistical model simulations for the average vertical velocity $\langle v_z\rangle$ against the Kolmogorov time $\tau^{(\eta)}$ (units of seconds)
for a swimmer following either the planar strategy~(\ref{eq:optimal}) [red,$\circ$], the full 3D strategy using two signals (\ref{eq:optimal_two_signals}) [blue, $\Diamond$], the full 3D strategy using four signals (\ref{eq:optimal_four_signals}) [magenta, $\vartriangle$], or the naive passively gyrotactic strategy (green, $\Box$).
Parameters of the swimmer are given in Table~\ref{tab:parameters}. The flow velocity is $u^{\rm rms}$ = \SI{1}{\milli\metre\per\s} (top row) and $u^{\rm rms}$ = \SI{10}{\milli\metre\per\s} (bottom row) with a constant Kubo number, $\ku=10$.
Middle column: Same for the vertical velocity due to swimming, $v^{({\rm s})}\langle n_z\rangle$ (the scale on the right axis shows the alignment $\langle n_z\rangle$).
Right column: Same for the vertical component of the flow velocity along swimmer trajectories, $\langle u_z\rangle$.
The displayed velocities are normalized by $\langle v_z\rangle_0$ in Eq.~(\ref{eq:vz0}).
}
\end{figure}

For the case of all four signals, $p_z$, $q_z$, $S_{np}$, and $S_{nq}$, it is harder to read off a simple strategy from our reinforcement learning results.
Since the best strategies found do not surpass the results of strategy~(\ref{eq:optimal_two_signals}), see Table~\ref{tab:DNS_signal_comb}, we do not expect that the reinforcement learning has converged to the global optimal strategy.
This is no surprise: with 9 actions and $81$ states considered here, the number of possible strategies is enormous, of the order $10^{77}$.
We therefore proceed in a different way to find an efficient and interpretable strategy.
In the strategy (\ref{eq:optimal_two_signals}), the signals $p_z$ and $q_z$ are used to strengthen the passive gyrotaxis.
In \cite{Qiu2021}, $S_{np}$ was used to increase the shape factor $\Lambda$ to a larger effective value, making the swimmers preferentially sample up-welling regions, which facilitates upward migration.
This was achieved by choosing $\omega^{({\rm s})}_q=\omega^{({\rm s})}{\rm sign}(S_{np})$ when $|S_{np}|>{S^{\rm th}}$ and 0 otherwise, i.e. adding a contribution to the angular velocity with the same sign as $S_{np}$, effectively increasing $\Lambda$ by $\omega^{({\rm s})}$ when $|S_{np}|$ is above the threshold value.
We choose a strategy that is a superposition of the two effects of strengthening the passive gyrotactic angular velocity and increasing the effective shape factor.
Testing different combinations of putting priority to either $\{p_z,q_z\}$, $\{S_{np},S_{nq}\}$, or a combination thereof, shows that prioritizing $\{p_z,q_z\}$ works best, i.e. use the strategy (\ref{eq:optimal_two_signals}) when the $p_z$- or $q_z$-signal is above its threshold and refine this strategy using $\{S_{np},S_{nq}\}$ when the signal is below the threshold:
\begin{align}
\omega^{({\rm s})}_p=-\omega^{({\rm s})}
\left\{
\begin{array}{ll}
1&\mbox{ if }q_z>p^{\rm th}_{z}\cr
-1&\mbox{ if }q_z<-p^{\rm th}_{z}\cr
1 & \mbox{ if }|q_z|<p^{\rm th}_{z}\mbox{ and }S_{nq}>{S^{\rm th}}\cr
-1 & \mbox{ if }|q_z|<p^{\rm th}_{z}\mbox{ and }S_{nq}<-{S^{\rm th}}\cr
0 & \mbox{ otherwise}
\end{array}
\right.
\hspace{0.5cm}
\mbox{and}
\hspace{0.5cm}
\omega^{({\rm s})}_q=\omega^{({\rm s})}
\left\{
\begin{array}{ll}
1&\mbox{ if }p_z>p^{\rm th}_{z}\cr
-1&\mbox{ if }p_z<-p^{\rm th}_{z}\cr
1 & \mbox{ if }|p_z|<p^{\rm th}_{z}\mbox{ and }S_{np}>{S^{\rm th}}\cr
-1 & \mbox{ if }|p_z|<p^{\rm th}_{z}\mbox{ and }S_{np}<-{S^{\rm th}}\cr
0 & \mbox{ otherwise}
\end{array}
\right.\,.
\label{eq:optimal_four_signals}
\end{align}
We did not find any strategy performing better than Eq.~(\ref{eq:optimal_four_signals}) using reinforcement learning.
We remark that a similar strategy was found in Fig.~3(d) in Ref.~\cite{Qiu2021} for the signals $p_z$ and $S_{np}$ in two-dimensional frozen flows.
But in that case the strain signal $S_{np}$ was prioritized in the optimal strategy, and the $S_{np}$ signal also dominated over $p_z$ for the case of a single signal.
The explanation for this apparent contradiction is that swimmers that follow the strategy (\ref{eq:optimal}) in two-dimensional frozen flows for the parameters considered in Ref.~\cite{Qiu2021}, tend to end up at stable fixed points or limit cycles, prohibiting them from upward migration unless a significant amount of Brownian noise is added.
This trapping is similar to gyrotactic trapping observed for naive swimmers without steering in shear flows~\cite{Durham2009,Santamaria2014,Cencini2019} and vortical flows~\cite{Durham2011}.
In chaotic frozen 3D flows, or if the flow fluctuates quickly enough due to turbulence, this trapping goes away and it is then beneficial to adopt the strategies for active gyrotactic stability considered here.

Fig.~\ref{fig:velocity_full} compares the robustness of the found strategies to changes in the flow for a range of $\tau^{(\eta)}$ with $u^{\rm rms}$ = \SI{1}{\milli\metre\per\s} (upper row) and $u^{\rm rms}$ = \SI{10}{\milli\metre\per\s} (lower row).
The case $u^{\rm rms}$ = \SI{1}{\milli\metre\per\s} can for example be obtained in a seasonal thermocline, where $\tau^{(\eta)}$ $\sim$ \SIrange{3}{30}{\s} and the corresponding Taylor scale Reynolds number is relatively small, ${\rm Re}$ $\sim$ \numrange{7}{70}~\cite{Yamazaki1996}.
The case $u^{\rm rms}$ = \SI{10}{\milli\metre\per\s} can be obtained in more turbulent environments, for example a fjord with $\tau^{(\eta)}$ $\sim$ \SIrange{0.3}{1}{\s} and ${\rm Re}$ $\sim$ \numrange{70}{200}~\cite{Gargett1984,Yamazaki1996}.
The data in Fig.~\ref{fig:velocity_full} is generated using the statistical model with simulation units such that $u^{\rm rms}$ and $\tau^{(\eta)}$ take their desired values in comparison to the parameters in Table~\ref{tab:parameters}.
The left column shows the average vertical velocity component, $\langle v_z\rangle$.
Using Eq.~(\ref{eq:eqm_v}) this can be decomposed as
\begin{align}
\langle v_z\rangle=\langle u_z\rangle+\langle v^{(\rm g)}_z\rangle+v^{({\rm s})}\langle n_z\rangle\,.
\label{eq:vdecomposition}
\end{align}
Fig.~\ref{fig:velocity_full} shows the two contributions $v^{({\rm s})}\langle n_z\rangle$ (middle column) and $\langle u_z\rangle$ (right column) to $\langle v_z\rangle$, normalized by the vertical velocity in a quiescent flow, Eq. (\ref{eq:vz0}).
We do not show the contribution $\langle v^{(\rm g)}_z\rangle/\langle v_z\rangle_0$ because it is approximately constant and equal to $-0.1$.

First, we compare the planar strategy using $\ve\omega^{({\rm s})}$ from Eq.~(\ref{eq:optimal}) [red,$\circ$] to the naive strategy using $\ve\omega^{({\rm s})}=0$ [green,$\Box$]. Fig.~\ref{fig:velocity_full}(a,d) shows that the planar strategy has larger average upward velocity $\langle v_z\rangle$ for all considered flow parameters, only being close for very weak flow gradients, $\tau^{(\eta)}\sim$ \SI{10}{\s}.
While the naive strategy has small or even negative values of $\langle v_z\rangle$, the planar strategy is of the order of the vertical velocity in quiescent flows, $\langle v_z\rangle_0$, for all considered parameter values, except for the case of strong flow velocity $u^{\rm rms}$ = \SI{10}{\milli\metre\per\s} and strong flow gradients, $\tau^{(\eta)}\sim$ \SI{0.1}{\s}.
The explanation to the difference in velocity between the two strategies is the additional alignment $\langle n_z\rangle$ of the planar strategy due to the active gyrotactic stability, Fig.~\ref{fig:velocity_full}(b,e).
Even though the planar strategy obtains a slightly more negative sampling of the vertical flow component, $\langle u_z\rangle$, than the naive case, see Fig.~\ref{fig:velocity_full}(c,f), this difference is negligible compared to the difference in the contribution to the velocity due to alignment, $v_{\rm s}\langle n_z\rangle$.

Next, we consider the full 3D model using two signals (\ref{eq:optimal_two_signals}) [blue,$\Diamond$].
In this model the alignment reaches a plateau, close to perfect alignment, $\langle n_z\rangle\approx 1$, unless the flow gradients are strong.
The mean upward velocity shows the same trend, but with a plateau somewhat below $\langle v_z\rangle_0$ due to the negative contribution from sampling of the vertical flow component, $\langle u_z\rangle<0$.
Finally, for the full 3D model using four signals (\ref{eq:optimal_four_signals}) [$\vartriangle$,magenta], the alignment $\langle n_z\rangle$ is approximately the same as for the case of two signals.
But the refined response using the strain components, leads to a sampling of the vertical flow component $\langle u_z\rangle$ that is less negative and even positive for some parameter values. The net result is a larger positive vertical velocity than the strategy with two signals, allowing vertical migration that is nearly as efficient as in the quiescent flow for some parameters.

Simulation results with $u^{\rm rms}$ = \SI{100}{\milli\metre\per\s} are identical to the data with $u^{\rm rms}$ = \SI{10}{\milli\metre\per\s} within numerical precision (not shown).
In this limit, the active mechanism only starts failing when the flow gradients $\sim 1/\tau^{(\eta)}$ are much larger than $\omega^{({\rm s})}$.
In contrast, the naive strategy fails when the flow gradients are much larger than $1/(2B)$, which is one order of magnitude smaller than $\omega^{({\rm s})}$ for the parameters from Table~\ref{tab:parameters}. We remark that these parameters are a typical sample. Specific plankton species in nature could have other values of $\omega^{({\rm s})}$ or $1/(2B)$, adjusting the relative importance of the active or passive reorientation mechanism compared to the flow gradients.
For values of $u^{\rm rms}$ much smaller than \SI{1}{\milli\metre\per\s}, the average alignment approaches unity for all the cases in the displayed range of $\tau^{(\eta)}$ (not shown).
In conclusion, the found strategies are robust, showing good performance for a large range of flow parameters.

\section{Conclusions}
\label{sec:conclusions}

We used reinforcement learning to find robust and efficient strategies for vertical migration of microswimmers.
In the simplest case, the swimmer has only access to a single signal $\Delta u_p$, or equivalently $p_z$, which allows for detection of the angle between the orientation of the swimmer (its $\ve p$-axis) and gravity.
By actively rotating in the appropriate direction around its $\ve q$-axis, the swimmer exhibits an active gyrotactic contribution to the angular velocity which is one order of magnitude larger than the passive gyrotactic contribution for typical copepods.
The active contribution results in increased upward alignment, leading to vertical migration of the order of that in quiescent flows unless turbulence is very vigorous.
If the swimmer in addition is able to sense $\Delta u_q$, it can, up to the resolution set by signal thresholds, measure its orientation relative to gravity leading to yet stronger upward alignment and vertical migration velocity.
By using the strain components $S_{np}$ and $S_{nq}$, the swimmer can further increase its migration velocity by exploiting up-welling regions of the flow~\cite{Qiu2021}.
Rotating in the opposite direction allows the swimmer to, even though being bottom heavy, align with gravity, providing an efficient means for downward swimming.

In the passive gyrotactic mechanism, the shape and mass distribution are important.
Using active gyrotactic stability, these parameters are not as important, even spherical swimmers with homogeneous mass distribution ($\Lambda=0$ and $B=\infty$) show the same degree of vertical alignment in turbulent flows. For the parameters in Table~\ref{tab:parameters}, the passive gyrotactic mechanism only becomes relevant in close to quiescent flows, where it allows for better upward alignment than what can be obtained by a single signal $\Delta u_p$.
The active mechanism is robust and efficient over a large range of the flow parameters $\tau^{(\eta)}$ and $u^{\rm rms}$. Simulations of the statistical model and DNS give similar results, both when finding the same types of optimal strategies when training in frozen flows and in the evaluation using time-fluctuating flows.

What bearing do our results have for understanding the behavior of plankton in the turbulent ocean?
It is believed that light is important for daily migration of plankton.
Strong light determines the swimming direction of many plankton species~\cite{Ringelberg2009}.
We propose that the mechanism discovered here may serve as a means for efficient vertical migration of plankton species at low light intensities, and may serve as a complementary guide also in the presence of light.
Further experiments are needed to verify whether plankton in nature have evolved to exploit our proposed mechanism.

\begin{acknowledgments}
KG acknowledges support from Vetenskapsrådet, Grant No. 2018-03974 and by a grant from the Knut and Alice Wallenberg Foundation, grant no. 2019.0079.
JQ and LZ were supported by the National Natural Science Foundation of China (Grant No. 11702158) and the Institute for Guo Qiang of Tsinghua University (Grant No. 2019GQG1012). LZ was supported by a collaboration grant from the joint China-Sweden mobility programme (NSFC-STINT) [grant numbers 11911530141 (NSFC), CH2018-7737 (STINT)].
Statistical model simulations were performed on resources provided by the Swedish National Infrastructure for Computing (SNIC).
\end{acknowledgments}

redpajama_set_name: RedPajamaArXiv


text:
McCain asks supporters to oppose stimulus bill
CNN's Sarah Parker
[cnn-photo-caption image= http://i2.cdn.turner.com/cnn/2009/images/02/03/art.getty.mccain.head.jpg caption="The former Republican presidential nominee tapped into his campaign lists Tuesday, asking supporters to sign a petition in protest of the economic stimulus package."](CNN) –- Sen. John McCain enlists the help of online supporters through his political action committee, Country First. The former Republican presidential nominee tapped into his campaign lists Tuesday, asking supporters to sign a petition in protest of the economic stimulus package.
"I cannot and do not support the package on the table from the Democrats and the Obama Administration. Our country does not need just another spending bill, particularly not one that will load future generations with the burden of massive debt. We need a short term stimulus bill that will directly help people, create jobs, and provide a jolt to our economy," McCain says in the e-mail. "I hope you will join me in saying no to this stimulus package as it currently exists by signing this petition."
The Arizona senator's request follows a similar message sent by President Obama to his online followers Monday. The president called on supporters to host gatherings or house parties to help push for the stimulus package.
McCain and nine other Senate Republicans met in Sen. Mel Martinez's office Tuesday to discuss an alternative to the Democratic plan. The former Republican presidential candidate said the group is trying to improve the stimulus package to enable job growth.
Filed under: economic stimulus • John McCain • Popular Posts
Looking for Truth
Well Nancy @1:46, regardless of who you or I or anyone else for
that matter, voted for or supported only a fool such as yourself
would support this stimulus package as it now stands. So get
off your high horse. I want a stimulus package that will actually
stimulate the economy, not go in some fat cats pocket.
February 3, 2009 02:11 pm at 2:11 pm |
The economy is sound....
Dina Phila., Pa
Wow! McShame knows how to utilize the Internet? I remember when he said that he would work with President Obama to help get things done! I guess after Mr. Steel was voted in as the new Republican Chair that was the straw that broke the leg completely off of McShame's rocking chair! I bet he will be jumping ship out of that party like so many of his other Republican colleagues have done already!
He's very rich and has no worried, so, why would he care about anyone else?
I would love to see his tax returns.
Wait a minute, isn't this the same guy who canceled his campaign to push for the previous bailout of banks that mostly ended up in CEO pockets?
Isn't this the same guy who with his economic adviser said the economy was fundamentally strong only a few months ago?
Isn't this the same guy that supported the policies of the last 8 years that got us into this mess?
He's got some nerve questioning Obama.
Frank, Las Vegas
McCain and the GOP (Grand Obstructionist Party) should remember that they LOST! The American overwhelmingly voted for the Democratic solutions and boldly rejected the GOP plans or lack there of. Now all they do is whine and cry about this or that or whatever gets them press. ENOUGH!
PhilT
"Our country does not need just another spending bill, particularly not one that will load future generations with the burden of massive debt."
I propose a one time windfall income tax of 10% on any US citizen worth more than $1,000,000 not including the primary residence and retirement accounts.
Since there are were 9.3 million american millionaires worth over $11.3 trillion in July of 2007, the tax woudld pay for the stimulus, and not "load future generations with the burden of massive debt".
Let's see how Johnny and his friends like that suggestion.
Reverend Z
The bill itself is over 700 pages long. Until one has read the entire thing, commenting on it's contents is ridiculous – no matter if you are a citizen or an also-ran.
JOHN MCCAIN WHO?
Um.....Hello? McCain proposed the same tax cut based economic policy when he was running for Pres. We voted, he lost. His plans lost. The Republicans lost. A majority of the county picked Obama and his stimulus plan. What do we, as Americans, have to do to get them out of the way? The will of the people is being subverted by the Republicans and nobody is calling them on it.
The deficits are a product of Bushie the Repub who came into office with a surplus. That they are now trying to call Dems big spenders is laughable. Giving more tax cuts to businesses (that keep production overseas) and to the wealthy is not going to fix our economy. Again, we already voted on this!!!!!
I say, really support Obama. Call your House Reps, Senators, and Governors. Ask that they publically proclaim support for Obama's plan. Then email them, send them a letter, write a blog, make a video, and call again. Repeat until the bill is passed and Republicans unclench their fists.
Judy from PA
I can't help but wonder how things would have gone had McCain won. He has worked with members of both parties over the years. I wonder if he would have gotten his version of the stimulus bill passed? Would there be as much partisan bickering?? Hmmm.
You democrats are so blind, read the package will you!!
A lot of stuff in this bill has nothing to do with stimulating the economy.
KK from Arkansas
Everyone, let us be 'real' about this economic problem and about the political games going on in Washington. From the previous comments, I see that not many have left behind the election and not many can see past their own political affiliations.
Let's stop thinking about party and start looking at these bills carefully. Republicans aren't the opposition party just as democrats aren't the ruling party. What everyone wants is a bill that betters America's economic future. Obviously, opinions vary widely.
Now, each political party has an idea about what makes that happen: Democrats prefer spending and social programs; Republicans prefer tax cuts and smaller government.
Stop harping on your political differences and start looking at what our politicians are spending. Personally, I am a little peeved that our congressional leaders are pushing a spending bill that is now about $900 billion and what do I get, $500. Now, I am not looking for a hand-out from the government; but just pay attention to the "crap" you as a taxpayer are buying with this "stimulus."
Why all the pork? Why all the promises of "Transparencies"? We need a stimulus package that addresses the "EXACT" problem, not push some other agenda or wasteful government spending. The American people have been screwed long and hard of enough by corporate America and our governement. Get this right!
McCain is a sore loser with bad ideas. I hope Arizona is paying attention to this obstructionist who is harming the future of our country. Glad he isn't our president.
John's the man
That's why I voted for him.
Give me a break J. McCain, You were willing to spend billions of dollars in the reconstruction of Iraq, which by the way we can not account for but have a problem spending our tax money on us even if it's a waist.
you are to old to be in the senate in the first place go home and let the younger people decide they future since you do not even know how no clue about technology.
The fact the McCain lost the election is irrelevant here.
Instead of blindly following everything BO does or says, try questioning him once in a while. That is our duty as American citizens, and the foundation on which this country was built. The President works for us, not the other way around.
BTW, the stimulus package WILL NOT WORK–and that's really the point, isn't it?
"JH in Texas February 3rd, 2009 1:46 pm ET
I have signed the petition a few minutes ago. Anyone and I mean anyone that support this Economic Stimulus package is crazy. Have these people lost their freak en minds!"
Anyone who listens to and follows Rush Limbaugh is crazy. Stop drinking the kool aid. There will never be a PERFECT stimulus package. Any package will be a risk. Had this Country not started a war based on lies, we probably would not be responding to this particular subject right now.
billbob
This bill is exactly what I thought Obama would do–payoff old buddies! "I can change WASHINGTON" YOU SURE CAN PAL!!!!
Now he will oppose it since he is no longer running for office and it is not the Republican's idea. He knows he screwed up when he voted for the bailout. News flash for Johnny -- you are irrelevant.
McCain is the reason Obama won the election. He never opposed anything Obama said before so he should just keep quiet and now pretend that he is a part of the Republican Party.
Country First? Which Country.
McCain PAC called Country First? What a joke. The only country the GOP cares about is India. The GOP would have no problem if the stimulus was to bail out India, China or the third world sweatshops McCain, Arlin Specter, and the GOP sent all our good manufacturing and software jobs. The GOP got us into this mess with frivilous expensive wars, outsourcing, and wasteful spending on tax cuts for the rich that only stimulated oursourcing. The could at least help the Deomcrats help up out of the Republican made mess.
This is what McCain calls working in a "bipartisan" way on the Stimulus plan? Sounds more like yelling "Fire!" in a crowded room.
Put a sock in it McCain!
So now all republicans are against President Obama's Plan on stimulating the economy, Where were they while GW was running America in the ground with its BIG SPEND government. At least when Pres.Obama wants to spend it will go to the benefit of all americans and not the select few. Why weren't the republicans raising hell then. Why havent' they objected to that HUGE amount of $$ given to HALIBURTON to build in IRAQ. Ask the Iraqi people how that's going. What about the 5 billion $ that got missing? The republicans aren't concerned about all of that because it was to their benefit. What's really funny is that RICH republicans don't care if they hurt poor republicans, but its the poor who keep them in office. American got the curtain pulled back by the Bush administration and now you want to not even give OUR NEW PRESIDENT a chance. I believe you(republicans) really want him to FAIL. Well NO ONE could ever be as INCOMPETENT as GW BUSH was during his term as president. I would cringe when he spoke, because he sounded like a third grader trying to talk to grown ups. IF AMERICA FAILS, BLAME THE IGNORANCE OF THE REPUBLICAN PARTY WHO PUTS PARTY FIRST AND TO HELL WITH THE NEEDS OF THE PEOPLE. We are not all WELFARE RECIPIENTS like you think we are. Oh and Republicans use the welfare system too! Just like BUSH, YOU DON'T CARE.
« Previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Next »

redpajama_set_name: RedPajamaCommonCrawl


text:
Information Technology Management with a Purpose
« When will the cloud burst?
Are you ready for in-memory computing? »
Apr 9 2012 8:45AM GMT
Taking an off for a vacation
S R Balasubramanian Profile: S R Balasubramanian
Many years ago, a senior colleague of mine in the company was treated as a blue-eyed boy of the department, and a person who, people said, could be relied upon. He was considered the most sincere and committed amongst us all and some others proudly said that there could be none like him. He was always in the office on time, would sit late whenever required, and would never take a leave. Most of his leaves were usually surrendered at the end of the year. When his earned leave were to lapse, he would apply for a leave and claim leave travel allowance (LTA) but still would attend office every day.
It took me some time to understand this great officer. He perhaps felt insecure and therefore created an air of indispensability about him, for example, some wondered what will happen if he was not there on any day. He did not delegate and kept all secrets to himself. I had left the organization but later learnt that the officer had to quit four years before his retirement due to failing health.
Why you must unwind
The point that I am trying to emphasize is that it is important for us to take a break, unwind and relax once in a while. Some people take a long break once a year and some take two short breaks a year but the intention clearly is to break the monotony, recharge ourselves, and give time to ourselves and to our family.
I still see a lot of my fellow CIOs being stingy with their leaves and they postpone taking a break every now and then. I have heard their families complain: "For him work is more important than family…." There is always a false sense of importance and a feeling that work may suffer in his absence.
I have also seen some of my friends take a two-day off and utilize the weekend to take a quick, four-day trip to a nearby hill resort, as if to complete a formality. Such breaks do nobody a good and are best avoided.
There could be a variety of reasons for skipping a vacation. One could be our attempt to emphasize our loyalty and sincerity; it could be our feeling that something may go wrong in our absence or a distrust of our subordinates. The question is – are we harming ourselves in the process?
Advantages of taking a break
It is indeed a wise to take off some time for ourselves and not burn up in the hope of making it big. Many a successful people I have met disappear for a few days every year. Taking off serves us in ways more than one.
Let's look at some of the advantages:
Repose trust in your staff: When we take a leave, we obviously ask our second in command to take over and manage in our absence. It shows we trust them to run the show. Even though there may be important projects running, we tell the rest of the organization to contact these people in your absence and in a way assure them that all matters will be taken care of.
Delegate and train: It is a wonderful opportunity for us to delegate work to our subordinates with clear instructions and let them handle matters which we otherwise manage in normal times. The staff is put to test and we assure them that we are just a phone call away. Imagine you are coming back and find everything in order – it proves that your people are capable and you can trust them with new responsibilities. In fact once when all of us (the seniors) went on a company-sponsored vacation for a week, the production and sales for that period were at a record high. People secretly shared the reason: they said there were no bosses around to disturb them in their work.
Rejuvenate and recharge: Constant work, day-in and day-out, wears us down even if we do not admit it. Our tired minds focus on day-to-day matters and troubleshooting, neglecting the long term measures and further development. Once back from a break, we can start thinking afresh and be different. Time away from routine work refreshes our body and mind, apart from the satisfaction of having spent a rich time with the family. That also helps in maintaining work-life balance.
So friends, take off your uniform and head for a place away from work for a well-deserved break. A vacation will do you a world of good.
The issue is not information technology, but management. Optimal utilization of technology and management, and IT/business alignment are the components of a successful strategy. Information technology management can be a tougher job than meets the eye, so here are some useful mantras for the CIO's arsenal.


Published at Wednesday, April 10th, 2019 - 06:19:54 AM. Office Desk. By Verrill Sorel.
There are a lot of places that people prefer to shop at for all of their office furniture needs, and you can choose the places that you find the most beneficial when shopping depending on which fits your needs. Of course, shopping around on the internet might be more beneficial if you have never had an office since you can get a feel for what you can get for the office, and the prices that you are looking at spending in order to furnish your office. You can start decorating and furnishing the office space of your dream today with a few simple key tips in mind. Have fun, and allow yourself to be as creative as you would like. You need to ensure that everything is as it should be in your office, and this can be done by choosing the right type of office furniture to hold the extras in your office. Start shopping for the perfect office furniture today.
We have desks to make work easier for us. We have them at home, classrooms and offices. The desks bought for the office should have special characteristics meant for fulfilling the functions in the office. Most people wish to impart a unique look to their office, making it look different from others. So when furnishing your office, you can pick up things that would enable you to portray your identity and personality. Office desks are present in every office and fulfill a number of functions- they are used to keep files, documents, office gadgets and other accessories. But if you choose a desk without looking for the one with special features, how can you expect to make your office look unique?


I don't know about you, but I've been dying inside with anticipation ever since I found out Disney cast Angelina Jolie as Maleficent.
So, naturally since Disney released this awesome sauce right here, they've just sped up my dying process. Thanks, Maleficent. I looked in the mirror & clearly you've cast a spell on me, too. Take one look at my mug and you'll realize I'm dying more and more each day. You're depleting my collagen stash slowly yet painfully. Give me back my collagen in my cheeks. My eyes need a lift and you've got to be joking me right now with this sun damage, hyperpigmentation & fine lines. Oh, well. At least I can say I got to watch Angelina Jolie as Maleficent before I go.
Amen to that. Holler. Woot. Woot.


text:
108: It's Moving in All Kinds of Ways
Phyllis Strong Interview.
Phyllis Strong began her work on Star Trek with the seventh season episode of Star Trek: Voyager called "Body and Soul," which she wrote with her writing partner Mike Sussman. After an additional three credits on that show, she was offered the position of Executive Story Editor for first...
107: Alt-Vulcan Movement
Changes to Alien Designs in Trek.
Star Trek has always had cool alien races, both friends and foes to the Federation. After five different live-action series, and fifty years of technological advancement, the designs and looks of these aliens have changed. While some have changed more than others, none of them look...
106: Eden Once Again
Tucker Smallwood Interview.
Born in Washington, D.C. his childhood included two years in Salonica, Greece and two years as a college student in Munich, Germany. He graduated from the University of Maryland in 1967 with a minor in German and a major in Speech/Television Production. Tucker began directing television for...
105: Teach Them Some Math
Eight Episode Enterprise/TOS Marathon.
Star Trek fans love to watch their favorite episodes in a format that has affectionately been dubbed "binge watching" since they have been able to watch the show on home video. However, most marathons tend to stick to one series at a time. What would happen if fans started to mix...
104: Down In Fraggle Rock
Retrospective: Season Three Part One.
Season three of Star Trek: Enterprise was an brave experiment of storytelling with the franchise's first season long story arc. As a response to the events of September 11, 2001, the creators of the show wanted to take Star Trek in a new, darker direction.


text:
Q: DES Encryption from Angular to Spring boot and vice versa not working I have implemented Encryption on both angular and spring boot sides, on either side I have used DES cryptography algorithm, the problem is ciphertext generated by Angular is not decoded on Spring Boot side and vice versa.
Angular:
convertText() {
    if (this.textToConvert.trim() === '' || this.password.trim() === '') {
      this.conversionOutput = 'Please fill the textboxes.';
      return;
    } else {
      if (this.encryptMode) {
        this.conversionOutput = CryptoJS.DES.encrypt(
          this.textToConvert.trim(),
          this.password.trim()
        ).toString();
      } else {
        this.conversionOutput = CryptoJS.DES.decrypt(
          this.textToConvert.trim(),
          this.password.trim()
        ).toString(CryptoJS.enc.Utf8);
      }
    }
  }

Java:
ENCRYPTION:
public static String encryptWithKey(String str, String keyText) {
        if (str == null) {
            return null;
        }
        Cipher ecipher = null;
        Cipher dcipher = null;
        byte[] salt = {
                (byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32,
                (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03
        };
        int iterationCount = 3;

        try {
            KeySpec keySpec = new PBEKeySpec(keyText.toCharArray(), salt, iterationCount);
            SecretKey key = SecretKeyFactory.getInstance(ALGO_NAME).generateSecret(keySpec);

            ecipher = Cipher.getInstance(key.getAlgorithm());
            dcipher = Cipher.getInstance(key.getAlgorithm());

            AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);

            ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
            dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
        } catch (java.security.InvalidKeyException e) {
            e.printStackTrace();
            log.error("error in InvalidKeyException in encryptWithKey method for string : " + str + ",key : " + keyText + " : " + " : " + e.getMessage());
        }
        try {
            byte[] utf8 = str.getBytes("UTF8");
//            utf8 = fromHexString(str);
            byte[] enc = ecipher.doFinal(utf8);
//            return new sun.misc.BASE64Encoder().encode(enc);
            return org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(enc);
//            return asHex(enc);

        } catch (javax.crypto.BadPaddingException e) {
            e.printStackTrace();
            log.error("error in BadPaddingException in encryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
            log.error("error in IllegalBlockSizeException in encryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            log.error("error in UnsupportedEncodingException in encryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (NullPointerException e) {
            e.printStackTrace();
            log.error("error in NullPointerException in encryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        }
        return null;
    }

DECRYPTION:
public static String decryptWithKey(String str, String keyText) {
        if (str == null || str.trim().equals("")) {
            return null;
        }
//        Cipher ecipher = null;
        Cipher dcipherLoc = null;
        byte[] salt = {
                (byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32,
                (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03
        };
        int iterationCountLoc = 3;
        try {
            KeySpec keySpec = new PBEKeySpec(keyText.toCharArray(), salt, iterationCountLoc);
            SecretKey key = SecretKeyFactory.getInstance(ALGO_NAME).generateSecret(keySpec);

//            ecipher = Cipher.getInstance(key.getAlgorithm());
            dcipherLoc = Cipher.getInstance(key.getAlgorithm());

            AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCountLoc);

//            ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
            dcipherLoc.init(Cipher.DECRYPT_MODE, key, paramSpec);
        } catch (java.security.InvalidAlgorithmParameterException e) {
            e.printStackTrace();
            log.error("error in InvalidAlgorithmParameterException in decryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (java.security.spec.InvalidKeySpecException e) {
            e.printStackTrace();
            log.error("error in InvalidKeySpecException in decryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (javax.crypto.NoSuchPaddingException e) {
            e.printStackTrace();
            log.error("error in NoSuchPaddingException in decryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (java.security.NoSuchAlgorithmException e) {
            e.printStackTrace();
            log.error("error in NoSuchAlgorithmException in decryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (java.security.InvalidKeyException e) {
            e.printStackTrace();
            log.error("error in InvalidKeyException in decryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        }
        try {
//            byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
            byte[] dec = org.apache.commons.codec.binary.Base64.decodeBase64(str);
//            byte[] dec = fromHexString(str);
            byte[] utf8 = dcipherLoc.doFinal(dec);
            return new String(utf8, "UTF8");

        } catch (javax.crypto.BadPaddingException e) {
            e.printStackTrace();
            log.error("error in BadPaddingException in decryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
            log.error("error in IllegalBlockSizeException in decryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            log.error("error in UnsupportedEncodingException in decryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        } catch (NullPointerException e) {
            e.printStackTrace();
            log.error("error in NullPointerException in decryptWithKey method for string : " + str + ",key : " + keyText + " : " + e.getMessage());
        }
        return "Invalid String";
    }

PROBLEM:
lets try to encode the string at angular end and try to decrypt the same in Spring boot
plain text: admin123
key: secretkey (common in both the end)
cipher text: U2FsdGVkX1/FV1+LoXaVyi7Aco0JOgl5BDXwL18Zqoc=
When I tried to decrypt the abve cipher text at spring boot end
 public static void main(String[] args) {
        System.out.println("Decrypt With Key=" + decryptWithKey("U2FsdGVkX1/FV1+LoXaVyi7Aco0JOgl5BDXwL18Zqoc=","secretkey"));
    }

TRACE:
javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
    at java.base/com.sun.crypto.provider.CipherCore.unpad(CipherCore.java:975)
    at java.base/com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1056)
    at java.base/com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853)
    at java.base/com.sun.crypto.provider.PBES1Core.doFinal(PBES1Core.java:432)
    at java.base/com.sun.crypto.provider.PBEWithMD5AndDESCipher.engineDoFinal(PBEWithMD5AndDESCipher.java:316)
    at java.base/javax.crypto.Cipher.doFinal(Cipher.java:2202)
    at com.nl.core.crypto.util.DesEncrypter.decryptWithKey(DesEncrypter.java:230)
    at com.nl.core.crypto.util.DesEncrypter.main(DesEncrypter.java:290)
18:59:00.920 [main] ERROR com.netlink.core.crypto.util.DesEncrypter - error in BadPaddingException in decryptWithKey method for string : U2FsdGVkX1/FV1+LoXaVyi7Aco0JOgl5BDXwL18Zqoc=,key : secetkey : Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
Decrypt With Key=Invalid String

It seems the secretkey is not working for decode mechanism, I am not able to figured it out what went wrong, as I am using DES at both the sides.

redpajama_set_name: RedPajamaStackExchange


text:
Q: C++ Copy Construction of Static Object #include <iostream>
using namespace std;

class A
{
public:
int x;
    A(){x= 30; cout << "A's constructor called " << endl;}
    A(const A& obj) { cout<<"A's copy constructor called " <<endl; }
};

class B
{
public:
    static A sample;
    B() { cout << "B's constructor called " << endl; }
    static A getSample() { return sample; }
};

A B::sample;

int main()
{
    A one;
    A two = B::getSample();
    cout<<B::sample.x<<endl;
    cout<<one.x<<endl;
    cout<<two.x<<endl;
    return 0;
}

The code above outputs:
A's constructor called
A's constructor called
A's copy constructor called
30
30
-1032819680

Why does not copy constructor copy value of x to B::getSample(). In another words, while B::getSample()=30, why two.x is -1032xxxxxx?

A: You have defined your own copy constructor that does not copy the value of x. So it is left uninitialized.

A: The behaviour is correct, copy constrcutors are called as they should be...but:
If you want two.xto be 30, you need to copy the x value within your copy constructor...which is not the case in your code. You just print A's copy constructor called but your copy constructor has no effect.
Just change it to
A(const A& obj)
{
    cout<<"A's copy constructor called " <<endl;
    x = obj.x; // added!
}

Then, program displays:
A's constructor called
A's constructor called
A's copy constructor called
30
30
30

A: two is initialized using copy constructor you defined. And in that definition you have not assigned any value to x. That's why it's printing garbage.

A: Be aware that, Compiler will create a default copy constructor, if you  don't define one.
This does a shallow copy meaning copies each member of the class individually using the standard assignment operator ('=').
 x=obj.x;

Since this is exactly what you would be doing anyway, there is really no reason to override.
This works well if you have a simple class with no dynamically allocated memory (or pointers). However if you want to copy a pointer (pointing to a chunk of data) shallow copy doesn't work.
This is because the assignment operator just copies the address of the pointer and not allocate any memory or copy the contents being pointed to.