\section{Introduction}
\label{sec:introduction}

\par Diamond is a promising architecture for quantum information processing \cite{Neumann2010a, Dolde2014,Taminiau2014, Waldherr2014,Wang2015,Kong2016,Bradley2019,Hou2019} and quantum sensing/ microscopy \cite{Neumann2013,Dolde2014a,Zaiser2016,Aslam2017} at both cryogenic and room temperautres. Optimised diamond quantum processors are crucial building blocks for large-scale diamond quantum computers and the next generation of quantum sensors and microscopes that are enhanced by embedded quantum memories and signal processing \cite{Unden2016, Haeberle2017,Pfender2017}. To date, diamond quantum processors have been used to implement quantum error correction codes \cite{Taminiau2014, Waldherr2014, Cramer2016}, quantum algorithms \cite{Shi2010, Xu2017}, detection of metallo-protein molecules \cite{Ermakova2013} as well as quantum simulation of the helium hydride cation \cite{Wang2015} and topological phase transition of a quantum wire \cite{Kong2016}. For technology applications, diamond quantum processors are distinguished from other quantum architectures due to their ability to operate in ambient conditions and with relatively simple microwave, radio-frequency and off-resonant optical control systems \cite{Doherty2017}. The resulting improvements in complexity, robustness and cost make diamond one of the most flexible and widely applicable quantum technology platforms.

\par  Diamond quantum processors consist of a nitrogen-vacancy (NV) centre with a local cluster of hyperfine-coupled nuclear spins. These coupled nuclear spins include the intrinsic N nuclear spin of the NV centre and isotopic $^{13}$C lattice impurities. Quantum computations are realised by using the electron spin of the NV centre as a quantum bus that initialises, mediates interactions between, and reads-out the coupled nuclear spins, which act as the physical qubits. Scaling of the diamond quantum architecture requires a mechanism to couple multiple NV centres and their qubit clusters. Coupling of separate NV centres has been demonstrated at cryogenic temperatures using photons \cite{Bernien2013,Hensen2015,Kalb2017}, and at room temperature using magnetic dipole coupling between proximate NV centres \cite{Dolde2014,Dolde2013}. Spin chains \cite{Yao2012} and coherent spin transport \cite{Oberg2019} have also been proposed as coupling mechanisms.

\par Previous work in optimising the quantum control of either the NV centre's electron spin or coupled nuclear spin qubits has already demonstrated excellent control fidelities, using techniques including dynamical decoupling \cite{Bradley2019,Hou2019,Viola1999,Khodjasteh2005,Lange2010,Wang2012,Zhao2012,Sar2012,Naydenov2011,Pham2012,Taminiau2012,Liu2013,Zhang2014,Abobeih2018} as well as numerical gate pulse-shaping techniques, such as the Chopped RAndom Basis (CRAB) quantum optimisation algorithm \cite{Doria2011, Caneva2011} and the GRadient Ascent Pulse Engineering (GRAPE) algorithm \cite{Khaneja2005}. Experimental application of the CRAB algorithm to the NV electron spin has yielded ultra-fast single-qubit gates (ie beyond the rotating wave approximation) with fidelities of $0.95\pm 0.01$ and $0.99\pm 0.016$ for $\pi/2$ and $\pi$ pulses, respectively \cite{Scheuer2014}. The GRAPE algorithm has been used to demonstrate single electron spin operations with fidelity $ F\approx 0.99$ \cite{Dolde2014} and generate entangled states of three nuclear spins with fidelities exceeding 85\% \cite{Waldherr2014}. Moreover, an average single-qubit gate fidelity of 0.999952 and two-qubit gate fidelity of 0.992 has been reported using composite pulses and a modified GRAPE algorithm, respectively \cite{Rong2015}. While some of the demonstrated gate fidelities are impressive, even with a gate fidelity of 0.999, for a fault-tolerant logical qubit to achieve logical error rates comparable to classical computers, effective surface code error correction is anticipated to require up to $10^4$ physical qubits \cite{Fowler2012,Campbell2017}. Therefore, there is a strong motivation to push for further reduction in gate errors.

\par There are two different optimisation problems to address to improve the performance of diamond quantum processors: improvement of initialisation/ readout fidelities and improvement of gate fidelities and speeds. The initialisation/ readout fidelities are optimised by selecting the $^{13}$C nuclear spin lattice sites that have the longest nuclear spin relaxation time during the projective single-shot optical readout process employed in diamond quantum processors \cite{Waldherr2014}. Broadly speaking, the best lattice sites are those whose hyperfine field is well aligned to NV centre's axis. As will be discussed later, overcoming the effects of hyperfine field misalignment and decoherence are crucial to achieve high gate fidelities. As such, there is some correlation between the choices made to optimise initialisation/ readout fidelities and gate fidelities. Consequently, for simplicity, in the following we will not discuss the optimisation of initialisation/ readout fidelities. Instead, we assume a particular selection of nuclear spin qubits with well-aligned hyperfine fields, and focus on the problem of optimising the gate fidelities due to control errors and speeds.

\par Optimisation of the processor gate operations requires simultaneous maximisation of gate speed and minimisation of: (1) spurious effects of control fields on qubits other than the target qubit(s) (ie cross-talk), (2) the effects of random control field errors (ie those caused by fluctuations in amplitude, frequency and phase), (3) the effects of decoherence, and (4) the effects of hyperfine field misalignment. Additional practical requirements are that the gate design: (A) complies with the physical constraints of the control systems, (B) is readily incorporated into a feedback-based optimisation routine that uses measurements to optimise the actual physical processor (and not just models of the processor) and supports updating of the optimisation during operation to adjust for system drifts, and (C) is parameterised so that the degree of convergence to optimisation limits can be deterministically and systematically assessed (in order to support design decisions concerning the costs and benefits of further optimisation) and the dominant error modes can be diagnosed (to improve processor design). As GRAPE involves direct numerical solving of pulses using model systems, it does not readily achieve the practical requirements (B) and (C) and relies heavily on the accuracy of its models \cite{Wu2018}. On the other hand, the nature of CRAB allows the integration of (B) but not (C) directly due to its inherent reliance on random numbers, and the number of free parameters required to optimise the control field \cite{Caneva2011}.

\par We propose a different approach to this optimisation problem. Our approach has three steps. The first step is to generate a complete semi-analytical basis of pulses that comply with (A) and minimises (1) in the approximation where time-ordering is neglected in the simulated quantum evolution. The second step is to find the linear combination of these basis functions that minimise (2). The final step is to further optimise the pulses to account for the effects of time-ordering in the quantum evolution via closed-loop optimisations. We have neglected time-ordering in the quantum evolution to efficiently estimate the initial coefficients of the linear combinations of basis functions required for closed-loop optimisations. Without an initial estimate, optimising the linear combinations of basis functions via closed-loop optimisations is computationally time consuming. This linear minimisation is fast and can include measurements of the processor and therefore readily complies with (B). Furthermore, since the basis is complete, the dimension of the non-trivial basis functions provides a clear parameter to analyse convergence to optimisation limits and interpretation of different error modes, and thus also complies with (C). The principal strategy for both minimising the effects of decoherence (3) and the effects of hyperfine field misalignment (4) is to maximise the gate speed. This minimises the time over which decoherence accumulates and the time under which the nuclear spin experience the hyperfine misalignment during two-qubit gates, whilst ensuring that the infidelity introduced by control errors is less than that introduced by decoherence and hyperfine field misalignment. We have adopted this strategy to minimise the errors due to decoherence rather than directly targeting the primary source of qubit decoherence (eg via dynamical decoupling) because the primary source is the NV centre's electron spin, whose strong interaction with the nuclear spins is required for the implementation of both one- and two-qubit gates. Indeed, owing to the strong interaction, the qubit coherence time $1/T_{2,n}$ is limited by the electron spin relaxation time $1/T_{1,e}$ \cite{Maurer2012,Shim2013}, which is approximately 2.4~ms at room temperature \cite{Herbschleb2019}. Note that our discussion here, and the results of this paper, are in the context of room-temperature operation of diamond quantum processors. At cryogenic temperatures, weakly coupled nuclear spins can instead be employed as qubits and as a result, their decoherence is influenced by other mechanisms \cite{Kalb2018}, at the cost of slower gate speeds.

