Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statevector drawer - state_to_latex's max_size parameter cause unintended rounding #9297

Closed
Slope86 opened this issue Dec 17, 2022 · 0 comments · Fixed by #9300
Closed

Statevector drawer - state_to_latex's max_size parameter cause unintended rounding #9297

Slope86 opened this issue Dec 17, 2022 · 0 comments · Fixed by #9300
Labels
bug Something isn't working

Comments

@Slope86
Copy link
Contributor

Slope86 commented Dec 17, 2022

Environment

  • Qiskit Terra version: 0.22.3
  • Python version: 3.10.8
  • Operating system: Windows 10 22H2

What is happening?

When I try to render the following state -

sv = Statevector(
    [
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 - 0.35355339j,
        0.0 + 0.35355339j,
        0.0 + 0.35355339j,
        0.0 - 0.35355339j,
    ],
    dims=(2, 2, 2, 2)
)

using sv.draw('latex', max_size=5)
I get the following latext output with the coefficient round to 5 decimal point.
未命名
The arg max_size=5 should only affect "Maximum number of non-zero terms in the expression", but also affects "Number of decimal places to round to".

How can we reproduce the issue?

Code to reproduce the issue -

sv = Statevector(
    [
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 - 0.35355339j,
        0.0 + 0.35355339j,
        0.0 + 0.35355339j,
        0.0 - 0.35355339j,
    ],
    dims=(2, 2, 2, 2)
)
sv.draw("latex", max_size=5)

What should happen?

Expected output should be like this :
未命名

Any suggestions?

In state_visualization.py, inside function _state_to_latex_ket, at line 1330、1336、1339.
When calling np.around() and numbers_to_latex_terms(), shouldn't use max_size as an argument to the parameter decimals.
https://github.com/Qiskit/qiskit-terra/blob/dd7f9390cf076f9545fa6086de486f2c06764ea5/qiskit/visualization/state_visualization.py#L1330-L1339

@Slope86 Slope86 added the bug Something isn't working label Dec 17, 2022
@Slope86 Slope86 changed the title Statevector drawer - state_to_latex's max_size parameter cause unintended roundrounding Statevector drawer - state_to_latex's max_size parameter cause unintended rounding Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant