# Cortical feedback loops bind distributed representations of working memory – Nature

Jul 27, 2022

### Mice and ethics

Table of Contents

All experiments were performed under the UK Animals (Scientific Procedures) Act of 1986 (PPL PD867676F) following local ethical approval by the Sainsbury Wellcome Centre Animal Welfare Ethical Review Body. A total of 7 PV-Cre (ref. 65) × Ai32 and 2 × VGAT-Cre × Ai32 mice (JAX 017320, JAX 016962 and JAX 024109, Jackson Laboratory; ChR2 expressed in inhibitory interneurons) were used for the behaviour and optogenetics experiments (Fig. 1). A total of seven mice—one wild type (Charles River), three Ai-148 (ref. 66) × Cux-creER (JAX 030328 and JAX 012243, Jackson Laboratory; GCaMP6f expressed in most excitatory layer 2/3 cells under the control of tamoxifen) and three Ai-148 (Cre-dependent GCaMP6f expression in all cells) mice—were used for the cell-body imaging experiments (Figs. 2 and 3). A total of seven PV-cre mice were used for the axonal imaging experiments (Figs. 4 and 5). Mice were of either sex (10 male and 13 female) and were between 8 and 16 weeks old at the start of their experiments. Before the experiments, the three Cux-creER mice were administered tamoxifen (10 mg ml−1) by intraperitoneal injection (1 mg per 10 g body weight), three times, every other day. Mice were co-housed with littermates in IVC cages, in reversed day–night cycle lighting conditions, with the ambient temperature and humidity set to 23 °C and 56% relative humidity, respectively.

### Surgical procedures

Before all surgeries, the mice were injected with an analgesic (carprofen 5 mg kg−1) subcutaneously. General anaesthesia was induced with 3% isoflurane, which was then reduced to maintain a breathing rate of around 1 Hz. A custom-designed stainless steel headplate was attached to the skull using dental cement (C&B Super Bond). In some of the older mice in the behaviour and optogenetics experiments (Fig. 1), the dorsal surface of the skull was carefully thinned with a dental drill. The exposed skull was then sealed with a thin layer of light-curing dental composite (Tetric EvoFlow).

For the cell-body calcium-imaging experiments (Figs. 2 and 3), after a minimum recovery time of three days and intrinsic signal imaging (see below), a second surgery was performed to make a cranial window over areas AM and M2, identified by intrinsic signal imaging and coordinates (0.5 mm lateral, 2.5 mm anterior of bregma), respectively. A 5 mm craniotomy was made over the dorsal surface of the skull and a 300 µm thick, 5 mm diameter glass window was implanted with cyanoacrylate glue (Pattex). In the three Ai-148 mice, two 50 nl viral injections of AAV9.hSyn.Cre.WPRE.hGH (Penn Vector Core) diluted to a low titre (5 × 1010 vg ml−1) in Ringer’s solution were made into areas AM and M2 with a Nanoject III microinjector (Drummond Scientific). In the wild-type mouse, two 50 nl viral injections of AAV1.hSyn.GCaMP6f.WPRE.SV40 (Addgene, 100837) diluted to 5 × 1012 vg ml−1 was likewise made into areas AM and M2. In four of the mice, a viral injection of AAVretro.hSyn1.mCherry-2A-iCre.WPRE.SV40 (1 × 1012 vg ml−1; v147 Zurich Vector Core) was made into AM (one mouse) or M2 (three mice), to help localize the respective connected areas.

For the axonal imaging experiments (Figs. 4 and 5), following a minimum recovery time of three days and intrinsic signal imaging, a second surgery was performed to make a cranial window over either area AM or M2 and perform the viral injections. In three of the mice, a 3 mm diameter craniotomy was made centred around area AM, and a smaller (less than 1 mm diameter) craniotomy was made over area M2 (identified with coordinates relative to bregma; 0.5 mm lateral, 2.5 mm anterior). Viral injections (100 nl) of AAV1.hSyn.DIO.ChrimsonR.tdTomato (3.9 × 1012; UNC Vector Core) and AAV1.hSyn.jGCaMP7b.WPRE (ref. 67) (2 × 1013; Addgene, 104489) were then made into areas AM and M2, respectively, with a Nanoject III microinjector (Drummond Scientific). Immediately afterwards, the larger area AM craniotomy was sealed with a 3 mm glass window. In the other four mice, the same procedure was done but with areas AM and M2 reversed.

