1
$\begingroup$

I am following this very nice qiskit tutorial on how to implement a simple variational quantum linear solver (VQLS). There are 3 examples implemented in the tutorial all of which are solving the $Ax=b$ problem, however I can only get the first one to work consistently. To be clear, for the discussion below, I am using the exact code given on their page.

Looking at their second example where $A = 0.55I + 0.225Z_2 + 0.225Z_3$ the solver fails to find an adequate solution. To show this, I use a metric defined on their page to measure the accuracy of the solution: $b(Ax)/|Ax|^2$. An accurate solution will be near $1$, however, they report $0.2920$ demonstrating that their method has failed. This is strange because they claim that it has succeeded. This can be easily checked by taking the optimized parameters they provide which are given as the following vector:

x: array([2.38122341, 1.98992817, 4.69971104, 1.56178653, 3.12971691,1.56423666, 0.66469388, 4.26774393, 0.7439952 ])

These parameters can be directly input into their apply_fixed_ansatz function to obtain the solution $x$. Doing this, one finds that $Ax\neq b$.

My question is, is the tutorial wrong as I have stated? If so, how is it wrong and what can I do to fix it? Otherwise, am I misunderstanding the tutorial and if so, where am I going wrong?

$\endgroup$
1
$\begingroup$

I have just run the tutorial in IBM Quantum Lab.

The output of the cell is in the end: ...

0.010566193641774357
0.010238918165696886
0.009971238578226349
     fun: 0.009971238578226349
   maxcv: 0.0
 message: 'Maximum number of function evaluations has been exceeded.'
    nfev: 200
  status: 2
 success: False
       x: array([3.21144819, 1.30553216, 3.11318068, 3.07952116, 1.43544259,
       1.73110611, 1.2182566 , 2.74153291, 4.13588463])
(0.9900287614218056-0j)

Therefore I think the code is okay but the output of the cell in the tutorial is maybe wrong?

Have you tried the code for yourself?

$\endgroup$
4
  • $\begingroup$ Which version of their code are you using? There are three examples on the page and I found that the first one works out of the box with no changes and I get similar results as you printed out here. I think that you are correct in saying that they put the wrong output on the tutorial page. After I posted my question, I found that the 2nd and 3rd examples also work, but I had to increase the number of iterations that the optimizer uses from 200 to about 400. $\endgroup$ Mar 12 at 20:29
  • 1
    $\begingroup$ I am using the code from the link in you`re question without any modifications. All three examples are working fine with 200 evals. $\endgroup$
    – tomtuamnuq
    Mar 12 at 22:06
  • $\begingroup$ Interesting. That is a good data point for me to have. I don't know why they would work for you with 200 evals but require more on my computer. $\endgroup$ Mar 12 at 22:35
  • $\begingroup$ I would also like to point out another mistake I found in the tutorial. In the "calculate_cost_function" used in the 3rd example, they divide the output state by 100,000. However, they only use 10,000 shots so this should be corrected to "m_sum = float(outputstate["1"])/10000." This correction has lead to a large increase in the solution accuracy for me. $\endgroup$ Mar 12 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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