Statevector.draw('latex') can't handle near zero numbers
See original GitHub issueEnvironment
- Qiskit Terra version: 0.19.1
- Python version: 3.8.10
- Operating system: win11x64
What is happening?
Performing Statevector.draw(‘latex’) on a statevector that includes numbers which are near zero, results in bad output.
How can we reproduce the issue?
A sample CSWAP-test circuit:
qc = QuantumCircuit(3)
qc.h(0)
qc.cswap(0, 1, 2)
qc.h(0)
evolution of a sample input statevector according to the CSWAP-TEST:
sv = Statevector.from_label('--0').evolve(qc)
print(sv.data)
Notice the near zero numbers at indices 1,3,5 and 7:
[ 5.00000000e-01+0.j 3.11164266e-19+0.j -5.00000000e-01+0.j
-3.11164266e-19+0.j -5.00000000e-01+0.j -3.11164266e-19+0.j
5.00000000e-01+0.j 3.11164266e-19+0.j]
Performing:
sv.draw('latex')
Produces:
What should happen?
Should produce:
Any suggestions?
Although a vector output and not Dirac notation, note that performing:
array_to_latex(sv)
does not suffer from the same problem. Is it possible to set up a global “snap to sigma” parameter to the whole system, such that all underlying auxiliary functions can follow? (and it would be nice to change ‘latex’ to ‘dirac’… 😃)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
qiskit.quantum_info.Statevector.draw
latex : An IPython Latex object for displaying in Jupyter Notebooks. latex_source: Raw, uncompiled ASCII source to generate array using LaTeX. qsphere: ...
Read more >qiskit - How to get full length output from statevector draw
It seems like a bug. A workaround is to use _state_to_latex_ket directly as follows: from IPython.display import Latex from qiskit.visualization ...
Read more >backends — ProjectQ 0.8.1.dev14 documentation
Compiler engine that prints command to the standard output. projectq.backends.DeviceNotHandledError. Exception raised if a selected device cannot handle the ...
Read more >CRAN - Package 'survival'
Arguments formula a formula object, with the response on the left of a '~' operator and the terms, separated by + operators, on...
Read more >The animate Package
graphics vector graphics animated GIF LaTeX dvips ps2pdf dvipdfmx XeLaTeX ... A frame number <num> may as well be given; <num> is zero-based,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you assign me please?
Oh that comment was meant to help whoever is going to patch the code, not for end user work around. My work around btw is to do this:
which is ugly but works 😃