Iterative Phase Optimization of Elementary Quantum Error Correcting Codes

M. Müller, A. Rivas, E. A. Martínez, D. Nigg, P. Schindler, T. Monz, R. Blatt, and M. A. Martin-Delgado Department of Physics, Swansea University, Singleton Park, Swansea SA2 8PP, United Kingdom Departamento de Física Teórica I, Universidad Complutense, Avenida Complutense s/n, 28040 Madrid, Spain Institut für Experimentalphysik, Universität Innsbruck, Technikerstrasse 25, A–6020 Innsbruck, Austria Institut für Quantenoptik und Quanteninformation, Österreichische Akademie der Wissenschaften, Technikerstrasse 21A, 6020 Innsbruck, Austria (Received 6 April 2016; revised manuscript received 23 June 2016; published 24 August 2016)


I. INTRODUCTION
The faithful execution of quantum algorithms, even on small-scale prototype quantum computers, poses formidable control requirements [1].The influence of a multitude of error sources and control parameters needs to be characterized and minimized in order to enable overall high-fidelity operations.Within the field of quantum control and optimization, many techniques have been developed [2][3][4][5][6][7][8] to characterize noise and decouple quantum systems to the highest possible degree from their environment.This allows one to increase the fidelity of desired target quantum operations under the remaining, ultimately unavoidable, residual sources of imperfections.
In particular, in a bottom-up approach to building quantum-information hardware, one usually optimizes the performance of individual building blocks such as, e.g., single-and two-qubit gate operations.In principle, imperfections in few-qubit operations can be characterized by full quantum process tomography.However, it is much more practical to use prior understanding of the dominant underlying noise processes to design an efficient protocol to characterize, validate, and finally reduce the resulting error sources.
In the following, we will separate the imperfections into a nonreversible coupling to a larger environment [9,10], including fluctuations of control parameters on the one hand and unknown but constant unitary operations on the other hand.The latter errors can, in principle, be compensated by measuring the unknown operation and applying the inverse operation onto the system.Simple laboratory examples are the systematic single-qubit phase shifts, which arise, e.g., if the frequency of the field driving the qubit does not perfectly match the qubit transition frequency [11].This transforms an initial state αj0i þ βj1i into αj0i þ βe iϕ j1i with an unknown but constant phase ϕ.The phase shift ϕ can be measured systematically with Ramsey-type experiments [12,13] and furthermore compensated for by applying one single-qubit rotation U comp ¼ expðiϕZ=2Þ, where Z denotes the third Pauli matrix [14].This Ramsey-based phase detection and compensation technique can be extended to certain classes of multiqubit states, such as, e.g., n-qubit GHZ states, αj0i ⊗n þ βe iϕ j1i ⊗n [14].
More general unitary errors can only be characterized by full quantum state tomography, which scales exponentially with the number of qubits.Thus, it is highly desirable to design protocols that allow one to efficiently and precisely determine specific systematic errors.An important class of such errors are unknown, though systematic, relative phases between the components of more complex quantum states.It should be noted, that the propagation of singlequbit phase shifts through complex algorithms cannot be measured efficiently with generic methods that are algorithm independent.
In this work, we introduce and experimentally demonstrate a method that allows one to compensate systematic, unknown, but constant phase-shift errors that arise in the encoding procedure of small quantum error correcting codes [15].We theoretically outline the protocol, numerically study its performance, and discuss how it was successfully used in a recent experimental realization of a seven-qubit quantum error correcting code with trapped ions [16].The iterative optimization protocol does not rely on full quantum state tomography [14,17], and furthermore, it is found to converge very rapidly for small quantum error correcting codes.As a consequence, the method can be experimentally applied "in situ"; i.e., it can be applied in real time to optimize the experimental performance.In fact, in the experiments of Ref. [16], the measurements and feedback steps required by the algorithm to optimize the overall performance of the whole encoding circuit were performed within a total time of a few minutes.This is short compared to typical time scales on which systematic parameter drifts take place [18].Here, we apply the protocol to a case where the encoding of logical states was achieved by a circuit of unitary gate operations.However, similar scenarios where systematic, constant phase shifts will arise in measurement-based encoding protocols can be addressed by the proposed technique [19,20].Furthermore, the method is readily applicable to other physical platforms for quantum-information processing, such as, e.g., Rydberg atoms [21][22][23] in optical lattices [24][25][26] or tweezer arrays [27,28].
In the following two sections, we first briefly review some basic properties of the implemented seven-qubit quantum error correcting code [29,30] and then present, in some detail, the experimental procedure used for the encoding of logical quantum states.The latter discussion aims at illustrating under which conditions the systematic phase-shift errors that our protocol tackles arise in the particular experiment of Ref. [16].Similar errors are expected to occur in other atom-or solid-state based architectures [31][32][33][34][35][36], in particular, those that exploit multilevel systems to enhance the systems' capability.

A. Ideal encoding of a seven-qubit quantum error correcting code
In Ref. [16], a seven-qubit quantum error correcting code has been demonstrated.This particular code corresponds to the seven-qubit Steane code [29] and also represents the smallest instance of a 2D topological color code [30].Since the realized quantum error correcting code belongs to the class of CSS codes [14,37], the code space is generated as the simultaneous þ1 eigenspace of a set of mutually commuting stabilizer operators S There, each plaquette involves four physical qubits and hosts one four-qubit Xand Z-type stabilizer.
Encoding of a logical state jψi L thus amounts to preparing the system of physical qubits in the þ1 eigenspace of all stabilizers.The logical state j0i L , for instance, being a þ1 eigenstate of the six plaquette generators as well as of the logical Z operator, Z L ¼ Q 7 j¼1 Z j , is explicitly given by the following superposition of 2 3 ¼ 8 computational basis states: Experimental encoding and origin of systematic phase shifts In Ref. [16], the outlined seven-qubit quantum error correcting code was realized using a string of seven trapped 40 Ca þ ions in a linear Paul-trap-based quantum computing architecture [18].Each of the ions hosts one physical qubit encoded in the computational subspace spanned by two (meta)stable, electronic states, as shown in Fig. 1(b).
Arbitrary operations can be applied to the quantum register with the following universal set of operations: Single-qubit rotations can be realized by a tightly focused laser beam illuminating single ions of the string, whereas collective (nonentangling) rotations can be implemented by a beam that collectively and homogeneously illuminates the entire string of n ions (see Ref. [18]).In addition, a bichromatic laser field, illuminating the entire string of ions, is used to implement a collective, n-qubit Mølmer-Sørensen (MS) entangling gate operation [38,39].Any arbitrary unitary operation can be realized by a sequence of these operations that can be found using refocusing techniques originally developed in NMR [40] or numerical optimization routines [41].
It is possible to extend the experimental toolbox by using more electronic levels than only the two electronic states of the qubit.This allows one to realize entangling operations on subsets of ions with less overhead than any known optimized sequence.Ions hosting physical qubits that are not supposed to participate in a given entangling operation are coherently transferred to an additional set of metastable electronic states that do not couple to the field that generates the operations, as shown in Fig. 1(b).The quantum state of these decoupled ions will ideally remain unaffected by the operation of the globally applied, bichromatic laser field driving the qubit transition and implementing the collective entangling MS gate operation.Subsequently, decoupled ions can be recoupled by coherently mapping their state back into the qubit subspace.
This extended set of operations was used in Ref. [16] to realize the encoding of an initial logical state, say j1i L , by a unitary circuit: There, the seven-ion system was initially prepared in a product state, say j1010101i, thus being already a þ1 eigenstate of the set of three Z-type stabilizer operators.Preparation of the seven-qubit system in the þ1 eigenspace of the X-type stabilizers was then realized by a sequence of three entangling operations, each acting on subsets of four qubits belonging to the three plaquettes of the code, respectively [see Fig. 1(c)].Each of the effective four-qubit MS gates creates GHZ-type entanglement between the four qubits belonging to a given plaquette.The entangling gates were interspersed by a series of onthe-order-of-hundred single-ion pulses (see Ref. [16] and supplemental material therein for details) to spectroscopically decouple and subsequently recouple ions that are not supposed to participate in the action of a four-qubit plaquette-wise entangling operation.
Along the application of this encoding sequence, undesired systematic phase shifts on all ions are generated, and they accumulate.These can be of various physical origins and unknown magnitude, arising, e.g., from off-resonant light shifts on ions residing in the decoupled electronic states during the application of the MS gate operations.Note that, in the present experiment, these phase shifts do not vary significantly even over long data accumulation times of several minutes or longer, as the laser light causing these ac-Stark shifts is well stabilized to ensure proper operation of the entangling operations [18].Other possible origins of such shifts are differential magnetic shifts between the different electronic states used to define the computational subspace and the decoupling of qubits, and a detuning of the control fields from the qubit transition frequency due to a slowly varying laser frequency.Measuring and compensating for such a qubit detuning can be performed using techniques developed in the context of quantum metrology [42].It is important to note that the MS entangling gate operation commutes with systematic phase shifts in the sense that the essential part of the complex circuit, namely, the three entangling gate operations, still generates a final quantum state that is locally equivalent to the ideal encoded state of Eq. ( 1), however, with a set of unknown, relative phases fϕ i g: In order to maximize the fidelity of the encoded state, these phases need to be characterized and compensated for.There is no simple Ramsey-type experiment to determine these phases; hence, we need to find a protocol to measure them without full quantum state tomography.

II. PROPOSED METHOD
Some of the error sources in a quantum state preparation process, such as in the encoding discussed in the previous sections, result in "true" decoherence, which cannot be reversed by a subsequent application of unitary operations.
The question of whether a given source of imperfections results in systematic, coherent errors that can be calibrated out, or in decoherence, depends strongly on the origin of the noise and is related to the noise fluctuation time scale as compared to the data acquisition time.For instance, phase shifts that vary over the (short) times required to execute an individual run or a few runs of a quantum circuit result in dephasing that the quantum error correcting procedure itself will take care of.In contrast, phase shifts that do not change their nature over (long) data acquisition times give rise to systematic coherent shifts that can be detected and compensated for.In the presented experiments, phase shifts are predominantly of this latter type, as they are mainly caused by ac-Stark shifts originating from entangling operations that are performed on neighboring qubits.These do not vary significantly over the data acquisition time required to implement the proposed phase optimization technique.The algorithm we propose aims at determining and undoing systematic unitary errors such as relative phase shifts in a simple, iterative manner without full state reconstruction.A simple model to outline the working principle of the proposed phase compensation technique is the formulation of the resulting final experimental state in the form of a Werner-type state, where the part proportional to the identity operator, representing a completely mixed state, stands for a white-noise component, accounting for irreversible decoherence processes (dim ¼ 2 7 ¼ 128 in the present case).The second term corresponds to the state jψ 0 0 i [see Eq. ( 2)] containing a set of unknown phase shifts, which will be compensated for by the application of corrective unitary phase shifts, in order to transform this component into the ideal encoded logical state jψ 0 i of Eq. ( 1).The parameter p ∈ ½0; 1 quantifies the magnitude of the irreversible noise component, interpolating between the ideal target state (up to the unitary phase shifts) for p ¼ 0 and a fully mixed state in the limit p ¼ 1.
For simplicity, we start by discussing the working principle of the phase compensation method for an intermediate state in the full encoding sequence shown in Fig. 1.The state we will optimize is the one that is reached after the application of the four-qubit entangling operations to the first and the second plaquettes of the planar, three-plaquette quantum error correcting code [see Fig. 1(a)].The ideal target state at this stage of the encoding sequence is given by It maximizes the value of the generating X-type stabilizer operators on the first and second plaquettes, x ¼ X 2 X 3 X 5 X 6 , as well as of the stabilizer operator formed by the product of both, S ð1Þ x S ð2Þ x : The state jψ 0 0 i containing unknown phase shifts accumulated up to this point then reads In order to compensate the relative phase shifts, we may apply single qubit Z rotations to three of the six qubits, for instance, where we have discounted the global phase factor e −iðθ 1 þθ 2 þθ 5 Þ .The problem is to find the correct set of values θ ¼ ½θ 1 ; θ 2 ; θ 5 that compensates the phases, and transform the state jψ 0 0 i into jψ 0 i.This can be viewed as an optimization problem, as it is equivalent to finding the point θ that is simultaneously a maximum of hS Experimentally, an exhaustive search to determine the set of values of the three phases θ that maximize the X-type stabilizers is impractical, as the number of possible phase configurations grows exponentially with the number of phases.Instead, we may apply the following iterative protocol: (1) Fixing of the phase-to-stabilizer correspondence: For each X stabilizer, an associated control parameter θ i that controls the compensation unitary expðiθ i Z i Þ, acting on ion i, is chosen.The particular assignment of stabilizer operators to phases θ is somewhat arbitrary; however, it is important that a given X stabilizer associated with a given phase depends on the application of the corresponding Z i rotation.This is the case if and only if the X stabilizer under consideration contains the Pauli matrix X i corresponding to the ion i, and thus does not commute with a Z i rotation.Note that once a particular phase-to-stabilizer assignment is chosen, this should not be altered during subsequent steps of the optimization algorithm.Here, we choose θ 2 for S x , θ 5 for S x , and θ 1 for S x , respectively.
(2) Choose an initial configuration for the set of rotation parameters θ ð0Þ ¼ ½θ Scan θ 2 over the interval ½0; 2π, while keeping θ 1 ¼ θ by scanning θ 5 , while keeping the other control parameters at their previously determined values, i.e., θ 2 ¼ θ i.e., scan over θ 1 at fixed values θ 2 ¼ θ x i not containing X 2 remains constant.For each scan, the stabilizer that takes part in the optimization procedure is highlighted by the bold line, and the corresponding maximum value is marked via the orange circle.After reading off and fixing θ 2 to the value that maximizes hS ð1Þ x i (orange circle), a Z rotation is applied to qubit 5 (c).This scan is used to fix θ 5 to the value that maximizes hS ð2Þ x i. Whereas, in principle, at this point one would proceed with the optimization of hS ð1Þ x S ð2Þ x i by a Z 1 -rotation scan, the data show that all three stabilizers, within experimental resolution, have already reached the maximum, indicating convergence of the protocol.This is also reflected by both X-type plaquette stabilizers now being positive and maximal (d), while the expectation values of Z-type stabilizers and of the logical Z operator have remained unchanged over the application of the algorithm-compare (a) and (d).Experimental parameters: In each scan, different values for the phases characterizing the single-qubit rotations were applied with an elementary step size of 2π=10.For each phase value, the experiment was repeated 200 times.
x i. Thereby, the component of the final state corresponding to jψ 0 0 i of Eq. ( 6) is transformed, as desired, into the correct one jψ 0 i [see Eq. ( 4)].
If systematic phase-shift errors were the only experimental source of imperfections, these maximal values would all be equal to 1, corresponding to the case p ¼ 0 in the model of Eq. (3).In practice, decoherence processes are significant (p > 0), and they reduce the experimentally attainable maximal values of the set of stabilizer operators.Figure 2 shows how the described phase optimization algorithm works in experiment.Here, it was applied to remove relative phase shifts in the ideal, intermediate state Eq. ( 4) after the first two entangling operations.Interestingly, the algorithm converges very quickly, namely, already after performing two optimization steps of stabilizers during the first round of iterations, n ¼ 1.Overall, this resulted in a time of ≈7 minutes required for the application of the phase optimization protocol, as compared to about ≈48 minutes necessary for a full sixqubit state tomography under comparable conditions.Note that the required time for full state tomography does not include state reconstruction as well as phase optimization.