### Intrinsic signal imaging

We used intrinsic signal imaging68 of the dorsal cortex to identify the locations of cortical areas V1 and AM. Intrinsic imaging was performed on awake mice while they were head-fixed on top of a freely rotating Styrofoam cylinder. The visual cortex was illuminated with 700 nm light, a macroscope was focused 500 µm below the cortical surface, and the collected light was bandpass-filtered centred at 700 nm (10 nm bandwidth; 67905, Edmund Optics). The images were acquired at a rate of 6.25 Hz with a 12-bit CCD camera (1300QF, VDS Vosskühler), an image acquisition board (PCI-1422, National Instruments) and custom software written in LabVIEW (National Instruments). The visual stimuli, presented on a display 22.5 cm away from the left eye, were generated using Psychophysics Toolbox69 running in MATLAB (MathWorks), and consisted of square-wave gratings, covering a 40° visual angle, 0.08 cycles per degree, drifting at 4 Hz in eight random directions, presented on an isoluminant grey background for 2 s, with 18 s inter-stimulus intervals. The gratings were presented alternatively at two positions, at 15° elevation and either 30° or 80° azimuth. Response maps to the grating patches at either position were used to identify the centres of V1 and AM, using a reference map70.

### Behavioural shaping and apparatus

Mice were trained for 2–6 weeks before the initiation of data acquisition. Mice were food-restricted for the full duration of the behavioural training and data acquisition, with no scheduled breaks. The maximum weight loss was limited to 80% of their pre-restriction body weight. Food restriction began at least three days after headplate implantation surgery. The mice were trained for approximately 2 h every day, once a day. For the first few days of training the mice were handled on a cloth and iteratively fed Ensure Plus strawberry milkshake (Abbott Laboratories) through a syringe to acclimate them to the behavioural training environment.

Over the next few days, the mice were trained to run on a freely rotating Styrofoam cylinder, while head-fixed, in front of the visual stimulation display (U2415, Dell; 60 Hz refresh rate), placed 22.5 cm away from their left eye and oriented at 32° relative to midline. A reward delivery spout was positioned under the snout of the mice from which a drop of Ensure Plus was occasionally delivered by the experimenter to encourage running. Licks were detected with a piezoelectric diaphragm sensor (Murata 7BB-12-9) placed under the spout.

Once the mice were running freely, they were trained to perform a simple visual detection task, in which the onset of a visual stimulus was associated with reward (a drop of Ensure Plus), delivered from the reward spout after the stimulus onset. The mouse running speed was recorded with a rotary encoder (05.2400.1122.1000, Kübler), and the mice had to run a specified distance between the stimulus presentations. This distance was variable and set such that the mice received roughly one reward per minute. Reward delivery was triggered when the mouse licked the spout any time during a response window of 1 s following the stimulus onset. If the mice failed to lick in response to the stimulus, an automatic reward was delivered at the end of the response window. The detection of licks, reward delivery, recording of data and the presentation of visual stimuli were controlled by a custom LabVIEW software (National Instruments). Visual stimuli were generated by custom software (https://github.com/Ivan-Voitov/Vizi) written in Unity (Unity Technologies). Hardware interfacing was conducted with a data acquisition board (PCIe-6321, National Instruments).

The visual stimuli were drifting square-wave gratings presented at 100% contrast, 0.025 cycles per degree, covering 60° of the visual field of the mice, centred at 15° elevation and 45° azimuth, presented on an isoluminant grey background. The luminance of the monitor was set at 0 cd m−2, 22.5 cd m2 and 45 cd m2, at black, grey and white values, respectively. The grating stimuli were cycling in a closed loop with the mouse running speed for the first one to two weeks of training, and were then fixed at 3.5 Hz for the remainder of the experiments.

Once the mice were running comfortably on the Styrofoam cylinder and licking in response to the presentation of grating stimuli (after one to four weeks of training), the task parameters were introduced to begin training either the Discrimination or the WM tasks. The order in which the two tasks were trained varied between mice.

### Task training and design

Both the Discrimination and the WM tasks consisted of alternating delay (grey background) and stimulus (full contrast grating) periods (Fig. 1a). Delay period durations were sampled from an exponential distribution with a mean of 800 ms, and then had 800 ms added (that is, a 800 ms offset or minimum duration). The sampled delay periods durations were then capped at 4,000 ms by resampling the duration from a uniform distribution between 3,600 and 4,000 ms whenever this cap was reached (to ensure a minimal effect on the average duration of the delay). The resulting average delay duration was 1,600 ms. The duration of the stimulus period was proportional to the mouse running speed that is, was a distance to traverse), and was set to either 100 cm or 80 cm depending on the average running speed of the mouse, such that the stimulus period took a similar time to traverse by all mice if they did not stop running. Forcing the mice to traverse a certain distance to get through the stimulus period promoted persistent running in mice over the course of each session, which in turn ensured stereotyped movement within the delay periods and reduced variability between mice. The resulting average stimulus duration was 1,967 ms.

In both the Discrimination and the WM tasks, the orientation of the grating stimuli classified them as either go or no-go (Fig. 1a and Extended Data Fig. 1a). The stimuli presented were cues (no-go; 80% of trials), probes (no-go, 10% of trials) or targets (go, 10% of trials). Cue stimuli were gratings oriented at 0° (vertical) in the Discrimination task and either +45° or −45° in the WM task; probe stimuli were gratings oriented at 90° (horizontal) in both tasks; and target stimuli were gratings oriented at +45° or −45° in both tasks. The stimulus presented for each trial was sampled randomly with the aforementioned probabilities, with the exception that after a probe or a target stimulus, a cue stimulus was mandatory (100% probability; Extended Data Fig. 1a). The only difference between the Discrimination and the WM tasks was that the cues were always vertical (0°) gratings in the Discrimination task, but the cues (oriented −45° or +45°) were mirrored in orientation relative to the current targets (+45° and −45°, respectively) in the WM task. Accordingly, in the WM task, the orientations of the cues were only switched after the presentation of a target, whereas in the Discrimination task the cues were always the same (vertical gratings). Because cues were more frequent than the other stimulus types (80% probability), most trials were consecutive cues of the same orientation. In addition to serving as common no-go stimuli in both tasks, the probes ensured that the mice were not using an odd-ball detection strategy to perform either task (that is, responding to rare stimuli), as the probe presentation probability was the same as the target probability.

Sequences of delay and stimulus epochs were presented continuously (that is, no inter-trial intervals), with individual trials composed of a delay and stimulus pair, such that each trial’s stimulus served as a cue to the subsequent stimulus. If mice licked the spout during a 1 s response window after the onset of the target stimuli (that is, go trials), the trials were classified as hit trials; otherwise, they were classified as miss trials. In the miss trials, the mice received an automatic reward at the end of the response window, consisting of half of the normal reward amount. The same 1 s response window was used to classify responses to the cue and probe stimuli (that is, no-go trials) as false alarms (FAs) or correct rejections (CRs). Licking during the no-go trials was not punished.

Once the mice were trained in both tasks (sequentially, with the order varying between mice), the blocked task structure was introduced, with the Discrimination and WM tasks alternating every 415 trials over the course of each session in the behavioural and optogenetic experiments, and a similar but variable number of trials (300–600) in the imaging experiments (to accommodate a variable number of trials between the rotation blocks; see below). Mice performed between three and eight task blocks per session. Mice switched task blocks quickly (within a few trials), as the presence or absence of the Discrimination task cue stimulus (a vertical grating) was informative of the task block. Similar two-task designs have previously been used to disambiguate the neural correlates of specific cognitive processes by isolating neural representations of interest from ‘condition-independent’ neural activity29,71. One potential drawback of the two-task design is that neural activity may be recruited that would otherwise be absent if the mice were only trained on one task. Nevertheless, ethological behaviour is characterized by flexible switching between a vast repertoire of previously learned behaviours, and two-task designs therefore impose a reasonably conservative control for investigating neural correlates of cognitive processes.

