## Abstract

Molecular Nanomagnets may enable the implementation of qudit-based quantum error-correction codes which exploit the many spin levels naturally embedded in a single molecule, a promising step towards scalable quantum processors. To fully realize the potential of this approach, a microscopic understanding of the errors corrupting the quantum information encoded in a molecular qudit is essential, together with the development of tailor-made quantum error correction strategies. We address these central points by first studying dephasing effects on the molecular spin qudit produced by the interaction with surrounding nuclear spins, which are the dominant source of errors at low temperatures. Numerical quantum error correction codes are then constructed, by means of a systematic optimization procedure based on simulations of the coupled system-bath dynamics, that provide a striking enhancement of the coherence time of the molecular computational unit. The sequence of pulses needed for the experimental implementation of the codes is finally proposed.

## Introduction

Reliable quantum computation demands the adoption of strategies to protect the information being processed from external noise, i.e., of quantum error correction (QEC) schemes^{1}. At the same time, while the ultimate quantum computer is expected to host QEC routines based on abstract, system-independent error models, the modern pioneering era of noisy intermediate-scale quantum devices^{2,3} calls for strategies tailored for the specific physical hardware utilized.

In their essence, QEC algorithms achieve information protection by suitably encoding an elementary two-state computational unit, a logical qubit, into a larger Hilbert space. This permits one to distinguish, and thus detect, different error occurrences without corrupting the information so that it is then possible to retrieve it^{4}.

While traditional QEC approaches realize the extra space by exploiting registers of many physical two-level systems, alternative routes to QEC have emerged wherein a logical qubit is hosted by a single many-level system (*multi-level* or *qudit* encodings)^{5,6,7,8,9,10,11,12,13,14,15,16}. The first advantage of the latter strategy is to prevent an overhead of physical units necessary to implement the code. Also, the manipulation of single or of pairs of logical qubits can be much easier, since they do not require controlling multiple physical objects at once^{17}. Moreover, the same multi-level object can provide protection against different types of errors^{12,15}.

A very promising architecture for the implementation of multi-level encodings is given by molecular nanomagnets^{13,16,18}. Indeed, these highly coherent systems^{19,20,21,22,23,24,25,26,27} offer many accessible spin levels^{28,29,30,31}, which can be manipulated with high accuracy through electromagnetic pulses, and they can be chemically engineered to meet desired requirements^{32,33,34,35,36,37,38,39,40,41,42,43,44}.

The most important error in molecular spin systems at low temperature is given by pure dephasing, that is, the suppression of coherence between different spin states. Such a decoherence mechanism originates principally from the hyperfine interaction of the central (electronic or nuclear) molecular spin with the bath of surrounding nuclear spins^{45,46,47}. Except from specific situations^{48}, decoherence of a central spin induced by a nuclear spin bath is known to produce non-exponential decay behaviour^{19,45,47,49,50,51,52,53}. This is due to many factors, such as non-negligible entanglement building up between the spin and an evolving bath, the limited number of nuclear spins (~10^{2}) usually surrounding the molecular spin \({{{\mathcal{S}}}}\), the slow relaxation timescales of the bath relative to the motion of the central spin. Although mandatory to design targeted codes, a QEC framework that takes into account both the multi-level nature of a spin *S* larger than 1/2 and the explicit structure and dynamics of the nuclear spin bath is still missing.

In this work, we develop a class of numerical spin qudit codes which are designed based on a detailed microscopic structure of the environment responsible for errors and which provide a strongly enhanced correction efficiency. Moreover, the sequence of control pulses and measurements needed for an experimental implementation of such codes is discussed. While the advantage of these codes as compared to a simple spin 1/2 is evident already using small *S*, the performance strikingly improves as qudits with larger spin are used, thus positively exploiting more and more available levels in the molecular spectrum.

The codes are derived by first analyzing the decoherence effects experienced by a qudit spin *S* > 1/2 embedded into a realistic nuclear spin bath, by means of numerical simulations of the coupled qudit-bath dynamics through a cluster-correlation expansion (CCE)^{54}. A systematic procedure is then put forward to capture the spin-dephasing process by means of error operators acting on the system, which is then used to derive optimized codewords for QEC. Thanks to the flexibility of the procedure, the numerical codes can be optimized taking into account the specific timescale of free evolution admitted between two subsequent QEC cycles, thus allowing one to largely reduce the number of correction steps sufficient to ensure a desired fidelity. As such, they are an optimal candidate for realizations in near-term devices, in which the implementation of the QEC can be noisy and can take relatively long times.

## Results

### Physical system and decoherence mechanisms

The system analyzed in the following is a molecular electronic spin \({{{\mathcal{S}}}}\) (sketched in Fig. 1), described by the Hamiltonian \({\hat{H}}_{{{{\mathcal{S}}}}}=D{\hat{S}}_{z}^{2}+{{\Omega }}{\hat{S}}_{z}\). Here, \(\{{\hat{S}}_{x},{\hat{S}}_{y},{\hat{S}}_{z}\}\) are spin *S* > 1 operators, with eigenstates of \({\hat{S}}_{z}\) being defined by \({\hat{S}}_{z}\left|m\right\rangle =m\left|m\right\rangle\). The parameter *D* indicates the zero-field splitting (assumed to be axial, for simplicity) and Ω = *g*_{z}*μ*_{B}*B*_{z}, with *g*_{z} the longitudinal *g*-factor and *μ*_{B} the Bohr magneton, characterizes the Zeeman interaction with a static magnetic field along the *z-*direction. The analysis developed here can apply both to a qudit given by a single spin-*S* ion and to a giant spin originating from the strong exchange interactions between different ions^{55}. Also, while we focus here on the case of an electronic qudit, the same treatment can also be applied to a nuclear qudit with small adaptations commented in “Methods”.

For a molecular electronic spin \({{{\mathcal{S}}}}\) at low temperature, the hyperfine coupling with the surrounding nuclear spin bath is the dominant source of decoherence. Indeed, as typically done in quantum computing platforms, we assume to work at temperatures much smaller than the relevant energy scales of the qudit (\({{\Omega }},D{k}_{{{{\rm{B}}}}}^{-1} \sim\) K), such that the thermal population of the excited states is negligible. In these conditions, phonon absorption is very unlikely. At the same time, the qudit energy gaps are much smaller than the Debye energy (typically in the ≳50 K range), thus making also resonant phonon emission (whose probability scales as the third power of the gap) negligible^{56}. In general, the effect of spin-phonon coupling on the system dynamics can be calculated from diagonalization of the rate matrix^{56}, yielding a decay of both diagonal and off-diagonal elements of the system density matrix (associated to relaxation and dephasing, respectively) on related time-scales. In particular, phonon-induced dephasing is limited by the relaxation time *T*_{1}. A body of experiments on molecular spin qubits and qudits^{29,40,57} demonstrate that this is not the case at low temperature, where *T*_{1} increases exponentially and becomes several orders of magnitude longer than the dephasing time. Hence, at low temperature phonons are not responsible for pure dephasing on the spin system and other mechanisms come into play.

Spin dipole−dipole interactions between electronic spins can have an important effect in concentrated samples, but this is strongly reduced if the magnetic centres are diluted in a diamagnetic matrix^{21} and are not relevant here because we consider a perspective architecture consisting of a single (or a few) molecular unit^{46,58}.

We, therefore, focus on the bath \({{{\mathcal{B}}}}\) of nuclear spins surrounding \({{{\mathcal{S}}}}\). The number of nuclear spins in the bath may range from a few tens to a few hundreds in realistic molecular complexes, thus being rather far from the infinite-bath limit underpinning typical Markovianity approximations. By working in the so-called ‘coherence window’^{59}, in which the system energy gaps are much larger than the gaps of the nuclear spin bath, off-diagonal operators inducing population transfer on the system can be neglected. The system-bath dynamics can be described in this regime by effective spin Hamiltonians featuring only a diagonal coupling between \({{{\mathcal{S}}}}\) and the bath, which are derived via perturbation theory. This type of Hamiltonians has been studied in the context of a (pseudo)spin *S* = 1/2 interacting with a nuclear spin bath^{6,45,60}. In “Methods”, we deduce an effective Hamiltonian for the dynamics of a generic spin *S* > 1/2. In interaction picture with respect to \({\hat{H}}_{{{{\mathcal{S}}}}}\) and to first order in Ω^{−1}, this Hamiltonian is of the form

Both the intrinsic and the qudit-conditioned Hamiltonians \({H}_{{{{\mathcal{B}}}}}^{(k)}\) of the bath can be written in the general form

where \(\{{\hat{I}}_{k}^{x},{\hat{I}}_{k}^{y},{\hat{I}}_{k}^{z}\}\) are spin operators for the *k*-th nuclear spin of the bath and \({\hat{I}}_{k}^{\pm }={\hat{I}}_{k}^{x}\pm {{{\rm{i}}}}{\hat{I}}_{k}^{y}\). The coefficients \({a}_{n,m}^{(k)},{b}_{n,m}^{(k)},{c}_{n,m}^{(k)},{d}_{n,m}^{(k)}\) are a function of the hyperfine couplings between \({{{\mathcal{S}}}}\) and \({{{\mathcal{B}}}}\), the nuclear spin−spin dipolar couplings, and Ω. In the following, nuclear spins are assumed to be protons (*I* = 1/2), since hydrogen nuclei typically represent the major decoherence source. Other relevant parameters and details on the simulations are given in “Methods”.

System-bath entanglement, generated by the Hamiltonian of Eq. (1), can be interpreted in terms of ‘which-way information’ accumulated in the state of the nuclear spins: depending on the state \(\left|m\right\rangle\) of \({{{\mathcal{S}}}}\), the bath undergoes different interacting evolutions described by Hamiltonians \({\hat{H}}_{{{{\mathcal{B}}}},m}=\left\langle m\right|\hat{H}\left|m\right\rangle\). These conditioned bath evolutions result in a decay of coherences in the system density matrix \({\rho }_{{{{\mathcal{S}}}}}(t)\), according to \(\left\langle n\right|{\rho }_{{{{\mathcal{S}}}}}(t)\left|m\right\rangle ={L}_{nm}(t)\left\langle n\right|{\rho }_{{{{\mathcal{S}}}}}(0)\left|m\right\rangle\). The function \({L}_{nm}(t)={{{\mbox{tr}}}}_{{{{\mathcal{B}}}}}\left[{{{{\rm{e}}}}}^{-{{{\rm{i}}}}{\hat{H}}_{{{{\mathcal{B}}}},n}t}{\rho }_{{{{\mathcal{B}}}}}(0){{{{\rm{e}}}}}^{{{{\rm{i}}}}{\hat{H}}_{{{{\mathcal{B}}}},m}t}\right]\), with \({\rho }_{{{{\mathcal{B}}}}}(0)\) the initial bath state, is computed numerically in the following through a CCE^{54,61}.

In a free-decay experiment, the main decoherence process is given by inhomogeneous broadening^{49}. The system-bath diagonal coupling \({a}_{n}^{(1)}{\hat{S}}_{z}{\hat{I}}_{k}^{z}\) has the effect of a classical random magnetic field—the Overhauser field—on \({{{\mathcal{S}}}}\). Uncertainty in the actual bath state then produces, for the density matrix \({\rho }_{{{{\mathcal{S}}}}}(t)\) of the qudit, a Gaussian decay for the single transition coherence,

with \({{{\Gamma }}}^{2}={\sum }_{k}{({a}_{n}^{(1)})}^{2}/4\) (see “Methods”), over timescales much faster than those set by the nuclear spin−spin interaction. This is shown in Fig. 2, where the squared fidelity \({{{{\mathcal{F}}}}}_{S}^{2}(t)\) with respect to the initial state, with \({{{{\mathcal{F}}}}}_{S}(t)={{{\mbox{tr}}}}_{{{{\mathcal{S}}}}}\sqrt{\sqrt{{\rho }_{{{{\mathcal{S}}}}}(t)}{\rho }_{{{{\mathcal{S}}}}}(0)\sqrt{{\rho }_{{{{\mathcal{S}}}}}(t)}}\)^{4}, is depicted for different spin *S*. The fidelity decays over timescales of hundreds of nanoseconds.

The dramatic effect of inhomogeneous broadening on the spin coherence is routinely compensated for in experiments by means of spin-echo/refocusing schemes, whose basic example is the Hahn echo. For different qudit spins, the echo dynamics is shown in Fig. 2b. The realization of the echo transformations is further described in ‘Practical Implementation’. The coherence decays over timescales of tens-to-hundreds of microseconds, signalling that the effect of inhomogeneous broadening is removed to a large extent. The decay is now due to the quantum dynamics of the bath, and is mainly determined by the contribution given by intra-bath interactions in \({H}_{{{{\mathcal{B}}}}}^{(0)}\), of the form \({c}_{n,m}^{(0)}{\hat{I}}_{n}^{+}{\hat{I}}_{m}^{-}\). If the latter were absent, the echo would recover unit fidelity independently from *S* over timescales of hundreds of microseconds, until virtual flip-flops described by the terms of type \({c}_{n,m}^{(1)}{\hat{S}}_{z}{\hat{I}}_{n}^{+}{\hat{I}}_{m}^{-}\) set in. This effect is still partially visible in Fig. 2b in the fact that for short timescales with respect to interactions in \({H}_{{{{\mathcal{B}}}}}^{(0)}\), the fidelity exhibits almost overlapping decay for different *S*.

### Optimized qudit encoding

While increasingly sophisticated echo pulse sequences can recover the effect of inhomogeneous broadening to a better and better degree, the spin coherence remains irremediably affected by the interacting quantum dynamics of the bath. We derive in the following qudit QEC codes as a means to protect the system from these effects. In particular, we develop a framework for designing optimal numerical codes, which are based on the detailed description of the system-bath dynamics adopted in this work.

A QEC code can be defined by following two fundamental steps. The first step is to identify error operators \({\hat{E}}_{k}\) which describe the effect of the noise source on the system, i.e., such that the state of \({{{\mathcal{S}}}}\) at time *t* can be related to the initial state through

The second step is the derivation of computational states \(\left|{0}_{L}\right\rangle\) and \(\left|{1}_{L}\right\rangle\) that satisfy Knill−Laflamme conditions for QEC^{62}, namely, for all *k* and *j*,

These conditions demand that, when errors \({\hat{E}}_{k}\) affect an initial state \(\left|{\psi }_{L}\right\rangle =\alpha \left|{0}_{L}\right\rangle +\beta \left|{1}_{L}\right\rangle\), the codewords are modified but the corresponding coefficients *α* and *β* are not, and the information they carry is thus preserved. Moreover, errors do not create ambiguity between \(\left|{0}_{L}\right\rangle\) and \(\left|{1}_{L}\right\rangle\): error words \({\hat{E}}_{k}\left|{w}_{L}\right\rangle\) span subspaces that are orthogonal to each other for different *w* = 0, 1.

If these conditions are fulfilled, then different errors \({\hat{E}}_{k}\) can be distinguished, detected, and corrected. In practice, a measurement is devised whose outcome discriminates the error occurrence and a recovery operation restores the initial state. Importantly, the 2*S* + 1 levels of a spin *S* offer enough state space to detect and correct a number *N*_{corr} = ⌊*S*⌋ of error operators \({\hat{E}}_{k}\)^{13}, where ⌊*S*⌋ indicates the largest integer smaller or equal than *S*. Given that a decomposition of the form (4) involves, in general, a larger number of \({\hat{E}}_{k}\), it is essential to identify the *N*_{corr} error operators which have a stronger effect, such that the code can be tailored for them ensuring optimal correction.

For the spin-dephasing scenario considered here, a decomposition of the form (4) with exact error operators is not known, thus preventing a derivation of adequate codewords for this type of noise. In order to overcome this limitation, we introduce an iterative numerical optimization procedure which, given \({\hat{\rho }}_{{{{\mathcal{S}}}}}(0)\) and \({\hat{\rho }}_{{{{\mathcal{S}}}}}(t)\) computed through CCE, aims at determining a number *N*_{corr} of operators \({\hat{E}}_{k}\) by decreasing contribution to \({\hat{\rho }}_{{{{\mathcal{S}}}}}(t)\). Starting from \({\hat{\rho }}_{{{{\mathcal{S}}}}}^{(0)}\equiv {\hat{E}}_{0}{\hat{\rho }}_{{{{\mathcal{S}}}}}(0){\hat{E}}_{0}^{{\dagger} }\), the *n*-step estimate \({\hat{\rho }}_{{{{\mathcal{S}}}}}^{(n)}\) to \({\hat{\rho }}_{{{{\mathcal{S}}}}}(t)\) of the iteration is defined according to

At the *n*-th step, the distance \(\parallel {\rho }_{{{{\mathcal{S}}}}}(t)-{\rho }_{{{{\mathcal{S}}}}}^{(n-1)}\parallel\) (here, ∥ ⋅ ∥ is the Hilbert−Schmidt norm) is numerically minimized in order to find optimal parameters for a parametrized form or \({\hat{E}}_{n}\) (specified in the following), and the outcome is used for the subsequent step of the iteration. If a hierarchy of \({\hat{E}}_{k}\) exists, a successful optimization will return error operators which give less and less contribution, in the norm, to the density matrix. In this sense, the numerical procedure then leads to an optimal decomposition of \({\hat{\rho }}_{{{{\mathcal{S}}}}}(t)\) in the form (4).

From the structure of the system-bath Hamiltonian \(\hat{H}\) of Eq. (1), it follows that \({\rho }_{{{{\mathcal{S}}}}}(t)\) can be generically written in the form (4) with error operators that are diagonal in the basis of states \(\left|m\right\rangle\). Given that the Hilbert space of \({{{\mathcal{S}}}}\) is finite with dimension 2*S* + 1, the error operators \({\hat{E}}_{k}\) can be expanded onto a basis \(\{{\hat{D}}_{m}\}\) of 2*S* + 1 diagonal operators. Indeed, a diagonal matrix in this space can have at most 2*S* + 1 linearly independent entries. This justifies an expansion for the error operators of the form

The coefficients *E*_{k,m} are the free parameters for the numerical optimization. The basis \(\{{\hat{D}}_{m}\}\) is chosen in the following to be given by the projectors \({\hat{D}}_{m}=\left|m\right\rangle \,\left\langle m\right|\) over the \(\left|m\right\rangle\) states. Once the error operators are found, the codewords enabling their QEC are determined by imposing Knill−Laflamme’s conditions (5) numerically, as detailed in “Methods”. The codewords obtained from this procedure are depicted in Fig. 3a for values of spin from *S* = 3/2 to *S* = 9/2. By construction, \(\left|{0}_{L}\right\rangle\) and \(\left|{1}_{L}\right\rangle\) have support on different subsets of \(\left|m\right\rangle\) states in an alternate fashion. This automatically guarantees the fulfilment of Knill−Laflamme’s condition (6), reducing the number of free parameters for the numerical search required to impose the condition (5).

The performance of the optimized qudit codes is remarkable, as shown in Fig. 3, where the fidelity after the QEC is reported, for a set of codewords corresponding to different qudit spin *S*. In particular, for each time *t*, Fig. 3b represents the squared fidelity of the recovered state with respect to the encoded state, achieved by performing an instantaneous QEC at time *t*. In panel 3c, we report instead the infidelity \(1-{{{{\mathcal{F}}}}}_{S}^{2}(t)\) in log−log scale for an inset of panel (b). One can observe that, while a squared fidelity above 0.9 is maintained for a spin 1/2 only up to ~30 μs, the recovered fidelity is above that value for as long as ~40, 65, 240, and 300 μs for qudit spin *S* = 3/2, 5/2, 7/2 and 9/2, respectively. Similarly, the same spin values guarantee a recovered fidelity above 0.99 for up to ~15, 20, 29, and 37 μs, well longer than the spin 1/2, ~10 μs. The possibility to recover high fidelity even after rather long evolution times is a crucial resource for near-term implementations. Indeed, if the rate at which subsequent QEC cycles need to be done is too large, the advantage of the correction may get lost in a realistic implementation because of the non-negligible time necessary to implement all the measurements and recovery operations of the QEC step.

The substantial advantage in increasing the spin of the qudit is further emphasized in Fig. 4, where the gain with respect to the spin 1/2,

is reported as a function of time, for different values of the spin *S*. A remarkable maximal gain, larger than 10, is attained, e.g., for a spin 7/2 at around 60 μs, and a maximal gain around 15 is attained for *S* = 9/2.

Depending on the time at which the optimization is performed, rather different numerical codewords can be obtained, reflecting the interplay of different interaction scales in the system-bath Hamiltonian. However, broad temporal windows can be recognized, in which the codewords maintain essentially the same structure, while being quite different in two different regimes. Therefore, a given set of codewords maintains a stable performance if the QEC is implemented in a rather broad time interval around the optimization time. These features can be observed in Fig. 5a, where the gain as a function of time is shown for three different codeword pairs obtained by optimizing at times *t*_{opt} = 10, 50, 100 μs for *S* = 3/2. As expected, while a unique pair giving the largest gain at all times cannot be found, codewords optimized at a given time provide very good performance in a rather large region around that time. We have finally checked that the performance of the numerically optimized codewords does not critically depend on the initial state chosen for our procedure, as demonstrated in Fig. 5b for the exemplary case of *S* = 3/2. The squared fidelity (colour scale) as a function of time (radial scale) is reported for different values of the angle *θ* (angular scale) characterizing an initial state of the form \(\cos (\theta )\left|{0}_{L}\right\rangle +{{{\rm{i}}}}\sin (\theta )\left|{1}_{L}\right\rangle\). Large fidelities are attained for all initial states, with fidelity increasing as one departs from the state with equal weights [*θ* = *π*/4], that is, the most decoherence-prone state, used in the other reported simulations.

### Practical implementation

Having analyzed the ideal efficiency of the optimized qudit codes, we now turn to a discussion of how to implement in practice all the steps of the QEC procedure, namely encoding, detection, and recovery, whose formal description is given in “Methods”. The manipulation of a spin *S* > 1/2 system requires of course more complex control sequences compared to a spin *S* = 1/2. Nonetheless, it can be realized in a total time sufficiently short so that it does not significantly impact the efficiency of the ideal QEC, as detailed in the following.

The population transfers required among spin states can be realized using sequences of resonant microwave/radiofrequency pulses. These are described in the Hamiltonian by time-dependent control fields of the form \({g}_{y}{\mu }_{{{{\rm{B}}}}}{B}_{y}(t)\cos (\omega t){\hat{S}}_{y}\) where the envelope *B*_{y}(*t*) is typically rectangular or Gaussian. These pulses induce transitions from a spin state \(\left|m\right\rangle\) to \(\left|m\pm 1\right\rangle\) when *ω* is set at the corresponding transition frequency, implementing a two-state unitary rotation \({Y}_{m}(\theta )=\exp [\theta /2(\left|m+1\right\rangle \left\langle m\right|-\left|m\right\rangle \left\langle m+1\right|)]\) between states \(\left|m\right\rangle\) and \(\left|m+1\right\rangle\) of an arbitrary angle *θ*. All the steps of the QEC are illustrated in the following, and the explicit realization for a *S* = 5/2 qudit code is depicted in Fig. 6. The implementation proposed here generalizes the one proposed for spin-binomial codes^{13}.

#### Encoding

We assume that the information, i.e., the coefficients *α* and *β*, is initially encoded in a simple state such as \(\alpha \left|-1/2\right\rangle +\beta \left|1/2\right\rangle\). The preparation of the logical state \(\alpha \left|{0}_{L}\right\rangle +\beta \left|{1}_{L}\right\rangle\) for arbitrary *α* and *β* is then realized by alternating pulses *Y*_{m}(*θ*) distributing population among the different \(\left|m\right\rangle\) states and *π*-pulses *Y*_{m}( ± *π*) which rearrange the different populations in the correct order. The angles *θ* of the two-level rotations are fully determined by the components of the code-words on each \(\left|m\right\rangle\) state. The explicit sequence for *S* = 5/2 is given in panel ‘encoding’ of Fig. 6a with the angles given in Table 1. Once the state has been codified, the system is left to decay freely for a time *t*/2, then a spin-echo pulse sequence is performed, and the QEC finally takes place at time *t* starting with the error detection. These pulse sequences can also be used to perform single-qubit gates between the code-words, for instance by first re-mapping the code-words to, e.g., \(\left|\pm 1/2\right\rangle\) states, performing the desired two-state operation, and re-encoding.

#### Spin echo

The Hahn echo for a spin 1/2 can be understood as a magnetic pulse along *x* or *y* which effectively flips the spin. Then, the spin can be viewed as effectively evolving with \(\hat{H}\) for a time *t*/2 and with the same Hamiltonian but with \({\hat{S}}_{z}\) changed to \(-\hat{{S}_{z}}\) for an equal time *t*/2, where *t* is the time at which the QEC is performed. Similarly, the echo scheme is extended here to a larger spin *S* > 1/2 by considering a ‘generalized-pulse’ transformation of the form \({U}_{{{{\rm{echo}}}}}={{{{\rm{e}}}}}^{-{{{\rm{i}}}}\pi {\hat{S}}_{x}}\) at time *t*/2 which inverts the spin, sending state \(\left|m\right\rangle\) to \(\left|-m\right\rangle\). This transformation can be realized with a sequence of *S* + 1/2 (for half-integer *S*) resonant *π*-rotations along *x* or *y*, coupling pairs of \(\left|m\right\rangle \leftrightarrow \left|-m\right\rangle\) states, followed by *Y*_{m}(±*π*) pulses to rearrange populations. For instance, in the case of a spin 5/2, *U*_{echo} is obtained by three independent rotations \(\left|5/2\right\rangle \leftrightarrow \left|-5/2\right\rangle\), \(\left|3/2\right\rangle \leftrightarrow \left|-3/2\right\rangle\) and \(\left|1/2\right\rangle \leftrightarrow \left|-1/2\right\rangle\). Due to the lack of a direct matrix element between \(\left|m\right\rangle\) and \(\left|-m\right\rangle\) in the architecture considered here, each of these Δ*m* > 1 transformations needs to be decomposed into Δ*m* = ±1 transitions. This is done, for instance, using the strategy discussed in “Methods-Pulse sequences”.

#### Detection

To realize the error detection, two additional ingredients are introduced in the system considered until now. The first one is a weak coupling of the qudit to a spin *s*_{A} = 1/2 ancilla. The ancilla is described by adding to the Hamiltonian of Eq. (12) the terms

where \(\{{\hat{s}}_{A}^{x},{\hat{s}}_{A}^{y},{\hat{s}}_{A}^{z}\}\) are spin-1/2 operators for the ancilla. The first term in Eq. (10) describes the Zeeman coupling of the ancilla to the static magnetic field whilst the second one describes the ancilla-qubit coupling parametrized by the tensor \({\mathbb{J}}\). For \({{\mathbb{J}}}_{x,y}\ll | {{\Omega }}-{{{\Omega }}}_{A}|\), such that states of qudit and ancilla remain essentially factorized, the excitation energies of the ancilla \({{{\Delta }}}_{A}^{(m)}\) depend on the state \(\left|m\right\rangle\) of the qudit via the diagonal coupling \({{\mathbb{J}}}_{z}{\hat{s}}_{A}^{z}{\hat{S}}_{z}\) only, i.e.,

By irradiating the ancilla with a resonant magnetic pulse at angular frequency \({{{\Delta }}}_{A}^{(m)}\) it is thus possible to selectively excite the ancilla only if the qudit is in state \(\left|m\right\rangle\). A subsequent measurement of the state of the ancilla then reveals whether the qudit state has support on \(\left|m\right\rangle\) or not. This mechanism will be exploited in the following to detect the different possible errors without corrupting *α* and *β*. Apart from this selective excitation immediately followed by a measurement, the ancilla is always in its ground state, and thus it does not affect the previously developed treatment of the qudit incoherent dynamics. For this reason, its coupling to the nuclear spins is also irrelevant for the present discussion.

The second ingredient is a coupling of the magnetic molecule to a microwave resonator. Crucial steps towards achieving the strong coupling between magnetic molecules and a resonator have been experimentally demonstrated recently^{63}. This coupling can then be exploited to measure the ancilla, building on techniques well developed in the field of circuit quantum-electrodynamics^{64,65,66} and adapted to Molecular Nanomagnets^{67,68}. The coupling of the molecule to the resonator induces a shift of the resonance frequency of the resonator which depends on the ancilla-qudit state. As explained below, this can be exploited to measure the state of the ancilla without collapsing the qudit state.

The error detection is described in an abstract setting by a projective measurement with the projector operators given in Eq. (25) of “Methods”. Given the difficulty to implement similar operators, that project into complex superpositions of system eigenstates, the detection is divided into two steps. In the first step, a sequence of pulses is performed which rotates the full basis of error words into the basis of \(\left|m\right\rangle\) states in both error spaces corresponding to \(\left|{0}_{L}\right\rangle\) and \(\left|{1}_{L}\right\rangle\) (see panel ‘basis rotation’ of Fig. 6 for *S* = 5/2)^{13}. This operation thus converts the detection of the projectors (25) into an easier-to-implement measurement in the \(\left|m\right\rangle\) basis, and the unitarity of the transformation ensures that *α* and *β* are preserved. At this point, every possible post-error state is of the form \(\alpha \left|m\right\rangle +\beta \left|m^{\prime} \right\rangle\) for different pairs of states \((\left|m\right\rangle ,\left|m^{\prime} \right\rangle )\).