III. ANALYSIS AND PROPERTIES OF THE METHOD
As already seen, the proposed phase optimization method provides correct results with very fast convergence for the two-plaquette case.Let us now analyze in more detail its mathematical background and performance for larger-dimensional optimization problems.

A. Connection to coordinate descent methods
To better explain the properties of the protocol and why it works, let us first consider a function of θ ¼ ½θ 1 ; θ 2 ; θ 5 defined as the sum of the stabilizer operators hS ð1Þ x i, hS ð2Þ x i, and hS ð1Þ x S ð2Þ x i given in Eqs. ( 8), (9), and (10): Instead of separately optimizing hS ð1Þ x i, and hS x i, we may maximize fðθÞ following the same method as in steps 3-5 above, i.e., fixing θ 2 ¼ θ This recipe is essentially a global version of coordinate descent (ascent) methods for minimizing (maximizing) functions of several variables; see Refs.[43,44].It is global in the sense that the optimization in every coordinate is done by searching the global maximum instead of applying gradient algorithms.It is clear from the very formulation of the method that f will monotonically increase, Therefore, the only way that f might not converge to its maximum point under this method is if it gets stuck in a local (but not global) maximum at some step.Nevertheless, one can show that the function fðθÞ in Eq. ( 11 x i as in steps 3-5 of the iterative algorithm outlined above.Nevertheless, the latter, experimentally used algorithm works as well because, on the one hand, the optimal point θ for hS ð1Þ x i is also optimal for hS ð2Þ x i and hS ð1Þ x S ð2Þ x i.In other words, there exists a common optimum point for every term contributing to the sum in fðθÞ.On the other hand, despite the fact that the maximization process of some stabilizer will, in general, reduce the value of other stabilizers at intermediate steps, the global optimization in every coordinate rapidly overcomes this effect.

B. Optimization of the entire seven-qubit encoding:
The three-plaquette case The practical applicability of the method has been tested and benchmarked by applying it to the more complex case of the entire encoding of the seven-qubit code.Here, the aim is to determine and remove the 2 3 − 1 ¼ 7 relative phases of the state equation ( 2) in the preparation of the logical j0i L .The procedure works similarly as in the case of two plaquettes discussed above; however, here we need to apply Z rotations to all seven qubits, to correct all phases by maximizing the seven expectation values of plaquette operators hS x i, hS

C. Convergence on average
Let us now obtain an estimate for the convergence rate.The function fðθÞ for two plaquettes in Eq. ( 11) can be written as a function of one component of the vector θ, say θ 1 , in the form of where A ¼ Aðθ 2 ; θ 5 ; ϕ 1 ; ϕ 2 ; ϕ 3 Þ, φ ¼ φðθ 2 ; θ 5 ; ϕ 1 ; ϕ 2 ; ϕ 3 Þ, and c ¼ cðθ 2 ; θ 5 ; ϕ 1 ; ϕ 2 ; ϕ 3 Þ.Specifically, By computing the mean value of this amplitude on a uniform distribution of their arguments, we obtain Ā ¼ 0.81, and similarly, the mean value of c is c ¼ 0. In a rough, conservative estimate where the average value of c remains constant when moving from the optimization of one coordinate of θ to the next one, we estimate that in every coordinate optimization step, we gain Ā=2 ¼ 0.40 on average.Therefore, since fðθÞ ¼ 0, we estimate that we will obtain convergence after n ¼ 2.47 iterations on average.A similar estimate for the three-plaquette case leads to a gain per coordinate optimization step of Ā=2 ¼ 0.40 on average, and thus estimated convergence after n ¼ 2.47 iterations on average, which is the same value as found for the two-plaquette case.
These values can be checked by a numerical simulation of the method averaging over many random configurations of phases ϕ.For two and three plaquettes, the simulation produces a mean value of n ¼ 1 (exact) and n ¼ 2.25 ( σ ¼ 0.50), respectively.On the one hand, the exact convergence after n ¼ 1 iterations for two plaquettes is due to the high degree of symmetry of fðθÞ in that case, which has not been taken into account in the rough estimation of the average convergence rate.On the other hand, the simulation is compatible with the estimate for the three-plaquette case, with a slightly improved, i.e., faster, rate of convergence.
To determine the convergence rate of the method optimizing individual mean values instead of their sum, we have numerically simulated this version of the algorithm used in the experiment, by averaging over random values of ϕ.This produces convergence after n ¼ 1 (exact) iterations for the two-plaquette case and n ¼ 2.16 ( σ ¼ 0.56) for the three-plaquette case.The numerically observed convergence of n ¼ 1 is in accordance with the experimentally observed convergence within a single iterative cycle of optimization (see discussion above and Fig. 2).Interestingly, the numerical results for the threeplaquette case suggest that the variant based on optimizing individual mean values converges slightly faster than optimizing the sum over all of them.Furthermore, as expected from the analytical arguments, our numerical study confirms that no phase configurations were encountered for which the optimization algorithm gets stuck or reaching convergence takes particularly long.In fact, the worst case in 10,000 random simulation runs corresponded to convergence after n ¼ 5 iterative cycles.Further details can be found in Appendix C.

D. Experimental optimization of the seven-qubit code
Figure 3 shows experimental results of the iterative phase optimization algorithm applied to the entire encoding sequence of the seven-qubit error correcting code.Whereas initially X-type stabilizer expectation values are nonmaximal because of the presence of unknown relative phase shifts in the state of Eq. ( 2), after two iterative cycles (n ¼ 2), composed of 14 elementary optimization steps, the algorithm converges within the experimental resolution and outputs a set of values for the compensation phase shifts θ ¼ ½θ 1 ; …; θ 7 , for which the initially unknown relative phases fϕ i g are removed.As a consequence, not only the Z-type stabilizer values, which are unaffected by the optimization protocol, but also all X-type stabilizers are positive-valued and maximal within the given accuracy of the encoding quantum circuit.The experimentally observed convergence after n ¼ 2 rounds is in very good agreement with the numerical prediction of n ¼ 2.16 for the threeplaquette case.

E. Scalability properties
Let us now briefly discuss to what extent the present protocol is scalable as quantum states of systems of larger number of qubits are considered.In the analyzed two-plaquette case, we have been able to compensate three undesired relative phases by applying three qubit Z rotations.For the complete minimal planar seven-qubit color code, we need to apply seven single-qubit Z rotations.Larger instances of 2D color codes (see Fig. 5 in the Appendix D) encode logical qubits in a larger number of physical qubits and thereby provide larger logical distances and increased robustness to errors.The number of computational basis states involved as components in logical states of such larger systems grows exponentially with the number of plaquettes (#), and so does the number (#) of relative phases that need to be compensated: In the most general case, these relative phases may be uncorrelated among each other, so an exponential number of independent Z-type Hamiltonian generators are required to unitarily compensate all phases.This can, in principle, be achieved by resorting not only to singlequbit Z rotations but also to two-qubit ZZ rotations, expðθ ij Z i Z j Þ, and three-qubit and higher-order n-body rotations.Following this route, the required operations become more and more nonlocal.One can then ask to which size of a planar color code the method can be extended such that only physically quasilocal rotations, i.e., n-qubit rotations only acting on qubits belonging to the same plaquette, are sufficient to correct the set of undesired phases.Combinatorics show (see Appendix D) that phases in the state of a logical distance d ¼ 5 color x i, hS x i, hS x i, and hS ð1Þ x S x i, the algorithm converges to a set of compensation phases, θ ¼ ½θ 1 ; …; θ 7 , for which all X-type stabilizers assume maximal values.The individual phase value θ i to the Z rotation, which is adjusted to maximize the corresponding stabilizer expectation value under consideration (bold line), is indicated by the orange circle for each optimization step [see (b)-(i)].Note that because of the periodicity in θ i , it is also possible to search for the minimum expectation value of the stabilizer under consideration and add the rotation angle 2θ ¼ π; see (c) for an example.The Zand X-type stabilizers of the logical state j0i L after two rounds of optimization steps are shown in (j).Intermediate steps of the second round of optimization are not shown.The experimental parameters are as specified in Fig. 2. code involving 17 qubits can, in principle, still be corrected by such physically quasilocal rotations, whereas the next-larger generation, a distance d ¼ 7 color code encoded in 31 qubits, would require physically nonlocal rotations acting on qubits on several plaquettes.This mismatch between degrees of freedom and local operations, which becomes more significant as the code size increases, is a generic feature and not specific to color codes.It will ultimately need to be circumvented by the implementation of quantum error correcting codes in physical architectures where physical error sources act quasilocally, and by using fault-tolerant encoding protocols [45,46], which avoid an uncontrolled propagation of errors during the encoding over the entire quantum hardware [19,20].

IV. CONCLUSIONS AND OUTLOOK
In this work, we have proposed and experimentally shown an iterative phase optimization protocol that allows one to efficiently compensate systematic, unknown but constant phase-shift errors, which can occur, e.g., in realizations of small quantum error correcting codes.The method allows one to determine and remove such relative phases without full quantum state tomography, and it converges very quickly when applied to small quantum error correcting codes.This algorithm was a key element in optimizing a recent successful implementation of a seven-qubit quantum error correcting code in a system of trapped ions [16].The method can be equally applied to alternative, nonunitary encoding protocols based, e.g., on quantum nondemolition (QND) measurements of stabilizer operators.Furthermore, the protocol demonstrated here is not limited to trapped ion systems, and we hope that it will be useful also for other, currently ongoing efforts in quantum computing and error correction in AMO and solid-state systems.

APPENDIX A: PHASE DEPENDENCE OF STABILIZER OPERATORS
The expectation values of the seven stabilizer plaquette operators for the state equation ( 13) are given by hS ð1Þ x S By considering all variables of θ fixed except one, say θ 1 , we have seen that the function fðθÞ can be written as a cosine, Eq. ( 14).Since this is true for every variable of θ when fixing the rest of them, the sections of the function fðθÞ in every variable are just cosine functions (one frequency).In such a situation, it does not seem possible to obtain local maxima or minima.This is because the hypersurface fðθÞ can be viewed as a modulation of a cosine profile along all the orthogonal directions by other cosine profiles; since the cosines do not have local extrema, their modulations do not create local extrema.In fact, the maximum (minimum) points are just the points that maximize (minimize) all sections individually.This can be checked with the two-plaquette case where the condition for the critical point of fðθÞ is By solving the three simultaneous conditions, we find that the critical points that are a maximum or a minimum (the rest are saddle points) are where k 1 ; k 2 ; k 3 ∈ Z.However, in this case, reaches either its absolute maximum (3) or its absolute minimum (−1).

APPENDIX C: CONVERGENCE SCALING
For practical purposes, the average number of iterations required by the phase optimization method (PHOM) depends on the value taken as a convergence threshold or, equivalently, on how close we demand the stabilizer mean values to get to their maximum value.In our case, we establish that convergence of the iterative optimization is reached once all stabilizer expectation values have assumed their maximal values to within 10 −3 .This is well within the experimental measurement accuracy [16,18], for which convergence is reached in practice.
For the sake of completeness, in Fig. 4, we show the average number of iterations as a function of the convergence threshold.We have quantified the latter by means of two figures of merit, namely, δ 1 ¼ jfðθÞ − 7j and δ 2 , which corresponds to the maximum among the distances of each individual stabilizer and its maximum value.Notably, fast convergence is observed throughout the whole range of numerical values considered.
are the product of Pauli X and Z operators, respectively, associated with subsets fig of qubits; see Fig. 1(a).Each generator is of X or Z type so that S ðiÞ x jψi L ¼ S ðiÞ z jψi L ¼ þjψi L holds for all subsets fig and any encoded logical state jψi L .A seven-qubit code with subsets as illustrated in Fig. 1 represents the minimal instance of a 2D color code.

2 FIG. 1 .
FIG.1.Schematics of the implemented seven-qubit quantum error correcting code and the encoding sequence.(a) One logical qubit is encoded in seven physical qubits forming a twodimensional triangular planar structure of three plaquettes.The code space is defined as the simultaneous þ1 eigenspace of a set of six four-qubit stabilizer operators associated with the plaquettes.(b) Physical qubits are encoded in (meta)stable electronic states of a string of seven 40 Ca þ ions.The computational subspace of each physical qubit is spanned by the two electronic states 4 2 S 1=2 ðm j ¼ −1=2Þ (j1i) and 3 2 D 5=2 ðm j ¼ −1=2Þ (j0i).Another pair of states [3 2 D 5=2 ðm j ¼−5=2Þ and 3 2 D 5=2 ðm j ¼−3=2Þ] is used to spectroscopically decouple individual ion qubits.Red arrows indicate sequences of pulses that are applied to realize this coherent decoupling (see Ref.[16] for more details).Decoupled ions [indicated by dashed lines in (c)] ideally will not participate in subsequent dynamics, until they are recoupled, i.e., coherently transferred back into the computational subspace [solid lines in (c)].This technique enables the application of entangling gate operations, which, in this setup, are implemented by illuminating the entire ion string by a global laser beam[18], to subsets of four qubits belonging to a given plaquette.(c) The logical qubit is encoded by coherently mapping the product input state j1010101i onto the logical state j0i L [see Eq. (1)].The quantum circuit combines spectroscopic decoupling and recoupling operations (white boxes) with plaquette-wise entangling operations that effectively create GHZ-type entanglement between qubits belonging to the same plaquette.
Note that under the application of Z-type rotations, Z-type stabilizer expectation values remain unchanged.

5 . ( 3 )
Experimentally optimize S ð1Þ x : The mean value of S ð1Þ x depends on control parameter θ 2 in the following sinusoidal form, hS

5
fixed.Measure all qubits in the X basis to determine and fix θ 2 to the value θ 2 ¼ θ ð1Þ 2 for which the measured mean value hS ð1Þ x i is maximized.(4) Next, experimentally optimize S ð2Þ x , hS

ð1Þ 2 and θ 5 ¼ θ ð1Þ 5 , 6 ); θ ðnÞ 2 ; θ ðnÞ 5 ,FIG. 2 .
FIG. 2. Experimental implementation of the phase optimization protocol.Here, the algorithm was applied to the intermediate state in the encoding sequence, which results from the application of the first two entangling operations acting on the qubits of the first (red) and second (blue) plaquettes of the planar seven-qubit quantum error correcting code.The resulting state (a), before the application of the iterative phase optimization technique, is characterized by positive values of Z-type plaquette stabilizer expectation values, which are maximal within the experimentally achieved accuracy of the encoding circuit [16].On the other hand, X-type stabilizer expectation values have arbitrary values (positive on the first, negative on the second plaquette), indicating the presence of undesired, unknown relative phase shifts [see Eq. (6)].In the first step of phase optimization (b), a Z rotation of variable magnitude is applied to qubit 2, which results in a sinusoidal behavior of the expectation values of the stabilizers hS ð1Þ x i and hS ð2Þ x i [cf.Eqs.(8) and (9)], whereas the expectation value hS ð1Þ x S

2 ,
and so on.
The explicit expressions of these expectation values showing their dependence on the control parameters θ ¼ ½θ 1 ; …; θ 7 are given in Appendix A.

FIG. 3 .
FIG.3.Experimental phase optimization of the complete seven-qubit quantum error correcting code.Here, the algorithm was applied to the final state resulting from the complete encoding sequence shown in Fig.1, i.e., three entangling operations applied to the qubits belonging to the first (red), second (blue), and third (green) plaquette of the code.Initially, X-type stabilizer expectation values are nonmaximal (a), indicating the presence of unknown, relative phases in the desired target state.After two rounds of iteratively maximizing the seven expectation values of plaquette operators hS ð1Þ x i, hS

FIG. 5 .
FIG. 5. Larger instances of planar color codes.The 17-qubit code (a) encodes a logical qubit of logical distance d ¼ 5; the 31qubit code (b) has distance d ¼ 7. Whereas the 17-qubit code would, at least in principle, allow for the correction of the undesired phases with physically quasilocal rotations, acting only on subsets of qubits belonging to the same plaquette, phase compensation for the 31-qubit case (and larger codes) would require nonlocal rotations involving qubits of several plaquettes.

6 FIG. 4 .
FIG.4.Number of iterations vs convergence threshold.This plot shows the scaling of the number of iterations required by PHOM with the tightness of the convergence criterion.As commented in the text, two figures of merit assess this, δ 1 and δ 2 .The former is related to the distance between the sum of stabilizers and its maximum value, and the latter is associated with the maximum value among the distances for each stabilizer.The simulations have been done for the case of PHOM applied to individual mean values.