For the imaging experiments (Figs. 2–5), the ±45° oriented gratings (that is, cues in the WM task and targets in both tasks) were instead oriented at ±30°, and the rotation block structure was introduced. The goal of the rotation blocks was to match the cue stimulus grating orientations between the Discrimination and WM tasks (Extended Data Fig. 1b). The rotation blocks consisted of blocks of several hundred trials, out of phase with the task blocks described above, during which all stimuli, except for the 90° oriented probes, were rotated either 15° clockwise or 15° counter-clockwise. As such, the resultant stimulus orientations for the cues and targets were −45°, −15° and +15°, and −15°, +15° and +45°, in the clockwise and counter-clockwise rotation blocks, respectively. In between two rotation blocks, the stimulus orientation angles were changed slowly in a continuous fashion (averaging around 10 min for a full 30° rotation), such that the mouse performance was not disrupted. No previous training was required for the mice to perform these rotation blocks, and there was minimal interference with the ability of the mice to alternate task blocks as the sudden presence or absence of a stimulus in between the two cues in the WM task remained an abrupt indicator of a task block switch. A typical session involved alternating between switching the task that the mice were performing and rotating the stimuli that the mice were seeing, such that the −15° and +15° oriented stimuli served as either the cues or the targets in both the Discrimination and the WM tasks, being matched in orientation across rotation blocks.

### Optogenetic inactivation of multiple cortical areas

To silence neuronal activity during behaviour (Fig. 1), we optogenetically activated ChR2-expressing inhibitory interneurons using a 473 nm laser (OBIS, Coherent) with a galvanometer scanning photostimulation system37. In brief, laser light was reflected off of two galvanometer scanning mirrors to target the light, expanded by two plano-convex lenses (5× magnification; LA1951-A and LA1384-A, Thorlabs) and then focused onto the brain with a 200 mm focal-length lens (AC508-200-A, Thorlabs). A polarizing beamsplitter was placed in the light path, enabling us to simultaneously image the surface of the skull (camera, 22BUC03, ImagingSource) to identify and select locations for cortical inactivation. The photostimulation and image acquisition were controlled by custom LabVIEW software and a data acquisition card (PCIe-6321; National Instruments). The laser light was pulsed at 50 Hz, with a 50% duty cycle. The laser power was set to 3 mW average (6 mW peak power) for the first 400 ms of stimulation and then linearly tapered off to 0 mW over 200 ms to minimize activity-rebound effects. The propagation of reflected light to the eyes of the mouse was blocked by either a cement wall around the visible skull or a custom 3D-printed plastic lightshield implanted during the headplate surgery. Silencing occurred in 12% of trials, at one of three epochs; the onset of the delay, the delay end (600 ms before stimulus onset) or the onset of the stimulus. Because silencing at the end of the delay was difficult to interpret, as the mice could use the silencing to predict the stimulus onset and respond pre-emptively, we discarded delay end silencing trials from all of our analyses. The cortical area to be silenced was chosen randomly trial-to-trial, and was identified either by the coordinates relative to bregma for areas M2 and S1, or by intrinsic signal imaging for areas V1 and AM.

A 470 nm masking light, emitted from an optical fibre (FT400EMT; Thorlabs) coupled to an LED (M470F3; Thorlabs), placed 20 cm above the mouse (roughly in line with the laser light path), diffusely illuminated the head of the mouse (2 mW at the fibre tip). The masking light was flashed on each trial in the same manner as the optogenetic silencing light (400 ms plus 200 ms ramp down), at one of the three onset times (delay onset, delay end or stimulus onset), chosen randomly on control trials and at a matched onset to the optogenetic silencing light in silencing trials. This masking light therefore had the same dynamics as the laser light, and was used to both mask the presence of the laser light during the silencing trials and as a negative control for possible light-onset-induced behavioural changes during the control trials. The masking light alone (that is, during the control trials) had no effect during the 600 ms of masking light presentation, in either the Discrimination or the WM task, and at either of the onset times, on running speed (n = 9 mice, P > 0.05 for all onset times and tasks, two-sided signed-rank test) or stimulus responses (n = 9 mice, P > 0.05 for all onset times and tasks, two-sided signed-rank test).

