Skip to content

Enhancements for SageMath Cloud #2

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

Merged
merged 2 commits into from
Dec 23, 2013
Merged

Conversation

haraldschilly
Copy link
Contributor

I've added a fix to the existing iplot() function to make it work like in the IPython notebook. (I've also fixed the quite ugly line for the <iframe ... >

The other fix is for encoding "native" Sage number types to JSON (They are implicitly created when numbers like 42 or 4.2 are entered in the Sage Notebook.)

To test it, install it in a project at https://cloud.sagemath.com

@chriddyp
Copy link
Member

This is sweet, thanks!

I had some trouble giving it a test run on cloud.sagemath.com. I started an IPython notebook and entered:

import sage
isinstance(3, sage.rings.integer.Integer)

and was told:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-d5e63bedef0f> in <module>()
----> 1 isinstance(3, sage.rings.integer.Integer)

AttributeError: 'module' object has no attribute 'rings'

It looks like I'm goofing somewhere, can you tell where? It's been a couple years since I last ran sage!
Also, it wasn't super clear to me how to instantiate the sage RealLiterals and the sage Integers, would you mind just providing a quick 1-liner example? Something along the lines of

p.iplot([sage.Integer(1), sage.Integer(2)], [sage.Real(3), sage.Real(4)])

would be super helpful for me. Thanks a bunch!

@haraldschilly
Copy link
Contributor Author

Hi, I have just thrown this together in like 10 minutes and I've not checked it -- I assumed there will be QA anyways 😀

On cloud.sagemath.com are two different types of "notebooks". The IPython notebook is a little bit enhanced (real-time sync between all collaborators) and should not be affected by this patch in any way. I.e. it's working with a pure python.
Then, there is a "Sage Worksheet" Notebook. Inside of that, you have additional Sage flavour, e.g. Literals like 42 and 4.2 are implicitly converted to native Sage types. They are the ones this additonal JSON converter is made for.
You can also run pure Python code in that Sage Worksheet by inserting %python at the top of the cell.

@haraldschilly
Copy link
Contributor Author

I've changed the second commit to be more Sage-idiomatic.

@haraldschilly
Copy link
Contributor Author

Ok, I have checked that my latest code works in three different modes on Sagemath Cloud:

Test Example:

import plotly
py = plotly.plotly(username='HaraldSchilly', key='XXXXXXX')
from numpy.random import beta
data=[]
for i in range(1,4):
    for j in range(1,4):
        data.append({'name':'beta({0},{1})'.format(i,j),'y':beta(i,j,1000)})

s={'type':'box','boxpoints':'all','boxmean':'sd','jitter':0.4,'pointpos':1.2,'marker':{'opacity':0.2}}
l={'title': 'Parameters of the Beta Distribution','showlegend':False}
py.iplot(data, style=s, layout=l)

It works in:

  • IPython Notebook
  • Sage Notebook - default Sage mode
  • Sage Notebook - in Python mode via an %python on the top of the cell

@chriddyp
Copy link
Member

Very sweet! The RR, ZZ JSON encoder is great.

I'm still having some trouble running the plotly.py in the cloud.sagemath Sage Worksheet. In particular, I can't get the requests library imported.

I tried:
1 - Opening up a terminal session and running (from here: https://github.com/sagemath/cloud/wiki/FAQ#wiki-pip)

$ pip install --user requests

2 - Making a new sage worksheet and running

%python
import requests

and got an import error

Error in lines 1-1
Traceback (most recent call last):
  File "/mnt/home/54656d87953e416d8f35f55fe5def3d5/.sagemathcloud/sage_server.py", line 671, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
ImportError: No module named requests

Any ideas? Thx a bunch!

@haraldschilly
Copy link
Contributor Author

Hi, the underlying "problem" might be, that this Sage process is only forked, not restarted. There is currently no provision to dynamically load newly installed libraries. So, maybe the red "reload" button inside the Sage Worksheet helps. If not, you have to go to the project specific settings ( 🔧 symbol ) and press the orange reload buttons (and then reload again).

I don't remember having to install the requests library, but I've maybe done it a while ago in that project, which is dedicated just for testing stuff ❓

Sorry for the confusion, this still has its rough edges, but I hope you can imagine where it is heading at 😀

@chriddyp
Copy link
Member

Cool, the big orange reload button did it. The plots look great in the worksheet (screenshot for those interested: http://grab.by/t3xC). Thanks for the help! I'll push out to PyPi this evening :)

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.

2 participants