\par In this paper, we report (i) a demonstration and analysis of our optimal design approach and (ii) simulation of an optimised diamond quantum processor. In \sref{sec:operatingprinciples}, we first discuss the operating principles of a diamond quantum processor before presenting a complete model of the processor, its gate operations and control system errors. \Sref{sec:idealgates} demonstrates the generation of gate basis functions, while \sref{sec:nonidealgates} demonstrates the optimisation of gate fidelities in the presence of control errors. In \sref{sec:gatewithdecoherence}, the effects of decoherence on a diamond quantum computer are investigated via master equation simulations and in \sref{sec:simulation}, we simulated the performance of 3 and 5 qubit quantum Fourier transforms (QFTs) on a diamond quantum processor. Fidelities of QFTs were chosen as a simple performance metric because QFTs are the foundation of many quantum algorithms. Thus, the fidelities of QFTs are basic indicators for the system's performance with more sophisticated algorithms.
\hypersetup{pageanchor=false}
\section{Quantum control model of diamond quantum processors}\label{sec:operatingprinciples}
\hypersetup{pageanchor=false}
\subsection{Operating principles of diamond quantum processors}
\par The NV centre is a point defect in diamond consisting of a substitutional nitrogen and an adjacent carbon vacancy \cite{Doherty2013}. Its electronic structure consists of a ground state spin triplet $(^3A_2)$ and an excited state spin triplet $(^3E)$ with two intermediate singlet levels ($^1E$ and $^1A_1$) . There exist spin-selective non-radiative intersystem crossings between the triplet and singlet levels, which lead to initialisation of the electronic spin state upon optical excitation of the centre's $^3A_2\rightarrow ^3E$ transition as well as read out via the differing fluorescence intensities of the spin states (see Ref.~\cite{Doherty2013} for further details). In addition to high fidelity optical spin initialisation and readout, the NV centre also has the longest electron spin coherence time of any solid state spin at room temperature ($T_2\approx 2.4$ ms) \cite{Herbschleb2019}.

\par Each NV centre is coupled to a register of one or more nuclear spins, which we use as qubits \cite{ Taminiau2014,Waldherr2014}. The quantum register consists of the NV centre's intrinsic nitrogen nuclear spin and nearby $^{13}$C nuclear spins. Hyperfine coupling between the NV electron spin and the nuclear spins results in a splitting of the electronic and nuclear energy levels. This splitting depends on the particular hyperfine coupling strength between each nucleus and the NV electron spin, and also on the respective electron and nuclear spin states \cite{Felton2009,Smeltzer2011} (see \fref{fig:estructure}). We choose a register with non-overlapping hyperfine couplings, allowing the use of frequency selectivity to individually address each nuclear spin qubit in the register.

\begin{figure}[h]
	\centering
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig1a}
	\caption[]{}
	\label{fig:conceptdesign}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig1b}
	\caption[]{}
	\label{fig:estructure}
	\end{subfigure}
	\caption[]{ (a) Conceptual design of a diamond quantum computer (Adapted with permission from \cite{Doherty2017}. \copyright Australian Institute of Physics). At the device scale (top), the quantum computer contains a diamond chip with an array of quantum processing nodes. Each node is formed by magnetically coupling a surrounding cluster of $^{13}$C nuclear spin qubits to the NV centre. Optical initialisations and readout of these quantum processing nodes via their NV centres are done using an optical system placed below the diamond chip. At the scale of a single node (middle), surface mirowave structures are used to realise single and two qubit gate operations. Internode two-qubit gate operation is mediated using spin quantum buses which are realised through chains of substitutional N defects. At the cluster scale (bottom), the NV centre consists of a substitutional N defect (blue) adjacent to a carbon vacancy (transparent). The nuclear spins of the N defect and cluster of nearby $^{13}$C atoms are depicted in blue and orange respectively, while the NV centre's electronic spin is depicted in red. (b) The hyperfine structure of the NV centre which arises from the interaction of two nearby $^{13}$C nuclear spin qubits. Optical initialisation and readout of the NV centre's electron spin are realised via a combination of spin-conserving optical transitions and spin-selective radiationless decay \cite{Doherty2013}. Using microwave pulses, this capability can be extended to the nuclear spin qubits by selectively swapping the electronic and nuclear spin states \cite{Waldherr2014,Morton2006,Filidou2012}. The computational and auxiliary subspaces are defined to be the $\left|-1\right>$ and $\left|0\right>$ electronic spin projections, respectively. Single qubit gate operations are realised in the computational subspace using spectrally-selective microwave pulses. A conditional-z (CZ) two-qubit gate operation is realised via selective $2\pi$ microwave pulses that involves, but does not occupy, the auxiliary subspace \cite{Waldherr2014,Morton2006,Filidou2012}.}
	\label{fig:conceptdesign_estructure}
\end{figure}

\par Key requirements for universal quantum computation are the initialisation and readout of the qubits, as well as the ability to apply single and two-qubit gate operations. In diamond quantum computing, each of these processes relies on high-fidelity quantum gates on the electron and nuclear spins. Initialisation and readout of a diamond quantum register is performed via a projective, single-shot readout of the nuclear spin qubits. This measurement scheme involves initialising the electron spin, entangling the nuclear spin qubits with the electron spin using a ${\rm C_nNOT_e}$ gate and then readout of the electron spin \cite{Neumann2010}. Single-qubit gate operations are realised using radiofrequency (RF) pulses. These pulses correspond to the $R_x$ and $R_y$ gates where they are the rotations about the $x$ and $y$ axes respectively. Other single-qubit gates can be constructed from combinations of these rotations. The intrinsic properties of the NV-nuclear spins system allows direct application of a CZ gate via microwave (MW) pulses. This CZ gate is achieved by performing a selective $2\pi$ pulse conditional on the nuclear spin register being in a particular state \cite{Waldherr2014,Morton2006,Filidou2012}. The CZ gate can be combined with single-qubit gates to realise any other two-qubit gate.

\par The splitting in the $^{3}A_2$ triplet ground state results in two types of subspaces which we identify as computational subspace and auxiliary subspace (\fref{fig:estructure}). The natural computational subspace is either of the $m_s=\pm 1$ states as they have non-zero hyperfine interactions, thus allowing the nuclear spin qubits to be individually addressed through frequency selectivity \cite{Dutt2007}.  Whilst the choice of either the $m_s=\pm 1$ state as the computational subspace is arbitrary, the $m_s=-1$ state is more often selected as it requires lower microwave frequencies for qubit gate operations. Single-qubit gates are realised in the computational subspace while a two-qubit CZ gate utilises, but does not occupy, the auxiliary subspace \cite{Waldherr2014,Morton2006,Filidou2012}.

\hypersetup{pageanchor=false}
\subsection{Model Hamiltonian}
\label{section:modelhamiltonian}
\par The Hamiltonian $H_I$ of the nuclear spins coupled to the NV centre is
\begin{equation}
H_I=\sum_i  \vec{S}\cdot \boldsymbol{A}_i \cdot \vec{I}_i -\sum_i \gamma_i \Big[I_{i,z}B_0+I_{i,x}B_1(t)\Big]\label{eq:Hamiltonian1}
\end{equation}
where $\gamma_i$ is the gyromagnetic ratio of the $i^{th}$ nucleus, $B_0$ is the background static magnetic field aligned with the NV axis, $B_1(t)$ is the applied radio frequency field, $\boldsymbol{A}_i$ is the hyperfine tensor of the $i^{th}$ nucleus with $\vec{S}$ being the dimensionless electron spin operator and $\vec{I}_i$ is the dimensionless nuclear spin operator of the $i^{th}$ nucleus.
For this model, we apply the secular approximation as a very strong magnetic field is applied along the $z$-axis during the operation of this quantum computer. Therefore, the nuclear spin Hamiltonian in the computational subspace simplifies to
\begin{equation}
H_{I,m_s=-1}=-\sum_i\vec{A}_{i,z}\cdot\vec{I}_i- \sum_i\gamma_i\Big[I_{i,z}B_0+I_{i,x}B_1(t)\Big]\label{eq:Hamiltonian2}
\end{equation}
$\vec{A}_{i,z}$ is now a vector instead of a tensor where
\begin{equation}
\vec{A}_{i,z}=A_{i,xz}\hat{x}+A_{i,yz}\hat{y}+A_{i,zz}\hat{z}
\end{equation}
 We simplify the expression by diagonalising the nuclear spin Hamiltonian in the computational subspace via a rotation of the spin operators about the angles defined by their hyperfine interactions. Assuming that only nuclei with hyperfine fields nearly aligned with the NV axis are chosen, we perform small angle approximations and by undoing a rotation about $z$-axis for further simplifications, this yields
\begin{equation}
H_{I,m_s=-1}=- \sum_i \omega_i I_{i,z}-\sum_i I_{i,x}\gamma_i B_1(t)\label{eq:Hamiltonian3}
\end{equation}
where $\omega_i$ is the transition frequency of the $i^{th}$ nucleus. We also transform the Hamiltonian into the interaction picture using the following transformation operator
 \begin{equation}
 H_{single}= \mathcal{T} H_{I,m_s=-1}\mathcal{T}^{-1} -\mathbbm{i}\mathcal{T}\frac{d}{dt} \mathcal{T}^{-1}\label{eq:HamiltonianTransform}
 \end{equation}
 where
\begin{equation}
\mathcal{T}=\exp\Big[-\mathbbm{i}t\sum_i\omega_i I_{i,z}\Big]\label{eq:HamiltonianTransformOperator}
\end{equation}
 Thus, for single-qubit gate operations, the Hamiltonian for the computational subspace in the interaction picture is given by
\begin{equation}
H_{\rm{single}}=- \sum_i \Bigg[I_{i,x} \cos\omega_it + I_{i,y} \sin\omega_i t\Bigg]\gamma_i B_1(t)
\end{equation}
\par The auxiliary subspace is involved to perform a CZ gate and this is enabled via the NV electron spin. The effective Hamiltonian for two-qubit gate operations is given by
\begin{equation}
H'=\frac{\Delta}{2}\sigma_z +\frac{\Omega}{2}\sigma_x B_1(t)+\sum_i \left(\alpha_i + \beta_i\sigma_z\right)I_{i,z}\label{eq:twoqubit}
\end{equation}
with $\Delta=D-\gamma_eB_0$ where $D$ denotes the zero-field splitting, $\Omega=\sqrt{2}\gamma_e$, $\alpha_i=-\gamma_iB_0/2-\omega_i/2$ and $\beta_i=-\gamma_iB_0/2+\omega_i/2$. When defining the Hamiltonian above, we ignore the interactions with the $m_s=+1$ state of the electron spin and the direct interaction between the nuclear spins and the microwave field $B_1(t)$. It is possible to do this because the microwaves are far detuned from these transitions. We have also ignored the interactions of the static magnetic field acting on the nuclear spin when the electron spin is in $m_s=0$ state. This interaction term arises from the hyperfine field misalignment and is discussed further in \ref{appendix:misalignmenteffects}. Likewise to the Hamiltonian for single-qubit gate operations, we transform $H'$ into the interaction picture with the transformation operator $\mathcal{T}'$ is given by
\begin{equation}
\mathcal{T}'=\exp\left[\mathbbm{i}t\left(\frac{\Delta}{2}\sigma_z+\sum_i\left(\alpha_i+\beta_i\sigma_z\right)I_{i,z}\right)\right]
\end{equation}
The transformed Hamiltonian for two-qubit gate operations is then given by
\begin{eqnarray}
\fl H_{\rm{multi}}&=\frac{\Omega}{2}B_1(t)\Bigg[\sigma_x\otimes\Big(\left|11\right>\left<11\right|\cos\left(\left[\Delta+\beta_1+\beta_2\right]t\right)+\left|10\right>\left<10\right|\cos\left(\left[\Delta+\beta_1-\beta_2\right]t\right)\nonumber\\
\fl &+\left|01\right>\left<01\right|\cos\left(\left[\Delta-\beta_1+\beta_2\right]t\right)+\left|00\right>\left<00\right|\cos\left(\left[\Delta-\beta_1-\beta_2\right]t\right)\Big)\nonumber \\
\fl &-\sigma_y\otimes\Big(\left|11\right>\left<11\right|\sin\left(\left[\Delta+\beta_1+\beta_2\right]t\right)+\left|10\right>\left<10\right|\sin\left(\left[\Delta+\beta_1-\beta_2\right]t\right)\nonumber\\
\fl &+\left|01\right>\left<01\right|\sin\left(\left[\Delta-\beta_1+\beta_2\right]t\right)+\left|00\right>\left<00\right|\sin\left(\left[\Delta-\beta_1-\beta_2\right]t\right)\Big)\Bigg]
\end{eqnarray}
where 0 and 1 are the $m_I=-1/2$ and $+1/2$ nuclear spin projections, respectively. We use the notation where the most left entry of a tensor product corresponds to the first qubit, i.e $\left|q_1, q_2,\dots\right>$

\subsection{Control Pulses and Gate Operations}
\label{sec:controlpulses}
\par Focusing on single-qubit gate operations within the computational subspace, the applied radio frequency field $B_1(t)$ can be parametrised as a linear combination of oscillating components where
\begin{equation}
\gamma_iB_1(t)=a(t)\cos\omega t+b(t)\sin \omega t \label{eq:3_gammai}
\label{eq:gammaB}
\end{equation}
By neglecting the time-ordering in the quantum evolution, we can write the evolution operator for the $i^{th}$ nucleus as
\begin{equation}
U_i=e^{-\mathbbm{i} I_{i,x} X_i } \qquad  {\rm{or}} \qquad U_i=e^{-\mathbbm{i} I_{i,y} Y_i} \label{eq:3_uoperator}
\end{equation}
with
\begin{eqnarray}
X_i&=-\int\limits_{-\tau/2}^{\tau/2} a(t)\cos\omega_it \cos\omega t+b(t)\cos\omega_it \sin \omega t\ dt \label{eq:Xi1}\\
Y_i&=-\int\limits_{-\tau/2}^{\tau/2} a(t)\sin\omega_i t \cos \omega t + b(t) \sin \omega_i t \sin \omega t\ dt  \label{eq:Yi1}
\end{eqnarray}
where $\tau$ denotes the gate time while $X_i$ and $Y_i$ parametrises the rotations about the $x$ and $y$ axes respectively, which realises the gate operation. We have neglected time-ordering in the quantum evolution to efficiently estimate the initial coefficients of the linear combinations of basis functions required for closed-loop optimisations. The effects due to time-ordering in the quantum evolution is discussed further in \ref{appendix:timeordering}.
\par If the $j^{th}$ nucleus is the intended target, then the operations on all other nuclei $(i\neq j)$ are simply identity operations. Thus we have : for $i\neq j$,
\begin{eqnarray}
X_i&=-\int\limits_{-\tau/2}^{\tau/2} a(t)\cos\omega_it \cos\omega_j t+b(t)\cos\omega_it \sin \omega_j t\ dt=0 \label{eq:Xi2}\\
Y_i&=-\int\limits_{-\tau/2}^{\tau/2} a(t)\sin\omega_i t \cos \omega_j t + b(t) \sin \omega_i t \sin \omega_j t\ dt=0 \label{eq:Yi2}
\end{eqnarray}
and for $i= j$
\begin{eqnarray}
X_j&=-\int\limits_{-\tau/2}^{\tau/2} a(t)\cos\omega_jt \cos\omega_j t+b(t)\cos\omega_jt \sin \omega_j t\ dt=X_T \label{eq:Xj1}\\
Y_j&=-\int\limits_{-\tau/2}^{\tau/2} a(t)\sin\omega_j t \cos \omega_j t + b(t) \sin \omega_j t \sin \omega_j t\ dt =Y_T \label{eq:Yj1}
\end{eqnarray}
We impose the restriction that $\omega=\omega_j$ where $\omega_j$ is the transition frequency of the targeted qubit. Using these gate parametrisations, we introduce the following inverse Fourier transforms, where
\begin{eqnarray}
a(t)&=\frac{1}{\sqrt{2\pi}}\int\limits_{-\infty}^{\infty} a(\omega)e^{\mathbbm{i}\omega t}\ d\omega \label{eq:fourierat}\\
b(t)&=\frac{1}{\sqrt{2\pi}}\int\limits_{-\infty}^{\infty} b(\omega)e^{\mathbbm{i}\omega t}\ d\omega \label{eq:fourierbt}
\end{eqnarray}