### Two-photon calcium imaging of cell-body populations

For the cell-body imaging experiments (Figs. 2 and 3), we imaged the calcium dynamics in layer 2/3 cells of areas AM and M2 simultaneously using a wide field of view two-photon microscope72. The surface blood vessel pattern above the imaging sites was compared with the blood vessel pattern from the intrinsic signal imaging maps to confirm the location of area AM. Fields of view over each area were 600 µm × 600 µm and spread over four axial planes 50 µm apart. Frames from all eight fields of view were acquired at 4.68 Hz. The image acquisition software was ScanImage73. Two cameras (22BUC03, ImagingSource) were positioned to acquire greyscale videos of the body and left pupil at 30 Hz. The visual stimulation display was turned off during the linear phase of the resonant scanners corresponding to the image acquisition (12 kHz), so as to avoid display light spill-through into the imaging frames.

The imaging data were pre-processed using modified CaImAn software74. In brief, cell masks were identified as point-seeds at individual cell locations by the experimenter, using the registered mean frame image as well as a pixel-surround correlation image. The CaImAn cell segmentation and neuropil demixing algorithms (based on constrained non-negative matrix factorization) were then applied to the seeds to define the mask boundaries and extract the calcium time series from individual masks. A second round of experimenter-mediated curation was performed on these masks, and the calcium time series were re-extracted. The calcium time series were then detrended, normalized (ΔF/F0) and deconvolved using the standard CaImAn algorithms (FOOPSI75). For all data for which the raw ΔF/F0 activity is shown, the underlying statistical analyses (for example, estimating the latencies of delay responses for Fig. 2e,h and Extended Data Fig. 5a,b) were done on the deconvolved calcium activity. For all other statistical and population analyses, only deconvolved calcium activity was used. Imaging frames with low correlations to the average image (putative movement artefacts), or significant pupil movements (greater than five standard deviations from the mean), were discarded. Finally, individual cells were further curated using local neuropil correlations, signal-to-noise ratio and the number of calcium events, to identify cells with sufficient levels of activity for analysis, resulting in an average of 311 ± 57 active cells per area AM experiment, and 309 ± 69 active cells per area M2 experiment.

### Two-photon calcium imaging for axonal imaging and simultaneous optogenetic silencing

For the feedback imaging and local silencing experiments (Figs. 4 and 5), we imaged the axonal calcium signals with a custom-built two-photon microscope. We acquired two planes 25 µm apart in layer 1 of area AM (n = 4 mice) or area M2 (n = 3 mice), with a field of view of 400 × 400 µm at a frame rate of 22.78 Hz. Two cameras (22BUC03, ImagingSource) were used to record the pupil and body positions at 30 Hz. For each imaging site, we also recorded a volumetric image stack to confirm the location of tdTomato-ChrimsonR transduced PV+ cells directly underneath the recorded axons.

The imaging data were registered and pre-processed using a modified Suite2p pipeline76. The data were registered, bouton masks were extracted, and their calcium traces were baseline-subtracted. F0 normalization was not performed owing to the very low baseline levels of fluorescence. Frames with low correlations to the registered average image or frames with significant eye movements were discarded. The boutons’ time-series data were then clustered into putative axons using custom scripts written in MATLAB (MathWorks). In brief, we used independent component analysis (ICA) to extract a 40-dimensional temporal feature space from the full dimensional time series. The activity of all boutons, projected into this feature space, was then clustered using a Gaussian mixture model. The number of clusters was chosen by minimizing an adjusted Akaike information criterion error. Boutons with significant distances from their allocated cluster centre were not clustered, and all other boutons were clustered together by simply averaging their signals. This clustering procedure returned the activity time series of putative axons, each averaging eight boutons, which were then used for all analyses.

