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

[Strings2] Improve string repr of Sum #5138

Merged
merged 62 commits into from Feb 8, 2024
Merged

[Strings2] Improve string repr of Sum #5138

merged 62 commits into from Feb 8, 2024

Conversation

Qottmann
Copy link
Contributor

@Qottmann Qottmann commented Feb 1, 2024

Sum instances are now displayed multiline and without unnecessary brackets. Further, all outputs should be copy-and-paste-able. Some examples how this now looks:

>>> qml.operation.enable_new_opmath()
>>> X(0) + X(1) + X(2) # short outputs <60 characters in single line
X(0) + X(1) + X(2)
>>> 0.5 * (X(0) @ X(1)) + 0.7 * (X(1) @ X(2)) + 0.8 * (X(2) @ X(3)) # larger outputs break into multiple lines. copy-paste-able with surrounding brackets
(
    0.5 * (X(0) @ X(1))
  + 0.7 * (X(1) @ X(2))
  + 0.8 * (X(2) @ X(3))
)

There are also some peculiarities that cannot be improved at the moment because they are due to the nesting and lazy execution of products and sums:

>>> 0.5 * (X(0) @ (0.5 * X(1))) + 0.7 * X(1)
0.5 * (X(0) @ (0.5 * X(1))) + 0.7 * X(1)

ToDo

  • Basic functionality
  • Tests
  • multiline threshold solution? (Problem from nesting in e.g. X(0) + X(1) + X(2))
  • changelog

Documentation will be updated together with the changes from #5116 in a follow-up PR

Builds on top of #5116
[sc-54959]
[sc-54955]

Copy link
Contributor

github-actions bot commented Feb 1, 2024

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@Qottmann Qottmann changed the base branch from master to paulistrings February 1, 2024 13:32
@Qottmann Qottmann changed the title Improve string repr of Sum [Strings2] Improve string repr of Sum Feb 5, 2024
Copy link
Contributor

@trbromley trbromley left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@albi3ro albi3ro 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 so much!

@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0428922) 99.68% compared to head (15fa31b) 99.67%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5138      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.01%     
==========================================
  Files         394      394              
  Lines       36298    36034     -264     
==========================================
- Hits        36183    35918     -265     
- Misses        115      116       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from paulistrings to master February 6, 2024 15:41
@Qottmann Qottmann enabled auto-merge (squash) February 6, 2024 19:18
@albi3ro
Copy link
Contributor

albi3ro commented Feb 8, 2024

Screenshot 2024-02-08 at 10 54 39 AM

@albi3ro albi3ro merged commit fd3e75e into master Feb 8, 2024
33 checks passed
@albi3ro albi3ro deleted the sumstrings branch February 8, 2024 15:54
Qottmann added a commit that referenced this pull request Feb 22, 2024
…tations of X, Y, Z and Identity (#5153)

Updating docs and codebase with `qml.X/Y/Z/I(*)` instead of
`qml.PauliX/Y/Z(*)` and `qml.Identity(*)` following
#5116 and updating
composite operation outputs in docs according to
#5138

ToDo

- [x] Improve
https://docs.pennylane.ai/en/stable/introduction/operations.html#qubit-operators
- [x] Update outputs in docs with PauliX(wires=*)
- [x] Update outputs in docs with SProds and other composites (i.e. with
extra spaces and removing unnecessary brackets)
- [x] manually check & update all intro pages
- [x] manually check & update pulse docs
- [x] All tests pass
- [x] changelog

---------

Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants