Arbitrary state preparation in quantum harmonic oscillators using neural networks Nicolas Parra-A, Vladimir Vargas-Calderón, Herbert Vinck-Posada Abstract Preparing quantum states is a fundamental task in various quantum algorithms. In particular, state preparation in quantum harmonic oscillators (HOs) is crucial for the creation of qudits and the implementation of high-dimensional algorithms. In this work, we develop a methodology for preparing quantum states in HOs. The HO is coupled to an auxiliary qubit to ensure that any state can be prepared in the oscillator [J. Math. Phys. 59, 072101 ( Pinna and Panati 2018 ) ]. By applying a sequence of square pulses to both the qubit and the HO, we drive the system from an initial state to a target state. To determine the required pulses, we use a neural network that predicts the pulse parameters needed for state preparation. Specifically, we present results for preparing qubit and qutrit states in the HO, achieving average fidelities of 99.9% and 97.0%, respectively. I Introduction State preparation refers to the process of transitioning a system from an initial state to a target state through a series of interactions applied to the system. This process is a fundamental step in many algorithms Rosenkranz et al. 2024 . Improperly preparing the initial states can significantly affect the algorithm’s behavior Mohseni et al. 2024 . For instance, in the simulation of physical systems, an initial state must be prepared before evolving it Altman et al. 2021 ; Bauer et al. 2023 . In quantum machine learning algorithms, information needs to be encoded into an initial state, which is then used to make predictions Cerezo et al. 2022 ; González et al. 2021 . Other examples requiring state preparation include algorithms for solving equations ( Brearley and Laizet 2024 ; Krovi 2023 ) , quantum chemistry ( Fomichev et al. 2024 ; Bauer et al. 2020 ) , quantum metrology Couteau et al. 2023 ; Li and Ren 2023 , among others applications such as quantum communications and quantum memories ( Dooley et al. 2017 ; Kollath-Bönig et al. 2024 ; Hasan et al. 2023 ) . The literature offers various approaches to determine the physical interactions needed to guide a system from an initial state to a target state. Some of these works employ Krotov’s methods Rojan et al. 2014 , quantum steering Volya and Mishra 2024 , quantum circuits ( Cai et al. 2021 ; Magann et al. 2021 ) , reinforcement learning ( Porotti et al. 2022 ; Khalid et al. 2023 ) and other techniques ( Torosov and Vitanov 2019 ; Shi et al. 2024a ; Zylberman and Debbasch 2024 ; Iaconis et al. 2024 ; Zhou et al. 2024 ) . However, these methods require the construction of an optimization problem for each target state–which makes the solution less scalable–or techniques that require a lot or computer resources. Other, more analytical techniques aim to solve the dynamics required to reach a specific target state from an initial state ( Law and Eberly 1996 ; Vogel et al. 1993 ) . These methods often yield a separate family of equations for each target state, making them impractical for multiple applications. Even though approximate methods have been proposed as alternatives, a truly scalable and practical solution demands a technique capable of rapidly receiving the target state on demand and predicting the interactions required in the physical system, ensuring efficient state preparation. In this work we propose using a neural network where the input is the target state to be prepared, and the output consists of the interactions required to achieve that state. We focus on preparing states in n -dimensional systems, also called qudits. These systems have received a growing appeal in recent years due to their enhanced capacity for encoding information, robustness to noise, and applications in high-dimensional quantum computing ( Luo and Wang 2014 ; Ringbauer et al. 2022 ; Chen et al. 2021 ; Vargas-Calderón et al. 2021 ) . The challenge of using these systems lies in the complexity of their manipulation, especially when it comes to state preparation Cozzolino et al. 2019 . In particular, we consider using harmonic oscillators (HOs) to realize control on a finite subset of a HO’s levels. In general, HOs cannot be fully controllable under a finite set of steps ( Bloch et al. 2010 ; Vogel et al. 1993 ) . To address this, an auxiliary system is traditionally employed. In the case of a HO, an auxiliary qubit is used to interact with the oscillator over a finite period. Under certain approximations, such as the rotating wave approximation Shore 2011 , an interacting Jaynes-Cummings-type system is formed, which is known to be completely controllable Pinna and Panati 2018 . When the physical nature of the HO is optical, as in the case of a microcavity, the best alternative to controlling this system involves optical pulses, with artificial atoms serving as the auxiliary system Kavokin et al. 2007 . Taking this into account, in our proposal, the neural network will receive the target state to be prepared in the HO as input, and the output will consist of the parameters of the pulses applied both to the HO and to the ancillary qubit to evolve the HO into the target state. The quality or “precision” of our model is evaluated using a state fidelity criterion. Additionally, we investigate how the number of pulses in the sequence enhances the precision with which the state can be prepared. The structure of this paper is designed as follows: in Section II we provide a detailed explanation of the proposed methodology, the physical details of the system, and the entire process required to train the neural network. In Section III , we delve into how the state evolves after each pulse sequence and present the model’s performance in terms of infidelity, analyzing the effects of the number of pulses on state preparation for qubits and qutrits, as well as the model’s limitations. Finally, in Section IV , we conclude with the main results of the work, a brief discussion of the results, and potential directions for future research. II Method In this section, we detail our proposal on using a neural network to predict the pulse parameters necessary to bring a HO coupled to a qubit to a separable state such that the HO’s state is any target state, when the HO’s basis is truncated to the first n levels. The system under consideration, i.e., a HO coupled to a qubit, can receive pulses on both the oscillator and the qubit. The basis of the quantum states of this system is \ket{\alpha}\otimes\ket{\beta} , where \ket{\alpha}\in\{\ket{0},\cdots,\ket{n}\} and \ket{\beta}\in\{\ket{0},\ket{1}\} . Note that we truncate the HO levels up to n excitations to be able to represent states an operators in a computer as vectors and matrices. Sometimes we drop the tensor product notation to save space. Modeling the HO-qubit interaction as a Jaynes-Cummings-type system, the Hamiltonian describing this system is Bocanegra-Garay et al. 2024 ( \hbar=1 ): \hat{H}=g(\hat{a}\hat{\sigma}_{+}+\hat{a}^{\dagger}\hat{\sigma}_{-})+\zeta(e^{i\phi}\hat{\sigma}_{-}+e^{-i\phi}\hat{\sigma}_{+})\\ +\xi(e^{i\varphi}\hat{a}+e^{-i\varphi}\hat{a}^{\dagger})+\Delta_{c}\hat{n}+\Delta_{\omega_{eg}}\frac{\hat{\sigma}_{z}}{2}, (1) where \hat{a} is the HO annihilation operator ( \hat{a}^{\dagger} is the creation operator), \hat{\sigma}_{+} and \hat{\sigma}_{-} are the raising and lowering operators of the qubit, g is the oscillator-qubit interaction constant, \zeta and \xi are the amplitudes of the driving pulses, and \phi,\varphi are the phases of the pulses for the qubit and HO, respectively. \Delta_{c} and \Delta_{\omega_{eg}} are the detunings of the HO and the qubit with respect to the driving lasers, respectively. For this work, we assume resonance of the qubit and the HO with the laser ( \Delta_{\omega_{eg}}=\Delta_{c}=0 ). Our goal is to manipulate the amplitudes \zeta,\xi and the phases \phi,\varphi to prepare a target state \ket{\psi_{\text{target}}} in the HO. Only square pulse profiles are considered, so that, for a single pulse, the pulse parameters are constant. The initial state of the system is always \ket{0,0} , and the evolution to a target state, for a single pulse, is given by: \displaystyle\begin{aligned} \ket{\psi_{\text{target}},\psi_{\text{res}}}&\overset{?}{=}\hat{U}({\bf\it\theta},T)\ket{0,0}\equiv\hat{U}(\zeta,\xi,\phi,\varphi,T)\ket{0,0}\\ &=e^{i\hat{H}(\zeta,\xi,\phi,\varphi)T}\ket{0,0},\end{aligned} (2) where {\bf\it\theta} is a short hand notation for the pulse parameters (\zeta,\xi,\phi,\varphi) , \ket{\psi_\text{res}} is some pure quantum state of the auxiliary qubit, T is the application time of the pulse, and the interrogation sign on top of the equal sign means that the equality holds only if the correct pulse parameters are found. An interesting question is whether these parameters exist, so that the only standing question is whether we can find these parameters. These parameters do exist, as pointed out by Pinna and Panati 2018 . As a strategy to increase the fidelity of the preparation, we use a composition of pulses (CP) Levitt 1986 . The CP technique involves using a sequence of N pulses, each of duration T/N : \displaystyle\ket{\psi_{\text{target}},\psi_{\text{res}}} \displaystyle=\hat{U}({\bf\it\theta}_{N})\cdots\hat{U}({\bf\it\theta}_{2})\hat{U}({\bf\it\theta}_{1})\ket{0,0} (3) \displaystyle=\hat{V}({\bf\it\Theta},T)\ket{0,0}=:\ket{\psi(\vb*{\Theta}, T)} (4) where {\bf\it\Theta} is the collection of the parameters of N pulses ({\bf\it\theta}_{1},\ldots,{\bf\it\theta}_{N}) applied in increasing order. Now the task is to find the parameters {\bf\it\Theta} and the total application time T such that the equation 4 is satisfied with high fidelity, i.e., such that \displaystyle F=tr\left[\outerproduct{\psi_\text{target}}{\psi_\text{target}}tr_{\beta}\left(\outerproduct{\psi(\vb*{\Theta}, T)}{\psi(\vb*{\Theta}, T)}\right)\right] (5) is close to 1. Here tr_{\beta} is the partial trace over the qubit degrees of freedom. There are many state-of-the-art alternatives for determining the pulse sequence required to prepare a state ( Rojan et al. 2014 ; Volya and Mishra 2024 ; Plesch and Brukner 2011 ; Magann et al. 2021 ; Porotti et al. 2022 ; Khalid et al. 2023 ; Torosov and Vitanov 2019 ; Shi et al. 2024a ) . However, these methods rely either on iterative techniques that optimize a cost function or on solving complicated equations, which increase in dimension as larger states are targeted, for each target state. The fact that each target state requires a separate solving routine makes these algorithm less scalable for real-world implementations requiring rapid encoding and/or state preparation, such as in quantum machine learning Cerezo et al. 2022 . In this work, we propose using a neural network to predict the pulse parameters {\bf\it\Theta} and total application time T as a function of the input target state. Our neural network is thus a parameterized function f_{{\bf\it\eta}}:\mathbb{R}^{d}\to\mathbb{R}^{4N+1} , where there are d real numbers that characterize the information in \ket{\psi_{\text{target}}} and 4N+1 real numbers that specify the 4 parameters (\zeta,\xi,\phi,\varphi) for N pulses, as well as the total application time T . {\bf\it\eta} are the neural network parameters (for more details, see appendix A ). We can thus write the fidelity in eq. 5 explicitly as a function of these parameters as \displaystyle F(\psi_{\text{target}},{\bf\it\eta})=\expectationvalue{\rho_\text{prepared}(\vb*{\eta})}{\psi_\text{target}}, (6) where \rho_{\text{prepared}}({\bf\it\eta}) is the state prepared in the HO \displaystyle tr_{\beta}\left(\hat{V}({\bf\it\Theta}({\bf\it\eta}),T({\bf\it\eta}))\outerproduct{0,0}{0,0}\hat{V}^{\dagger}({\bf\it\Theta}({\bf\it\eta}),T({\bf\it\eta}))\right). (7) Previous to the actual neural network, we calculate the expected values of the d=n^{2}-1 matrices that form a complete basis of SU(n) Pfeifer 2003 with respect to the target state \ket{\psi_{\text{target}}} (for more details, see appendix B ). These expected values are then passed to the neural network. A schematic of the information flow through the neural network can be seen in Figure 1 . The neural network parameters are optimized using stochastic gradient descent Narkhede et al. 2022 . In the machine learning jargon, carrying out this optimization is called “training” the neural network. Training is done by minimizing the average infidelity over random target states, i.e., \displaystyle C({\bf\it\eta})=1-\mathbb{E}\left[F(\psi_{\text{target}},{\bf\it\eta})-\sum_{n=1}^{N}\lambda\left(\zeta_{n}({\bf\it\eta},\psi_{\text{target}})+\xi_{n}({\bf\it\eta},\psi_{\text{target}})\right)^{2}\right] (8) where the expected value in eq. 8 is taken over random states \ket{\psi_{\text{target}}} , sampled from SU(n) according to the Haar measure. The second term in the expectation value is a regularization term with strength \lambda , added to prevent the generation of excessively high amplitudes ( \zeta_{n} and \xi_{n} for the n -th pulse) that could excite levels beyond the desired ones. Thus, we aim to minimize the average infidelity between a set of target states and the states prepared using the pulses predicted by the neural network. As previously mentioned, this is done through stochastic gradient descent, which requires \gradient_{{\bf\it\eta}}C({\bf\it\eta}) to be calculated. Figure 1: Scheme of the proposed methodology. The target state information is fed into the neural network to predict the parameters for a sequence of N pulses. These pulses are applied to the system’s initial state \ket{0,0} , leaving the harmonic oscillator prepared in the target state. III Results In this section we present results on the quality achieved by neural network models when minimizing the cost function in eq. 8 . However, we first numerically characterize the training’s behavior as a function of training data size, as well as the quantum dynamics convergence as a function of the HO’s basis size. III.1 Training data size First, we select an appropriate number of states to use for training. Using too many states can significantly increase training time, while using too few states might avoid the neural network from generalizing adequately. To find the optimal number of states, we perform an analysis of average infidelity as a function of the number of states used for training. In this analysis, we use a sequence of four pulses, a coupling g=1 , a regularization parameter \lambda=0.8 , and study the cases of preparing a qubit ( n=2 ) and a qutrit ( n=3 ). The results are shown in Figure 2 . The shaded area represents the range between the maximum and minimum infidelity values, while the point indicates the average infidelity value. These values are computed using three different datasets with the same data size, each generated with distinct random seeds. When the dataset reaches approximately 4000 states, the infidelity converges as the number of training states increases, for both the qubit and the qutrit cases. For the remainder of this work, the training dataset will consist of 4096 states uniformly sampled according to the Haar measure. Figure 2: Average preparation infidelity as a function of the training set size for a qubit and a qutrit. The fidelity is evaluated using a separate validation set of 100 states, also sampled from the Haar measure. The shaded area represents the range between the maximum and minimum infidelity values, while the point indicates the average infidelity value. III.2 Computational basis size Figure 3: Infidelity between (i) a state prepared for an n -level target state using a model with truncation at n_{\text{comp}} and (ii) a state prepared for the same n -level target state using a model with truncation at n_{\text{prepared}} . Shaded regions correspond to 75% confidence intervals using bootstrapping of Virginia nd , where the different values for each n_{\text{prepared}} correspond to three models train different seed in dataset train generation. We use 1250 n -level target states. The top panel is the qubit case ( n=2 ) and the bottom panel is the qutrit case ( n=3 ). If we aim to train a model to prepare states with n levels, we can restrict the states to this finite subspace. However, a key challenge arises: the used control pulses might inadvertently excite levels beyond n , leading to dynamics outside the defined subspace. Having dynamics outside this defined subspace is not problematic in an experimental setup, but it is problematic in a computational setup because the numerical calculations will produce unphysical dynamics for the probability amplitudes of the system. To avoid this, we study the convergence of the quantum dynamics as a function of the HO’s computational basis size. We call this computational basis size n_{\text{comp}} such that n_{\text{comp}}>n , where n is the number of levels for our qudit. In other words, even if levels above n are excited during the system’s evolution, we verify that the quantum dynamics numerically converge as we increase n_{\text{comp}} . To help convergence, the regularization term in eq. 8 limits the chances that levels above n are excited during the evolution. Now, let us turn our attention to the computational basis size given by n_{\text{comp}} . We train models that predict the parameters for N pulses of a HO-qubit system simulated with a HO basis truncated at n_{\text{comp}} levels. This means that the prepared state is no longer \rho_{\text{prepared}} as in ( 7 ), but it requires additionally tracing out the degrees of freedom corresponding to excitations beyond n levels, i.e., we have a new prepared state \tilde{\rho}_{\text{prepared}} given by \displaystyle\sum_{j=n+1}^{n_{\text{comp}}}(\mathbbm{1}_{n}\otimes\bra{j})\rho_{\text{prepared}}(\mathbbm{1}_{n}\otimes\ket{j}) (9) where \mathbbm{1}_{n} is the identity operator over the first n levels 1 1 1 We have also split the Hilbert space of the HO into two: the first n levels, and the rest of the space up to n_{\text{comp}} . . Note that \tilde{\rho}_{\text{prepared}} needs not be normalized. In fact, its norm is less than or equal to 1. This means that if we use \tilde{\rho}_{\text{prepared}} to evaluate any fidelity as in ( 6 ), the fidelity will be penalized if the dynamics produces a state with probability in the HO states beyond n excitations. With this context, let us now consider models that prepare n -level states with the basis truncated at n_{\text{prepared}}\geq n_{\text{comp}} . If we measure the infidelity between (i) a stated prepared for an n -level target state using a model with truncation at n_{\text{comp}} and (ii) a state prepared for the same n -level target state using a model with truncation at n_{\text{prepared}} –if the dynamics has converged–there should be no difference between states (i) and (ii), and if there is (there might be a difference, as model training is stochastic), this difference should not change as a function of n_{\text{prepared}} . If there is a difference that changes as n_{\text{prepared}} is increased, it is because models with a basis truncated to n_{\text{comp}} levels do not converge correctly. In figure 3 , we verify this infidelity behavior for a qubit n=2 and a qutrit n=3 . The optimal n_{\text{comp}} is the one that makes the infidelity converge as n_{\text{prepared}} increases while keeping it as small as possible. This indicates that increasing the number of levels considered does not result in the excitation of levels beyond n_{\text{comp}} . For both the qubit and the qutrit cases, the n_{\text{comp}} that shows the best results is n_{\text{comp}}=6 . For the remainder of the work, these values will be used for the size of the considered basis. III.3 Neural network performance: qubit case Figure 4: Trajectory of the state in the HO when attempting to prepare the target state \ket{1} with a sequence of five pulses. Additionally, the pulse profiles and the evolution of the purity in function of the time are presented. To understand how the model works, Figure 4 shows the trajectory of the state in the HO after applying each of the pulses generated by the trained model for five pulses. Specifically, this pulse sequence is designed to prepare the state \ket{1} . Additionally, the purity of the state in the HO as a function of time is shown in the same figure. Although, the state becomes mixed as it evolves, which is why the trajectory enters inside the Bloch sphere, by the end of the pulse sequence the state is prepared in the target state, with high fidelity (0.9911) and high purity (0.9978). This is very important, as one of the general challenges in control techniques using auxiliary systems is to ensure the purity of the HO prepared state. In the same plot, we also see the pulse sequence applied to the cavity ( \xi ) and to the auxiliary qubit ( \zeta ). Although the sequence is originally constructed to apply five pulses, the neural network is capable of predicting steps where no pulse needs to be applied. The actual composition to be constructed in an experiment would consist of 3 pulses in both cases, HO and auxiliary qubit. Even though we do not show the trajectories for other states, the fidelity of preparation for some states and their purity value at the end of the preparation are shown for the same model in table 1 . In general, it is observed that the preparation fidelity and purity are high. In particular, the third state is very important as it is a magic state, which is crucial in quantum computing Bravyi and Kitaev 2005 . State Fidelity Purity \frac{1}{\sqrt{2}}(\ket{0}-\ket{1}) 0.99864 0.99994 \frac{1}{\sqrt{2}}(\ket{0}+i\ket{1}) 0.99860 0.99992 (\cos(\frac{\pi}{8})\ket{0}+\sin(\frac{\pi}{8})\ket{1}) 0.99949 0.99988 Table 1: Fidelity and purity for three qubit target preparad in the HO. The model used is for five pulses. III.4 Number of pulses One of the most common aspects in the literature on pulse composition is that increasing the number of pulses in the sequence improves the quality of the preparation Torosov and Vitanov 2019 ; Shi et al. 2024a . To evaluate this result in our model, three models were trained for each value of the number of pulses (2–8) and n (2–3). The difference between the three models lies in the fact that they were trained with different datasets derived from distinct random seeds. For each model, the average infidelity is calculated over 1000 target states prepared using the model. These results are shown in figure fig. 5 . The points correspond to the average infidelity value of the three models, and we include a 75% confidence interval. It is clear that increasing the number of pulses significantly improves the fidelity with which qubit and qutrit states can be prepared. For the case of qubit states, an optimal point is observed when using seven pulses in the sequence. At these seven pulses, average fidelities exceeding 99.9\% are achieved. Figure 5: Preparation infidelity using the proposed neural network for 100 different states and with three models with different parameters for the same number of pulses. The red line corresponds to preparing qubit states in the HO, and the blue line corresponds to preparing qutrit states in the HO. Shaded regions correspond to 75% confidence intervals using bootstrapping of Virginia nd In the case of qutrit state preparation, with a composition of eight pulses, the model achieves an average fidelity of 97\% . Although this is not a poor result, it does not exhibit the same precision as in the qubit case. It is expected that when attempting to prepare states utilizing higher levels, performance decreases due to the increase in the size of the Hilbert space, making it more difficult for the model to relate the pulse parameter space to the possible target states to be prepared. Architectures such as deep networks or convolutional networks have shown significant improvements in multiple tasks compared to simpler architectures such as the one used in this work Sharma and Singh 2017 , which is an indication to explore other architectural approaches. To exemplify how more complicated neural networks can improve our results, we added a new hidden layer with 100 neurons to the neural network, making it deeper. This experiment achieved a fidelity of 98\% on qutrit states. For this reason, we believe that refining the network architecture would improve the results, especially in the cases of qutrits or higher-level systems. Future work will focus on exploring architectures that enable the preparation of states with more levels. We have already seen that the model allows for the preparation of many states with high precision, especially when increasing the number of pulses used in the composition, but the question remains of which states or families of states the model is not capable of preparing with high fidelity. To address this, in fig. 6 , panels a and b, we show the preparation the square root infidelity over the Bloch sphere for states prepared in the first two levels of the HO, i.e., the qubit case. We use the square root to improve the contrast in the image. Figure 6: Preparation fidelity over the Bloch sphere for 6400 states using a sequence of seven pulses. States with fidelities lower than 99\% are normalized to this value. In general, the model exhibits similar behavior across the entire Bloch sphere, however, there are two specific regions where the infidelity is drastically reduced. These regions appear to exhibit symmetry, as panel a) corresponds to the back face of the Bloch sphere with the region located in the upper hemisphere, while panel b) corresponds to the front face with the region located in the lower hemisphere. This resembles a reflection symmetry across the x-axis. This phenomenon is quite unusual, which is why in Figure 6 , panels c and d, we show the average area of the pulses implemented to prepare each state on the Bloch sphere. It is evident that in the same region where the infidelity drop occurs, the pulse area is larger. Although one might think this is an effect of the model’s learning process, the existence of symmetry and, additionally, the correlation between infidelity and pulse area suggests that some other effect, yet to be understood, might be at play. Beyond this, it is worth noting the model’s ability to prepare nearly any state with high fidelity in the case of a qubit, making it a useful tool for assisting in on-demand arbitrary state preparation. IV Conclusions In this work, a methodology based on neural networks was developed to predict the parameters of a sequence of square pulses applied to a quantum harmonic oscillator coupled to a qubit. The goal is to prepare a target state in the coupled quantum harmonic oscillator. This methodology allows for the preparation of arbitrary states of a qubit, qutrit, or qudits on the harmonic oscillator. Additionally, the way it is trained, considering a truncation greater than the required oscillator levels and using a regularization term in the cost function, ensures that higher energy levels are not excited, without the need to use experimental techniques to create a significant energy gap between the utilized levels and higher excited states. It was also confirmed that by gaining controllability through the use of a coupled auxiliary system, we do not lose purity, as the algorithm ensures high purity in the prepared state of the harmonic oscillator. As known in the state of the art, increasing the number of pulses in the sequence should improve the quality of the preparation. This effect was also evidenced in our model, allowing us to achieve average fidelities of 99.9\% in the preparation of qubit states in the quantum harmonic oscillator, with some states reaching fidelities of up to 99.999\% . For the case of qutrits, an average fidelity of 97\% was achieved, relatively low compared to the state of the art. In general, for qudit states with more levels, the performance will be lower. To improve these results, one alternative is to iterate and enhance the architecture of the neural network, as we are currently using a simple architecture with two hidden layers. As is well known in the state of the art, more complex architectures such as deep networks and convolutional networks show better results in various tasks Sharma and Singh 2017 . Another possible alternative in our methodology is to use a train of Gaussian pulses instead of a sequence of square pulses. Experimentally, in systems based on matter-radiation interactions, Gaussian pulses are more commonly used. Additionally, the choice of the regularization parameter did not follow an adequate optimization, and using such a high value significantly affects the model’s performance. However, smaller values were not used to avoid fidelity loss due to excitation at higher levels. Proper optimization of this parameter could lead to significant improvement, especially in states with higher levels. It was also found that for the case of preparing qubit states, almost the entire Bloch sphere can be prepared with high fidelity. However, there are two regions with a certain reflection symmetry where the preparation fidelity decreases significantly. This region correlates with the pulse area where the model uses pulses of larger area for the preparation. The nature of this effect remains unknown at this time. Finally, this work does not consider noise. Noise could have two types to model. First, the noise directly associated with the pulses, as instruments will always have systematic errors Shi et al. 2024b ; Kokaew et al. 2022 . Second, the noise from considering the open quantum physical system could have very significant effects on the quality of the preparation. To better approach real-world applications, these effects should be taken into account. Although we do not consider them in this work, they are compatible with the methodology, as only changes in the system modeling are required, not in the cost function. Appendix A Neural network In this work, we consider a full-forward neural network, which results from the consecutive application of neural network layers. A neural network layer is a parameterized function l:\mathbb{R}^{\text{in}}\to\mathbb{R}^{\text{out}} defined as \displaystyle l({\bf\it x})=a(W{\bf\it x}+\mathbf{b}), (10) where a is an element-wise function, called the activation function, W\in\mathbb{R}^{\text{out}}\times\mathbb{R}^{\text{in}} is called the weights matrix, and {\bf\it b}\in\mathbb{R}^{\text{out}} is the bias vector. Both the weight matrix and the bias vector contain the parameters of the layer. Layers can be composed to form a full-forward neural network, which are the ones considered in this work. Such a neural network is defined as \displaystyle f_{{\bf\it\eta}}({\bf\it x})=l_{L}\circ l_{L-1}\circ\cdots\circ l_{1}({\bf\it x}) (11) for a neural network of L layers. We have made it explicit that {\bf\it\eta} are the neural network’s parameters, which are all the weight matrices and bias vectors from the neural network’s layers. The last layer’s output size is 4N+1 , to accommodate all 4N parameters for the N pulses, plus their total duration T . The first layer’s input is d , where d refers to the components that specify the input target state. The rest of neural network thath we used consists of two hidden layers with 100 and 300 neurons, respectively. Appendix B Basis of SU( n ) The SU( n ) basis that we consider is the union of the following n\times n families of matrices Pfeifer 2003 : \begin{pmatrix}0&1&\cdots&0&0\\ 1&0&\cdots&0&0\\ \vdots&\vdots&\ddots&\vdots&\vdots\\ 0&0&\cdots&0&0\\ 0&0&\cdots&0&0\end{pmatrix},\begin{pmatrix}0&0&1&\cdots&0\\ 0&0&0&\cdots&0\\ 1&0&0&\cdots&0\\ 0&\vdots&\ddots&\vdots&\vdots\\ 0&0&\cdots&0&0\end{pmatrix},\cdots\begin{pmatrix}0&0&\cdots&0&0\\ 0&0&\cdots&0&0\\ \vdots&\vdots&\ddots&\vdots&\vdots\\ 0&0&\cdots&0&1\\ 0&0&\cdots&1&0\end{pmatrix} (12) \begin{pmatrix}0&-i&\cdots&0&0\\ i&0&\cdots&0&0\\ \vdots&\vdots&\ddots&\vdots&\vdots\\ 0&0&\cdots&0&0\\ 0&0&\cdots&0&0\end{pmatrix},\begin{pmatrix}0&0&-i&\cdots&0\\ 0&0&0&\cdots&0\\ i&0&0&\cdots&0\\ 0&\vdots&\ddots&\vdots&\vdots\\ 0&0&\cdots&0&0\end{pmatrix},\cdots\begin{pmatrix}0&0&\cdots&0&0\\ 0&0&\cdots&0&0\\ \vdots&\vdots&\ddots&\vdots&\vdots\\ 0&0&\cdots&0&-i\\ 0&0&\cdots&i&0\end{pmatrix} (13) \begin{pmatrix}1&0&0&\cdots&0\\ 0&-1&0&\cdots&0\\ 0&0&0&\cdots&0\\ \vdots&\vdots&\vdots&\ddots&0\\ 0&0&0&\cdots&0\\ \end{pmatrix},\sqrt{\frac{1}{3}}\begin{pmatrix}1&0&0&\cdots&0\\ 0&1&0&\cdots&0\\ 0&0&-2&\cdots&0\\ \vdots&\vdots&\vdots&\ddots&0\\ 0&0&0&\cdots&0\\ \end{pmatrix},\cdots,\sqrt{\frac{2}{n(n-1)}}\begin{pmatrix}1&0&0&\cdots&0\\ 0&1&0&\cdots&0\\ 0&0&1&\cdots&0\\ \vdots&\vdots&\vdots&\ddots&\vdots\\ 0&0&0&\cdots&-n+1\\ \end{pmatrix} (14) This basis correspond to n^{2}-1 matrices. Using this basis, for a target state \ket{\psi_{\text{prepared}}} , the inputs for the neural network are n^{2}-1 expected values.