Optogenetic silencing of the area targeted by the feedback axons was achieved by stimulating the PV+ ChrimsonR-expressing cells immediately underneath the imaging site. A 637 nm laser (OBIS, Coherent) was relayed through a 400 µm-diameter optical fibre to a 100 mm focal-length lens, which then relayed the light onto the back aperture of the objective. The optogenetic laser power, measured immediately in front of the objective, was 6 mW (average, 12 mW peak power), pulsed at 60 Hz with a 50% duty cycle. Optogenetic silencing occurred in 15% of trials, during which the light was introduced at the onset of the delay period at full power for 400 ms, and then linearly ramped down to 0 mW over the following 200 ms. The optogenetic laser and the visual stimulation display were turned off during the linear phase of the resonant scanner (12 kHz), so as to avoid light spill-through during ongoing imaging frame acquisition.

### Data analysis

Trials in which mice stopped running or licked during the inter-stimulus delay period (Extended Data Fig. 3b), trials following either targets or probes (that is, the trials that were 100% probable to be cues), and trials in which optogenetic silencing occurred at the end of the delay period (see above) were excluded from all analyses. All optogenetic silencing trials were excluded from analyses that characterized the behaviour (Fig. 1b–f and Extended Data Fig. 2). For the d′ analyses of per-mouse delay duration effects (Fig. 1e), positive infinities (that is, when no misses occurred) were treated as non-existent data points for statistical analysis. d′ was defined as:

$${d}^{{\prime} }={\phi }_{({\rm{Hit}}\;{\rm{rate}})}^{-1}-{\phi }_{({\rm{FA}}\;{\rm{rate}})}^{-1},$$

in which φ is the Gaussian cumulative distribution function.

Statistical analyses of optogenetic inactivation effects (Fig. 1i and Extended Data Fig. 4) were done by pooling trials from nine mice (n = 173,432 trials) and performing a Fisher’s exact test, separately for cue, probe and target trials, and split by task. Significance levels were accordingly adjusted for multiple comparisons. Bar plot values were the trial-averaged optogenetic silencing effects subtracted from the averages of the control trials (in which no silencing occurred), and error bars represent the 95% CI of the silencing trials (that is, binomial confidence intervals).

For the imaging experiments (Figs. 2–5), although the inter-stimulus delay periods ranged from 0 to 4 s as in the behaviour and optogenetics dataset (Fig. 1), the lower numbers of trials available within each individual imaging session led to there being too few long delay duration trials to be used for neural activity analysis (owing to the exponential distribution of delay durations). As such, all analyses were limited to delay durations ranging from 0 to 3.2 s.

As comparisons of neural activity between tasks were made across rotation blocks (Extended Data Fig. 1b), if both rotation blocks were present in both tasks within a single session, individual experiments consisted of the Discrimination and WM task blocks with the matched task stimuli (+15° or −15°) that occurred during opposite rotation blocks (that is, there were up to two experiments per session). If only one task stimulus was common to both tasks (for example, if only one task switch and stimulus rotation occurred), experiments were simply the full imaging sessions. All subsequent analyses of neural activity (Figs. 2–5) were conducted on such experiments. For depictions of single-cell responses (Fig. 2), if there were two experiments within a single session, the second experiment within the session was discarded so as to not depict the same cells multiple times.

In the cell-body imaging experiments, for analyses limited to delay- or stimulus-responsive cells (Fig. 2b,d,e,h and Extended Data Fig. 5a,b), we defined delay or stimulus responsiveness as exceeding an effect size threshold (0.2 deconvolved ΔF/F0 difference post- versus pre-delay or -stimulus) and being significantly different post- versus pre-delay or -stimulus onset (two-sided paired-sample t-test; α = 0.01). For axonal imaging data, we likewise restricted analyses to axons that had a significant amount of delay-evoked activity, defined as 0.2 z-scored ΔF more in any one second of the delay than the last second of the preceding stimulus with a α = 0.01 significance difference. For the analyses of the latency of single-cell responses during the delay (Fig. 2e,h and Extended Data Fig. 5a,b), all odd-numbered trials were taken out and used to estimate the response latencies (by taking the mean of Gaussian curves fit to the trial-averaged responses), and all of the remaining (even) trials were split by task and averaged for display.

For the analysis of low-dimensional neural dynamics (Fig. 2f,g,i,j), the activity (deconvolved ΔF/F0) of all cells was pooled across all experiments. First, we trial-averaged the delay and stimulus responses of all active cells in all experiments, concatenated the resulting delay and stimulus responses and calculated the PCs of these responses (that is, of the pooled pseudo-population of cells). We then separately projected the trial-averaged Discrimination task and WM task activities of all cells into the first three PCs. To plot the resultant activity dynamics (Fig. 2f,i), we further separated trials by the length of their delay period, and then interpolated and smoothed the resulting activity projections with a half-normal filter (that is, causal; σ = 100 ms) to help with visualization. The respective statistical analyses (that is, the Euclidean distances between projections; Fig. 2g,j) were performed using all trials with no interpolation or smoothing.

For all of the population analyses (Figs. 3 and 4), we identified the task or cue coding dimensions (CDTASK and CDCUE, respectively) by fitting a simple linear model (using LDA) to the condition-specific (condition being the task or cue identity of each trial) delay-averaged population activity (deconvolved ΔF/F0) within each experiment (that is, a cells × trials matrix describing the activity of each cell averaged over each trial’s delay period). The coding dimensions were defined as the vectors that separated the population activity during the delay periods of the Discrimination and WM tasks (CDTASK), or the delay periods after the two cues in the WM task (CDCUE). The coding dimensions were not orthogonalized. Incorrect trials and trials with optogenetic silencing were excluded when calculating these coding dimensions. We used the following formula to identify the discrimination vectors:

$${{\rm{CD}}}_{\overrightarrow{ab}}={\hat{\sum }}^{-1}({\mu }_{a}-{\mu }_{b})$$

$$\hat{\sum }=\sum +I\gamma$$

in which a and b are the trial conditions (the task or cue), Σ is the cells’ covariance matrix (that is, of the cells × trials matrix) and γ is a regularization parameter. γ was set to a low value (1 × 10−4), and served to stabilize matrix inversion; changing the value of γ did not change the results significantly. Using other linear binary classifiers (for example, logistic regression) to identify these coding dimensions achieved very similar results. For Fig. 3b and Extended Data Figs. 5c–n and 7, the PCs were calculated from single trials, concatenated in time, from all data that were nominally used for analysis (that is, the first trial after a probe or a target and trials during the stimulus rotation periods were excluded; see above).

All reported task or cue decoding accuracies were the average cross-validation (leave-one-out) test accuracies, calculated by averaging each trial’s prediction of task or cue given the coding dimensions derived from the respective experiment’s remaining trials (that is, one classification accuracy was derived per experiment). All projections of the neural population activity onto the respective coding dimensions (for example, Figs. 3c,f,i,l and 4e,k) are likewise the projections of the activity of left-out single trials onto the coding dimensions calculated from their respective experiment’s remaining trials. The decoding accuracies of the training sets are reported in Extended Data Fig. 7. Importantly, the reported decoding accuracies for incorrect trials (Fig. 3e,h,k,n), optogenetic silencing trials (Fig. 4e,f,k,l) and Discrimination task CDCUE trials (Extended Data Fig. 9a–h), which were excluded from the training sets, were calculated using the same models as those used for the reported decoding accuracies of the (left-out) correct and non-silenced CDTASK and CDCUE trials.

For the analyses decoding the task or cue before correct or incorrect behavioural responses (Fig. 3e,h,k,n), instead of projecting the average delay activity of a trial onto the coding dimensions to identify that trial’s score, we instead averaged five randomly sampled imaging frames (1,068 ms of data) from the delay. This was done to eliminate any potential confounds introduced by the fact that longer delay period trials have a higher signal-to-noise ratio (that is, more frames to average) as well as a higher probability of preceding a false alarm during the WM task (Fig. 1c). Similar results were attained without this procedure, or by averaging the first five frames of each trial’s delay period.

### Reporting summary

Further information on research design is available in the Nature Research Reporting Summary linked to this paper.