printing in quantum

11 views
Skip to first unread message

krastano...@gmail.com

unread,
May 26, 2011, 3:18:29 PM5/26/11
to sy...@googlegroups.com, Brian Granger
Hi,

First of all, I am sorry that I left the pull request I'll be talking about halfway finished after taking so much of your time with questions about the code. I had some more urgent responsibilities lately.

I'm talking about the pull request dealing with changes in the way that quantum prints stuff. I have some questions to ask and I will also explain why my code is the way it is. All this is somewhere in the commit messages but those are not clear enough (sorry). Also an issue about this stuff is open.

https://github.com/sympy/sympy/pull/186

print_repr is not tested at all. Before committing it should be tested, but I would like some pointers on this one.

The main change is in the behavior of the printing methods of QExpr:
     # Printing of labels
     # This should print only the quantum numbers
     def _print_label(self, printer, *args):
     # Printing of contents
     # This prints the quantum numbers and the rest of the information
     def _print_contents(self, printer, *args):
     # Main methods
     # They would add brackets if needed in the subclasses
     def _sympystr(self, printer, *args): and others
 
And the brackets stuff is now only in State and TimeDepState.

The children of State and TimeDepState are not changed and from their point of view nothing has changed.
but now printing of inner product is simpler because I don't need to search for brackets and remove them.

Before this was necessary because there was no real separation between the stuff done by _print_label
and _print_content. Frequently _print_label was used for stuff that should be done by _print_content or
_print_content was adding brackets to the content.


Those changes permitted shorter and cleaner code to be written for those two problems:


First problem - printing of inner products with something more complex than the simplest Ket:
Currently we have:
In [3]: from sympy.physics.quantum import TimeDepKet
In [4]: k = TimeDepKet('psi', 't')
In [5]: k.dual*k
Out[5]: ⟨ψ❘ψ;t⟩
The output from my code is:
Out[5]: ⟨ψ;t❘ψ;t⟩

The code is cleaner as there is no more hacking on characters and now not only the label but the whole content is printed. That's why the refactoring of the label and content method was necessary.


Second problem - printing of spin states is ambiguous, there is no way to distinguish Jz from Jx states:

Currently:
In [6]: from sympy.physics.quantum.spin import JzKet
In [7]: j = JzKet('1/2','1/2')
In [8]: j
Out[8]: ❘1/2,1/2⟩
My code:

Out[8]: ❘z:1/2,1/2⟩

The same stuff.


Proof of the fact that the higher classes were not affected is that no problems were detected later, when I was adding tests.

In the pull request there are also some new tests for the printing and some cleanup on the latex stuff.

Also a small question: the pull request contains to many commits. Should I group them in bigger commits? Be aware that for some reason GitHub is not listing them chronological (at least to me).

Are there any problems with the approach I have chosen?
Should I add more tests or change something?

Stefan

Vinzent Steinberg

unread,
May 27, 2011, 11:44:43 AM5/27/11
to sympy
On 26 Mai, 21:18, "krastanov.ste...@gmail.com"
<krastanov.ste...@gmail.com> wrote:
> Also a small question: the pull request contains to many commits. Should I
> group them in bigger commits? Be aware that for some reason GitHub is not
> listing them chronological (at least to me).

Using git rebase it should be possible to change the order of commits.
This change should be reflected in github too. Do you get the same
order there as with 'git log'?

Vinzent

krastano...@gmail.com

unread,
May 27, 2011, 12:45:19 PM5/27/11
to sy...@googlegroups.com
It's not the same order. git log and https://github.com/sympy/sympy/pull/186#commits-pushed-e60b5d0 are most definitely showing different orders and the one in git hub is not chronological. I have rebased it a number of times, but I have never tried to change the order of commits.

But this is just an issue with the order I see in github. It's not that important for the pull request. I just find it strange.

What about the code? I'm looking at the print_repr tests. Is the rest OK?

Stefan



--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.


krastano...@gmail.com

unread,
May 27, 2011, 3:16:00 PM5/27/11
to sy...@googlegroups.com, Brian Granger

https://github.com/sympy/sympy/pull/186

I've just finished adding the repr tests. All works well and after adding the tests no bugs were found.

So as a recap:
-the printing methods are more straightforward (at least I hope so ;)
-the printing of InnerProduct and Spin looks better
-many test were added for the printing
-some bugs in the latex strings were found and fixed
-some typos in comments were fixed

Am I missing something?

Stefan
Reply all
Reply to author
Forward
0 new messages