As the signal is finite in time domain, we can enforce that $a(t)$ and $b(t)$ are zero outside $t\in \left[-\tau/2,\tau/2\right]$. This enables us to change the limits of the time integral to $\pm \infty$ and pass the time integral through the frequency integral. We also use the following identity
\begin{equation}
\frac{1}{\sqrt{2\pi}}\int\limits_{-\infty}^{\infty} e^{-\mathbbm{i}\omega t}dt =\sqrt{2\pi}\delta\left(\omega\right)
\end{equation}
for further simplifications. For $a(t)$ and $b(t)$ to be real functions with well defined phases, we enforce
\begin{eqnarray}
a^*(\omega)&=a(\omega)=a(-\omega)\\
b^*(\omega)&=b(\omega)=b(-\omega)
\end{eqnarray}
Using the above conditions, we arrived at the expressions where : for $i\neq j$
\begin{eqnarray}
X_i&=-\frac{\sqrt{2\pi}}{2} \Bigg[a\left(\omega_i+\omega_j\right)+a\left(\omega_i-\omega_j\right)\Bigg]=0
\label{eq:xi}\\
Y_i&=\frac{\sqrt{2\pi}}{2} \Bigg[b\left(\omega_i+\omega_j\right)-b\left(\omega_i-\omega_j\right)\Bigg]=0
\label{eq:yi}
\end{eqnarray}
and for $i=j$
\begin{eqnarray}
X_j&=-\frac{\sqrt{2\pi}}{2} \Bigg[a\left(2\omega_j\right)+a\left(0\right)\Bigg]=X_T
\label{eq:xj}\\
Y_j&=\frac{\sqrt{2\pi}}{2} \Bigg[b\left(2\omega_j\right)-b\left(0\right)\Bigg]=Y_T
\label{eq:yj}
\end{eqnarray}
where $X_T$ and $Y_T$ are the intended angles of rotation on the $x$-axis and $y$-axis respectively.
\hypersetup{pageanchor=false}
\subsection{Statistical Model of Gate Errors}
\label{sec:statisticalmodel}
In reality, the control fields have noises and the frequencies of the qubits fluctuate slowly between the computational shots. Thus, the real control field can be written as
\begin{equation}
\fl \gamma_iB_1(t)=\left(1+\epsilon\right)\Bigg[a(t)\cos\left(\left(\omega+\delta \right)t+\phi\right)+b(t)\sin\left(\left(\omega+\delta\right) t+\phi\right)\Bigg]
\end{equation}
where $\epsilon,\phi$ and $\delta$ are free parameters representing the amplitude, phase and frequency noises respectively. Let the target evolution operator for a single qubit gate on the $j^{th}$ nucleus within an $N$ qubit cluster to be
\begin{eqnarray}
G_{T,x}&=I_1\otimes \dots \otimes I_{j-1}\otimes e^{-\mathbbm{i}\left(I_{j,x}X_T\right)}\otimes I_{j+1}\otimes \dots \otimes I_N\\
G_{T,y}&=I_1\otimes \dots \otimes I_{j-1}\otimes e^{-\mathbbm{i}\left(I_{j,y}Y_T\right)}\otimes I_{j+1}\otimes \dots \otimes I_N
\end{eqnarray}
The actual evolution operator is defined as
\begin{equation}
G_{A,x}=\bigotimes_{i=1}^{N} e^{-\mathbbm{i}\left(I_{i,x}X_i\right)} \qquad {\rm{or}}\qquad  G_{A,y}=\bigotimes_{i=1}^{N} e^{-\mathbbm{i}\left(I_{i,y}Y_i\right)}
\end{equation}
The analytical expression for infidelity can be written as
\begin{equation}
I=1-\frac{\Tr\Big[G_T^\dagger G_A\Big]}{\Tr\Big[G_T^\dagger G_T\Big]} \label{eq:infidelity}
\end{equation}
This expression for infidelity compares an ideal gate to an experimental gate \cite{White2007}. It is used as it requires minimal computation when compared to other figures of merit, and is equivalent to the usual performance function implemented in the GRAPE algorithm \cite{Khaneja2005}. Assuming the gates are rotating about the x-axis, the infidelity expression can be written as
\begin{eqnarray}
\fl I &=1-\frac{1}{2^N}\Bigg[\prod_{i\neq j}^{N} \Tr\left(e^{-\mathbbm{i}\left(I_{i,x}X_i\right)}\right)\Bigg]\Tr\Bigg[\left(e^{-\mathbbm{i}\left(I_{j,x}X_T\right)}\right)^\dagger e^{-\mathbbm{i}\left(I_{j,x}X_j\right)}\Bigg]\nonumber\\
\fl &=1-\Bigg[\prod_{i\neq j}^{N}\cos\left(\frac{1}{2}X_i\right)\Bigg]\Bigg[\cos\left(\frac{X_j-X_T}{2}\right)\Bigg] \label{eq:intrinsicinfone}
\end{eqnarray}
Assuming small errors in the regime where $X_i\ll 1$ for $i\neq j$ and $\left(X_j-X_T\right)\ll 1$, we can then expand the above expression, and keep only the terms up to second order, which gives
\begin{equation}
I\approx \frac{1}{8}\sum_{i\neq j}^{N} X_i^2 +\frac{1}{8}\delta_X^2
\end{equation}
 Repeating the same procedure for the rotations about the y-axis gives
\begin{equation}
I\approx \frac{1}{8}\sum_{i\neq j}^{N} Y_i^2 +\frac{1}{8}\delta_Y^2
\end{equation}
where $\delta_X=X_j-X_T$ and $\delta_Y=Y_j-Y_T$
\par The control signal has a general form of
\begin{eqnarray}
a(\omega)&=\sum_nc_n a^{(n)}(\omega) \label{eq:linearcombX}\\
b(\omega)&=\sum_nd_n b^{(n)}(\omega) \label{eq:linearcombY}
\end{eqnarray}
As such, the set of linear coefficients $c_n$ and $d_n$ that minimise the infidelity caused by the amplitude, phase and frequency noises can be solved.
\par We assumed the noise in the qubit frequencies $\delta$, pulse amplitudes $\left(1+\epsilon\right)$ where $\epsilon$ is the fractional error of the pulse amplitudes and phase $\phi$ are described by Gaussian distributions centred at zero with their respective standard deviations of $\sigma_\delta,\sigma_\epsilon$ and $\sigma_\phi$. The Gaussian distribution for frequency error is justified by experiments \cite{Rong2015,Balasubramanian2009}. Whilst there is no clear evidence of either Gaussian or Lorentzian distribution for the amplitude error, we assumed Gaussian distribution and noting that Ref.~\cite{Rong2015} observed a Lorentzian distribution for the convolution of power fluctuations and pulse shape errors. The analytical expression for the average infidelity can be written as
\begin{eqnarray}
\fl \left<I\right>&=\int\limits_{-\infty}^{\infty} P(\delta;\sigma_\delta)\int\limits_{-\infty}^{\infty}P(\epsilon;\sigma_\epsilon)\int\limits_{-\infty}^{\infty}P(\phi;\sigma_\phi) I(\omega_1,\dots,\omega_N) d\delta d\epsilon d\phi\nonumber\\
\fl&=\frac{1}{8}\Bigg[\int\limits_{-\infty}^{\infty} p(\delta;\sigma_\delta)\int\limits_{-\infty}^{\infty}p(\epsilon;\sigma_\epsilon)\int\limits_{-\infty}^{\infty}p(\phi;\sigma_\phi)\delta_X^2  d\delta d\epsilon d\phi \nonumber\\
\fl&+\sum_{i\neq j}^{N} \int\limits_{-\infty}^{\infty} p(\delta;\sigma_\delta)\int\limits_{-\infty}^{\infty}p(\epsilon;\sigma_\epsilon)\int\limits_{-\infty}^{\infty}p(\phi;\sigma_\phi) X_i^2  d\delta d\epsilon d\phi\Bigg] \label{eq:avginf}
\end{eqnarray}
A similar infidelity expression can be obtained for rotations about the y-axis. The minimum average gate infidelity is found when
\begin{eqnarray}
\frac{\partial \left<I\right>}{\partial c_n}&=0\\
\frac{\partial \left<I\right>}{\partial d_n}&=0
\end{eqnarray}
are satisfied for each function in the expansion.

\section{Generation of Basis Functions}
\label{sec:idealgates}
In this paper, we use frequency-shifted sinc functions as an ansatz for our control pulses in the frequency domain. Sinc functions were chosen as they represent pulses of finite duration in the time domain. As previously demonstrated in equation~\ref{eq:linearcombX} and \ref{eq:linearcombY}, the key property is the amplitude at very specific frequencies $\left(\omega_i,\omega_j\right)$. The interference of frequency-shifted sinc functions allow us to cancel the pulse amplitude at certain frequencies whilst at the same time amplifying other frequencies. The parametrisation of $a(\omega)$ and $b(\omega)$ is given by
\begin{eqnarray}
a^{(n)}\left(\omega\right)&=f^{(n)} \tau\Bigg[{\rm sinc}\Big(\frac{\tau}{2}\left(\omega-\mu^{(n)}\right)\Big)+{\rm sinc}\Big(\frac{\tau}{2}\left(\omega+\mu^{(n)}\right)\Big)\Bigg]
\label{eq:basisfunctiona}\\
b^{(n)}\left(\omega\right)&=g^{(n)} \tau \Bigg[{\rm sinc}\Big(\frac{\tau}{2}\left(\omega-\nu^{(n)}\right)\Big)+{\rm sinc}\Big(\frac{\tau}{2}\left(\omega+\nu^{(n)}\right)\Big)\Bigg]
\label{eq:basisfunctionb}
\end{eqnarray}
where $f^{(n)}$, $g^{(n)}$ are the pulse amplitudes in the frequency domain, $\tau$ is the gate time, $\mu^{(n)}$ and $\nu^{(n)}$ are the frequency shifts and $(n+1)$ is the total number of basis functions used in the optimisation procedure.
\par  If the frequency shifts for the $n^{\rm th}$ solution are defined as
\begin{eqnarray}
\mu^{(n)}=n\left(\frac{2\pi}{\tau}\right)\\
\nu^{(n)}=n\left(\frac{2\pi}{\tau}\right)
\end{eqnarray}
then the above simply becomes a Fourier series, which is known to be a complete basis function. However, as seen in equation \ref{eq:basisfunctiona} and \ref{eq:basisfunctionb}, the $a^{(n)}(0)$ and $b^{(n)}(0)$ terms would then be
\begin{eqnarray}
a^{(n)}(0)&=  2f^{(n)}{\rm sinc}\Bigg(n\pi\Bigg)\\
b^{(n)}(0)&=  2g^{(n)} {\rm sinc}\Bigg(n\pi\Bigg)
\end{eqnarray}
 where for $n\geq1$, $a^{(n)}(0)$ and $b^{(n)}(0)$ terms will always be 0. Hence, without any contributions from the  $a^{(n)}(0)$ and $b^{(n)}(0)$ terms, generating an optimal pulse from only the $a^{(n)}\left(2\omega_j\right)$ and $b^{(n)}\left(2\omega_j\right)$ terms would require extremely large amplitudes.
 \par One possible method to overcome this complication is to use Kadec's 1/4 Theorem, where an additional small frequency shift is introduced to the Fourier series whilst retaining the completeness of the Fourier series. It was shown that when the additional frequency shift is bounded by a maximum value of $0.25\left(2\pi/\tau\right)$, the inequality will still be able to generate a continuous set of sinc basis functions \cite{Avantaggiati2016}. In this paper, we have chosen the upper bound to be $0.2\left(2\pi/\tau\right)$ as it enables us to resolve better solutions for the pulse amplitudes (see figure~\ref{fig:f1shifts}).

\begin{figure}[H]
\centering
\includegraphics[width=0.7\textwidth]{fig2}
\caption[]{Plots of infidelity (equation~\ref{eq:intrinsicinfone}) versus pulse amplitude $\left(f^{(1)}\right)$ for a $\pi$ rotation about the x-axis with $\tau=1~\mu$s and $n=1$. This is the first step of the optimisation procedure where we generate optimal solutions for the pulse amplitudes in the absence of control errors. Due to the experimental hardware constraints, the maximum pulse amplitude in the time domain is set to be approximately 25~Mrad/s. We arbitrarily set the corresponding search range for $f^{(n)}$ and $g^{(n)}$ to be $f^{(n)},g^{(n)} \in \left[-5,5\right]$ and noting that the amplitude in the time domain has an additional factor of $2\sqrt{2\pi}$ from the inverse Fourier transform of the basis functions. An additional shift of $0.2\left(2\pi\right)$ allows us to resolve better solutions with lower infidelity compared to no additional shift and a 0.1$\left(2\pi\right)$ shift within a bounded search range for the amplitudes. See text for more discussions regarding the optimisation procedures.}
\label{fig:f1shifts}
\end{figure}
The frequency shifts are then redefined as
\begin{eqnarray}
\mu^{(n)}&=\left(n+\frac{1}{5}\right)\left(\frac{2\pi}{\tau}\right)\\
\nu^{(n)}&=\left(n+\frac{1}{5}\right)\left(\frac{2\pi}{\tau}\right)
\end{eqnarray}
As a result, there are many solutions in $a^{(n)}\left(\omega\right)$ and $b^{(n)}\left(\omega\right)$ that we can consider and these solutions form a linear basis for the construction of optimal pulse functions. These optimal pulse functions are found by determining the linear coefficients that minimise the effects of the pulse errors on average.
\par As an example, consider a two-qubit system which consists of $^{15}$N and $^{13}$C nuclear spins. Their respective hyperfine interactions are given by $A_N\approx  3$~MHz \cite{Felton2009} and $A_C\approx 0.413$~MHz \cite{Waldherr2014}. The background static magnetic field is chosen to be $B_0=0.62$~T \cite{Waldherr2014}. Using these parameters, we demonstrate the optimisation procedure for an X gate targeted at the $^{13}$C nuclear spin $\left(X_2\right)$. Since we are performing rotations only in the x-axis/ y-axis, we assumed there are no mixed signals in the pulse and thus, there are no contributions from the $b(\omega)$/ $a(\omega)$ components. Hence, the equations that are satisfied by the solutions are given by
\begin{eqnarray}
X_1&=-\frac{\sqrt{2\pi}}{2} \Bigg[a\left(\omega_N+\omega_C\right)+a\left(\omega_N-\omega_C\right)\Bigg]=0
\label{eq:onequbitx1}\\
X_2&=-\frac{\sqrt{2\pi}}{2} \Bigg[a\left(2\omega_C\right)+a\left(0\right)\Bigg]=\pi
\label{eq:onequbitx2}
\end{eqnarray}
where $\omega_N=A_N+\gamma_NB_0$ and $\omega_C=A_C+\gamma_CB_0$. The first step of the optimisation routine is to generate a set of basis functions that minimise the infidelity landscape in the absence of control errors against the pulse amplitude, $f^{(n)}$ and $g^{(n)}$ in the frequency domain as described by equation \ref{eq:intrinsicinfone}. This step minimises crosstalk between the qubits.

\par The search range for the pulse amplitudes is constrained by the design of our MW/RF system and this corresponds to the shortest gate time that we can perform for our qubit gate operations. In the time domain, the pulse amplitude, $a(t)$ is determined by $\gamma_iB_1(t)$ where $\gamma_i$ is the gyromagnetic ratio of the nuclear spin qubits and $B_1(t)$ is the maximum amplitude of the oscillating MW/RF magnetic field. Implementing the typical values used in an experiment, the pulse amplitude $a(t)$ is thus limited to a maximum value of approximately 25~Mrad/s. The corresponding search range for $f^{(n)}$ and $g^{(n)}$ is then arbitrarily set to $f^{(n)},g^{(n)} \in \left[-5,5\right]$ and noting that the amplitude in the time domain has an additional factor of $2\sqrt{2\pi}$ from the inverse Fourier transform of the sinc basis functions.

\par Similarly, the set of basis functions for a two-qubit CZ gate is generated using the same procedure. In this case, the pulse amplitude is limited to approximately 80 Mrad/s. The search range for $f^{(n)}$ is bounded in the region of $f^{(n)}\in \left[0.5,15\right]$ as the intrinsic infidelity expression used to describe two-qubit gate operations, equation \ref{eq:intrinsicinftwo} is symmetrical. Using $f^{(n)}=0$, the optimisation will be stuck in a local minimum and clearly, $f^{(n)}=0$ corresponds to no physical pulse. Thus, in order to find sensible solutions, we shifted the initial search boundary by 0.5 to stimulate the optimisation to find another local minimum. The equations that are satisfied by the solutions are given by equations \ref{eq:twoqubitx1}, \ref{eq:twoqubitx2}, \ref{eq:twoqubitx3} and \ref{eq:twoqubitx4}.

\par As seen in table~\ref{tab:1qdiffrotation}, the pulse amplitudes are dependent on the angle of rotations and gate time. This is consistent with the formulation of our sinc basis functions where larger amplitudes are expected to generate greater angle of rotations for a given frequency shift and gate time. We are also able to resolve solutions with lower infidelity for smaller angle of rotations at shorter gate times as the pulse amplitudes are smaller. We observed a trend, shown in table~\ref{tab:1qdiffrotation} and \ref{tab:diffrotationCZ}, where at short gate times, higher order basis functions have solutions which correspond to the lower or upper bound of the allowed values. These pulse amplitudes minimise the infidelities within the search range imposed on them as set by physics. While some of the pulse amplitudes correspond to the maximum or minimum allowed values, the critical factor in this optimisation routine is the linear combinations of these generated basis functions as discussed in the following section.

\section{Optimal Gates for Non-Ideal Control System}
\label{sec:nonidealgates}
\par Applying this optimal control method, we optimise the infidelities of an X gate, Hadamard gate and a CZ gate due to the control errors. We approximated the standard deviations of the Gaussian phase, amplitude and frequency noises to be $\sigma_\phi=1/2\pi$~kHz, $\sigma_\epsilon=10^{-3}$, $\sigma_\delta=  1$~kHz for nuclear spins and $\sigma_\delta= 27.5$~kHz for the electron spin \cite{Balasubramanian2009}. Phase noises are excluded from the calculation of average infidelities for a CZ gate as we are performing a $2\pi$ pulse. The first order effects due to the phase errors are negligible.

\begin{figure}[ht]
\centering
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig3a}
	\caption[]{}
	\label{fig:xgate}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig3b}
	\caption[]{}
	\label{fig:ygate}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig3c}
	\caption[]{}
	\label{fig:Hgate}
	\end{subfigure}
	\caption[]{Calculated infidelities of various gates for different gate times. (a) The performance of an X gate, (b) a $\pi/2$ rotation about the y-axis and (c), a Hadamard gate in the presence of frequency, amplitude and phase noises. The infidelities are plotted as a function of total number of basis functions, $M$ and gate time, $\tau$. Gate infidelities of $\sim 10^{-6}$ can be achieved by using linear combinations of two or more basis functions. The infidelities are decreasing with an increasing number of basis functions used in the optimisation procedure (not shown on scale). In general, 3 basis functions are needed for the infidelities to converge to the optimisation limits. For a system with two qubits, using more than 3 basis functions does not have significant improvements on achieving lower infidelities.}
	\label{fig:1qubitgateinf}
\end{figure}
\newpage
\par As shown in figure~\ref{fig:1qubitgateinf}, the average infidelities for an X gate, a $\pi/2$ rotation about the y-axis and a Hadamard gate fluctuate with a single basis function, since the function parameters depend on the local infidelity landscape during the initial basis function computation. However,  the optimised linear combinations of two or more basis functions yield infidelities of approximately $10^{-6}$ for an X gate and a Hadamard gate. Infidelities up to $10^{-7}$ can be achieved for a $\pi/2$ rotation about the y-axis. The infidelities are monotonically decreasing with increasing number of basis functions and only 3 basis functions are required for the infidelities to converge to the optimisation limits. Thus, this demonstrates the capability of this optimal control method, and allow us to systematically assess the degree of convergence to the optimisation limits. For a system with two qubits, using more than 3 basis functions does not significantly lower the infidelities. In general, we expect to achieve infidelities on this order (of $10^{-6}$) for any single-qubit operation.

\par Given that this method can achieve low infidelities, the main objective is to shorten the gate time without significantly affect the infdelity, in order to minimise the effects due to decoherence. We analyse the overall amplitudes of the respective linear combinations of the sinc basis functions in order to find the minimum gate time for which the pulse amplitude can still be practically generated. Using estimated constraints described in the previous section, the maximum threshold for the amplitude is set to be $\log_{10}$(25)$\approx 1.40$.

\par Figure~\ref{fig:singleabsamp} depicts the overall amplitudes of the basis functions in the linear combinations for different basis size and gate times. At some gate times, the linear combinations have larger amplitudes when more basis functions are used. Since the optimal control method optimises the linear combinations of the basis functions such that the infidelities are monotonically decreasing, therefore, if the amplitude in the initial basis function is large, then it may result in larger amplitudes for the subsequent basis functions when the basis size is increased. Based on the generated data, we determined that a $0.5~\mu$s X gate with an infidelity of $\sim 10^{-6}$ can be achieved with just two basis functions (figure \ref{fig:single2lc}). Despite being able to perform a $0.5~\mu$s X gate, we need to take into account various gate times required for different types of rotations where slower gates are required for bigger angle of rotations. Thus, on average, a conservative estimate for the fastest single-qubit gate that we are able to perform with $\sim 10^{-6}$ infidelity is approximately $1~\mu$s.

\begin{figure}[H]
\centering
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig4a}
	\caption[]{}
	\label{fig:single1lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig4b}
	\caption[]{}
	\label{fig:single2lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig4c}
	\caption[]{}
	\label{fig:single3lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig4d}
	\caption[]{}
	\label{fig:single4lc}
	\end{subfigure}
\end{figure}
\begin{figure}[H]
\ContinuedFloat
\centering
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig4e}
	\caption[]{}
	\label{fig:single5lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig4f}
	\caption[]{}
	\label{fig:single6lc}
	\end{subfigure}
	\caption[]{Plots of the overall amplitudes, $A$, which realises an X gate with the minimum average infidelity ranging from 1 basis function (a), to 6 basis functions (f). At certain gate times, the overall amplitudes become very large when the number of basis functions are increased. The overall amplitudes are dependent on the initial solutions generated in the minimisation of the infidelity expression (equation \ref{eq:intrinsicinfone}). These amplitudes are optimised to generate lower infidelities with an increasing number of basis functions. Thus, a large amplitude in the first basis function may result in linear combinations with larger amplitudes when the basis size is increased.}
	\label{fig:singleabsamp}
\end{figure}
\par Applying our method now to two-qubit gates, the maximum threshold for the amplitude of a two-qubit CZ gate is set to be $\log_{10}$(80)$\approx 1.9$. From figure~\ref{fig:czgate}, on average, gate infidelities of $10^{-4}\sim 10^{-6}$ can be achieved with 4 or more basis functions for gate times $\tau \geq 1~\mu$s. The calculated infidelities are monotonically decreasing with increasing basis size for $\tau \geq 1~\mu$s. Monotonicity was not fully demonstrated for $\tau<1~\mu$s due to numerical integration errors. These errors are exacerbated for $\tau<1~\mu$s because of many linear combinations of basis functions with extremely large amplitudes at short gate times, resulting in a high oscillatory integrand.  On average, more than 8 basis functions are required for the convergence of these infidelities to their respective optimisation limits. Based on the optimisations shown in figures \ref{fig:czgate} and \ref{fig:CZabsamp}, the fastest two-qubit CZ gate that we can perform with an infidelity of $\sim 10^{-6}$ is $1~\mu$s and it requires 6 linear combinations of basis functions.

\begin{figure}[H]
\centering
	\includegraphics[width=0.7\textwidth]{fig5}
	\caption[]{The performance of a two-qubit CZ gate in the presence of frequency and amplitude noise. The infidelities are plotted as a function of total number of basis functions $M$ and gate time $\tau$. On average, gate infidelities of $10^{-4}\sim 10^{-6}$ can be achieved by using linear combinations of at least 4 basis functions for gate times $\tau \geq 1~\mu$s. Monotonicity was not fully demonstrated for $\tau<1~\mu$s due to numerical integration errors. This is caused by many linear combinations of basis functions with extremely large amplitudes which results in a high oscillatory integrand. We observed convergence of these infidelities to their respective optimisation limits and it requires at least 8 basis functions on average.}
	\label{fig:czgate}
\end{figure}

\begin{figure}[H]
\centering
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig6a}
	\caption[]{}
	\label{fig:CZ1lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig6b}
	\caption[]{}
	\label{fig:CZ2lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig6c}
	\caption[]{}
	\label{fig:CZ3lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig6d}
	\caption[]{}
	\label{fig:CZ4lc}
	\end{subfigure}
\end{figure}
\begin{figure}[H]
\centering
\ContinuedFloat
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig6e}
	\caption[]{}
	\label{fig:CZ5lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig6f}
	\caption[]{}
	\label{fig:CZ6lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig6g}
	\caption[]{}
	\label{fig:CZ7lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig6h}
	\caption[]{}
	\label{fig:CZ8lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig6i}
	\caption[]{}
	\label{fig:CZ9lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig6j}
	\caption[]{}
	\label{fig:CZ10lc}
	\end{subfigure}
\end{figure}
\begin{figure}[H]
\ContinuedFloat
\centering
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig6k}
	\caption[]{}
	\label{fig:CZ11lc}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
	\includegraphics[width=1\textwidth]{fig6l}
	\caption[]{}
	\label{fig:CZ12lc}
	\end{subfigure}
	\caption[]{Plots of the overall amplitudes, $A$, which generate the minimum averaged infidelity of a CZ gate ranging from 1 basis function (a), to 12 basis functions (l). Similar to an X gate, at certain gate times, the overall amplitudes are much larger when the number of basis functions are increased to generate monotonically decreasing infidelities and they are dependent on the initial solutions generated in the minimisation of the intrinsic infidelity expression (equation \ref{eq:intrinsicinftwo}).}
	\label{fig:CZabsamp}
\end{figure}
\par Additionally, we have analysed the infidelities of a CZ gate for a range of electron spin linewidths that may occur in materials with different densities of $^{13}$C. Figure~\ref{fig:CZlinewidth2} and \ref{fig:CZlinewidth3} depicts the CZ gate infidelities with $\sigma_\delta=2\times27.5$~kHz and $4\times 27.5$~kHz , respectively. Meanwhile, Figure~\ref{fig:CZconvergence} demonstrates convergence of CZ gate infidelities with $\tau=2.25~\mu$s occuring at different number of basis functions for different electron spin linewidths, with larger linewidths requiring larger number of basis functions. Overall, we are still able to obtain infidelities less than $10^{-4}$ across the range of linewidths, but at a cost of longer gate time and larger number of basis functions.

\begin{figure}[H]
\centering
\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig7a}
	\caption[]{}
	\label{fig:CZlinewidth2}
	\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig7b}
	\caption[]{}
	\label{fig:CZlinewidth3}
	\end{subfigure}
\end{figure}
\begin{figure}[H]
\ContinuedFloat
\centering
	\begin{subfigure}[b]{0.45\textwidth}
		\includegraphics[width=1\textwidth]{fig7c}
	\caption[]{}
	\label{fig:CZconvergence}
	\end{subfigure}
	\caption{CZ gate infidelities for electron spin linewidth $(\sigma_\delta)$ of (a) $ 2\times 27.5$~kHz and (b) $4\times 27.5$~kHz. (c) shows the convergence of CZ gate infidelities for different electron spin linewidths with $\tau=2.25~\mu$s. Convergence of infidelities occurs at approximately 5 and 11 basis functions for $\sigma_\delta= 27.5$~kHz and $ 2 \times 27.5$~kHz, respectively. Convergence of infidelities was not observed for $\sigma_\delta=4\times 27.5$~kHz, implying that we would require more basis functions for convergence to occur. While increasing the linewidths would amount to increasing the gate infidelities, we are still able to obtain infidelities of less than $10^{-4}$, but at the cost of longer gate times and larger number of basis functions.}
	\label{fig:CZadditionallinewidth}
\end{figure}
\par We now turn our attention to the final step of the optimisation process, which is to incorporate time-ordering in the quantum evolution into our optimisation routine. As a proof of principle demonstration, we have performed this optimisation process on an X gate (see \ref{appendix:timeordering}). Through further optimisations where the quantum evolution is evaluated numerically using a finite-difference method, we found that an X gate can theoretically achieve infidelities of $10^{-5}$ or lower. We believe that with the addition of more advanced numerical optimisation techniques, then higher number of basis functions can be included as well as the treatment of two-qubit gates. Thus, we are confident that we can reduce the control errors to the order of $10^{-5}$ or better for all gates. However, it is not necessary to involve the numerical optimisation techniques if we are performing experiments on the diamond quantum processors as the same feedback-based optimisation routine will occur.
\par Now, we must assess the implications for neglecting the hyperfine field misalignments when attaining these infidelities. From \ref{appendix:misalignmenteffects}, the hyperfine field misalignment only affects the two-qubit gate. While we are able to minimise the gate infidelities due to control errors to the order of $10^{-5}$ or $10^{-6}$, the inclusion of the correction terms from the hyperfine field misalignment introduced an additional infidelity on the order of $10^{-3}$. This additional infidelity arises from the projection of the applied magnetic field due to the rotation of the nuclear spin coordinates in the computational subspace. One way to overcome this effective field is to include radiowave pulses which are resonant with the nuclear spins in the $m_s=0$ state in conjunction with the microwave pulses which drive the electron spin transitions. This dual application of radio and microwave pulses is beyond the scope of this work and should be pursued in future work. There is no physical reason why these errors due to hyperfine field misalignment cannot be reduced to the level of our control errors.

\section{Gate Performances in Presence of Decoherence}
\label{sec:gatewithdecoherence}
 \par As mentioned in \sref{sec:introduction}, the nuclear spin qubits undergo pure dephasing due to the relaxation of the electron spin. Thus, the coherence time of the qubits is bounded by the relaxation time of the electron spin. Here, we introduce the master equation which is also known as the Lindblad equation \cite{Gorini1976, Lindblad1976}
\begin{equation}
\fl\dot{\rho}(t)=\mathcal{L}(\rho) \equiv -\frac{i}{\hbar}\left[H,\rho(t)\right]+\sum_{m=1}^{N}\Bigg(L_m\rho(t)L_m^\dagger-\frac{1}{2}L_m^\dagger L_m\rho(t)-\frac{1}{2}\rho(t)L_m^\dagger L_m\Bigg)
\end{equation}
where the sum over $m$ is the summation of the decoherence mechanism over the individual nuclear spins. Instead of solving the differential equations, we can express the Lindblad equation as a vectorized density matrix \cite{Havel2003}
\begin{equation}
\dot{\rho}=\left(\mathbf{H}+\mathbf{G}\right)\rho
\end{equation}
where $\mathbf{G}$ is the decoherent part of the Lindblad equation with the form of
\begin{equation}
\mathbf{G}=\sum_{m=1}^N \Bigg(\overline{L}_m \otimes L_m -\frac{1}{2}\mathbbm{I}\otimes \left(L_m^\dagger L_m\right)-\frac{1}{2}\left(\overline{L}_m^\dagger \overline{L}_m\right)\otimes \mathbbm{I}\Bigg)
\end{equation}
and
\begin{equation}
\mathbf{H}=-\frac{i}{\hbar}\Bigg(\overline{H}\otimes \mathbbm{I}-\mathbbm{I}\otimes H\Bigg)
\end{equation}
The overline denotes the complex conjugate, $\dagger$ is the adjoint, $H$ is the Hamiltonian of the qubit system and $\mathbbm{I}$ is the $2^N\times 2^N$ identity matrix where $N$ is the number of qubits in the system. For a time dependent Hamiltonian, the Linblad equation is given by
\begin{equation}
\rho(t)=\exp\left[\int\limits_{-\tau/2}^{\tau/2}\mathbf{H}~dt+\mathbf{G}t\right]\rho(0)
\label{eq:density}
\end{equation}
The Lindblad operator $L$ describing the dephasing of the nuclear spin qubits induced by a random electron spin flip can be written as
\begin{equation}
L_m=\sqrt{\frac{1}{2T_2}} \sigma_{z,m}
\end{equation}
where the nuclear spin $T_2$ is defined by the relaxation time $T_1$ of the electron spin (1.8~ms \cite{Balasubramanian2009}) and $\sigma_{z,m}$ is the Pauli matrix for the $z$ component of each nuclear spin.
 \par To assess the effects of decoherence due to dephasing, we consider an example with a perfect X gate. The aim now is to solve for $\rho(t)$ and calculate its state fidelity defined as
 \begin{equation}
 F=\frac{\Tr\Big[\rho_I^\dagger \rho\Big]}{\Tr\Big[\rho_I^\dagger \rho_I\Big]}
 \label{eq:statefid}
 \end{equation}
where $\rho_I$ is the ideal density matrix without the effects of decoherence and $\rho$ is the simulated density matrix of the system.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.6\textwidth]{fig8}
	\caption[]{Effects of decoherence on two different different initial states by applying a perfect X gate. The fidelity is simulated with respective of multiples of the fastest single-qubit gate time of $1~\mu$s. The errors are found to be on the scale of $10^{-3}\sim10^{-4}$.}
	\label{fig:decoherenceexample}
\end{figure}
\par As shown in figure \ref{fig:decoherenceexample}, the errors in both cases have magnitudes of approximately $10^{-3}\sim 10^{-4}$. These errors are much larger than the errors caused by the effects of frequency, phase and amplitude noises as demonstrated in section \ref{sec:nonidealgates} and the decoherence errors increase with longer gate times. The decoherence errors also have the same order of magnitude $\left(\sim 10^{-3}\right)$ as the errors introduced by hyperfine field misalignment on CZ gates (see \ref{appendix:misalignmenteffects}). Since we cannot remove the electron-nuclear spin coupling as it is required for the selective operations, this leads to the conclusion that for a given electron relaxation time $T_{1,e}$, the only solution to improve the gate fidelity is to make the gate operations faster.

