Table of Contents
Fetching ...

Computing the gradients with respect to all parameters of a quantum neural network using a single circuit

Guang Ping He

TL;DR

The paper tackles the high cost of gradient computation in quantum neural networks by leveraging a single-circuit approach that uses two ancilla qubits to probabilistically realize all parameter shifts within one circuit run. This reduces circuit depth from $O(n^2)$ to $O(n)$ and lowers memory requirements, while still enabling accurate estimation of all gradients via shot statistics. Experimental results on simulators and IBM hardware demonstrate substantial compilation-time savings and a speedup in total runtime for larger data sets, despite increased running time per shot and additional qubits. The method generalizes to other parameter-shift gates and suggests hardware and algorithmic refinements to further improve performance in practical quantum training tasks.

Abstract

Finding gradients is a crucial step in training machine learning models. For quantum neural networks, computing gradients using the parameter-shift rule requires calculating the cost function twice for each adjustable parameter in the network. When the total number of parameters is large, the quantum circuit must be repeatedly adjusted and executed, leading to significant computational overhead. Here we propose an approach to compute all gradients using a single circuit only, significantly reducing both the circuit depth and the number of classical registers required. We experimentally validate our approach on both quantum simulators and IBM's real quantum hardware, demonstrating that our method significantly reduces circuit compilation time compared to the conventional approach, resulting in a substantial speedup in total runtime.

Computing the gradients with respect to all parameters of a quantum neural network using a single circuit

TL;DR

The paper tackles the high cost of gradient computation in quantum neural networks by leveraging a single-circuit approach that uses two ancilla qubits to probabilistically realize all parameter shifts within one circuit run. This reduces circuit depth from to and lowers memory requirements, while still enabling accurate estimation of all gradients via shot statistics. Experimental results on simulators and IBM hardware demonstrate substantial compilation-time savings and a speedup in total runtime for larger data sets, despite increased running time per shot and additional qubits. The method generalizes to other parameter-shift gates and suggests hardware and algorithmic refinements to further improve performance in practical quantum training tasks.

Abstract

Finding gradients is a crucial step in training machine learning models. For quantum neural networks, computing gradients using the parameter-shift rule requires calculating the cost function twice for each adjustable parameter in the network. When the total number of parameters is large, the quantum circuit must be repeatedly adjusted and executed, leading to significant computational overhead. Here we propose an approach to compute all gradients using a single circuit only, significantly reducing both the circuit depth and the number of classical registers required. We experimentally validate our approach on both quantum simulators and IBM's real quantum hardware, demonstrating that our method significantly reduces circuit compilation time compared to the conventional approach, resulting in a substantial speedup in total runtime.
Paper Structure (16 sections, 23 equations, 6 figures, 1 table)

This paper contains 16 sections, 23 equations, 6 figures, 1 table.

Figures (6)

  • Figure 1: (a) The general structure of a variational quantum circuit (VQC). All qubits $q_i$ ($i=1,...,n$) are initialized in the state $\left\vert 0\right\rangle$, then pass through three blocks: the feature map, the ansatz and the observable, which apply certain unitary transformations. Finally they are measured in the computational basis, and the result is sent to the classical register $c$. All the adjustable parameters $\vec{\theta}=(\theta _{1},...\theta _{n})$ are contained in the ansatz. (b) An example of the RealAmplitudes ansatz on three qubits, with two repetitions and full entanglement. $RY(\theta _{i})$ ($i=1,...,9$) are single-qubit RY rotation gates, with the adjustable parameter $\theta _{i}$ denoting the rotation angle about the $y$-axis. The blue icons are CX (controlled-NOT) gates. The red dashed boxes denote where the additional circuit of our improved approach shown in Fig.3 will be added.
  • Figure 2: Diagram of the conventional approach, in which the circuits of many VQCs are stacked in serial using Qiskit's “ compose” function. Each black box contains all the components of the complete VQC shown in Fig.1(a), i.e., the feature map, the ansatz, and the observable along with the measurement. But the adjustable parameters $\vec{\theta}=(\theta _{1},...\theta _{n})$ for each ansatz take different values.
  • Figure 3: The quantum circuit for our improve approach. The section inside the red dashed box can be put into any one of the three red dashed boxes in Fig.1(b). Here $q_{a}$ and $q_{b}$ are the additional control qubits. They need to be initialized in the states $\left\vert 1\right\rangle _{q_{a}}$ and $\left\vert 0\right\rangle _{q_{b}}$ only once at the very beginning of Fig.1(b). The two green/blue/purple dashed boxes will create the shift $\pm s$ to the gates $RY(\theta _{1})/RY(\theta _{2})/RY(\theta _{3})$, respectively, with equal probabilities as controlled by $q_{a}$ and $q_{b}$. Each of these dashed boxes starts with a controlled-RY gate $CRY(\gamma _{j})$, where $\gamma _{j}$ is defined in Eq. (\ref{['gamma j']}). Then a measurement is made on $q_{b}$, with the result recorded in the classical registers. Another controlled-RY gate $CRY(\pm s)$ is placed between $q_{b}$ and $q_{i}$ ($i=1,2,3$), followed by a CX gate between $q_{b}$ and $q_{a}$. Finally, $q_{b}$ is reset to the state $\left\vert 0\right\rangle _{q_{b}}$.
  • Figure 4: Individual number of shots actually computed for each cost function in our improved approach, corresponding to the experiment shown in the last column of Table 1. The average number of shots is taken to be $s=500$. The number of input data is $m=20$. The cost function with index $1$ is the unshifted cost function, while the other $12$ cost functions are all shifted ones. The dots with the same color represent the number of shots for the same input data point.
  • Figure 5: Runtimes as a function of the number of input data $m$. The dashed lines represent the time $t_{c}$ spent on compiling the circuit, the dotted lines represent the time $t_{r}$ spent on running the circuit, and the solid lines represent the total runtime $t_{s}=t_{c}+t_{r}$. All blue lines stand for the conventional approach, and all green lines stand for our improved approach. (a) Exp.1: The VQC used in the experiment in Fig.4, with $8$-dimensional classical input data and the RealAmplitudes ansatz containing $r=1$ repetition and full entanglement, run on quantum simulator. (b) Exp.2: The same VQC as that of Exp.1, run on real quantum hardware. (c) Exp.3: A VQC with $784$-dimensional classical input data, with the RealAmplitudes ansatz containing $r=2$ repetitions and full entanglement, run on quantum simulator. Note that the green solid and dotted lines almost overlap with each other since $t_{c}\gg t_{r}$ so that $t_{s}\simeq t_{c}$ for our improved approach in this case.
  • ...and 1 more figures