Tuesday, March 1, 2011

Sage Server Through VMware

Sage is a open source frontend and server that I use to replace Mathematica in particular, but will also serve as a frontend for Mathematica, Matlab, Latex, Python (it's foundation), and more. It is almost powerful enough to completely replace Mathematica as an analytic mathematics software. It's really close. It surpasses Mathematica in the ease and speed in which you can do real coding for numerical mathematics as well. It uses Python, numpy and scipy so all the standard Matlab stuff is included. It spits out really nice figures too. The server side is one of the best parts! Documentation is kinda poor to get the install right but once you do, it will automatically store accounts and log in information for multiple simultaneous users. It's browser based, so you never have to install anything on your personal machine and it just so convenient!

Enough about that! The biggest problem - poor documentation for the novice since it doesn't have a Windows version. It has a virtual machine version and ok documentation to install with Windows as the host but screw that! If you're a research group or company, I would forgo all the VMware stuff I'm including here and just build a dedicated Linux server. You'll get more performance, less set up, and you can use it to run all kinds of other code scripts so each client machine doesn't have to have all that garbage installed.

I had help setting my instance from this document. I did things a little differently and that's why i'm posting about it now.

  • Install VMware. Get VMware. We had a copy of VMware Workstation that was unused so I know it works. Virtual Box probably works too.
  • Install Linux on VMware. I installed Ubuntu x64. Overall, Ubuntu is the least foreign to my simple Windows using mind;). File-New-Virtual Machine-Install from iso-follow the onscreen directions
  • If this is a VMware install, I assume this is a test bed and not a full implementation. If this is true, select the amount of RAM and Disk Space you want to allocate in the OS settings through VMware. The Network Adapter should be set to Bridged: Connect directly to the physical network. The checkbox "Replicate physical ..." is unchecked. This step is important for assigning a unique IP address to the Virtual Machine so it can be accessed directly and not just through the host.
  • Install an ssh server. Sage is a command line software (so is Mathematica, Matlab, Python...etc) with a frontend attached. Command line access through ssh can be helpful if you want to remotely run code...any code...not just sage...so I recommend doing this regardless of what you plan on putting on your server. Do this with sudo apt-get install openssh-server
  • Download Sage from sagemath.org. Make sure you get the right version for your operating system.
  • Install. I never remember how to install anything in Linux...I can't understand why Linux operating system designers make it so damn complicated. I think the correct install command for sage is sudo ./ but it might simply be sudo ./sage ...I don't really remember but I think it actually just extracts somewhere and is done so you might want to make sure the install file is already in the folder you want the final install in...I just can't remember. It might actually have a debain package that "just works" when you double click it.
  • Test to make sure it installed. open terminal and type the word "sage" you should get a sage: prompt. If you type notebook() a web browser should pop up with the generic server index page. More specifically type notebook(address='',port=8000,accounts=True) to start a server on that ip with that port and user accounts enabled.
  • To really make this a server, it is convenient to set up some symbolic links. Enter (from the document linked above)
ln -s sage
cd /usr/local/bin
sudo ln -s /sage sage
sudo ln -s /local/bin/sage-python sage-python
Here, is the full path to the Sage directory, something
To test the links, go to your home directory and type:
This should start Sage. Then enter:
This will start the version of Python that comes with Sage.

  • Now we want a script to start the server with all the options already set. I'm not sure if it has to be a Python script but Python plays nice with Linux and that's a good thing. In the home directory make a file called notebook.py with the following commands inside
from sage.all import*

all the Xs are for the IP address of the virtual machine. make sure the apostrophes are included. accounts=True allow for private user accounts to be created on the server. When you run this script terminal will give an error about being crazy if you don't have secure=True but True seems to disallow access over the internet.

  • Start the server with sage-python notebook.py
  • Make a launcher from the desktop. I think there is a way to have the server start with the machine but I'm to dumb to use Linux. My small brain can only hand simple Windows and the super convenient Startup folder. If you're like me, right click on the desktop and create launcher. It's either type: application or application in terminal. I don't remember. and the command: sage-python notebook.py
  • THIS STEP PROBABLY ISN'T NEEDED FOR BRIDGED NETWORK ADAPTERS. From Windows go to Allow program through firewall and open port 8000 in UDP and TDP.
  • The server can now be accessed through any web browser by typing http://XXX.XXX.XX.XXX:8000 or by pointing any ssh client to the same address
Sage is sweet! I can access and share my personal notebooks through any browser - including my phone. You can make really professional documents and reports directly in a web browser if you know a little html programming too. I hope this project continues. It is one of the most remarkable examples of how open source software can actually be very good!

No comments: