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

physics.quantum: Respect local printer settings in _sympystr. #19424

Merged

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented May 25, 2020

Calling sstr, str, or "%s" % inside _sympystr discards local printer settings and uses the global ones.
It also means subclasses of sympy.printing.str.StrPrinter are ignored.

References to other Issues or PRs

Brief description of what is fixed or changed

Other comments

Release Notes

  • physics.quantum
    • When printing, Commutator, Anticommutator, InnerProduct, TensorProduct, and OuterProduct now respect keyword-arguments to sstr.

Calling `sstr`, `str`, or `"%s" %` inside `_sympystr` discards local printer settings and uses the global ones.
It also means subclasses of `sympy.printing.str.StrPrinter` are ignored.
@sympy-bot
Copy link

sympy-bot commented May 25, 2020

Hi, I am the SymPy bot (v158). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • physics.quantum
    • When printing, Commutator, Anticommutator, InnerProduct, TensorProduct, and OuterProduct now respect keyword-arguments to sstr. (#19424 by @eric-wieser)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.7.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

Calling `sstr`, `str`, or `"%s" %` inside `_sympystr` discards local printer settings and uses the global ones.
It also means subclasses of `sympy.printing.str.StrPrinter` are ignored.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed


#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* physics.quantum
  * When printing, `Commutator`, `Anticommutator`, `InnerProduct`, `TensorProduct`, and `OuterProduct` now respect keyword-arguments to `sstr`.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@eric-wieser eric-wieser changed the title physics.quantum: Respect local printer settinsg in _sympystr. physics.quantum: Respect local printer settings in _sympystr. May 25, 2020
@codecov
Copy link

codecov bot commented May 25, 2020

Codecov Report

Merging #19424 into master will increase coverage by 0.007%.
The diff coverage is 100.000%.

@@              Coverage Diff              @@
##            master    #19424       +/-   ##
=============================================
+ Coverage   75.611%   75.618%   +0.007%     
=============================================
  Files          652       652               
  Lines       169634    169684       +50     
  Branches     40032     40049       +17     
=============================================
+ Hits        128263    128313       +50     
- Misses       35758     35760        +2     
+ Partials      5613      5611        -2     

@oscarbenjamin
Copy link
Contributor

Are there any examples where the output is changed as a result of these changes?

@eric-wieser
Copy link
Member Author

Yes, any call of sstr(obj, **kw) where kw contains keys from StrPrinter._default_settings that have a visible effect.

@oscarbenjamin
Copy link
Contributor

Can you give an example (in code)?

I often look at the added tests as a starting point to understand the effect of the changes in a PR. This doesn't add or change any tests though.

@eric-wieser
Copy link
Member Author

eric-wieser commented May 25, 2020

This is one of those cases where it's a lot easier to see that the logic is wrong than it is to construct the corner case when it matters.

Here's the one I came up with:

from sympy import symbols, sstr
from sympy.physics.quantum import AntiCommutator
from sympy.physics.quantum import Operator
x, y = symbols('x,y')
A = Operator('A')
B = Operator('B')
sstr(AntiCommutator(A, B + 1.0), full_prec=True)
# before: '{1.0 + B,AA}'
# after: '{1.00000000000000 + B,AA}'

@oscarbenjamin
Copy link
Contributor

Okay, thanks. I would suggest adding that as a test but I'm not sure if the object makes sense mathematically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants