{'fraction_non_alphanumeric': 0.033965297782541704, 'fraction_numerical': 0.01118778053192202, 'mean_word_length': 4.784074396977623, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Tuning environmental timescales to evolve and maintain generalists

Natural environments can present diverse challenges, but some genotypes remain fit across many environments. Such `generalists' can be hard to evolve, out-competed by specialists fitter in any particular environment. Here, inspired by the search for broadly-neutralising antibodies during B-cell affinity maturation, we demonstrate that environmental changes on an intermediate timescale can reliably evolve generalists, even when faster or slower environmental changes are unable to do so. We find that changing environments on timescales comparable to evolutionary transients in a population enhances the rate of evolving generalists from specialists, without enhancing the reverse process. The yield of generalists is further increased in more complex dynamic environments, such as a `chirp' of increasing frequency. Our work offers design principles for how non-equilibrium fitness `seascapes' can dynamically funnel populations to genotypes unobtainable in static environments.

Evolutionary outcomes are driven by environmental pressures, but environments are rarely static [1]. In a changing environment, some genotypes -termed generalists -maintain a uniformly high fitness over time, even if they are not globally fit at any particular instant. A striking example is that of broadly-neutralizing antibodies (bnAbs) against HIV and other viruses -these antibodies maintain potency against the large diversity of viral strains that may arise in an infected individual over time [2][3][4]. It is desirable for the immune system to select for generalist antibodies during B-cell affinity maturation, a rapid evolutionary process [5], but generalists are often out-competed by specialists that only bind particular viral strains.
Recent work has suggested that sequential vaccination with different viral antigens, rather than a single cocktail of those antigens, can better select for generalist antibodies during affinity maturation [6][7][8][9]. This result is consistent with the broader idea that a time-varying environment can drive evolution out of equilibrium and into genotypes unevolvable in static environments [10][11][12][13][14]. However, the broader principles underlying generalist selection by dynamic environments remain unknown. In particular, the interplay of environmental and evolutionary timescales and choices of correlated antigens generates a high-dimensional space of possible vaccination protocols. Hence guiding principles are needed to find optimal protocols for evolving generalist genotypes.
Here, we take a phenomenological approach to design dynamic environments that select generalists. We analyze situations in which generalists are entropically disfavoured or isolated by fitness valleys, and thus unevolvable in a static environment. We find that a dynamic environmental protocol can maximize the yield of generalists if the environment changes on the same timescale as the evolutionary transients of the population, i.e., on * Correspondence: shenshen@physics.ucla.edu, amuru-gan@uchicago.edu † These authors contributed equally the timescale for allele frequencies to reach steady state. Consequently, switching antigens before antibody populations have evolved to a steady state can dynamically funnel finite populations from specialists to generalists, even when faster or slower switching is unable to do so.
We understand these results in terms of a kinetic asymmetry between generalists and specialists. Environmental dynamics at the right timescale perturbs specialist populations while leaving generalists relatively undisturbed. This asymmetry favours evolution from specialists to generalists without enhancing the time-reversed process. In contrast, faster or slower environmental dynamics may be cast into effective static fitness landscapes [15], and are thus unable to maintain a strong kinetic asymmetry between specialists and generalists. In this sense, the intermediate cycling mechanism studied here exploits a truly non-equilibrium evolutionary 'seascape' [11,13] with no static analog.
Our framework proposes novel protocols for evolving generalists, such as a 'chirp' where the environment is cycled at an increasing frequency, and predicts optimal correlations between antigens to be used. Since we use a sufficiently abstracted model of B-cell affinity maturation, our analysis might be adapted for other temporal evolution protocols, e.g., to avoid antibiotic resistance [16][17][18] and for cancer treatments [19,20].
Numerous works have studied evolution in timevarying environments, including in the context of evolving generalists [21][22][23][24][25][26][27][28]. Relatively fewer works [15,[29][30][31] have analyzed the case of intermediate timescales where the environment changes before populations reach steady state. In this broader sense, our work is a step towards a theory of evolution in time-varying environments with no separation of timescale between the evolutionary response of populations and environmental changes. RESULTS We present our results in two broad models of how specialists and generalists can be distributed in sequence space, paralleling different assumptions about antigenantibody binding. In both cases, we model populations (e.g., the population of B-cells across all germinal centers in an organism). We explain our results in terms of the rate at which a population of specialists evolves generalists in time-varying environments relative to the rate of the time-reversed processes from generalists to specialists.

A. Entropically disfavored generalists
A basic difficulty in evolving generalists is that generalists are often far fewer in number than specialists. This is schematically shown in Fig. 2a, where specialists in each environment form a connected set of genotypes of similar fitness. The relatively few generalists, found at the intersection of such sets, can easily mutate into the more numerous specialists in any fixed environment.
We study the problem quantitatively in a simplified molecular model of antigen-antibody binding, as used for affinity maturation against HIV antigens. Antibodies bind to a single epitope, partially conserved across antigens η = 1, 2. A (binary) antibody sequence x binds to an epitope sequence h η with an affinity given by an additive sum-of-sites model: x · h η . Antibodies that bind above a threshold T are assigned fitness s( − 1) > 0, while those that bind weaker have fitness −s < 0. We take 1 < < 2, such that the average fitness of an antibody across antigens is negative.
Since the epitope is relatively but not entirely, con-served across antigens, h η for different antigens are assumed to share a conserved region of length L c = 12 but have a variable region of length L v = 7 [9] (see SI for other choices). While based on a simple model of molecular binding, our results below apply broadly to the phenomenological description of specialists as connected islands of relatively uniform fitness, with no fitness barriers separating the generalists. We simulate a finite population (N ∼ 500) of antibodies in an environment that switches between antigens 1 and 2 on a timescale τ epoch using a birth-death model (see SI), working in the limit of frequent mutations (µN > 1). Initializing a monoclonal population in a random specialist state for antigen η = 1, we monitor the fraction of generalists in the populations at late times (Fig. 2d), systematically varying the timescale of switching τ epoch . Averaging over many simulation, we find that neither fast nor slow cycling is able to reliably elicit generalists in the population; however, an intermediate timescale of switching is able to do so (Fig.2b).
We sought to understand the origin of this nonmonotonic behaviour by examining population dynamics in the limits of fast and slow cycling. For fast cycling, (i.e., small τ epoch ), the initial specialist population is repeatedly confronted with an antigen it cannot bind to. Without enough time to mutate into a generalist, purifying selection drives the population to extinction (Fig.  2d,i). Consequently, the fraction of trials in which specialists evolve into generalists, χ s→g , is low (Fig. 2c).
In fact, in this limit the dynamics of the population are effectively described by a static, average landscape, where the specialist has fitness s( − 2) < 0. In this regime, we find that purifying selection drives the population to extinction when s > µ log N ; see SI for derivation and discussion of alternative cases.
On the other hand, for very slow cycling (large τ epoch ), any generalists that arise have enough time to specialize again by mutational drift (Fig. 2d,iii). As a result, the fraction of an initially-generalist population that stay generalists over an environmental cycle, χ g→g , falls with τ epoch , as seen in Fig.2c.
Consequently, we find that intermediate timescale cycling strikes a balance: providing enough time to for specialists to evolve into generalists (high χ s→g ), but not enough time for generalists to switch back to specialists again (high χ g→g ). In the SI, we determine this regime to be, (1) where C init and D are combinatorial factors that account for the mutational distance of the initial naive repertoire from generalists and the number of generalist genotypes, respectively; see SI.
Note that if population sizes are small and sequence space is large, we find τ min > τ max , i.e., it takes longer for generalists to evolve from specialists than to specialize again. In this regime, the entropic bias in sequence (c) An initially-specialist population is more likely to evolve generalists (higher χs→g) with slower cycling since (d,i) fast cycling typically leads to death of the entire population before any generalists are evolved. In contrast, slow cycling allows generalists to specialize; the fraction χg→g of an initially-generalist population that remains generalists falls with τ epoch (see (d,iii)). (d,ii) Intermediate timescale switching allows sufficient time for generalists to evolve from specialists without providing enough time for generalists to specialize. space driving generalists to specialists is large; even fixed frequency cycling may not produce generalists.
Hence, we propose a new dynamic protocol -a 'chirp' -that can alleviate this tension between evolving generalists from specialists (χ s→g ), which requires slower cycling, and the ability to maintain a population of generalists (χ g→g ), which requires faster cycling. A chirp, shown in Fig. 3, starts with slow cycling and increases the cycling frequency over time. Such highly dynamic 'chirp' protocols outperform any fixed frequency cycling protocol; see Fig. 3c.

B. Generalists isolated by fitness valleys
We now consider a more general case where fitness valleys separate viable genotypes, and specialists and generalists form disconnected sets in sequence space. Such models have been used to describe antibodies for influenza and malaria [32-35], as well as describing RNA molecular fitness landscapes [36,37]. In the affinity maturation context, such a model naturally arises if each antigen has multiple epitopes, with one epitope shared across antigens [35]. Epistasis in antigen-antibody binding interactions, quantified recently[38], can also give rise to such disconnected sets.
Here, we take a phenomenological approach that is agnostic to molecular details. Exploiting Hopfield's [39] (or more generally, Gardner's [40]) construction, we con-struct fitness landscapes for each antigen with fitness islands around sequences corresponding to each epitope. In particular, consider P epitopes on each antigen η = 1, 2, that bind to antibody sequences h η α (α = 1, . . . P ). The fitness of an antibody with sequence x confronted by antigen η is chosen to be F η ∝ α (x · h η α ) 2 . This minimal construction produces fitness landscape with peaks at the specified epitopes h η α , provided P is sufficiently small compared to sequence length L [41].
By making different choices for the epitopes h η α , we may construct fitness landscapes with arbitrary amounts of correlation between them. We begin by studying the minimal case where 1 epitope is shared between the two antigens, h 1 1 = h 2 1 , with the others epitopes being uncorrelated. Later, we relax this assumption. For our theoretical analysis, we assume selection is strong and beneficial mutations are rapidly fixed, sN µN , sN 1; hence fitness valleys between islands play a significant role.
We simulate a finite population of antibodies evolving via Moran dynamics. Initialising a monoclonal population at a specialist, we once again carried out simulations at different antigen switching times, τ epoch , and quantified the fraction of generalists in the population at long times. As seen in Fig.4b, an intermediate timescale of switching elicits generalists in the population. This is reminiscent of the entropic model above, but for different underlying reasons.
Here, fast switching fails to produce generalists because populations stay confined to their initial position[42] (Fig.4d). In fact, as τ epoch → 0, the fitness landscape is effectively static, F ∼ F (1) + F (2) , corresponding to the time-averaged fitness. This static landscape F generally inherits the attractors of F (1) and F (2) , as well as potentially numerous additional 'spurious' attractors [41]. Consequently, the population remains segregated away from the generalist genotypes by valleys of low-fitness, and generalist acquisition, χ s→g , is small. In practice, such populations stuck in a specialist genotype for extended time can go extinct in the presence of multiple antigens [9].
In contrast, at slower switching times, evolution in each environment can shift the population away from its initial position in the prior environment (Fig.4d). As shown in the SI, this requires at least time τ min ∼ d 12 /µ, where d 12 is the typical mutational distance separating specialists across environments. Consequently, the population is forced to continually traverse genotype space. This continual evolution is by necessity stochastic (Fig.4f), contingent on the random order of mutations that arise, as well as on any potential population variance. This cycling-induced mobility, augmented by stochasticity, allows the population to widely explore genotype space and find the generalist, and hence χ s→g rises (Fig.4d).
Importantly, upon evolving into generalists, environmental cycling no longer disturbs the population, as the fitness of generalist sequences does not appreciably change over time. Thus cycling breaks the symmetry between specialists and generalists and enhances χ s→g without enhancing χ g→s . Intuitively, intermediate cycling selectively 'warms up' (i.e., increases stochasticity) specialist parts of sequence space, naturally leading the population to collect in 'cooler' generalist sequences.
Cycling significantly slower than τ min is counterproductive. The cycling-induced leaks from specialists to generalists only occur due to environmental switches; hence unnecessarily long τ epoch only adds dead time with no additional population divergence.
In the meantime, as shown in the SI, escape from generalists to specialists becomes significant on timescales of (1/µ)e ∆FgN where ∆F g is the fitness of the generalist relative to the fitness valley separating it from specialists; N is the population size. See [42-44] for calculations of valley crossing rates in other parameter regimes. These considerations limit intermediate timescales favorable for evolving generalists:

Correlation between specialists
The effectiveness of this theoretical cycling mechanism depends on the correlation between specialists of F (1) and F (2) [45]. For example, if specialists of F (1) and F (2) are similar or are carefully arranged as to be well within each others attractors, cycling will primarily cycle the population between specialists with minimal divergence into generalists. As shown in the SI, we can quantify relevant correlations by where c η,γ = 1 LP α,β =1 h η α · h γ β excludes the generalist pattern h 1 1 = h 2 1 . When F (1) |F (2) s is high, cyclinginduced variance is low; see Fig.4g. Consequently, the small asymmetry between χ s→g and χ g→s created by a single environmental cycle must be compounded by cycling multiple times; however, in practice, other considerations might limit the number of such cycles. Hence, our proposal requires the specialists of F (1) and F (2) to be sufficiently uncorrelated (low F (1) |F (2) s ).
Is cycling a practical strategy given physiological parameters for population dynamics and the correlations between specialists antibodies found during HIV infection? We analyzed specialist and generalist antibody sequences collected from an HIV patient [46-48]; see Fig.5a. We constructed landscapes F (1) , F (2) with fitness peaks at these observed specialist and generalist sequences following Gardner's construction [40]; see SI for details.
Simulations of cycling environments F (1) , F (2) constructed from the above sequence data evolved generalist antibodies, while simultaneous presentation of both antigens, a practical alternative to fast cycling [9], fails to produce such generalists; see Such evolution introduces sequence variance even in initially monoclonal specialist populations (red arrows in (e), quantified in (f)) but not for generalists. Such higher variance for specialists enhances specialists-to-generalists transitions but not the reverse process. (g) Cycling-induced variance is largest when specialists in shuffled antigen labels for antibodies, so that CH105 was considered a Ag2 specialist and CH186, an Ag1 specialist and reconstructed F (1) , F (2) . This artificial shuffling significantly increased the correlation F (1) |F (2) s = 0.78 compared to the real data ( F (1) |F (2) s = 0.43). Cycling is now less effective in evolving generalists. We conclude that the low correlation between specialists in the real data is crucial for time-varying selection of generalists.
While our model here did not explicitly account for extinction, simultaneous presentation or fast cycling can cause most specialist B-cells to perish, especially if many distinct antigens are use (see SI). In this more realistic case, 'chirped' cycling at increasing frequency as in Fig.3 will provide the dual advantage of evolving generalists from specialists through slow cycling and then enhance generalist yield by removing specialists through fast cycling. DISCUSSION We have shown that environmental changes on intermediate timescales can dynamically funnel populations from specialists to generalists. Our quantitative framework suggests broad new classes of experimental protocols such as 'chirped cycling' that further enhance the evolution of generalists.
The relevant intermediate timescale here is that of evolutionary transients in a population -the environment must change slow enough for significant changes to accumulate but fast enough to prevent the population from settling to a steady state distribution. This intermediate regime creates a highly dynamic fitness 'seascape' with no effective static description [11]. This dynamic regime has been relatively less explored[15] than limits where the environment changes much faster or slower than evolutionary transients and which can be understood using effective static environments.
The simple models studied here ignore many ingredients present in B-cell affinity maturation and other evolutionary processes in the natural world. For instance, affinity maturation starts from a specific naive antibody repertoire[49], population response timescales can vary widely [50]; our results require an ensemble of lineages to participate [9] and ignores clonal interference [51].
Nonetheless, our analysis has broad applicability, since it relies only on a simple phenomenological characterization of how specialist and generalist genotypes are organized in sequence space. Further, our results are fundamentally linked to the fact that generalists experience less time variation of fitness than specialists, leading, e.g., to higher stochasticity and mobility for the specialist parts of sequence space but not for the generalists. In this sense, the dynamic strategies presented here represent a broader class of non-equilibrium evolution-  (2) with peaks at red, blue sequences resp. and simulated evolution with realistic parameters (see SI). Generalists are evolved only if antigens are cycled. Cycling is less effective if we shuffle antibody-antigen assignment: CH105 now considered specialized for strain 2 (i.e., now red), CH186 for strain 1 (i.e., now blue). Shuffling artificially increases specialist correlation F (1) |F (2) s from 0.43 to 0.78.
ary strategies[11, 13] that can enhance the rate of transitions from specialists to generalists without enhancing the time-reversed processes. Dynamic protocols have been investigated recently in other evolutionary contexts, e.g., in antibiotic resistance, where correlations in response to different antibiotics have been exploited to maximize cross-vulnerability[17, 52-54]. While such cross-vulnerabilities have been primarily studied in the slow switching limit, switching antibiotics after a partial evolutionary response like that explored here might open a larger space of strategies.
While we have discussed dynamic environments as a prescriptive mechanism, natural environments are also dynamic [1]. To construct landscapes with entropically disfavored generalists, we model antibodies and antigens in a manner similar to the one described by by Wang et. al [1]. In this model, the sequence of each antibody, x is a sequence of length L with entries ±1. Each antigen, indexed by η, is assumed to have an epitope of sequence, h η . Each epitope is length L with entries ±1. The binding affinity of a given antigen to an antibody is given by an additive sum-over-sites model: The fitness of each antibody x in the presence with antigen η is given by thresholding its binding affinity, as follows: Here, Θ(x) is the Heaviside function. T is the binding affinity threshold that an antibody must overcome before reaping a fitness benefit. By construction, all fit individuals have the same fitness s( − 1) > 0 and all unfit individuals are equally unfit to an extent −s, resulting in a degeneracy of fit and unfit genotypes.

B. Specialists and Generalists
Biological constraints impose that parts of an antigen's epitope is conserved, while other parts are variable as the viral strain evolves. As such, we suppose L c sites of the L total sites are fixed across η, while the others are unique to each antigen. This constraint results in the possibility that some antibody sequences have a positive fitness for all antigens. Such antibodies are called generalists. The number of generalists is a function of the threshold T and the lengths of the conserved L c and variable L v = L − L c regions. In particular, if (T + L)/2 > L c + 1 2 L v , there are no generalists. A simple equation to compute the number of generalists against the number of viable antibodies is given as follows: where, N m is the combinatorial function. By rule, this function is zero if m > N or m < 0. Here, we considered L = 19, L c = 12, and T = 11. The proportion of viable antibodies that are generalists for these parameter choices is ≈ 1.3%. This choice is qualitatively similar to the analysis developed in [1] based on experiments there.

C. Finite population simulation
We simulate a population of antibodies evolving in the landscapes Eq. 2, subject to mutation, growth, and death. In particular, we use a 'Yule' process [2] with the following stochastic events: • Birth-death with rate λ per individual, in which the individual is duplicated with probability: If the individual does not reproduce, it is removed from the population. Here, N is the current population size, K = 500 is a carrying capacity that prevents the population from growing indefinitely, and F (η) is the fitness of that individual in the (current) landscape η.
At each event, time is advanced by the usual exponentially distributed amount. The environment η is taken to alternate between η = 1 and η = 2 every τ epoch . Choosing units of time by setting the birth-death rate λ = 1, we set the mutation rate to µ = 0.05. Finally, we set the carrying capacity K = 500. We can infer from these choices that s = 1, = 2 − 2N K . We evolved an initially monoclonal population of size N = 10 (initialised with x = h η for all individuals). Simulations were run for either a fixed time t = 100 (in units of λ) or for t = 10τ epoch , whichever is longer, and we performed 25 replicates for each value of τ epoch . For each run, we saved the number of generalists and the overall population size at the end of the simulation. In Fig. 2b of the main text, we plotted the proportion of trials that had more than 10 generalist antibodies at the end of the simulation, finding that the proportion was high for an intermediate rate of cycling.

D. Evolution between Specialists and Generalists: χs→g and χg→g
As discussed in the main text, there are two possible failure modes: (1) at cycling rates too fast, the population does not have the time to evolve a generalist before adverse selection result in population extinction, (2) at cycling rates too slow, the population loses its ability to maintain generalists. In order to illustrate the tension between cycling too fast and cycling too slow, we compute two quantities: • χ g→g , the fraction of generalists remaining a generalist after one epoch. We define this quantity as the fraction of an initially monoclonal generalist population remaining a generalist after a single epoch.
• χ s→g , the fraction of trials in which a monoclonal population of specialists, initialized at x = h (1) , evolve a single generalist within an epoch.
Both χ g→g , χ s→g are computed from 50 replicates for each τ epoch . As plotted in Fig. 2c, we observe that χ s→g starts initially at 0 and rises with τ epoch , while χ g→g starts at 1 and falls with τ epoch .
Population traces: Fig. 2d shows population traces in single runs. As in Section I C, we initialized a population at x = h (1) with parameters as above. Generalist fraction is defined as number of generalists population size . We use the following values of τ epoch for Fig.2(d): Fast cycling τ epoch = 1 (Fig. 2d(i)), Intermediate cycling τ epoch = 60 (Fig.2d(ii)), Slow cycling τ epoch = 400 (Fig.2d(iii))

E. Timescale Analysis
Our numerical study found that an intermediate timescale of environmental cycling, τ min < τ epoch < τ max , was most effective at obtaining generalists. Here we estimate the bounds, τ min and τ max , in terms of the mutation rate µ, the population size N , the length of the genotype L, and the distance from the initial ancestral genotype to the generalist, d i→g .
Finding the generalist: τmin Consider a population initialised as a specialist for antigen 1. For sufficiently strong selection pressure (s > µ log N ), purifying selection drives the population to extinction if a generalist has not been discovered before the environment switches to antigen 2. Thus we demand that τ epoch is long enough for the population to evolve a generalist in a single epoch.
As fitness is uniform across the specialist region, the population must discover the generalist by diffusion. An initially monoclonal population of size N diffuses out from the initial genotype. If the population size is much smaller than the number of possible genotypes (N 2 L ), there are two possible regimes of the diffusive search: 1. The initial genotype is far from the generalist: more precisely, the population size N is smaller than the set of sequences between the initial genotype and the generalist. In terms of the Hamming distance between the initial genotype to the generalist, d i→g : In this regime, finding the generalist is a rare event, requiring time µτ min ∼ 2 L , i.e. the time taken to explore all of genotype space. It is therefore extremely improbable that the generalist will be found, and population extinction is likely.
2. The initial genotype is close to the generalist: that is, the generalist is sufficiently close to the initial condition that it may be found by the diffusing population of antibodies: For L = 19 and N = 500, as used in the simulation, this suggests that for d i→g ≤ 4 the generalist may be reasonably found by diffusion.
Assuming that we are in the latter regime, we may estimate τ min from d(t) , the average distance away from the initial condition that an individual has diffused in time t, by solving: We compute d(t) as follows: the probability that a diffusing individual may be found at (Hamming) distance d from its initial genotype is: Thus, Inserting into Eq. 7 and solving for τ min : where the approximation is valid for d i→g /L 1. For values used in the simulation (L = 19, d i→g = 3), we obtain µτ min ≈ 3.5, which is consistent with our numerical results.

Maintaining a generalist: τmax
We may similarly estimate the upper bound for effective cycling, τ max . Supposing that an evolving population has found the generalist, it must now remain localised there. For this to happen, the environment must switch rapidly enough to prune, by purifying selection, those individuals that diffuse away from the generalist.
Consider a monoclonal population of size N at a generalist at time t = 0. For simplicity, we assume that any single mutation out of the generalist is into a specialist. This is reasonable when the number of generalists is small compared  1. (a) We compute the probability of evolving generalists for varying Hamming distances from the generalist, given by d, using the method described in Section I C. We note that as d increases, the time at which generalists begins to be evolved increases, though the time at which they probability decays remains fixed. (b) We compute χs→g for each initial condition and take τmin to be the smallest time where χs→g > 0.6. We find that this rises, eventually rising above τmax for large enough d. By construction, τmax is independent of d.
to specialists, as is the case for our numerical calculations. Then, from Eq. 8, the number of generalists remaining at time t is: Then, τ max is defined as the time taken for the occupancy of the generalist to fall below 1 individual: where in the last step we have taken the limit of large sequence length L.
For the parameters used in the simulations (L = 19, N = 500), we have µτ max ≈ 8, which is consistent with the numerical results.

Existence of an intermediate timescale
Existence of an intermediate timescale τ epoch that produces generalists requires τ min < τ max . However, the above expressions make it clear that τ min < τ max only if (a) the initial condition is close enough to generalists (small d), (b) the fraction of generalists relative to specialists is large enough (large L c /L).
SI Fig.Fig.1a shows how the yield of generalists at intermediate timescales disappears as the initial conditions are made less favorable. This panel was constructed using the simulation method described in Section I C with variations on the initial condition for x such that the Hamming distance between x and the generalist varied by some distance d. SI Fig.1b shows that τ min rises in this limit and exceeds τ max . We approximated τ min by computing the smallest time for which χ s→g > 0.6 and τ max by computing the largest time for which χ g→g > 0.6. When τ min < τ max is not satisfied, there is no intermediate timescale. The time needed for generalists to specialize is shorter than the time needed to evolve generalists from specialists. In this case, the chirp protocol described below is still successful at producing generalists.

F. Simultaneous presentation of antigens
The cycling strategy explored in this paper may not be practical in the fast limit in the context of B-cell affinity maturation. A common practical alternative is vaccination with a cocktail of antigens, i.e., simultaneous exposure to multiple antigens.
Such simultaneous exposure to multiple antigens is mathematically equivalent to fast cycling of those antigens if specific microscopic assumptions about antibody-antigen interactions in germinal centers hold [1]. During the affinity maturation process, folicular dendritic cells (FDCs) host antigens on their surface for B-cells to interact with, and if antibodies expressed on B-cells bind the antigens with high enough affinity, B-cells internalize those antigens. This process enables those B-cells to avoid apoptosis, and thus proliferate and continue affinity maturation.
There are two currently experimentally unresolved hypotheses about antigen presentation by FDCs: 1. Antibodies are fit only if they can bind ALL presented antigens: In this hypothesis, FDCs only present a single antigen or present antigens in a spatially heterogeneous manner. Consequently, each B-cell is randomly exposed to a single antigen at the selection stage of the affinity maturation process. A B-cell must be able to bind ALL presented antigens to survive selection.
Such simultaneous presentation is qualitatively similar to the fast cycling limit studied in this paper. When presented with such a cocktail vaccine, antibodies starting from a naive repertoire are expected to go extinct since such antibodies typically cannot bind all antigens with high affinity, as seen in the experiments of [1].
2. Antibodies are fit if they can bind ANY one of the presented antigens: If the FDCs present the antigens in a homogeneous manner, each B-cell only needs to bind ANY single one of the presented antigens to avoid apoptosis.
In this case, specialists are fit enough to survive early rounds of selection and evolve generalists. But generalists cannot be maintained in preference over specialists unless selection pressures are fine tuned (e.g., specialists are strongly out-competed by generalists once generalists evolve, despite specialists having significant fitness to begin with). We do not consider this model of B-cell -FDC interactions in this paper.

G. Death and fast cycling
In the fast cycling limit, τ epoch → 0, the fitness of specialist antibodies is the average of their fitness in different environments; as seen Eqn. 2, this fitness is s( − 2).
As discussed above for simultaneous presentation, we only consider the case where fast cycling corresponds to hypothesis (1), where antibodies need to bind all antigens to survive. Hence, we need s( − 2) to be sufficiently negative, so that a specialist population of size N typically dies out before reaching the generalists in this fast cycling limit. Since the latter process takes time τ min ∼ d i→g /µ as derived earlier and the initial population size is N , the condition for a specialist population to go extinct in the fast limit is N exp(s( − 2)τ min ) ∼ N exp(s( − 2)/µ) < 1. Assuming that 1 < < 2, we find s > µ log N as a conservative criterion independent of .

H. Dependence on initial repertoire
In the main paper, we initialize our population from a genotype that exactly binds the antigen characterized by genotype h (1) . In SI Fig.2, we show that not only does intermediate cycling increase the likelihood of evolving generalists from a given initial condition, it also increases the number of initial conditions (e.g., initial B-cell repertoire) that can lead to generalists. Hence, intermediate cycling increases the effective attractor size of the fitness peak associated with a generalist. In SI Fig.2, we consider cycling fast (µτ epoch = 0.05 < µτ min ), cycling at an intermediate rate (µτ epoch = 3), and cycling slowly (µτ epoch = 15 > τ max ). Blue regions in the heatmap correspond to initial conditions that led to few surviving populations after ten epochs. Yellow regions in the heatmap correspond to initial conditions that led to many surviving populations after ten epochs. We ran each ordered pair of conserved matches and variable matches for 50 replicates in environment η = 1 and symmetrized over environments. Here, the color in the color map represents the proportion of trials leading to a generalist, where yellow corresponds to all trials, while blue corresponds to no trials leading to a generalist. We initialize our population at size N = 10 with a carrying capacity K = 500. We maintain L = 19, Lc = 12, and T = 11. We ran our simulations for a total of ten epochs. We ran each ordered pair of conserved and variable matches for 50 replicates in environment η = 1 and assumed symmetry over environments. does not lead to generalists for any initial condition since this limit is unable to maintain generalists.

I. Chirp protocol
Trade-off in fixed frequency cycling: The anticorrelated behavior of χ s→g and χ g→g is indicative of a trade-off between evolving generalists and maintaining them in the population.
We first assess this by only considering simulation runs used in Fig.2b that did not result in extinction and computed the number of generalists at the end of such simulations. This number is plotted in Fig.3a. We note that as epoch length increases, the number of generalists remaining in the population decreases, but the probability of a population evolving a single generalist increases.
To illustrate this point we compute two quantities for each simulation for a given τ epoch : • The number of generalists (if non-zero): The number of generalists is simply the average number of generalists in the population for simulations where the population survived an evolutionary run. This is plotted on the y-axis of Fig.3c.
• The probability of a surviving population: The proportion of trials for a given τ epoch that a population does not go extinct during the evolutionary run. This is plotted on the x-axis of Fig.3c.
By plotting these two quantities against each other, as in Fig.3c in black dots, we observe a tradeoff front. Chirp Cycling Breaks the Trade-off: This trade-off leads us to proposing a 'chirp' protocol. In a 'chirp' cycling protocol, we decrease the length of the epoch using a multiplicative factor after each cycle, enabling us to take advantage of high probability of population survival (favored by slow cycling) and still obtain high yield (favored by fast cycling). We update τ epoch according to the following rule: where k is some number smaller than 1. We continue evolving the population until τ epoch << λ. Plotted in Fig.3b is a time trace of the population size and the fraction of the population that is of a generalist genotype. Generalist fraction is Number of Generalists Population Size . We note that as the length of each epoch decreases, the generalist fraction decreases less in time, until eventually, it remains stabilized at ≈ 1. Additionally, fluctuations in population size are suppressed. We ran the chirp protocol for 25 replicates and computed the number of generalists at the end of each run, if the population survived the run, and the probability that the population survived a chirp protocol. Plotting this in Fig.3c. demonstrates that the tradeoff boundary has been broken.
Chirped Cycling Evolves Generalists when τ max < τ min By implementing the same chirped strategy for initial conditions where τ max < τ min , we find that we have high generalist yield at rates match are near the maximum probability of evolving generalists of the fixed frequency evolutionary runs.

A. Model
We model the fitness landscape of an antibody binding to an antigen with multiple epitopes through a phenomenological construction, inspired by Hopfield's spin glass landscape.
Consider an antigen η with P η epitopes (i.e., sets of residues on the antigen that form binding locations for antibodies). Suppose that for each epitope, an antibody with sequence h (η) α of length L with entries ±1 binds with high affinity (with α ∈ {1, ..., P η } indexing epitopes). Then, the overall binding affinity to antigen η of any antibody with sequence x, of length L with entries ±1 is taken to be: This construction naturally produces islands of high fitness around the epitope-binding antibodies h (η) , separated by regions of low fitness. Here, κ (η) α is the binding affinity of the ideal antibody h (η) to its cognate epitope. We shall take epitope α = 1 to be present for all antigens, thus defining the generalist. In keeping with the assumption that the generalist is less fit in any landscape, we take its binding affinity κ Weighting the various solutions: We impose that the height of the fitness peak associated with the generalist is lower than the peaks of the specialist ( = 0.8), reflecting fitness costs associated with being a generalist relative to specialists in a fixed environment.

B. Population Simulations
We simulate a population of antibodies evolving in these landscapes by implementing a Moran process [3] with three events: • Environment shifts with a deterministic rate, 1 τ epoch • Mutation with a rate, µ per individual, where a single site on x is bit-flipped • Reproduction with a rate, λ per individual, where an individual is selected from the population with probability proportional to exp(F (η) ) to be duplicated and another individual from the population to be removed with uniform probability and a population size of N . In our population simulations, we impose the following values for our simulation parameters. We fix the total number of epitopes for each landscape, P η = 11 across all η, keeping just one generalist. We impose sequence length to be L = 100, generating each optimal epitope-binding antibody randomly. We initialize our simulations from a random monoclonal initial condition of size N = 100 unless otherwise specified. We impose a per individual mutation rate of µ = 0.25 and a reproduction rate of λ = 1.
C. Fig.4b: Resonance Peak in Generalist Discovery as a function of τ epoch We ran our simulation for 50 replicates from random monoclonal initial conditions of size N = 100 with sequences of length L = 100. We initialize the landscapes with 10 specialist antibodies and 1 generalist antibody (i.e. P η = 11 for all η). Our simulations were run for a total of 100 τ epoch s. We swept over τ epoch s. We note that during the simulations, regardless of the frequency of environmental shifts, the population remains tightly clustered as it evolves in time. This behavior corresponds to evolution in the strong selection and weak mutation limit. We consider a generalist to have been discovered if, after a run, there exists at least one individual whose overlap with the generalist antibody is 90%. Using these simulations, we demonstrate that an intermediate regime of switching enhances the discovery of generalists. We plot the results of these simulations in Fig. 4b.
Time traces of the population from its initial condition: To identify the reason for this resonant peak, we run the simulation for a 100 cycles and plot in SI Fig.3 how far the population is from its initial condition in hamming distance after a fixed number of epochs We initialize a population at a specialist antibody and a generalist antibody, comparing the behavior for fast cycling and slow cycling. We show that for generalist initial conditions, regardless of cycling rate, the population remains in the generalist. There is some fluctuation out but the population returns to the generalists often. Given enough time, the population will escape though this is a slow process. However, for specialist initial condition, slow cycling enables the population to escape its initial condition, while fast cycling does not allow such escape.

D. Timescale Analysis
Computing the minimum epoch length, τ min : Cycling benefits evolution of generalists in fitness landscapes with barriers by enabling the population to escape specialist peaks in one landscape by evolving subject to a different fitness landscape. To escape from a specialist peak in environment 1, the population must accrue enough mutations when subject to environment 2, such that when environment 1 returns again, the population is not likely to return to the original specialist peak.
We first consider the strong selection limit sN 1. Consider a monoclonal population at a specialist peak h (1) α in fitness landscape F (1) . When such a population is now subject to landscape F (2) for a time τ epoch , h (1) α serves as an initial condition of typical low fitness and will evolve towards a fitness peak h (2) β in F (2) . If we switch back to F (1) after a sufficiently long time, the population genotype x will be sufficiently mutated compared to h (1) α that the population will likely fix to an alternative fitness peak h (1) β in F (1) . Let us assume that the number of such mutations needed is d 12 .
Since the population in genotype h (1) α is typically of low fitness in landscape F (2) , most mutations are beneficial. Then, in the strong selection limit, the time needed to acquire d 12 beneficial mutations is by the mutation rate,

Fig.
This minimal number of mutations d 12 to escape the 'attractor basin' of a fitness peak h (1) α is model dependent. -d 12 depends on the size of the attractor basin around h (1) α and the correlations between F (1) and F (2) . In our Hopfield-inspired model of fitness landscapes F (η) , if the fitness peaks are randomly distributed in a sequence space of length L, then the empirical value of d 12 ∼ 1 4 L. In real fitness landscapes, this distance d 12 can vary widely for different specialists which can have attractor regions of different size.
Computing the maximum epoch length, τ max : Unnecessarily long times τ epoch > τ min spent in each environment is counter-productive. To see this, note that specialists are most likely to evolve to generalists in a short duration of time after an environmental switch. Any extra time spent τ epoch > τ min in the same environment is simply 'dead time' that does not increase the yield of generalists further. Hence the effective rate of evolving generalists from specialists falls as 1/τ epoch for τ epoch > τ min .
Meanwhile, existing generalists can specialize again. Let the rate of this process be r g→s . The yield of generalists is reduced when this escape rate r g→s from generalists to specialists is larger than the switching-induced rate from specialists to generalists 1/τ epoch . Hence, τ max ∼ 1/r g→s .
The rate r g→s at which generalists specialize is easily estimated since the fitness landscape does not change in time for sequences near the generalist. Hence this process is the well-studied process of an asexual population crossing a fitness valley by picking up a sequence of deleterious mutations. This process has been studied in numerous regimes with different assumptions about population sizes, selection pressure [4][5][6]. Here, we assume strong selection and weak mutation, allowing us to use the simple result r gs ∼ µ e −N ∆Fg result obtained from the analogy of statistical physics and population dynamics; population size N plays the role of temperature and ∆F g , the fitness difference between the generalist peak and the fitness valley, plays the role of an energy barrier. Hence, Real populations can often violate these assumptions; in that case, any other relevant result [4][5][6] for valley crossing rates can be used in place of r g→s . The presence of a resonant peak in Fig. 4b is suggestive an underlying tension between discovering the generalist and escaping the generalist, similar to that in the earlier model of entropically disfavored generalists. As such, we re-introduce the quantities χ s→g and χ g→g : • χ s→g is the proportion of trials initialized from a monoclonal random initial condition that evolve a generalist (i.e. a single member of the population matches 90% of the generalist) antibody emerges within 30 epochs of an evolutionary run for a given τ epoch  Fig. 4c and illustrate the same behavior as in the entropically disfavored models.

F. Cycling-induced variance and correlations between environments
To illustrate how cycling enables the discovery of generalists, we consider population trajectories during cycling. We consider the impact of the initial condition of the population on these trajectories and the impact of the correlation structure between the different environments. To this end, we introduce a measure of correlation and introduce a new simulation to capture the effective behavior of the population.

Definition of Correlations between Environments
We measure the correlation between landscapes, denoted F (1) |F (2) s using the following equation: where we have defined the function c(h (1) , h (2) ) = This measure of correlation is high if the specialist genotypes for different antigens are highly similar in pairs; e.g., if each specialist for antigen 1 is similar to a specialist for antigen 2. As seen below, a high correlation by this measure implies that specialist antibodies do not evolve significantly due to cycling and thus generalists are not easily evolved.
Note that this measure is normalized so the measure is unaffected by the diversity c(h (η) , h (η) ) of specialist genotypes for a single antigen η.

Modeling Population Trajectories with Single Walkers
To measure the role of cycling between landscapes and the correlation structure of the landscape, we studied the dynamics of single walkers. This is justified as the population is shown to be roughly monoclonal in its evolutionary trajectories. Single walkers were simulated via the well-known Metropolis-Hasting algorithm [7]. We preserve definitions of x, F (η) (x), and all related quantities from before. The process is as follows: • Randomly select a single site to mutate to create new variant x from original x
Because of the differences between single walker dynamics and population dynamics, we include an overall scale for the landscapes, β. β is chosen to be β = 4.

Fig.4f: Cycling-Induced stochasticity
We begin by considering antigens with uncorrelated specialists (ie, F (1) |F (2) s ≈ 0). Starting from two initial conditions, a generalist antibody and a specialist antibody for antigen η = 1, we evolve the walker for k proposals in the presence of antigen 2, and then allowed the walker enough proposals to relax to a stable solution in the presence of antigen 1. By computing the final state for 20 different walkers in a given landscape, and averaging over 20 random landscapes, we can compute the variance in the final positions of the walkers. This is accomplished by computing the average pairwise distance between walkers in the same landscape, and then averaging over landscapes. To demonstrate the importance of the number of proposals, k, which is serving as a proxy for τ epoch , we swept over k. The result is plotted in Fig. 4f.
We see that when starting from a specialist initial condition, cycling-induced variance rises when τ epoch is sufficiently large. Generalists, as predicted, are unaffected by cycling, as those genotypes are fit in both environments.

Fig.4g: Impact of Correlation Structures Between Cycled Environments
We then repeated the same simulations as above with increasing correlation structure between the landscapes. We enforced that k = 250 was large enough to ensure high stochasticity in uncorrelated environments. We see that as correlation between the landscapes rises, cycling-induced stochasticity decreases. The results are plotted in Fig. 4g.

G. More than 2 Antigens
Throughout the main text, we only consider the evolution of generalists in the presence of two antigens. Here, we demonstrate that when we increase the number of antigens, discovery of the generalist becomes easier. We demonstrate this in the Moran simulations by increasing the number of randomly constructed landscapes with a single generalist peak shared across the landscapes. In order to probe a dynamic range of antigen number, we weight the generalist to be smaller than in previous trials, setting κ (η) 1 = 0.07, rather than 0.08. We ensure each antigen is presented at least once, cycling for at least 30 epochs. We maintain the parameters used before.
We find that increasing the number of antigens increases the discovery-likelihood of generalists, as plotted in SI Fig.4. We interpret these results as due to effectively reduced correlation between landscapes since correlations shared across a subset of the antigens may not be shared across all antigens. For example, the population can settle into a limit cycle between specialists with only 3 antigens but evolution in the presence of other antigens allows escape from such cycles. As a result, we increase the rate of evolution from specialists to generalists without enhancing the reverse process. We increased the number of distinct antigens in stepsfrom 2 through 20, each with 10 randomly chosen specialist epitopes, and one generalist epitope common to all of them. We cycle between these landscapes using the Moran simulation described in Section II B for 30 τ epoch . We consider the evolutionary run to have evolved a generalist if at least one antibody has an overlap of 90% with the generalist. We find that increasing the number presented increases the likelihood that generalist genotypes are discovered. We further consider the number of cycles needed for the first generalist to appear as a function of the number of antigens. This can be interpreted as the number of vaccine doses needed when using a particular number of strains in the vaccine course. We probe this by running Moran dynamics at a fixed µτ epoch = 40 with κ (η) 1 = 0.08, as in other simulations, for as many epochs as needed to discover a generalist. We run 50 replicates of this simulation, reporting the average time at which a generalist first appeared across those replicates. Our choice of epoch length is the epoch length at probability of evolving generalists appears to maximize. We find that the number of vaccine doses decreases as the number of antigen strains increases, as plotted in 5.

III. HIV ANTIBODY DATA
The success of our proposed cycling strategy depends on specific assumptions about correlations between different antigens. In particular, antigens need to be sufficiently correlated in that the same generalist antibodies can bind them (e.g., the antigens share a epitope). And yet antigens need to be sufficiently uncorrelated : i.e., specialist antibodies that bind different antigens must be sufficiently distinct as measured by F (1) |F (2) s (e.g., the specialist epitopes on antigens must be sufficiently distinct).
We sought to test whether these correlation conditions are met by antibodies evolved in response to real HIV strains.

A. Antibody sequences and Binding Affinity Data
Several works have studied viable antibodies from individuals afflicted with different strains of HIV [8][9][10]. These works sequenced viable antibodies, studied their binding affinities to different strains, and proposed intermediate antibodies in between the germline antibody and the discovered broadly neutralizing antibody. They evaluated the binding affinities of each of these antibodies using the ELISA assay. The binding affinity data is presented in SI Table  I. The mutational distance between each antibody is given in SI Table II.
Antibody Sequence Data: Two classes of antibodies are presented here: mature antibodies observed in patients during their course with HIV and antibody sequences inferred to be [8][9][10] intermediate between the germline and the mature broadly neutralizing antibody. The natural antibodies appear with the prefix 'CH', and the inferred antibodies, which were synthesized, appear with the prefix 'IA'.
Antibody Binding Data: The binding affinity of each antibody to two different strains of HIV, 31D8gp120/293F and 11D8gp120, is evaluated using the ELISA assay. Particular values for binding are presented in table I. We impose a cutoff of 10 log(AUC) to indicate when an antibody has bound an HIV strain. By this rule, • 31D8gp120/293F is bound by antibodies IA2, IA3, CH105, and CH103.
B. Constructing landscapes F (1) and F (2) Let F (1) and F (2) define the fitness landscape of antibody space corresponding to 31D8gp120/293F and 11D8gp120 respectively. In each landscape, the experimentally discovered and synthetically produced antibodies will define disconnected neighborhoods of antibodies that are fit for that landscape.
We begin constructing these landscapes by converting the sequence of each antibody into a binary vector with entries ±1, noting that each antibody is length L = 121. We accomplish this randomly generating a binary vector with entries ±1 of length L to represent the unmutated common ancestor. Then, using the sequence data given by [8][9][10], we determine where each antibody differs from the unmutated common ancestor and introduce a binary spin vector for each that preserve the differences from the unmutated common ancestor as presented in the real data. We define the sequences associated with F (η) as h to the sequence of the generalist antibody CH103.
We take the binding affinity of an antibody, represented by x with entries ±1 and length L, to be E (η) (x) = α (h (η) α · x) n . Here, n controls the size and depth of each well. Here, we take n = 4. The fitness of each antibody is then given as: s defines the overall scale of the selection pressure, as before. Here, we take s = 1. The function thresholds the amount of fitness benefit an antibody can obtain from matching a correct sequence, so it features both degeneracy of neighboring genotypes and disconnected islands.

C. Simulations
We simulated evolution using the technique described in Section II F 2. Given that mutation rates in B-cells undergoing somatic hypermutation are taken to be 10 −3 per base pair per division [1], we choose our epoch length to  [8][9][10]. Higher values reflect stronger affinity. We consider an antibody to be a specialist for a strain using a cutoff of 10 logAUC. Note that only CH103 is a generalist in this dataset.  [8][9][10]. Using the raw sequence data and the binding energy presented in I, we can construct fitness landscapes F (1) and F (2) with fitness peaks that reflect these mutational distances.
be long enough that the population accumulates 100 mutations. This corresponds to an epoch length that allows 800 total divisions. The initial condition for these simulations was set to be the unmutated common ancestor (UCA). We note that if the population is not started from the UCA, the simulation fails to find successful antibodies.

D. Shuffled assignment
We earlier demonstrated that the correlation structure of the landscape impacted the ability of the landscape to effectively cycle its way to a generalist. Here, we find that which reflects the distance between specialist sequences for the two strains in the data of [8][9][10] (see Table II). With such low correlations between specialists, the simulations discover generalists around 60% of the time when cycling in this landscape, as shown in Fig. 5b.
To understand how increasing the correlation structure can impact generalist discovery in real data, we artificially shuffled the antibody binding data. In particular, we treated CH186 as a specialist antibody for 11D8gp120 and CH105 as a specialist antibody for 31D8gp120/293F and then followed the same construction of landscapes described in III B. In the new constrution, we find that the two things are substantially more correlated.
Then, after running simulations with changing environments, we find that recovery rates of the generalist drops significantly, as shown in Fig. 5b.