# sympy/sympy

### Subversion checkout URL

You can clone with
or
.

# Quantum printing tests#908

Merged
merged 6 commits into from
+782 −36

### 3 participants

Collaborator

This pull gives full coverage of all the printing methods in the physics.quantum module, inspired as the first step in @Krastanov 's old pull #186 to rework the printing in the quantum module.

This first commit implements tests for all printing methods in the quantum module, which I checked with the coverage report. No changes are made to the printing methods, this is just to establish a baseline for verifying valid output capable of working in the ipython Qt console and html notebook. Note XFAIL tests show where there are errors in the printing methods.

Also in this pull is a fix for latex printing of AntiCommutator, which would give an invalid latex expression which would not display in either the Qt console or html notebook. The current implementation gives valid latex output which displays in the ipython html notebook, but I could not get the ipython Qt console to output the curly brackets.

I have a few decently large nested expressions which can display alright in the html notebook, but I may gradually add some depending on when this is merged and how much free time I get. Any suggestions on these would be greatly appreciated.

I have a ipynb file that can be run to see the output from everything in the new tests rendered by the html notebook and a py script that does the same for the qtconsole. Note that the py script is not a normal example, as has function calls to display in the IPython environment when executed with %run magic.

TODO:

Collaborator

SymPy Bot Summary: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYz6MJDA

Interpreter: /usr/bin/python2.5 (2.5.4-final-0)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: e04388e
branch hash: 85b8b1fb40c0590cfac7849fecd4852792017f9c

Automatic review by SymPy Bot.

Owner

Fantastic! This is really helpful. It looks quite complete and after the test suite is run it can be merged.

Owner

To run the notebook in the qtconsole, export it as a .py file and then run it using %run.

Let's create a notebook directory in the examples and save this notebook in that location. @asmeurer how does that sound?

Owner

See http://code.google.com/p/sympy/issues/detail?id=2940 and linked IPython discussions. I think we should convert all of our examples to use the notebook. We need to figure out doctesting, as well as a way to export them for users who don't have IPython, but I think this can be a good start to that (by the way, if anyone wants to work on that issue, that would be great).

So on other words, go ahead and include it, and start thinking about how to fix that issue.

Owner
Owner

There is now an option in the notebook that will automatically save
.py versions of the notebook side by side with the .ipynb versions for
situations like this.

Can this be done automatically? In other words, can we just make it part of the setup.py dist process when we release.

And how about html or pdf versions of the notebooks, for when there is extensive text with LaTeX math and/or plots/images?

So I am hearing you say that the .ipynb files
should be in the existing examples dir rather than a separate
location.

Yeah, go ahead and do that. If you can start the infrastructure for using IPython notebooks with examples, that would be great. It would be a lot easier for you than for me, as you already know how the IPython API works.

Owner

The notebook uses MathJax, right? I just want to make sure that all LaTeX output works in SymPy Live. You can check by setting the printer to LaTeX, and just executing the string.

Owner
Collaborator

Also, I can't get %run to output any of the latex stuff. I opened the notebook file, saved it to a py, added some imports from sympy to get it to run and used %run to run it in a qt console, but I don't get any output from it rendered by matplotlib (or any output at all, for that matter). On the latest ipython git and with ipython-qtconsole --profile=sympy.

Owner
Collaborator

I got a response back from the IPython list and got it working by doing from IPython.core.display import display and then calling display to show each element. This, however, means it's not as simple as exporting from the notebook. I've made up a py file that can check the qtconsole output, but I'm not sure where to put it in the examples folder.

Owner
Owner
Owner

I see.

I think for now this is OK, because we still haven't fleshed out all the details of issue 2940. I guess what we will have to do is create a custom script that converts the outputs into pprint() for the .py file. And then it won't be necessary to call display() either in the notebook version. The script could do other formatting things too (like, we could do without all the <codecell> things).

Perhaps for now you should just upload the notebook version. Whenever we get a reasonable notebook to .py script going, we will generate them automatically anyway. That also means you can remove all the display() calls too.

Owner

Ah, so I probably should have actually looked at what this was before I commented on it. The notebook isn't really an example, it's just a test of some sort.

I do see the value of testing the MathJax output, and hopefully once ipython/ipython#1195 is fixed, this can happen. But it seems out of place in the examples directory as it is now. Perhaps it can be converted into an actual example or examples (which are desperately needed for the quantum module anyway). If we do that, I wouldn't worry about having exact copies of each printing test. If the examples coverage is high enough, then it will provide sufficient testing.

Owner

I guess I view it both as a test and examples. I think it does serve as a valid test as it stands now, it just requires human intervention to make sure the latex output is rendered properly.

Collaborator

So should I include the py and ipynb files? and if so where? I see they're not examples in the way the current examples are written, but they are very useful in quickly checking the output rendering, which is partially negated by splitting the examples up. I'd say they should be maintained somewhere, the question is where.

Collaborator

On a separate note, the curly braces for the anticommutator can't be rendered by the qtconsole, despite my trying several different things, though it is rendering fine in the html notebook. @ellisonbg do you know how to get matplotlib to render the curly braces? As a note, the version in the current master does not render in either the qtconsole or notebook (and is incorrect latex, to boot).

 flacjacket Implement printing tests for quantum module This commit implements tests for all printing methods in the quantum module. No changes are made to the printing methods, this is just to establish a baseline for verifying valid output capable of working in the ipython Qt console and html notebook. Note XFAIL tests show where there are errors in the printing methods. 2edc5c2 flacjacket Fix latex printing of AntiCommutator in ipython notebook Fix for latex printing of AntiCommutator, such that it is now a valid latex expression. Printing works with the ipython notebook, but not with the Qt console. c58c35a flacjacket Get rid of old quantum tests b0b23cd flacjacket Fix issues with str and srepr printing b3bc093 flacjacket Fix printing tests for new coupled spin state args af4d93b
Collaborator

I moved the commit which added the ipython notebook and qtconsole test files to a new branch, in addition to update the tests since I changed some spin printing stuff, so this should be good to go. When this is in, I have another branch that makes some improvements to the quantum printing system and I can sit on the ipynb file until we have some way for dealing with them.

Collaborator

SymPy Bot Summary: There were test failures.

@flacjacket: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYlZMRDA

Interpreter: /usr/bin/python2.5 (2.5.4-final-0)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: de84ed2
branch hash: af4d93b

Automatic review by SymPy Bot.

Collaborator

SymPy Bot Summary: There were test failures.

@flacjacket: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY4PsQDA

Interpreter: /usr/bin/python3 (3.2.2-final-0)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: de84ed2
branch hash: af4d93b

Automatic review by SymPy Bot.

 flacjacket Fix quantum printing test for UGate c6c3a2e
Collaborator

And this commit fixes the change in UGate that was causing that failure.

Collaborator

SymPy Bot Summary: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYkOwQDA

Interpreter: /usr/bin/python2.5 (2.5.4-final-0)
Architecture: Linux (64-bit)
Cache: yes
Test command: bin/test quantum
master hash: de84ed2
branch hash: c6c3a2e

Automatic review by SymPy Bot.

Collaborator

Without the notebook, this should be fine by all counts. I'll run the tests and if they're still good, merge this.

Collaborator

SymPy Bot Summary: There were test failures.

@flacjacket: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYjbwTDA

Interpreter: /usr/bin/python3 (3.2.2-final-0)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 3dd9bc0
branch hash: c6c3a2e

Automatic review by SymPy Bot.

Collaborator

SymPy Bot Summary: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY8MMTDA

Interpreter: /usr/bin/python3 (3.2.2-final-0)
Architecture: Linux (64-bit)
Cache: yes
Test command: bin/test quantum
master hash: 3dd9bc0
branch hash: c6c3a2e

Automatic review by SymPy Bot.

Collaborator

SymPy Bot Summary: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY8cMTDA

Interpreter: /usr/bin/python2.5 (2.5.4-final-0)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 3dd9bc0
branch hash: c6c3a2e

Automatic review by SymPy Bot.

merged commit 6b25e77 into sympy:master
referenced this pull request
Merged

### Quantum printing improvements #1233

Commits on Feb 19, 2012
1. flacjacket authored
This commit implements tests for all printing methods in the quantum
module. No changes are made to the printing methods, this is just to
establish a baseline for verifying valid output capable of working in
the ipython Qt console and html notebook.

Note XFAIL tests show where there are errors in the printing methods.
2. flacjacket authored
Fix for latex printing of AntiCommutator, such that it is now a valid
latex expression. Printing works with the ipython notebook, but not with
the Qt console.
3. flacjacket authored
4. flacjacket authored
Commits on Mar 21, 2012
1. flacjacket authored
2. flacjacket authored