As depicted in Fig. 1a, the NV center consists of a substitutional nitrogen atom with an adjacent vacancy site in the diamond crystal lattice. The ground state of NV center is an electron spin triplet state with three sublevels |m S = 0〉 and |m S = ±1〉. A static magnetic field is applied along the NV symmetry axis ([1 1 1] crystal axis) to remove the degeneracy between the |m S = +1〉 and |m S = −1〉 states, yielding the electron and nuclear Zeeman splitting. The Hamiltonian of the electron spin and the 14N nuclear spin system is

$$H_{{\mathrm{NV}}} = 2\pi \left( {DS_z^2 + \omega _eS_z + QI_z^2 + \omega _nI_z + A_{zz}S_zI_z} \right),$$ (1)

where S z and I z are the spin operators of the electron spin (spin-1) and the nuclear spin (spin-1). The electronic zero-field splitting is D = 2.87 GHz and the nuclear quadrupolar interaction is Q = −4.95 MHz. The two spins are coupled by a hyperfine interaction A zz = −2.16 MHz. The two-qubit quantum system is composed of |m S = 0, m I = +1〉, |m S = 0, m I = 0〉, |m S = −1, m I = +1〉, and |m S = −1, m I = 0〉 without considering the other spin levels. The four energy levels are denoted by |1〉, |2〉, |3〉 and |4〉 as shown in Fig. 1a. At the magnetic field strength of 500 G, the spin state of the NV center is effectively polarized to |m S = 0, m I = +1〉 when a 532 nm laser pulse is applied.12

Fig. 1 Two-qubit programmable quantum processor in NV center. a Schematic atomic structure and energy levels of the NV center. The experiments are implemented on the two-qubit system composed of four energy levels within the dashed box (i.e., |m S = 0, m I = +1〉, |m S = 0, m I = 0〉, |m S = –1, m I = +1〉, and |m S = −1, m I = 0〉 denoted by |1〉, |2〉, |3〉 and |4〉). b Circuit diagrams for arbitrary unitary transformations. The brackets highlight the decomposition of arbitrary two-qubit operation into (C ⊗ D) · V · (A ⊗ B). R(θ, φ) corresponds to a rotation angle θ around the axis in the XY plane. φ denotes the angle between the axis and the X axis. R z (φ z ) represents a rotation angle φ z around the Z axis. The entangling two-qubit gate U zz is exp(iπS z ⊗ I z ). c Realization of the single-qubit gates. The single-qubit rotations on the electron spin are realized by hard microwave pulses with fixed Rabi frequency of Ω 1MW = 40 MHz. The duration of the pulses corresponds to the rotation angle θ. The single-qubit rotations on the nuclear spin are realized by decoherence-protected gates consisting of dynamical decoupling of the electron spin and nuclear spin driving during the time interval. The strength of the nuclear spin driving is determined by the rotation angle. The time τ corresponds to the interaction between electron spin and nuclear spin Full size image

Arbitrary single-qubit gates combined with applications of a maximally entangling two-qubit gate are sufficient for realization of universal two-qubit unitary operation. Our choice of a universal gate library consists of single-qubit gates and an entangling two-qubit gate, U zz = exp(iπS z ⊗ I z ), which can be realized by the free evolution under the hyperfine coupling between electron spin and nuclear spin. We decompose a given two-qubit unitary operation U into U = (C ⊗ D) · V · (A ⊗ B) as shown in Fig. 1b, where V is a two-qubit gate and A, B, C, D are single-qubit gates. The decomposition follows a three-step procedure analogous to that in ref. 4. First, the matrix eigenvalues of V and U are matched to find the three parameters α, β and δ shown in the dashed rectangle in Fig. 1b. Second, the four remaining single-qubit gates, A, B, C and D, are found by mapping the eigenvectors of V and U to satisfied the equation U = (C ⊗ D) · V · (A ⊗ B). Finally, the single-qubit gates are parameterized by the decomposition R z (φ z,j ) · R(θ j , φ j ) for j = [A, B, C, D]. R(θ j , φ j ) = exp[−iθ j (cosφ j S x + sinφ j S y )], corresponds to a rotation of angle θ around the axis in the XY plane. φ denotes the angle between the axis of rotation and the X axis. R z (φ z,j ) represents a rotation of angle φ z,j around the Z axis. After the procedure discussed above, arbitrary two-qubit unitary transformations can be realized using the universal quantum circuit with fifteen parameters, which are α, β, δ, θ A , φ A , φ z,A , θ B , φ B , φ z,B , θ C , φ C , φ z,C , θ D , φ D , and φ z,D .

For the quantum processor, the two-qubit entangling gate, U zz , is realized by the free evolution under the hyperfine coupling H hf = 2πA zz S z I z . So the time duration of U zz is 231.5 ns. The single-qubit rotations on the electron spin are realized by microwave (MW) pulses with fixed Rabi frequency of Ω 1MW = 40 MHz. The pulses flip the electron spin practically independent of the nuclear spin state for the large Rabi frequency comparing to the hyperfine coupling A zz . The length of the MW pulse t is determined by the rotation angle θ as shown in the upper panel in Fig. 1c. Since the states of the electron and nuclear spin evolve and decohere at very different rates, decoherence-protected gates are implemented to realize the single nuclear spin rotation10 as shown in the lower panel in Fig. 1c. The XY-4 sequence is applied on the electron spin to protect the electron’s coherence. The states of nuclear spin is driven during the time between the decoupling pulses. A rotation of the nuclear spin, which is independent of the electron spin state, is constructed by choosing τ = 2nπ/A zz with integer n. Here we fixed τ = 2777.8 ns with n = 6 and the strength of the radio-frequency (RF) pulses is set as Ω 1RF = θ/4τ. The rotation around the Z axis R z (φ z ) is realized by adding a phase to the drive field for all subsequent gates.

To exhibit the flexibility of the processor to generate unitary transformations, we first implement the Deutsch–Jozsa algorithm13 as an example. It has been employed in different systems to demonstrate the exponential speedup in distinguishing constant from balanced functions with respect to the corresponding classical algorithm.9,14,15,16,17,18,19 A function that has an n-bit input and a 1-bit output (f:0, 1, 2, …, 2n − 1 → 0, 1) is balanced when exactly half of the inputs result in the output 0 and the other half in the output 1, while a constant function assumes a single value irrespective of the input. The constant function (f(0) = f(1) = 0) and the balanced function (f(0) = 0, f(1) = 1) are mapped onto the unitary operators U i with U 1 = I and U 2 = CNOT as shown in the quantum circuit in Fig. 2a, where the I denotes the identity and the CNOT is the controlled-NOT gate. A measurement of the populations, P = {P 1 P 2 P 3 P 4 }, of the final state determines if the function is constant or balanced. The populations, P, of the final state are determined by performing a set of measurements with different pulse sequences to redistribute the population of the final state. Comparing to the direct measurement of the final state, π e and π n pulses on the electron and nuclear spin respectively are also applied on the final state to flip the populations within the two-qubit system. The population of each energy level can be achieved from the resulting photoluminescence of these states. The entire quantum circuit combined with the flipping pulses can be treated as a unitary operator. This unitary operator is decomposed into the universal quantum circuit as shown in Fig. 1b following the three steps discussed above. The corresponding 15 parameters are shown in Table 1. Different unitary operators are implemented using the universal quantum circuit with different sets of parameters. Measurement of output P = {1000} indicates a constant function, while P = {0010} indicates a balanced function. In Fig. 2b, c, we show the measured population of each spin level of the final state after the Deutsch-Josza algorithm. The red bars indicate the ideal result, while the green bar is the simulation result considering the decoherence of the electron spin and the imperfect polarization (see Supplementary Information Section 2). The experimental results (blue bars) are in good agreement with the simulated results. The average success probability is 0.88(2) for constant and 0.93(2) for balanced functions.

Fig. 2 Experimental demonstration of Deutsch-Josza algorithm. a Quantum circuit of Deutsch–Josza algorithm. Y \(\left( {\overline {\mathrm{Y}} } \right)\) indicates the π/2 (−π/2) rotation around the Y axis. The constant function and the balanced function are mapped onto the unitary operators U 1 = I and U 2 = CNOT, respectively. b, c The experimental results of Deutsch–Josza algorithm with constant and balanced functions, respectively. P 1 , P 2 , P 3 and P 4 denote the population of |1〉, |2〉, |3〉 and |4〉, respectively. The red bars are the ideal case. The green bars are the simulation results considering the imperfect polarization and the decoherence. The blue bars are the experimental results Full size image

Table 1 The parameters of the two-qubit programmable processor for Deutsch–Josza algorithm Full size table

Now we show that another quantum algorithm, named Grover search algorithm, can be executed by our programable quantum processor by just adjusting the 15 parameters. The Grovers search algorithm20 provides an optimal method for finding the unique input value x 0 of a function f(x) that gives f(x 0 ) = 1 and f(x) = 0 for all other values of x. It has been demonstrated in various systems.21,22,23,24 In the two-qubit version of this algorithm there are four input values, x ∈ (00, 01, 10, 11), resulting in four possible functions f ij (x), with i, j ∈ (0, 1). These functions are mapped onto the C-Phase gate cU ij that encodes f ij (x) in a quantum phase, \(cU_{ij}\left| x \right\rangle = ( - 1)^{f_{ij}(x)}\left| x \right\rangle\). The C-Phase gate cU ij is denoted by the oracle U i as shown in the quantum circuit in Fig. 3a. The quantum circuits to realize the C-Phase gate cU ij are designed specifically to the four cases in the conventional implementation of the two-qubit version of Grover search algorithm. In our work, the algorithm is demonstrated by the universal quantum circuit. The unitary operator of the four possible quantum circuit is programmed into the four sets of parameters as shown in Table 2. A measurement of the populations, P = {P 1 P 2 P 3 P 4 }, of the final state finds the state that has been marked. In Fig. 3b–e, we show the measured the population of each spin level of the final state after the Grover search algorithm of four possible oracle functions. The experimental results (blue bars) are in good agreement with the simulated results (green bars). The average success probability is 0.85(1), 0.82(2), 0.81(2), and 0.84(2) for four possible functions, respectively.

Fig. 3 Experimental demonstration of Grover search algorithm. a Quantum circuit of Grover search algorithm. Four possible function f ij (x) are mapped onto the oracle U i which is the C-Phase gate cU ij . b–e The results of Grover search algorithm characterized by the population of each spin level of the final state. P 1 , P 2 , P 3 , and P 4 denoted the population of |1〉, |2〉, |3〉, and |4〉, respectively. The red bars are the ideal case. The green bars are the simulated case considering the imperfect polarization and the decoherence. The blue bars are the experimental results Full size image