0
$\begingroup$

I am working on a project in which I need to simulate the paper https://arxiv.org/abs/1910.01155. So I am a complete beginner to qiskit but I read its documentation so I know some stuff. So basically I need to implement a doubly stochastic gradient descent algorithm, now what I am familiar is classical stochastic gradient descent for lets say a MSE loss function. But now when I have to use qiskit to implement it, I have two major doubts here:

1)So from what I understand what we do here is first take a random data point if we use just one point for stochasticity and put it in the cost function and then take gradient and update the parameters. So what I don't understand is how do I take gradient using parameter shift rule, because in the paper the parameter shift rule is given very vaguely and I don't know how to implement it.

  1. Also what I don't undertstand is whose expectation value are we finding in the whole procedure, and what is even this expectation value giving, is it the gradient or something else?
$\endgroup$

2 Answers 2

2
$\begingroup$

What is $( f(\theta) $)?

  1. Initial Quantum State: Start with $( |0\rangle $).
  2. Unitary Operation: Apply a parameterized unitary operation $( U(\theta) $) to get the state $( |\psi(\theta)\rangle = U(\theta)|0\rangle )$.
  3. Observable: Measure an observable ( O ).

The output $( f(\theta) $) is the expectation value: $$ f(\theta) = \langle \psi(\theta) | O | \psi(\theta) \rangle $$

Example with MSE

  1. Quantum Part:

    • Run the quantum circuit to get $( f(\theta) $).
  2. Classical Part:

    • Use the mean squared error (MSE) cost function to compute the difference between the predicted and actual values.
    • For binary classification, the observable ( O ) could be a Pauli-Z operator, giving labels 0 or 1.

Steps

  1. Initialize: Set initial parameters $( \theta )$.
  2. Run Circuit: Get $( f(\theta) )$.
  3. Compute MSE: Calculate the MSE based on $( f(\theta) )$ and true labels ( y ): $$ \text{MSE}(\theta) = \frac{1}{n} \sum_{i=1}^n \left( f(\theta)_i - y_i \right)^2 $$
  4. Compute Gradient: Use the parameter shift rule to compute the gradient: $$ \frac{\partial f(\theta)}{\partial \theta} \approx \frac{f(\theta + \epsilon) - f(\theta - \epsilon)}{2\epsilon} $$
  5. Update Parameters: Adjust $( \theta )$ to minimize MSE: $$ \theta \leftarrow \theta - \eta \nabla \text{MSE}(\theta) $$
  6. Iterate: Repeat until MSE is optimized.

By iteratively updating $( \theta )$ and running the circuit, you find the optimal parameters that minimize the MSE for your classification task.

$\endgroup$
2
  • $\begingroup$ I had a last question, is the stochastic gradient descent talked about in the paper and the SPSA algorithm the same? $\endgroup$ Commented Jun 16 at 17:10
  • $\begingroup$ No. They are different optimization techniques. $\endgroup$ Commented Jun 17 at 8:59
0
$\begingroup$

To understand and implement the parameter shift rule in Qiskit, you can refer to the official Qiskit documentation and tutorials. The parameter shift rule is a method used to calculate the gradient of a quantum circuit's output with respect to its parameters. This technique is particularly useful in variational quantum algorithms, such as the Variational Quantum Eigensolver (VQE) and Quantum Approximate Optimization Algorithm (QAOA).

  1. Initial Setup: Begin with an initial state vector $( |\psi(\theta)\rangle = U(\theta)|0\rangle )$, where $( U(\theta) )$ represents a parameterized quantum circuit. Here, $( \theta )$ parameterizes the quantum circuit.

    The parameter shift rule allows you to compute the gradient of a quantum circuit with respect to its parameters by evaluating the circuit at shifted parameter values. For a parameter $( \theta $), the gradient $( \frac{\partial f}{\partial \theta} )$ can be approximated as:

    $$ \frac{\partial f(\theta)}{\partial \theta} \approx \frac{f(\theta + \epsilon) - f(\theta - \epsilon)}{2} $$

    Here, $( f(\theta) )$ represents the output of the entire quantum circuit, typically with respect to an observable ( O ).

  2. Observable ( O ): The choice of observable ( O ) depends on the application. For instance, in binary classification tasks, you might choose the Pauli-Z operator, which measures in the computational basis (returns 0 or 1), corresponding to labeling outcomes. In VQE, the observable could be a local Hamiltonian, as described in the VQE section of the paper you referred to.

This approach allows for efficient computation of gradients using quantum circuits, facilitating optimization tasks in variational quantum algorithms.

You can incorporate this understanding into your implementation in Qiskit by following examples and tutorials provided in the Qiskit documentation and related resources. Look at RealAmplitudes, which includes the parameterization of the circuit, which is later being optimized in VQC. For theoretical details of parameter optimization , you can follow up this paper.

$\endgroup$
5
  • $\begingroup$ So, is the quantum computing part used for computing gradient, right? And just to understand, if we take the cost function as something like mean squared error(MSE) is f(theta) here nothing but just the cost function? What do you mean by the line that f(theta) represents the output of the entire quantum circuit? $\endgroup$ Commented Jun 15 at 6:08
  • $\begingroup$ Also what I don't get it is how this observable is determined, I am not quite familiar with VQE or QAOA, but I am more familiar with MSE cost function, so what would be the observable when considering this cost function. $\endgroup$ Commented Jun 15 at 6:09
  • $\begingroup$ Oh, and that Qiskit documentation link that you gave, would be really helpful thanks so much. $\endgroup$ Commented Jun 15 at 6:16
  • $\begingroup$ Follow the second answer for computing MSE in a classification task. The MSE cost function and parameter optimization are performed classically. However, the training function evaluation $( f(\theta) )$ happens in the quantum domain. Quantum computing helps evaluate complex functions, while parameter optimization $( \theta )$ occurs in the classical domain to ensure the training model works well. This hybrid approach leverages quantum computing for function evaluation and classical computing for optimization, making it a hybrid classical-quantum method. $\endgroup$ Commented Jun 15 at 11:16
  • $\begingroup$ Also we run the circuit to get expectations value of f($\theta). Only single evaluation gives the observation as 0 or 1 for pauliz observable. Multiple evaluation gives the expected value..how much 0 and how much 1 ..this is for binary classification $\endgroup$ Commented Jun 15 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.