# A Reconfigurable Framework for Hybrid Quantum-Classical Computing
## 3 Proposed Framework
### Quantum Machine Learning Task
#### 3.1.4 Training: Gradient Computation and Loss Function  
The gradient computation mechanism implements a stochastic gradient descent approach for parameter optimization, which is designed to handle the complexities of quantum circuit training. This process begins with a forward pass of the circuit using the current weights to establish a baseline prediction and loss value. A matrix of perturbed weight configurations is generated, where each weight is independently perturbed by a small epsilon value, \(\epsilon\), to maintain numerical stability. This perturbation size is carefully chosen to balance numerical stability with accuracy; too large an epsilon would result in poor gradient estimates, while too small a value could lead to numerical instability due to floating-point arithmetic limitations. A key optimization in this implementation is the batch processing of forward passes for all perturbed configurations, which significantly reduces the computational overhead compared to sequential processing. We also designed a kernel that computes cross-entropy loss values for each perturbed configuration, handling numerical stability through careful epsilon-based adjustments. The final gradi  
Figure 3: Parameterized quantum circuit for QML (4 variational layers shown). ent computation approximates partial derivatives through finite differences, calculating (Loss_perturbed - Loss_original)/epsilon for each parameter. We implement a mini-batch processing strategy in the quantum-classical hybrid learning system that balances computational resources with optimization stability. The system processes data in small batches, where each batch undergoes quantum circuit evolution followed by classical parameter updates (Figure 2). The process begins with shuffling the training data to prevent learning biases, then iterates through the batches, computing the quantum state creation for each sample using the state vector simulator. For each batch, gradients are computed using the stochastic gradient descent (with \(\epsilon=10^{-8}\)) and averaged across the batch samples, providing more stable parameter updates compared to single-sample training. The gradient for each parameter \(\theta_{j}\) using finite differences can be expressed as  
\[\
abla_{\theta_{j}}\mathcal{L}(\theta)\approx\frac{\mathcal{L}(\theta_{1}, \ldots,\theta_{j}+\epsilon,\ldots,\theta_{n})-\mathcal{L}(\theta)}{\epsilon} \tag{2}\]  
where  
* \(\theta=[\theta_{1},\theta_{2},\ldots,\theta_{n}]\) are the circuit parameters. * \(\epsilon\) is a small perturbation (\(\epsilon=10^{-8}\)). For batch gradient averaging (mini-batch size \(B\)),  
\[\
abla_{\theta_{j}}\mathcal{L}_{\text{batch}}(\theta)\approx\frac{1}{B}\sum_ {i=1}^{B}\frac{\mathcal{L}^{(i)}(\theta_{1},\ldots,\theta_{j}+\epsilon,\ldots, \theta_{n})-\mathcal{L}^{(i)}(\theta)}{\epsilon} \tag{3}\]  
where \(\mathcal{L}^{(i)}\) represents the loss calculated on the \(i^{th}\) sample of the mini-batch. The forward pass function maps input data to quantum states through parameterized circuit operations, while the loss function with added numerical stability (\(\epsilon=10^{-8}\)) computes the cross-entropy loss between predicted and actual outputs. The cross-entropy loss for a single data sample with actual label \(y\) and predicted probability \(\hat{y}\) (from the quantum circuit output) is  
\[\mathcal{L}(y,\hat{y})=-[y\log(\hat{y}+\epsilon)+(1-y)\log(1-\hat{y}+\epsilon)] \tag{4}\]  
where  
* \(\hat{y}\) is the quantum circuit prediction probability for the positive class (output from the quantum circuit after forward pass). * \(y\in\{0,1\}\) is the actual label. * \(\epsilon\) is a small constant (\(\epsilon=10^{-8}\)) added for numerical stability to avoid \(\log(0)\).