1
$\begingroup$

I am trying to follow some tutorials for Qiskit and came to the point where I wanted to get some statevector containing $1/\sqrt{2}$ with the following line of code:

outputstate = result.get_statevector(circ, decimals=3)

By specifying the option decimals=3, it should round the numerical value in the statevector to 0.707. However, it does not do that. Instead, what is displayed is 0.70710678+0.jas it apparently fails to round.

What could be the problem causing this? Or how else could I resolve this issue to get nicer looking results when displayed?

$\endgroup$
2
  • $\begingroup$ Which version are you using? It seems that problem was solved in qiskit-terra 0.17 github.com/Qiskit/qiskit-terra/issues/5428 $\endgroup$ – luciano Jul 9 at 10:40
  • $\begingroup$ I just updated to qiskit-terra 0.17.4 and now it is working properly again. $\endgroup$ – Tobias95 Jul 9 at 10:52
1
$\begingroup$

This looks like it could be a bug so it might be worth checking the Qiskit repo to raise an issue or see if anyone else has spotted it already.

If you are simply looking to format the results, you can use Python's f strings, for example print(f'{outputstate:.3f}') would print outputstate to 3 decimal places.

$\endgroup$
1
  • 1
    $\begingroup$ Thanks for the tip with the Qiskit repo. It was indeed already solved there! $\endgroup$ – Tobias95 Jul 9 at 10:33

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.