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

Fix for None in state_to_latex latex output #8273

Merged
merged 19 commits into from
Sep 23, 2022

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Jun 29, 2022

This is an alternative to #8174, with the same test.

Fixes #8169
Fixes #8073
Fixes #7513

1ucian0 and others added 2 commits June 29, 2022 15:08
Co-authored-by: Rishabh Chakrabarti <rishacha.dev@gmail.com>
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

@coveralls
Copy link

coveralls commented Jun 29, 2022

Pull Request Test Coverage Report for Build 3113876507

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.004%) to 84.38%

Files with Coverage Reduction New Missed Lines %
qiskit/extensions/quantum_initializer/squ.py 2 79.78%
Totals Coverage Status
Change from base Build 3109482377: -0.004%
Covered Lines: 59286
Relevant Lines: 70261

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking again, the premise of this fix isn't quite right, but that's because the current implementation is convoluted. The gist is that nonzero_indices purports to be the source of which items should be printed, but it's not: that's decided by whether the entry in latex_terms is not None. nonzero_indices is built by comparing to exactly 0, whereas the LaTeX output bits use a fuzzier comparison. The errors arise because those two things disagree: there should only be one source of truth. I think the LaTeX output here needs a bit of refactoring, if we're touching it now: we're just adding more warts to something that already looks like it's been complicated by several "bugfixes" not addressing the root cause.

@1ucian0
Copy link
Member Author

1ucian0 commented Jun 29, 2022

Ill take it. The root of the problem is that _round_if_close is not rounding correctly. I fully removed it and called np.around directly.

@1ucian0 1ucian0 added this to the 0.22 milestone Jul 11, 2022
rishacha
rishacha previously approved these changes Jul 11, 2022
Copy link
Contributor

@rishacha rishacha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mtreinish mtreinish self-assigned this Jul 25, 2022
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a simpler solution to the problem, thanks. I still don't like our data flow in this whole process, but this change at least makes things consistent and fixes the error without introducing any more complexity. Two minor comments, but otherwise this looks fine.

frankharkins added a commit to frankharkins/qiskit-terra that referenced this pull request Aug 16, 2022
Copy link
Member

@frankharkins frankharkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like decimals, is probably clearer. Side note, I also think this PR would close #8073 and #7513.



def num_to_latex_ket(raw_value: complex, first_term: bool) -> Optional[str]:
def num_to_latex_ket(raw_value: complex, first_term: bool, decimals: int = 0) -> Optional[str]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a high number (e.g. 10 or 15) would be a more appropriate default here. I think it's unlikely someone would want to round amplitudes to 0 decimal places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to 10 in cef4fb6

@@ -1293,20 +1287,22 @@ def num_to_latex_ket(raw_value: complex, first_term: bool) -> Optional[str]:
return None


def numbers_to_latex_terms(numbers: List[complex]) -> List[str]:
def numbers_to_latex_terms(numbers: List[complex], max_size: int) -> List[str]:
Copy link
Member

@frankharkins frankharkins Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs changing to decimals too, probably with a default value as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. done in cef4fb6

@1ucian0
Copy link
Member Author

1ucian0 commented Sep 4, 2022

I also think this PR would close #8073 and #7513.

Indeed! adding fixes note. Thanks!

@1ucian0 1ucian0 added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Sep 4, 2022
@@ -1291,20 +1285,21 @@ def num_to_latex_ket(raw_value: complex, first_term: bool) -> Optional[str]:
return None


def numbers_to_latex_terms(numbers: List[complex]) -> List[str]:
def numbers_to_latex_terms(numbers: List[complex], decimals: int = 10) -> List[str]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was on the fence about asking for a release note for this new kwarg. I decided that we didn't need it because we don't re-export this function from the root of visualization or document it in the visualization api. But if people feel strongly that we should document this new kwarg we can always add it as part of the release prep.

@mergify mergify bot merged commit cb715a3 into Qiskit:main Sep 23, 2022
derwind added a commit to derwind/qiskit-aer that referenced this pull request Jan 12, 2023
mergify bot pushed a commit to Qiskit/qiskit-aer that referenced this pull request Jan 24, 2023
* Add __init__.py to run tests for terra.states

* Update tests to follow Qiskit/qiskit#8273

* Install matplotlib for plot_state_qsphere according to CI log

* Install seaborn for plot_state_qsphere according to CI log

* Fix suppressions for Jupyter warnings

Co-authored-by: Hiroshi Horii <hhorii@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
7 participants