2013/08/22

Sage(math) in the Amazon Web Service

A few days a go a new version of Sage has been released, the 5.11.

When I was doing a coursera's High Performance Scientific Computing, I've learn how to have a small machine in the Amazon Web Services. In particular I've set up, as the course shows but was just one of the options I would do, an Ubuntu 13.04 Amazon Machine Image (It look that the ami I used is no longer available).

With this very small virtual machine (64bits, Up to 2 EC2 Compute Units (for short periodic bursts), 613 MiB memory, 8GB Hard disk, I/O Performance: Low). And for the first year the service is for free.

What to do with a machine in the cloud? Lets be sage...

There is a easy way to have your sage installation and someone else will maintain the sagemath package. With 3 commands you can have an installation in your ubuntu.

The thing I did by hand was and script to insert this as a service in the init.d:
#!/bin/bash
# configuration
SAGE_OPTS="-notebook interface='' secure=True"
SAGE_LOG="/var/log/sage/sage.log"
SAGE_USER='ubuntu' #default in aws machine
# commands
CMD_ECHO="/bin/echo"
CMD_GREP="/bin/grep"
CMD_SLEEP="/bin/sleep"
CMD_KILLALL="/usr/bin/killall"
sage_start() {
        $CMD_ECHO "Starting Sage..."
        (su - $SAGE_USER -c "sage $SAGE_OPTS" 2&>1 ) >> $SAGE_LOG &
}
sage_stop() {
        $CMD_ECHO "Stopping Sage..."
        # CAUTION : maybe you kill something important in your server
        #$CMD_KILLALL python
        ps -ef |grep "sage -notebook" |grep -v grep|awk '{print $2}' |xargs kill -9
}
case $1 in
        start)
                sage_start
                ;;
        stop)
                sage_stop
                ;;
        restart)
                sage_stop
                $CMD_SLEEP 5
                sage_start
                ;;
        *)
                $CMD_ECHO "Use: $0 {start|stop|restart}"
                exit 1
                ;;
esac
exit 0

After that, a simple:
$ /etc/init.d/sage_daemon start
is enough to have the notebook  up and running. Perhaps you would prefer to insert it to the boot process
$ sudo update-rc.d sage_daemon defaults 95
(this is only an example)

Best of all is that since I installed it (it was version 5.9) to the current 5.11, those two updates have been as simple as:
$ sudo apt-get dist-upgrade


Incredible, I'm really happy with this, the only point I'm missing is to have those binaries also available for debian's installations.

2013/08/20

working with git(hub)

After so many years of work with cvs and later with svn, many of the project I work with uses git. It's not so easy to start with git, but once you did, you will fall in love.

I only can imagine what a young developer can start using version control directly from git, but my knowledge is conditioned by my previous experience. First time I've work with cvs, I never remember how the commands works, what they mean, which order was the correct. But you learn. Migration to subversion, was good. Many of the things starts to work the way you think.

But git is a big step further. It has been a big change for me. To mention to books have helped:

Shorted than books are videos, and the one that I prefer about git is:


Recently I've seen another video that helps me on improve my way to work with git: the git flow.

This, together with the decentralized repository schema, make me happy. A long a go I was trying to find a way to have code in more than one repository and have them synchronized.

Nowadays this feature is even documented!

For example, the work with the Lima project. The main sources are on github but instead of have all the developers working in parallel and all of us committing to the same trunk (specially because I know a very short number of people that works with subversion with branches), each of the developers have their own branch by make a fork. That is great! You have your own branch, and with the sync feature mention before it's incredibly easy to get the official changes to your repository:

The first time you do it, from your clone of your fork:
$ git remote add esrf-bliss https://github.com/esrf-bliss/Lima.git

And when you like to take those changes:
$ git fetch esrf-bliss
$ git checkout master
$ git merge esrf-bliss/master

And with this you can upload the result of your synchronization:
$ git push origin master

Further than that, you can have as many remotes as forks it has. And you can repeat this with any of the branches that the other developers can do (remember that the master is only one branch more with an special name, meaning what you think is the trunk).