Skip to content

Add warning for bad justify input, in circuit_drawer #12458

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

Merged

Conversation

GuillermoAbadLopez
Copy link
Contributor

@GuillermoAbadLopez GuillermoAbadLopez commented May 25, 2024

CHECKS:

  • I have read the CONTRIBUTING document.
  • I have added the tests to cover my changes.
  • I have updated the documentation accordingly.
  • All available test passing:
Screenshot 2024-06-17 at 17 41 26

Summary current state:

PR originally tackling #12089, to raise a warning for bad justify argument inputs.

The relevant code changes of this PR (+ after first review), are:

  • Changed the default value of justify, to "left" (previously None).
  • Added the corresponding DeprecationWarning, saying we will error for wrong justify arguments in the future.
  • Added the corresponding tests for the warning.
  • Some minor auto-formater reordering of imports (can be undone, if desired).

Corner cases now working better:

  1. If the user manually passes justify=None (which ends as justify="left") we raise a warning, which before since itwas the default value, we couldn't...

  2. If the user manually passes any justify that passes as True if justify:, but which is not a string. Since before we would have done justify.lower() to it, getting a non-personalized error message: 'X'object has no attribute 'lower'...




OUTDATED original Summary (before first review):

(before changing the default value None to "left", when only a warning was raised [except for None])

PR tackling #12089, where I have added a warning, for when the justify argument is not in the three accepted cases "left", "right" and "none".

@GuillermoAbadLopez GuillermoAbadLopez requested review from nonhermitian and a team as code owners May 25, 2024 12:31
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label May 25, 2024
@CLAassistant
Copy link

CLAassistant commented May 25, 2024

CLA assistant check
All committers have signed the CLA.

@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 following people are relevant to this code:

@GuillermoAbadLopez GuillermoAbadLopez marked this pull request as draft May 25, 2024 12:45
@GuillermoAbadLopez GuillermoAbadLopez changed the title Add warning for bad justify input, in circuit_drawer [WIP] Add warning for bad justify input, in circuit_drawer May 25, 2024
@GuillermoAbadLopez GuillermoAbadLopez marked this pull request as ready for review May 25, 2024 17:46
@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 following people are relevant to this code:

@GuillermoAbadLopez GuillermoAbadLopez changed the title [WIP] Add warning for bad justify input, in circuit_drawer Add warning for bad justify input, in circuit_drawer May 25, 2024
Copy link
Collaborator

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks! This looks good to me 🚀 I'll be OOO till the 15th, so will defer to others to finish review.

@GuillermoAbadLopez
Copy link
Contributor Author

GuillermoAbadLopez commented Jun 6, 2024

Currently, tests are not passing due to a circular import, most likely due to using _is_valid_justify_arg, in all the files...

I had a couple of quick ideas, but it requires moving this function definition, to places, where it doesn't feel right..


Update: Regex check has been removed, for the sake of not complicating this more! 👍

@GuillermoAbadLopez
Copy link
Contributor Author

I'm getting this error in the Preliminary tests now, due to the release note:

lint: commands[4]> pylint -rn qiskit test tools

------------------------------------
Your code has been rated at 10.00/10

lint: commands[5]> python /home/vsts/work/1/s/tools/verify_headers.py qiskit test tools examples crates
lint: commands[6]> python /home/vsts/work/1/s/tools/find_optional_imports.py
lint: commands[7]> python /home/vsts/work/1/s/tools/find_stray_release_notes.py
lint: commands[8]> reno -q lint
  docs: FAIL code 1 (606.14=setup[410.84]+cmd[24.06,171.24] seconds)
  lint: OK (673.33=setup[175.87]+cmd[39.08,2.25,0.73,53.68,397.27,0.16,0.66,0.08,3.56] seconds)
  evaluation failed :( (1279.88 seconds)

##[error]Bash exited with code '255'.

In local everything passes correctly, but I think its not checking new files...
Screenshot 2024-06-19 at 05 31 30

Also, I have tried various changes I thought would solve it, but nothing worked so far.
If you have encountered this before, any help would be appreciated.

@Eric-Arellano
Copy link
Collaborator

@GuillermoAbadLopez reno lint was a red herring :/ The warning is from Sphinx higher up in CI logs:

/home/vsts/work/1/s/docs/release_notes.rst:438: WARNING: Inline interpreted text or phrase reference start-string without end-string.

--

I talked more to @1ucian0 and @kevinsung we decided to indeed go back to using None as the default argument. While it makes the documentation a little less clear, Qiskit SDK tends to use None as the default like this and then set the "true default" at runtime because it gives more flexibility for the future.

For example, imagine we want to change the default of left to a new value like justified -- that is a breaking behavior change and would need a deprecation cycle. To detect when people are using the default—rather than explicitly setting ='left'—we would need to check if arg is None. But we can't do that check anymore if we've now set the default directly to be 'left'; we no longer know if you explicitly set the value or you're relying on the default.

So, please go back to using None as the default arg, which results in left being used. But, of course, still warn on otherwise invalid arguments.

Pardon the back-and-forth and thank you for persistence on this issue!

@GuillermoAbadLopez
Copy link
Contributor Author

@GuillermoAbadLopez reno lint was a red herring :/ The warning is from Sphinx higher up in CI logs:

/home/vsts/work/1/s/docs/release_notes.rst:438: WARNING: Inline interpreted text or phrase reference start-string without end-string.

That makes a lot of sense, found something, thanks! 👍

@GuillermoAbadLopez
Copy link
Contributor Author

GuillermoAbadLopez commented Jun 19, 2024

No worries at all, we should do what its best for the stack, in the end!

I'll change it, but it might take a bit, since I'm going OOO for a couple of days 👍

I talked more to @1ucian0 and @kevinsung we decided to indeed go back to using None as the default argument. While it makes the documentation a little less clear, Qiskit SDK tends to use None as the default like this and then set the "true default" at runtime because it gives more flexibility for the future.
...

@coveralls
Copy link

coveralls commented Jun 20, 2024

Pull Request Test Coverage Report for Build 9584452045

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 18 of 18 (100.0%) changed or added relevant lines in 3 files are covered.
  • 22 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.02%) to 89.753%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 93.13%
crates/qasm2/src/parse.rs 18 96.69%
Totals Coverage Status
Change from base Build 9578841868: -0.02%
Covered Lines: 63571
Relevant Lines: 70829

💛 - Coveralls

@GuillermoAbadLopez
Copy link
Contributor Author

GuillermoAbadLopez commented Jun 26, 2024

Last suggestions addressed!

  1. Have gone back to None as the default value for justify

  2. Simplified the deprecation logic to a simple warn, similar to the starting one.
    (Since even though the @arg_dreprecation decorator/wrapper was better for localizing the error, it seemed a bit confusing for the future maintainer that would have finally deprecated this, with single lines around to delete, that he could have missed..., now it's super simple! Also this way allows for a Regex check in the test)

  3. Some final changes to the docstrings (both public and private), and updated the release note.

@Eric-Arellano @kevinsung @1ucian0

Copy link
Collaborator

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thank you! @Qiskit/terra-core @1ucian0 can you please merge?

@1ucian0 1ucian0 added the Changelog: Deprecation Include in "Deprecated" section of changelog label Jul 1, 2024
@1ucian0 1ucian0 added this pull request to the merge queue Jul 1, 2024
@coveralls
Copy link

coveralls commented Jul 1, 2024

Pull Request Test Coverage Report for Build 9741924018

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 18 of 18 (100.0%) changed or added relevant lines in 2 files are covered.
  • 13 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.006%) to 89.767%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/parse.rs 6 97.61%
crates/qasm2/src/lex.rs 7 91.6%
Totals Coverage Status
Change from base Build 9718390567: -0.006%
Covered Lines: 64079
Relevant Lines: 71384

💛 - Coveralls

Merged via the queue into Qiskit:main with commit ed87f2f Jul 1, 2024
@GuillermoAbadLopez GuillermoAbadLopez deleted the circuit_drawer_warn_bad_justify_input branch July 1, 2024 15:54
Procatv pushed a commit to Procatv/qiskit-terra-catherines that referenced this pull request Aug 1, 2024
* add warning for bad justify input in circuit_drawer

* change justify after raising error

* typo indentation + improving warning string

* Undo max_lenght limit by autoformater (120 > 105)

* Make lines fullfill 105 max lenght requirement

* Solve regex matching parenthesis problem and don't trigger the wanring for default value

* Change justify default value to "left", & add deprecation wrapper

* Change and extend warnings tests

* Solve various layers of same argument DeprecationWarning

* Added a clarification comment for the solution, about multiple deprecationwarnings

* Ignore cyclic import error, as above

* Apply suggestions from code review

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* Apply suggestions from code review

* Improve DeprecationWarning readability, and fix warning checks tests

* Remove `_is_valid_justify_arg` from `@deprecate_arg`, for solving circular import

* in `deprecate_arg` change `since` to "1.2.0"

* black formater suggestion

* negate conditions for `predicate` in `@deprecate_arg`

* remove `pending=True`, since then warning is not raised

* change qiskit version on tests

* remove assert Regex for DeprecationWarning

* Add release note, and remove two undesired changes in imports

* changing release note naming from "_" to "-"

* Add extra line in the end, for lint

* Redid release file from start, with shorter name, and correct spacings

* Remove final spaces in all lines...

* Try without deprecations_visualization section..

* Solve, bad Sphinx spacing, go back to deprecations_visualization

* Go back to `None` as default value

* Simplifying deprecation logic

* Remove unused imports and changed missing default value

* Improve docstring for public methods

* Improve error readbility and testing of it with regex

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Deprecation Include in "Deprecated" section of changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants