Italian workshop on Arduino/Ikea Lamps!

It came to my attention today that a workshop took place in Italy a while ago on Arduino/Ikea lamps. This was an Arduino Workshop, part of the Torino Design Week.

Event Description:
http://arduino-tdw-2009.eventbrite.com/

Video on Vimeo:
http://www.vimeo.com/8559277

Arduino Code:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1263217950/

Blog post:
http://www.alluvionemediatica.it/Blog/tabid/59/entryid/25/Default.aspx

My original Arduino/Ikea lamp post was used quite a bit. One of my photos was used on the event description
and a few code posts referenced my site. I was surprised to see that I even got a credit on the video posted at Vimeo! Thanks guys!

Python & Gnuplot & AHK & Processing

Gnuplot is a great command line tool that creates very quickly graphs from data files.

The official site of Gnuplot is: http://www.gnuplot.info/ . To see examples of graphs produced by Gnuplot, you should have a look here: http://gnuplot.sourceforge.net/demo_4.4/.

Using python and gnuplot, I produced approx 80 graphs similar to the one below, that fitted nicely on 5 A4 pages. gnuplot_sample

Python scans a very long file with all the historical data and passes the required data for each graph to gnuplot. The result is 80 graphs as png files in less than a minute. Then another script in processing puts everything together in a 5 page pdf file (2 cols x 8 rows = 16 per page). AutoHotKey is what “glues” everything together and makes this a “single click” solution.

Nice tutorials and book on Python

You can find a lot of tutorials on Python, but these is a pretty good one (actually 7) from Nick Parlante from GoogleDevelopers on youTube – here is the link to the first one: http://www.youtube.com/watch?v=tKTZoB2Vjuk. This is a really a great tutorial for beginners.

The book I’m using as my main python textbook (and would definitely recommend) is “Core Python Programming” from Wesley J. Chun:
http://www.amazon.co.uk/dp/0132269937 .
The book website is here: http://corepython.com/

Joggler on Ubuntu

O2, the UK mobile phone operator had an amazing offer a few days ago: they were selling their O2 Joggler for £49.99.
O2_joggler_main

This little gadget, with a touchscreen, wifi and an intel atom processor, wasn’t really a best seller for your average cosumer and O2 ended up selling them at a loss.

I picked one up and installed Ubuntu successfully on an 8GB stick, following religiously the instructions from this
site.

DSCF1236_w500

DSCF1234_w500

Other interesting/useful sites on the Joggler are:

http://www.canonical.com/projects/ubuntu/unr

http://www.linuxformat.co.uk/forums/viewtopic.php?p=87157&sid=ed063024114914ddf6e977294bcb427a

http://www.backtrack-linux.org/forums/hardware-compatibility-list/2738-o2-joggler-openpeak-open-frame-7-touch-device.html

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=80756&view=next
DSCF1241_w500DSCF1237_w500

The installation was pretty straight forward and uneventful but a bit long. I installed everything on the usb key, using my linux laptop. Everything was supported and worked out of the box, including the touch-screen and the wifi. I added a belkin bluetooth adaptor (which also worked out of the box) and installed skype on it. Unfortunately, the performance of skype with a bluetooth headset was below expectations. I’m also having performance issues: sometimes it’s slow, but I think this is because of my usb key being relatively slow.

It’s a great little system and for £50 I can’t fault it (I’ve paid more for photo frames!). I wish it had a few additional usb ports that I could use (instead of my ugly hub).
DSCF1243_w500

Also, it would be great if linux could be loaded on the device (instead of doing this on an additional external usb key).

I just had a look on the O2 site: it’s now priced at £99.99, but cheaper ones are available on ebay.

Stay tuned for more news and comments on this little gem!

Playing with Python in the wild Amazon (elastic cloud)

This Easter bank holiday, I spent some time working on a little problem I have at work with a simulation I’m writing in Python.

It’s basically a Monte-Carlo simulation which is performing billions of calculations. To be more exact, the simulation is a script that performs about half a million of calculations and it has to run a few hundreds of thousands of times. In other words, a lot of number crunching… And as my bosses are a bit impatient, it has to be done quickly, i.e. in hours as opposed to days.

I was running benchmarks at work with various machines (an old G5, a new intel duo laptop and and old P3 desktop). Based on my benchmarks, the old P3 desktop would need approx 10 days to complete the required calculations and it became clear that, if I want to complete these calculations within a reasonable amount of time, I will need a significant amount of processing power.

Over the weekend, I decided to try and quantify/benchmark the performance of Amazon’s EC2 service. I used the m2.4xlarge option (“High-Memory Quadruple Extra Large Instance 68.4 GB of memory, 26 EC2 Compute Units (8 virtual cores with 3.25 EC2 Compute Units each” per Amazon’s description), 1690 GB of local instance storage, 64-bit platform”) which gives the highest computing power. To my surprise, the python script was running on this virtual machine just slightly faster than when it was running on my laptop. After having a look at the monitoring service Amazon offers, I realised that less than 20% of the computing power of this VM was used while running the model…

After a bit of searching/googling/reading, I found that
– My python script was essentially only using one of the cores of the VM machine, in other words 1/8th of it’s capacity.
– To use many processors efficiently one could use the multiprocessor package which is available in version 2.6, but this really complicates things and introduces new levels of complexity on my project.
– I also tried Parallel Python, but I didn’t see any significant changes in the CPU usage.
– A very interesting video on this issue (Python GIL) from David Beazley can be found here.

After reading all this and spending a lot of time experimenting, I took a step back and tried to think this through. As far as my project was concerned and due to the way a Monte Carlo simulation works, my 50 billion calculations were actually 100,000 repetitions of half a million calculations,but these repetitions were independent of each other. In other words, they could run concurrently.

In the end, a simple bash script solved this problem:

#!/bin/bash

for i in {0..1000}
do
python 50M.pyx &
done

In the above script, I was running 1,000 times a simple script (50M.pyx) which contains a loop of 100 iterations of my main set of calculations (half a million calculations). In other words, (1,000 x 100 x 500,000 = ) 50 billion calculations.
The ampersand at the end of the python line indicates that the shell should not wait for the command to finish before it moves on. As a result, it practically launches 1,000 simultaneous instances of the 50M.pyx script. With this simple method, the powerful VM server is working to the max:

max_cpu_usage

It ended up taking 9 hours 13 mins to run 50 billion calculations on this machine. On an old P3 Dell desktop this would take approx 10 days, so the lesson is that, if we use many python instances that run concurrently and a (much much) better machine, there is a significant improvement in performance. Am I stating the obvious? 🙂

When my simulation is ready, I will probably use 10 instances to get the calculations finished in less than 1 hour.

Turnkey Linux Fileserver

One of the great things about linux is its versatility. Ironically, this is one of its problems too…

What do I mean by that? Simple. If I download a standard linux distribution with the purpose of setting up a file server, I will probably end up spending the better part of a weekend setting it up.
– Which packages should I include?
– Which should I exclude?
– How should I set up the security / firewall etc?
– Setting up samba from scratch?
– Setting up some sort of backup system?
– What about remote access?

I used to just install everything from whatever distribution I had in hand and spend a lot of time tweaking.

Turnkey Linux (http://www.turnkeylinux.org/) provides a great solution. Instead of downloading the standard ubuntu DVD, you download a small distribution that’s already customised to do exactly what you want. There are many different appliance to choose from: LAMP servers, File servers, domain controller appliance, etc etc… The images are tiny (around 100-200MB) compared to the full-blown DVD image and they are also supplied as VM images! In other words you can just download one and run it on VirtualBox or any other VM system!

Turnkey Linux appliances are based on Ubuntu, which means that there are thousands of packages you use to customise your appliance.

My file server at home is now powered by Turnkey Linux.