\section{Simulation of QFT On A Diamond Quantum Processor}
\label{sec:simulation}

In this section, we set a benchmark for the optimal performance of a diamond quantum processor by simulating quantum algorithms. The benchmark will provide us with insights into the limits of the processor, which can be used to aid the design and comparison of the device in the near future.
\par Owing to our expectations that with modifications to the control system, errors due to the hyperfine field misalignment can be reduced to the level of control errors, which are small compared to the effects of decoherence. Hence, building on the results from \sref{sec:gatewithdecoherence} and \ref{appendix:misalignmenteffects}, we can simulate quantum algorithms on the diamond quantum computer by only considering the effects of decoherence. The key metrics for simulation will be the error probability and the total computational time (ignoring initial loading time of the computational control systems). These two metrics are chosen since computational time is the primary resource and the error rate is the key quality of a quantum computer. We have chosen to compute quantum Fourier transforms (QFT) for simulation as QFT is widely used in quantum algorithms \cite{NielsenChuang2010}. A further motivation is the similarity to the algorithms used for enhanced quantum sensing using a register of nuclear spin qubits. The initial state was chosen in a way such that an output state of $\left|001\right>$ (3 qubit QFT) and $\left|00001\right>$ (5 qubit QFT) will be the only outcome with a probability of 1.

\begin{figure}[h]
	\centering
	\includegraphics[width=1\textwidth]{fig9}
	\caption[]{The full circuit used for the simulations of 5 qubit quantum Fourier transform. $U\left(\theta\right)$ denotes the phase gate of $\theta$. The 2 dots joined with a line denotes a controlled-phase gate with their respective phases written in the circuit. We can write the controlled-phase gate in this notation as the matrix representation for this operation is the same regardless of which qubit is the control/target qubit, i.e ${\rm C}_1{\rm PHASE}_2={\rm C}_2{\rm PHASE}_1$. For a 3 qubit quantum Fourier transform, gate operations are performed on the first three qubits only (starting from the top).}
	\label{qftcircuit}
\end{figure}

\par The simulations of QFT on the diamond quantum computer are done using equation~\ref{eq:density} with electron relaxation time of $T_{1,e}\approx 1.8$ ms. These simulations will be iteratively solved for multiples of the fastest single and two-qubit gate times by only considering the effects of decoherence as the effects due to hyperfine field misalignments have the same order of magnitude and only affect CZ gates. The total number of pulses required for 3 qubits (QFT3) and 5 qubits (QFT5) quantum Fourier transforms after the decomposition into rotations about the $x$ and $y$ axis and CZ gate are 75 and 195 for QFT3 and QFT5 respectively (\ref{appendix:gatedecomposition}).

\par The total computation time on a diamond quantum computer can be broken down into shot time and initialisation/readout time. Shot time can be regarded as the total duration of the pulses required for an experiment. Assuming single-qubit gate times of 1~$\mu$s and CZ gate time of $1~\mu$s, the optimal pulse duration for QFT3 and QFT5 are approximately $75~\mu$s and $195~\mu$s, respectively. For the initialisation/readout time (single-shot readout), we are going to apply $M$ number of readout cycles per qubit. Thus, the total time for initialisation/readout is given by
\begin{equation}
{\rm Initialisation/Readout\ Time}=n\times M\times t_c
\end{equation}
where $n$ is the number of qubits, $M$ is the number of readout cycles applied per qubit and $t_c$ is the time per cycle. Time per cycle is based on the time of the optical pulse required for readout $(t_{\rm opt})$ and the time of the microwave pulse $(t_{\rm mw})$ required to perform the CNOT gate for repetitive measurements. These two time quantities are approximately 1~$\mu$s each. $M$ is chosen to be 500 as it has the same magnitude as other numbers of repetition which achieve an initialisation fidelity of 0.99 given a specific relative shift of the initialisation threshold \cite{Waldherr2014}. The time required for a single-shot readout is given by
\begin{eqnarray}
T_{\rm QFT3}&=75\times 10^{-6} + 3\times 500\times 2\times 10^{-6}\approx 0.0031~{\rm s}\\
T_{\rm QFT5}&=195\times 10^{-6} + 5\times 500\times 2\times 10^{-6}\approx 0.0052~{\rm s}
\end{eqnarray}

\begin{figure}[H]
	\centering
	\begin{subfigure}[b]{0.45\textwidth}
		\centering
		\includegraphics[width=1\textwidth]{fig10a}
		\caption[]{}
		\label{fig:nvfidelity}
	\end{subfigure}
	\begin{subfigure}[b]{0.45\textwidth}
		\centering
		\includegraphics[width=1\textwidth]{fig10b}
		\caption[]{}
		\label{fig:nvtime}
	\end{subfigure}
	\caption[]{(a) Single-shot simulated fidelity of 3 qubits and 5 qubits quantum Fourier transform. We assumed perfect initialisation/readout fidelity. (b) Simulated total computation time of QFT3 and QFT5 assuming optimal gate time of 1~$\mu$s and $1~\mu$s for single-qubit gates and CZ gate, respectively. }
	\label{fig:nvperformance}
\end{figure}
As depicted in figure \ref{fig:nvfidelity}, simulation of QFT3 is able to achieve higher fidelity ($\approx 0.964$) than QFT5 ($\approx 0.855$) when they are simulated using the optimal gate time of $1~\mu$s for single-qubit gates and $1~\mu$s for CZ gate as QFT3 has smaller circuit size. Implementing a lesser number of gates will introduce less errors during the evolution of the quantum states, thus an algorithm with a smaller circuit size will achieve greater output state fidelity. The larger decay constant in the fitted model of QFT5 indicates that it is important to perform optimal control on the pulses to obtain the fastest gate possible with the lowest infidelity, as well as optimising our circuit size. Consequently, this will give us the best result when an experiment is performed using an actual diamond quantum computer.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.6\textwidth]{fig11}
	\caption[]{Total computation time and the fidelity of performing QFT3 and QFT5 on a simulated diamond quantum computer. The simulation on a diamond quantum computer assumed perfect initialisation/readout fidelity.}
	\label{ibmvsnv}
\end{figure}
\par To simulate the performance of a diamond quantum computer over time, we first create a binomial distribution of probabilities with the respective optimal values for QFT3 and QFT5 simulated on a diamond quantum computer. Then, we simulate the probability distribution for a range of shots using Markov chain Monte Carlo method. Markov chain Monte Carlo allows us to approximate the probability distribution of the fidelities through random sampling. With short computation time per shot for QFT3 and QFT5, the simulations of QFT3 and QFT5 on a diamond quantum computer are able to converge to their respective optimal values of 0.964 and 0.855 in less than 10~s. These results can be used as a benchmark for comparison with other quantum computing architectures in the future.

\section{Conclusion}
\par In summary, we have presented a complete model of a diamond quantum processor, the gate operations and their implementations. We have developed a semi-analytical optimal control method which theoretically produces fast, high fidelity gates with control errors that are less than those introduced by decoherence and hyperfine field misalignment. This optimal control method has three steps. First, we generate a complete semi-analytical basis of pulses that minimises cross-talk between qubits in absence of time-ordering in the quantum evolution. Second, we generate linear combination of these basis functions to minimise the control field errors. Third, we further optimise the pulses to account for the effects of time-ordering in the quantum evolution. We used frequency-shifted sinc functions as an ansatz for the control pulses. We have demonstrated the first two steps of this optimal control method on a Hadamard gate and a CZ gate with an additional third step on an X gate.  The simulated performance of a diamond quantum computer shows promising results where it can perform fast computations with low error probability. Our results will aid the design and the development of diamond quantum computers and enhanced quantum sensors.
\par A future extension should include more advanced numerical optimisation techniques to optimise the pulses in the presence of time-ordering in the quantum evolution. However, if the optimisation is being performed experimentally, this step may not be required. Instead, we can implement a feedback control system as an optimal control method which tunes the pulse parameters based upon the output of a physical diamond quantum computer. Subsequent work should also include the introduction of a more complex optimal control technique to mitigate the errors of the hyperfine field misalignment through the application of simultaneous radiofrequency and microwave pulses.

\ack
We acknowledge support from the Australian Research Council (DP170103098 and DE170100169) as well as the Australian National University, University of Canberra and Charles Sturt University through the Discovery Translation Fund 2.0, managed by ANU Connect Ventures.