We now aim to induce an excitation of the ancilla only for a superposition state of the qudit with components on \((\left|m\right\rangle ,\left|m^{\prime} \right\rangle )\), without collapsing the superposition. We achieve this by applying a two-tone two-photon drive at frequencies \({{{\Delta }}}_{A}^{(m)}\), \({{{\Delta }}}_{A}^{(m^{\prime} )}\) (panel ‘ancilla measurement’ of Fig. 6)^{69}. Then, in the dispersive limit, the coupling *G* between resonator and ancilla induces a shift of the cavity angular frequency *ω*_{c} of ±*G*^{2}/*δ*^{m}, with \({\delta }^{m}={{{\Delta }}}_{A}^{(m)}-{\omega }_{c}\) and the sign of the shift depending on the state of the ancilla^{64}. Since here we need to measure the ancilla irrespective of the state of the qudit in the subspace \((\left|m\right\rangle ,\left|m^{\prime} \right\rangle )\), a frequency-independent measurement of the state of the ancilla must be performed. Two different approaches to solve this same issue, by detecting the amplitude (but not the frequency) of the output field, are described in^{69}. The ancilla is then measured by exploiting its coupling to the resonator and the qudit wavefunction is projected onto such states. The sequence of measurements is then repeated probing each (mutually exclusive) pair of \((\left|m\right\rangle ,\left|m^{\prime} \right\rangle )\) states sequentially, returning a yes/no answer at each step if the system is found in the corresponding error state, and stopping if a positive outcome is obtained. Hence, there will be at most ⌊*S*⌋ measurements given that the number of possible errors for a qudit of spin *S* is ⌈*S*⌉, where ⌈*S*⌉ (⌊*S*⌋) indicates the smallest integer larger (largest integer smaller) or equal than *S*.

#### Recovery

After detection, the system has been projected into a superposition state of the form \(\alpha \left|m\right\rangle +\beta \left|m^{\prime} \right\rangle\) with known *m* and \(m^{\prime}\). The simplest way to restore the encoded state \(\alpha \left|{0}_{L}\right\rangle +\beta \left|{1}_{L}\right\rangle\) is then to first use a few *π*-pulses to send \(\left|m\right\rangle \to \left|1/2\right\rangle\) and \(\left|m^{\prime} \right\rangle \to \left|-1/2\right\rangle\), and then to repeat the pulse sequence which implements the encoding (panel ‘recovery’ in Fig. 6). Alternatively, one can save a few pulses by redesigning the encoding sequence starting from each possible pair \(\left|m\right\rangle\), \(\left|m^{\prime} \right\rangle\) resulting from detection.

#### Impact on performance

The non-instantaneous duration of the QEC procedure in a realistic implementation (during which information is *not protected*), together with related potential imperfections, may cause a loss of efficiency in the correction. We thus here discuss to what extent such effects can reduce the expected performance.

The operations described to implement the QEC involve sequences of resonant pulses (and ancilla measurements) only. In electronic spin systems, a single *π*-pulse requires less than 10 ns for achieving a state transfer with high fidelity, and this time could be further reduced by pulse-shaping techniques^{70,71,72}. The measurement time for the ancilla readout through a microwave resonator can be roughly estimated from the field of circuit QED to be of 40−100 ns with fidelity above 0.98^{65,73}. Then, for the spins *S* ≤ 9/2 considered here the QEC procedure requires a total time ranging from a few hundreds of nanoseconds to few microseconds at most, and is hence much shorter than the decay time that can be allowed by the optimized code-words while ensuring a recovery fidelity above 0.99. Indeed, the latter can be of tens of microseconds, as visible from Figs. 3 and 5.

The practical implementation of the QEC is thus expected not to significantly reduce the correction performance for the qudits studied here. However, one could also predict that the growth of the complexity of the implementation for very large spins will eventually set a tradeoff between gain and duration of the QEC favouring the use of moderately large spins, similarly to what was observed for spin-binomial codes^{13}. Importantly, this limitation can be mitigated in the present scheme by optimizing the codewords at larger times. Moreover, it should be noted that the bottleneck in the specific experimental implementation proposed here for large spins is related to the rapid scaling of the number of pulses required with *S*. This, in turn, is due to the low connectivity of the 2*S* + 1 spin levels that permits resonant state transfers only between states with Δ*m* = ±1. A possible way around this problem is to consider magnetic molecules with competing interactions^{46,74,75,76,77}, for which the multi-level structure used for the qudit encoding is given by low-energy states belonging to different multiplets that can provide larger state connectivity.

## Discussion

We have investigated decoherence effects produced by a realistic nuclear spin bath on a spin qudit *S* > 1/2 in Molecular Nanomagnets, by simulating the coupled system-bath dynamics via a CCE. Building on this analysis, we have developed a versatile numerical strategy to construct optimal QEC codes tailored for the specific spin-dephasing errors induced by the bath, thus bridging the gap between traditional general-purpose correction algorithms and the necessity of hardware-specific strategies meeting current experimental capabilities. The resulting qudit codes achieve a remarkable performance, and can be optimized by taking into account constraints on the time interval between subsequent QECs. Moreover, the increase in performance with the increase of the qudit spin is striking, signalling that the codes exploit the available levels of the molecular system as a resource very efficiently. The proposed codes can be implemented experimentally using standard sequences of resonant control pulses. Such sequences are explicitly designed and discussed, and their practical realization is predicted not to set important limits on the efficiency of the codes. Given these results, the proposed codes are a promising candidate for realizing error-protected quantum computational units embedded at the single-molecule level, a central building block for implementing reliable quantum information processing on short-term molecular devices.

Recent works^{47} point out that the CCE method used here correctly reproduces the phenomenology of coherence enhancement due to the existence of a nuclear diffusion barrier^{53}. An interesting perspective is the integration of the framework developed in this work with chemical engineering techniques for achieving an even longer lifetime of the error-corrected logical qubit through this mechanism. The synergy of tailored QEC codes as investigated here with engineered nuclear spin distributions may pave the way towards a class of highly coherent molecular qubits.

The framework developed in this work is general, and can be applied to a wide landscape of molecular systems and also to other individual spin systems such as impurities in semiconductors, in order to design a proof-of-principle experiment to demonstrate the effectiveness of the QEC code. In addition, it can be extended, in the future, to investigate decoherence effects affecting superpositions of spin states belonging to different spin multiplets^{74,75}. This would be interesting since, on the one hand, the use of many low-*m* spin states belonging to different multiplets may allow one to increase the number of levels available for error correction without exasperating dephasing effects given by large \(m-m^{\prime}\) transitions. On the other hand, it would enable a thorough study of standard block encodings embedded in a single molecule, wherein a register of qubits is achieved through many effective spin-1/2 systems selected from different spin multiplets.

## Methods

### Derivation of the effective Hamiltonian

The spin Hamiltonian describing the interacting evolution of the molecular spin \({{{\mathcal{S}}}}\) and the bath \({{{\mathcal{B}}}}\) of *N* nuclear spins is

where \({\hat{H}}_{{{{\mathcal{S}}}}}=D{\hat{S}}_{z}^{2}+{{\Omega }}{\hat{S}}_{z}\), \(\hat{{{{\boldsymbol{S}}}}}=\{{\hat{S}}^{z},{\hat{S}}^{+},{\hat{S}}^{-}\}\), \({\hat{{{{\boldsymbol{I}}}}}}_{n}=\{{\hat{I}}_{n}^{z},{\hat{I}}_{n}^{+},{\hat{I}}_{n}^{-}\}\). The tensors \({{\mathbb{D}}}_{n}\) contain dipole−dipole couplings between \({{{\mathcal{S}}}}\) and \({{{\mathcal{B}}}}\), while the tensors \({{\mathbb{E}}}_{n,m}\) contain nuclear−nuclear dipolar couplings. The elements of \({{\mathbb{D}}}_{n}\) satisfy

and the same holds for the corresponding elements of \({{\mathbb{E}}}_{n,m}\). A canonical perturbative (Schrieffer-Wolff) transformation generated by

with h.c. indicating the hermitian conjugate, is constructed such that \({\hat{H}}_{G}={{{{\rm{e}}}}}^{G}\hat{H}{{{{\rm{e}}}}}^{-G}\), within first order in Ω^{−1}, does not contain off-diagonal couplings between \({{{\mathcal{S}}}}\) and \({{{\mathcal{B}}}}\) with respect to the states \(\left|m\right\rangle\)^{45,48,60,78}. As detailed in the following, *G* is proportional to Ω^{−1} and leading orders in \({\hat{H}}_{G}\) can thus be computed from the Baker−Campbell−Hausdorf expansion

The coefficients \({G}_{k}^{\alpha \beta }\) are determined explicitly by imposing the cancellation of the off-diagonal couplings between \({{{\mathcal{S}}}}\) and \({{{\mathcal{B}}}}\) to first order. This results in the relation

The coefficients \({G}_{k}^{\alpha \beta }\) then read

These expressions are indeed of order Ω^{−1} and the transformation generated by *G* is thus perturbative, such that its effect on the initial factorized qudit-nuclei state is neglected. By keeping terms in Eq. (15) to first order in Ω^{−1} only and neglecting energy-non-conserving terms, the effective Hamiltonian of Eqs. (1) and (2) is obtained with coefficients

and \({b}_{n}^{(2)}={c}_{n}^{(2)}={d}_{n}^{(2)}=0\). The energy of \({{{\mathcal{S}}}}\) is also renormalized according to

but this is absorbed into the interaction picture in Eq. (1).

### Simulations and dephasing timescales

The configuration of nuclear spins in space is generated randomly within a sphere of radius 15 Å from the spin \({{{\mathcal{S}}}}\), as sketched in Fig. 1. Further, a minimal distance of 3 Å is considered between nuclear spins and between each nuclear spin and \({{{\mathcal{S}}}}\). In all the simulations presented in this work, configurations of *N* = 100 nuclear spins are considered, whose initial state is taken to be thermal at temperature *T* = 2 K. Moreover, a static magnetic field *B*_{z} = 1 T along *z* is assumed, for achieving the regime of large Zeeman energy of \({{{\mathcal{S}}}}\). The decoherence function,

is computed by means of a CCE^{54,61}. This expansion decomposes *L*_{nm}(*t*) as a product of contributions originating from clusters involving an increasing number of nuclear spins, and is formally equivalent to a perturbative expansion in small intra-bath effective couplings. Clusters involving more and more spins contribute smaller and smaller corrections to *L*_{nm}(*t*), justifying a truncation of the expansion to few-spin clusters for practical applications. For inclusion up to *n*-size clusters, we call this truncation CCE-*n*, which yields the truncated function \({L}_{nm}^{(n)}(t)\).

The effect of inhomogeneous broadening is well captured by CCE-1^{61,79}. Given that nuclear gaps are of the order of millikelvin in magnitude, an initial thermal state of the nuclear spin-bath at temperatures *T* of a few kelvins is to a good approximation a fully unpolarized state

Under this approximation, the CCE-1 can be solved analytically also for *S* > 1/2 giving

Here, \({{\mathbb{D}}}_{k}^{zz}\) is the hyperfine coupling \(\propto {\hat{S}}_{z}{\hat{I}}_{k}^{z}\) between \({{{\mathcal{S}}}}\) and the *k*-th nuclear spin. For small \({{\mathbb{D}}}_{k}^{zz}t\), this is well approximated by \({{{{\rm{e}}}}}^{-{(n-m)}^{2}{{{\Gamma }}}^{2}{t}^{2}}\) with \({{{\Gamma }}}^{2}={\sum }_{k}{({D}_{k}^{zz})}^{2}/4\) as given in the main text.

For the echo dynamics, we find that CCE-2 gives essentially converged results, as tested by including also larger clusters. For this reason, the numerical results reported here are obtained using CCE-2. This convergence confirms that intrinsic nuclear flip-flop processes give the dominant contribution to spin dephasing after echo. Indeed, an inspection of the magnitude of the coefficients \({a}_{n,m}^{(k)}\), \({b}_{n,m}^{(k)}\), \({c}_{n,m}^{(k)}\), \({d}_{n,m}^{(k)}\) reveals three fundamental interaction scales at play, which ordered by decreasing strength, are associated to (i) the diagonal coupling between \({{{\mathcal{S}}}}\) and nuclear spins (terms \(\propto {\hat{S}}_{z}{\hat{I}}_{k}^{z}\) which are compensated for by the echo), (ii) the intrinsic interacting evolution (terms \(\propto {\hat{I}}_{n}^{\alpha }{\hat{I}}_{m}^{\beta }\)), (iii) the \({{{\mathcal{S}}}}\)-conditioned interacting evolution (terms \(\propto {\hat{S}}_{z}{\hat{I}}_{m}^{\alpha }{\hat{I}}_{n}^{\beta }\)). These different energy scales are responsible for contributions to decoherence over different timescales, with (ii) being dominant in the echo decay.

### Nuclear spin qudit

The quantitative analyses presented in this work are focused on the case of an electronic spin qudit. Nevertheless, the theoretical framework applies also to the case of a nuclear spin qudit. The crucial approximation underlying the physical model studied here is that the qudit energy gaps are much larger than the gaps of surrounding nuclear spins of the bath. For an electronic qudit, these energy differences can be made intrinsically large by using a sufficiently large static magnetic field. For a nuclear spin qudit of a magnetic ion (coupled to an electronic spin), whose interaction with surrounding nuclear spins is mediated by virtual excitations of the electronic spin, the necessary energy difference mainly originates from contact hyperfine interaction between the nuclear and electronic spin. The construction of the effective Hamiltonian, and the hierarchy of the interaction scales at play, then follows as discussed above.

### Derivation of numerical qudit codes

The iteration defined by Eq. (7) is first used to determine the error operators given in Eq. (8). The numerical codewords \(\left|{0}_{L}\right\rangle\) and \(\left|{1}_{L}\right\rangle\) are found by starting from the following *ansatz*, inspired by spin-binomial codes^{13},

This *ansatz* permits one to impose Eq. (6) by construction and hence to reduce the number of free parameters, thanks to \(\left|{0}_{L}\right\rangle\) and \(\left|{1}_{L}\right\rangle\) having non-zero components on different sets of \(\left|m\right\rangle\) states.

Knill−Laflamme conditions (5) are finally enforced on the coefficients \({\gamma }_{\ell }^{(0)/(1)}\) by numerically minimizing the function

### Detection and recovery

The abstract detection and recovery operations follow the general QEC theory of ref. ^{62}. Once a set of operators \({\{{\hat{E}}_{k}\}}_{k = 0,\ldots ,\lfloor S\rfloor }\) to be corrected with a spin *S* is identified, the two error subspaces corresponding to \(\left|{0}_{L}\right\rangle\) and \(\left|{1}_{L}\right\rangle\) are first determined. These two subspaces are defined as the linear span of the states \({\hat{E}}_{k}\left|{0}_{L}\right\rangle\) and \({\hat{E}}_{k}\left|{1}_{L}\right\rangle\) for all *k*, respectively. For each of these subspaces, a basis \(\{\left|{e}_{k}^{(0)}\right\rangle \}\) (\(\{\left|{e}_{k}^{(1)}\right\rangle \}\)) is selected. This is chosen here to be given by a Gram−Schmidt orthonormalization of states \({\hat{E}}_{k}\left|{0}_{L}\right\rangle\) (\({\hat{E}}_{k}\left|{1}_{L}\right\rangle\)). The detection measurement is then described by the projectors

with *k* = 0, …, ⌊*S*⌋. Finally, the recovery operation, given an outcome *j* of the measurement, maps back the states \(\left|{e}_{j}^{(0)}\right\rangle\) and \(\left|{e}_{j}^{(1)}\right\rangle\) corresponding to that outcome to the computational states \(\left|{0}_{L}\right\rangle\) and \(\left|{1}_{L}\right\rangle\), respectively. Since the coefficients *α* and *β* of the encoded state have been preserved, this operation then fully restores the logical state \(\left|{\psi }_{L}\right\rangle\). The recovery is formalized by a set of transformations \(\{{\hat{R}}_{k}\}\) such that

for *c* = 0, 1. Here, each transformation \({\hat{R}}_{k}\) is constructed as a rotation in the two-dimensional space spanned by \(\left|{e}_{k}^{(c)}\right\rangle\) and \(\left|{c}_{L}\right\rangle\).

### Pulse sequences

To systematically convert a generic transformation *U* acting on the state space of a spin *S* > 1/2 into a sequence of resonant *Y*_{m}(*θ*) pulses, one can exploit known decomposition strategies from quantum control theory^{13,80}. In a first step, the unitary *U* can be decomposed into a sequence of two-state planar rotations using the algorithm given in ref. ^{80}. This gives a sequence of two-state transfers which involve states \(\left|m\right\rangle\) and \(\left|m^{\prime} \right\rangle\) also with \(| m-m^{\prime} | > 1\). To further convert such two-state rotations into rotations *Y*_{m}(*θ*), i.e., with \(| m-m^{\prime} | =1\), one finally exploits *π*-pulses to bring the population of \(m^{\prime}\) close to *m* and back. For instance, defining

for \(m^{\prime}\, > \,m\), one can iteratively exploit the properties

As an example, the pulse sequence depicted in panel ‘basis rotation’ of Fig. 6a, which realizes a transformation mapping the basis of error words \(\left|{e}_{k}^{(c)}\right\rangle\) to the basis of \(\left|m\right\rangle\) states, is obtained with the procedure sketched here. The resulting angles are given in Table 1.

### Spin-binomial codes

In order to compare the numerical codes with other qudit approaches to spin dephasing, we test recently-proposed spin-binomial codes^{13}. These codes are based on a description of spin dephasing as produced by a Markovian bath which couples to the system via operator \(\sqrt{\gamma }{\hat{S}}_{z}\). The latter model can only describe an exponential decay of coherence with rate *γ* and contributions of order (*γ**t*)^{n} to the density matrix can be computed exactly and are determined by powers up to \({\hat{S}}_{z}^{n}\). We find that, while spin-binomial codes still give an interesting performance, they are largely overwhelmed by the numerical codes. This can be appreciated by comparing Figs. 3 and 4 with Fig. 7, both in terms of fidelity and gain. The fact that spin-binomial codes still give an increasing gain for increasing qudit spin despite being designed for a simpler dephasing mechanism, suggests that small powers of the coupling operators \({\hat{S}}_{z}\) play a fundamental role in the decoherence process also in the present scenario, over short timescales with respect to the intra-bath interaction strength.

## Data availability

The datasets generated during and/or analyzed during the current study are available from the corresponding author on reasonable request.

## Code availability

The codes developed for the numerical simulations are available from the corresponding author on reasonable request.

## References

- 1.
Terhal, B. M. Quantum error correction for quantum memories.

*Rev. Mod. Phys.***87**, 307–346 (2015). - 2.
Preskill, J. Quantum computing in the NISQ era and beyond.

*Quantum***2**, 79 (2018). - 3.
Tacchino, F., Chiesa, A., Carretta, S. & Gerace, D. Quantum computers as universal quantum simulators: state-of-the-art and perspectives.

*Adv. Quantum Technol.***3**, 1900052 (2020). - 4.
Nielsen, M. A. & Chuang, I. L.

*Quantum Computation and Quantum Information*(Cambridge University Press, 2000). - 5.
Gottesman, D., Kitaev, A. & Preskill, J. Encoding a qubit in an oscillator.

*Phys. Rev. A***64**, 012310 (2001). - 6.
Troiani, F., Bellini, V. & Affronte, M. Decoherence induced by hyperfine interactions with nuclear spins in antiferromagnetic molecular rings.

*Phys. Rev. B***77**, 054428 (2008). - 7.
Leghtas, Z. et al. Hardware-efficient autonomous quantum memory protection.

*Phys. Rev. Lett.***111**, 120501 (2013). - 8.
Mirrahimi, M. et al. Dynamically protected cat-qubits: a new paradigm for universal quantum computation.

*N. J. Phys.***16**, 045014 (2014). - 9.
Vlastakis, B. et al. Deterministically encoding quantum information using 100-photon Schrödinger cat states.

*Science***342**, 607–610 (2013). - 10.
Li, L. et al. Cat codes with optimal decoherence suppression for a lossy bosonic channel.

*Phys. Rev. Lett.***119**, 030502 (2017). - 11.
Hu, L. et al. Quantum error correction and universal gate set operation on a binomial bosonic logical qubit.

*Nat. Phys.***15**, 503–508 (2019). - 12.
Michael, M. H. et al. New class of quantum error-correcting codes for a bosonic mode.

*Phys. Rev. X***6**, 031006 (2016). - 13.
Chiesa, A. et al. Molecular nanomagnets as qubits with embedded quantum-error correction.

*J. Phys. Chem. Lett.***11**, 8610–8615 (2020). - 14.
Pirandola, S., Mancini, S., Braunstein, S. L. & Vitali, D. Minimal qudit code for a qubit in the phase-damping channel.

*Phys. Rev. A***77**, 032309 (2008). - 15.
Cafaro, C., Maiolini, F. & Mancini, S. Quantum stabilizer codes embedding qubits into qudits.

*Phys. Rev. A***86**, 022308 (2012). - 16.
Hussain, R. et al. Coherent manipulation of a molecular Ln-based nuclear qudit coupled to an electron qubit.

*J. Am. Chem. Soc.***140**, 9814–9818 (2018). - 17.
Chiesa, A. et al. Embedded quantum-error correction and controlled-phase gate for molecular spin qubits.

*AIP Adv.***11**, 025134 (2021). - 18.
Godfrin, C. et al. Operating quantum states in single magnetic molecules: implementation of Grover’s quantum algorithm.

*Phys. Rev. Lett.***119**, 187702 (2017). - 19.
Bader, K. et al. Room temperature quantum coherence in a potential molecular quit.

*Nat. Commun.***5**, 5304–5309 (2014). - 20.
Zadrozny, J. M., Niklas, J., Poluektov, O. G. & Freedman, D. E. Millisecond coherence time in a tunable molecular electronic spin qubit.

*ACS Cent. Sci.***1**, 488 (2015). - 21.
Shiddiq, M. et al. Enhancing coherence in molecular spin qubits via atomic clock transitions.

*Nature***531**, 348–351 (2016). - 22.
Atzori, M. et al. Room-temperature quantum coherence and rabi oscillations in vanadyl phthalocyanine: toward multifunctional molecular spin qubits.

*J. Am. Chem. Soc.***138**, 2154–2157 (2016). - 23.
Atzori, M. et al. Spin dynamics and low energy vibrations: Insights from vanadyl-based potential molecular qubits.

*J. Am. Chem. Soc.***139**, 4338–4341 (2017). - 24.
Atzori, M. et al. Structural effects on the spin dynamics of potential molecular qubits.

*Inorg. Chem.***57**, 731–740 (2018). - 25.
Atzori, M. et al. Quantum coherence times enhancement in vanadium(IV)-based potential molecular qubits: the key role of the vanadyl moiety.

*J. Am. Chem. Soc.***138**, 11234–11244 (2016). - 26.
Yu, C.-J. et al. Long coherence times in nuclear spin-free vanadyl qubits.

*J. Am. Chem. Soc.***138**, 14678–14685 (2016). - 27.
Graham, M. J. et al. Influence of electronic spin and spin-orbit coupling on decoherence in mononuclear transition metal complexes.

*J. Am. Chem. Soc.***136**, 7623–7626 (2014). - 28.
Wojnar, M. K., Laorenza, D. W., Schaller, R. D. & Freedman, D. E. Nickel(II) metal complexes as optically addressable qubit candidates.

*J. Am. Chem. Soc.***142**, 14826–14830 (2020). - 29.
Fataftah, M. et al. Employing forbidden transitions as qubits in a nuclear spin-free chromium complex.

*J. Am. Chem. Soc.***138**, 1344 (2016). - 30.
Ako, A. M. et al. A ferromagnetically coupled Mn

_{19}aggregate with a record*S*= 83/2 ground spin state.*Angew. Chem. Int. Ed.***45**, 4926–4929 (2006). - 31.
Baniodeh, A. et al. High spin cycles: topping the spin record for a single molecule verging on quantum criticality.

*npj Quantum Mater.***3**, 10 (2018). - 32.
Luis, F. et al. Molecular prototypes for spin-based CNOT and SWAP quantum gates.

*Phys. Rev. Lett.***107**, 117203 (2011). - 33.
Wedge, C. J. et al. Chemical engineering of molecular qubits.

*Phys. Rev. Lett.***108**, 107204 (2012). - 34.
Aromí, G., Aguilà, D., Luis, F., Hill, S. & Coronado, E. Design of magnetic coordination complexes for quantum computing.

*Chem. Soc. Rev.***41**, 537–546 (2012). - 35.
Aguilà, D. et al. Heterodimetallic [LnLn’] lanthanide complexes: toward a chemical design of two-qubit molecular spin quantum gates.

*J. Am. Chem. Soc.***136**, 14215 (2014). - 36.
Chiesa, A. et al. Molecular nanomagnets with switchable coupling for quantum simulation.

*Sci. Rep.***4**, 7423 (2014). - 37.
Ardavan, A. et al. Engineering coherent interactions in molecular nanomagnet dimers.

*npj Quantum Inf.***1**, 15012 (2015). - 38.
Ferrando-Soria, J. et al. A modular design of molecular qubits to implement universal quantum gates.

*Nat. Commun.***7**, 11377 (2016). - 39.
Ferrando-Soria, J. et al. Switchable interaction in molecular double qubits.

*Chem***1**, 727–752 (2016). - 40.
Ding, Y.-S., Deng, Y.-F. & Zheng, Y.-Z. The rise of single-ion magnets as spin qubits.

*Magnetochemistry***2**, 40 (2016). - 41.
Atzori, M. et al. A two-qubit molecular architecture for electronmediated nuclear quantum simulation.

*Chem. Sci.***9**, 6183 (2018). - 42.
Atzori, M. & Sessoli, R. The second quantum revolution: role and challenges of molecular chemistry.

*J. Am. Chem. Soc.***141**, 11339 (2019). - 43.
Gaita-Ariño, A., Luis, F., Hill, S. & Coronado, E. Molecular spins for quantum computation.

*Nat. Chem.***11**, 301–309 (2019). - 44.
Macaluso, E. et al. A heterometallic [LnLn’Ln] lanthanide complex as a qubit with embedded quantum error correction.

*Chem. Sci.***11**, 10337 (2020). - 45.
Troiani, F., Bellini, V. & Affronte, M. Decoherence induced by hyperfine interactions with nuclear spins in antiferromagnetic molecular rings.

*Phys. Rev. B***77**, 054428 (2008). - 46.
Ghirri, A. et al. Coherent spin dynamics in molecular Cr

_{8}Zn wheels.*J. Phys. Chem. Lett.***6**, 5062–5066 (2015). - 47.
Chen, J. et al. Decoherence in molecular electron spin qubits: Insights from quantum many-body simulations.

*J. Phys. Chem. Lett.***11**, 2074–2078 (2020). - 48.
Coish, W. A., Fischer, J. & Loss, D. Exponential decay in a spin bath.

*Phys. Rev. B***77**, 125329 (2008). - 49.
Klauder, J. R. & Anderson, P. W. Spectral diffusion decay in spin resonance experiments.

*Phys. Rev.***125**, 912–932 (1962). - 50.
Abe, E., Itoh, K. M., Isoya, J. & Yamasaki, S. Electron-spin phase relaxation of phosphorus donors in nuclear-spin-enriched silicon.

*Phys. Rev. B***70**, 033204 (2004). - 51.
Witzel, W. M., de Sousa, R. & Das Sarma, S. Quantum theory of spectral-diffusion-induced electron spin decoherence.

*Phys. Rev. B***72**, 161306 (2005). - 52.
Ardavan, A. et al. Will spin-relaxation times in molecular magnets permit quantum information processing?

*Phys. Rev. Lett.***98**, 057201 (2007). - 53.
Graham, M. J., Yu, C.-J., Krzyaniak, M. D., Wasielewski, M. R. & Freedman, D. E. Synthetic approach to determine the effect of nuclear spin distance on electronic spin decoherence.

*J. Am. Chem. Soc.***139**, 3196–3201 (2017). - 54.
Yang, W. & Liu, R.-B. Quantum many-body theory of qubit decoherence in a finite-size spin bath.

*Phys. Rev. B***78**, 085315 (2008). - 55.
Chiesa, A. et al. Magnetic exchange interactions in the molecular nanomagnet Mn

_{12}.*Phys. Rev. Lett.***119**, 217202 (2017). - 56.
Würger, A. Magnetic relaxation of mesoscopic molecules.

*J. Phys.: Condens. Matter.***10**, 10075–10099 (1998). - 57.
Bader, K., Winkler, M. & van Slageren, J. Tuning of molecular qubits: very long coherence and spin-lattice relaxation times.

*Chem. Commun.***52**, 3623–3626 (2016). - 58.
Takahashi, S. et al. Coherent manipulation and decoherence of

*S*= 10 single-molecule magnets.*Phys. Rev. Lett.***102**, 087603 (2009). - 59.
Stamp, P. C. E. & Tupitsyn, I. S. Coherence window in the dynamics of quantum nanomagnets.

*Phys. Rev. B***69**, 014401 (2004). - 60.
Yao, W., Liu, R.-B. & Sham, L. J. Theory of electron spin decoherence by interacting nuclear spins in a quantum dot.

*Phys. Rev. B***74**, 195301 (2006). - 61.
Yang, W. & Liu, R.-B. Quantum many-body theory of qubit decoherence in a finite-size spin bath. II. ensemble dynamics.

*Phys. Rev. B***79**, 115320 (2009). - 62.
Knill, E. & Laflamme, R. Theory of quantum error-correcting codes.

*Phys. Rev. A***55**, 900–911 (1997). - 63.
Gimeno, I. et al. Enhanced molecular spin-photon coupling at superconducting nanoconstrictions.

*ACS Nano***14**, 8707–8715 (2020). PMID: 32441922. - 64.
Blais, A., Huang, R.-S., Wallraff, A., Girvin, S. M. & Schoelkopf, R. J. Cavity quantum electrodynamics for superconducting electrical circuits: an architecture for quantum computation.

*Phys. Rev. A***69**, 062320 (2004). - 65.
Blais, A., Grimsmo, A. L., Girvin, S. M. & Wallraff, A. Circuit quantum electrodynamics.

*Rev. Mod. Phys.***93**, 025005 (2021). - 66.
Krantz, P. et al. A quantum engineer’s guide to superconducting qubits.

*Appl. Phys. Rev.***6**, 021318 (2019). - 67.
Jenkins, M. D. et al. A scalable architecture for quantum computation with molecular nanomagnets.

*Dalton Trans.***45**, 16682–16693 (2016). - 68.
Carretta, S., Zueco, D., Chiesa, A., Gomez-Leon, A. & Luis, F. A perspective on scaling up quantum computation with molecular spins.

*Appl. Phys. Lett.***118**, 240501 (2021). - 69.
Royer, B., Puri, S. & Blais, A. Qubit parity measurement by parametric driving in circuit QED.

*Sci. Adv.***4**, eaau1695 (2018). - 70.
Motzoi, F., Gambetta, J. M., Rebentrost, P. & Wilhelm, F. K. Simple pulses for elimination of leakage in weakly nonlinear qubits.

*Phys. Rev. Lett.***103**, 110501 (2009). - 71.
Theis, L. S., Motzoi, F., Machnes, S. & Wilhelm, F. K. Counteracting systems of diabaticities using DRAG controls: the status after 10 years.

*Europhys. Lett.***123**, 60001 (2018). - 72.
Werninghaus, M. et al. Leakage reduction in fast superconducting qubit gates via optimal control.

*npj Quantum Inf.***7**, 14 (2021). - 73.
Walter, T. et al. Rapid high-fidelity single-shot dispersive readout of superconducting qubits.

*Phys. Rev. Appl.***7**, 054020 (2017). - 74.
van Slageren, J. et al. Static and dynamic magnetic properties of an [Fe

_{13}] cluster.*Phys. Rev. B***73**, 014422 (2006). - 75.
Schnack, J. Effects of frustration on magnetic molecules: a survey from Olivier Kahn until today.

*Dalton Trans.***39**, 4677–4686 (2010). - 76.
Adelnia, F. et al. Low temperature magnetic properties and spin dynamics in single crystals of Cr

_{8}Zn antiferromagnetic molecular rings.*J. Chem. Phys.***143**, 244321 (2015). - 77.
Baker, M. L. et al. Studies of a large odd-numbered odd-electron metal ring: inelastic neutron scattering and muon spin relaxation spectroscopy of Cr

_{8}Mn.*Chem. Eur. J.***22**, 1779–1788 (2016). - 78.
Bravyi, S., DiVincenzo, D. P. & Loss, D. Schrieffer−Wolff transformation for quantum many-body systems.

*Ann. Phys.***326**, 2793–2826 (2011). - 79.
Maze, J. R., Taylor, J. M. & Lukin, M. D. Electron spin decoherence of single nitrogen-vacancy defects in diamond.

*Phys. Rev. B***78**, 094303 (2008). - 80.
D’Alessandro, D.

*Introduction to Quantum Control and Dynamics*(CRC Press, 2007).

## Acknowledgements

This work received financial support from the European Project ‘Scaling Up quantum computation with MOlecular spins’ (SUMO) of the call QuantERA, cofunded by the Italian MUR, and the European Union’s Horizon 2020 programme under Grant Agreement No. 862893 (FET-OPEN project FATMOLS).

## Author information

### Affiliations

### Contributions

S.W., P.S., and S.C. conceived the research. F.P. derived the theoretical model and produced the numerical data. F.P., A.C., and S.C. analyzed the data. All authors discussed the results. F.P. and A.C. wrote the paper, with input from all the co-authors.

### Corresponding author

## Ethics declarations

### Competing interests

The authors declare no competing interests.

## Additional information

**Publisher’s note** Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

## Rights and permissions

**Open Access** This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.

## About this article

### Cite this article

Petiziol, F., Chiesa, A., Wimberger, S. *et al.* Counteracting dephasing in Molecular Nanomagnets by optimized qudit encodings.
*npj Quantum Inf* **7, **133 (2021). https://doi.org/10.1038/s41534-021-00466-3

Received:

Accepted:

Published: