# Quantum printing tests #908

Merged
merged 6 commits into from Apr 12, 2012

## Conversation

Projects
None yet
3 participants
Member

### flacjacket commented Dec 30, 2011

 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:
Member

### flacjacket commented Jan 3, 2012

 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.
Member

### ellisonbg commented Jan 4, 2012

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

### ellisonbg commented Jan 4, 2012

 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?
Member

### asmeurer commented Jan 4, 2012

 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.
Member

### ellisonbg commented Jan 4, 2012

 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. So I am hearing you say that the .ipynb files should be in the existing examples dir rather than a separate location. On Wed, Jan 4, 2012 at 1:34 PM, Aaron Meurer reply@reply.github.com wrote: 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. Reply to this email directly or view it on GitHub: #908 (comment) Brian E. Granger Cal Poly State University, San Luis Obispo bgranger@calpoly.edu and ellisonbg@gmail.com
Member

### asmeurer commented Jan 4, 2012

 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.
Member

### asmeurer commented Jan 4, 2012

 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.
Member

### ellisonbg commented Jan 5, 2012

 Yes, it uses MathJax for rendering latex. On Wed, Jan 4, 2012 at 3:01 PM, Aaron Meurer reply@reply.github.com wrote: 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. Reply to this email directly or view it on GitHub: #908 (comment) Brian E. Granger Cal Poly State University, San Luis Obispo bgranger@calpoly.edu and ellisonbg@gmail.com
Member

### flacjacket commented Jan 5, 2012

 I've added the notebook file. 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.
Member

### ellisonbg commented Jan 5, 2012

 Sean, Can you pose this question to the IPython user list. There may be a bug or something you are missing. It should work as far as I am concerned. Maybe create a simple sympy using example that others could try and post the .ipynb and .py files. Cheers, Brian On Wed, Jan 4, 2012 at 6:59 PM, Sean Vig reply@reply.github.com wrote: I've added the notebook file. 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. Reply to this email directly or view it on GitHub: #908 (comment) Brian E. Granger Cal Poly State University, San Luis Obispo bgranger@calpoly.edu and ellisonbg@gmail.com
Member

### flacjacket commented Jan 5, 2012

 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.
Member

### ellisonbg commented Jan 5, 2012

 Sean, Let me play with it a bit - I think it should work without the extra display calls. Brian On Thu, Jan 5, 2012 at 9:12 AM, Sean Vig reply@reply.github.com wrote: 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. Reply to this email directly or view it on GitHub: #908 (comment) Brian E. Granger Cal Poly State University, San Luis Obispo bgranger@calpoly.edu and ellisonbg@gmail.com
Member

### ellisonbg commented Jan 5, 2012

 OK I understand what is going on. The %run magic does not trigger the display logic automatically so the display calls are needed. I should note that the display calls will also work fine in the notebook, so I would just put them them are they will automatically appear in the .py file. The only problem with that is that are .py examples would depend on IPython. @asmeurer, what do you think about that? On Thu, Jan 5, 2012 at 9:13 AM, Brian Granger ellisonbg@gmail.com wrote: Sean, Let me play with it a bit - I think it should work without the extra display calls. Brian On Thu, Jan 5, 2012 at 9:12 AM, Sean Vig reply@reply.github.com wrote: 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. Reply to this email directly or view it on GitHub: #908 (comment) Brian E. Granger Cal Poly State University, San Luis Obispo bgranger@calpoly.edu and ellisonbg@gmail.com Brian E. Granger Cal Poly State University, San Luis Obispo bgranger@calpoly.edu and ellisonbg@gmail.com
Member

### asmeurer commented Jan 6, 2012

 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  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.
Member

### asmeurer commented Jan 6, 2012

 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.
Member

### ellisonbg commented Jan 6, 2012

 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.
Member

### flacjacket commented Jan 7, 2012

 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.
Member

### flacjacket commented Jan 7, 2012

 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 added some commits Dec 29, 2011

 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 
 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 
 Get rid of old quantum tests 
 b0b23cd 
 Fix issues with str and srepr printing 
 b3bc093 
 Fix printing tests for new coupled spin state args 
 af4d93b 
Member

### flacjacket commented Mar 21, 2012

 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.
Member

### flacjacket commented Mar 21, 2012

 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.
Member

### flacjacket commented Mar 21, 2012

 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.
 Fix quantum printing test for UGate 
 c6c3a2e 
Member

### flacjacket commented Mar 21, 2012

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

### flacjacket commented Mar 21, 2012

 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.
Member

### flacjacket commented Apr 12, 2012

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

### flacjacket commented Apr 12, 2012

 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.
Member

### flacjacket commented Apr 12, 2012

 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.
Member

### flacjacket commented Apr 12, 2012

 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.

### flacjacket added a commit that referenced this pull request Apr 12, 2012

 Merge pull request #908 from flacjacket/quantum_printing_tests 
Quantum printing tests
 6b25e77 

Merged