Showing posts with label mobihf. Show all posts
Showing posts with label mobihf. Show all posts

Sunday, October 18, 2015

Running mobihf on the iPhone

mobihf (https://sites.google.com/site/tovganesh/s60) is a code that I wrote almost a decade ago on my first phone: the Nokia 6600. mobihf was meant to be an educational tool on how to write a basic Hartree-Fock Quantum Chemistry code from scratch, and to me it was a way to experiment on how much can I push the mobile device to do scientific number crunching. At that time the processing power of my mobile was just about 100MHz with just about 10MB of RAM! And now I have this two year old iPhone 5s that has a 1.3GHz 64 bit processor, with about 1GB of RAM.

To test out how things have panned out for my purely Python mobihf (not the C++ integral code that I wrote later), I tried a number of Python interpreters available on the Apple App store.  While Python for iOS (https://itunes.apple.com/us/app/python-2.7-for-ios/id485729872?mt=8) seemed like a good choice, its editor was never able to even load the mobihf script to do anything meaningful. A mail to the developer did not get me any response (as of this writing).

Next up was pythoni (https://itunes.apple.com/in/app/pythoni-run-code-autocomplete/id493505744?mt=8). This is surprisingly well written app with custom keyboard shortcuts and well made editor for editing Python scripts. It is worth buying the pro features in this app if you do a lot of Python programming on the move. So, finally I was able to run the pure Python mobihf code (available from GitHub: https://github.com/tovganesh/myrepo/blob/master/mobihf.py). This code is heavy on numeric computations (evaluations of exponential functions, matrix and vector algebra etc.). Without going into the details of what the code does, I typically run two test cases to see how things are going. These are for two very simple molecules: H2 (hydrogen molecule) and H2O (water molecule) at a basis level called STO-3G. All very basic to the one who knows Quantum Chemistry, and pretty much a jargon to the rest ;-) Since I am using iOS9, I decided to run the job in two modes: once with battery saver on and another without.


As can be observed above, even with battery saver on, there is 50 to 65 times improvements in the timings over the same pure Python. And, to top it the timings also handsomely beat the C++ compiled code on the old phone.



With the battery saver turned off, the performance improves as expected. What is surprising however is that in comparison to when the battery saver is on, the performance improvement is about 60%. That is quite a hit to keep the phone going for longer. I wish we have some radical improvements in the battery technology so that we can keep enjoying our devices at full speed.

The next app was Sketch Python (https://itunes.apple.com/in/app/sketch-python/id984990674?mt=8). There are a number of different Python implementations and each can give you a different performance numbers. So far I have found Sketch Python to be the fastest.

With the battery saver on, Sketch Python performs almost as fast as pythoni with battery saver off. That says a lot about the performance of Sketch Python interpreter, especially in handling Python code with heavy numeric computation.


The performance of Sketch Python to run mobihf increases substantially when battery saver is off, and is probably the best timing that I can get on the A7 processor of iPhone 5s. If you do the math, this is 140-166 times faster than the pure Python code that ran on my Nokia 6600 a decade ago. In comparison to the C++ (native code) running on Nokia 6600, the gains are an order of magnitude times less, but still impressive. I am sure if I port this code over to native, we can do pretty complicated Quantum chemical calculations on the phone. The newer A9 processor in iPhone 6s or the Qualcomm processors (8-core 810 or higher), would be interesting processors to see the current state. But I can say that these mobile processors have reached the performance levels of the most desktop processors for all practical purposes. And this is exactly that I had in mind when I took a look at the ability to run scientific codes on mobile processors (https://sites.google.com/site/tovganesh/s60).

On a different note, the ARM architecture also makes an interesting case for computational codes because of the low power requirement, a topic I briefly touched, but now studied much deeper by Kristopher et.al. (http://pubs.acs.org/doi/abs/10.1021/acs.jctc.5b00713). Alistair Rendell, my postdoc guide, is a co-author in this paper, so it must be real good :)

Note: The experiments above were run 5 times, and the lowest time was taken.
PS: This post has been since mentioned on MacInChem.org (http://www.macinchem.org/blog/files/0c7f90a37910d2ed90402dcddb6cf4e2-1814.php)



Saturday, November 01, 2008

MeTA Studio updates (shh... voice!) and source release

Well here is the long promised source update to MeTA Studio (v2.0.01112008), get it from the usual place at: http://code.google.com/p/metastudio/downloads/list

The binary update is from the now usual online update scheme.. download the latest full package from http://code.google.com/p/metastudio/ and then get the online update from with in MeTA Studio.

Well this release adds assortment of bug fixes as usual and add some cool new features which you will discover as you use MeTA Studio. But one stuff to mention is that you can now do voice communication with in MeTA Studio talk! Yes! you heard it correct ;-) The voice feature is not very stable and has not been extensively tested as yet, but is usable.

meta_talk_voice

Another feature is that you can now dock the talk window with an existing window in MeTA Studio, allowing you to work and collaborate more comfortably. Right now the docking can only be done to a MoleculeViewer window, in future other widows will be supported.

Ok thats it for this post! I will be taking a short break on development of MeTA Studio as I would be moving out and am working on some other related projects… Have fun with the latest (source and binary) MeTA Studio :-) All suggestions, code contributions, documentation is ofcourse welcome ;-)



PS: Some what unrelated but I updated the mobihf code for s60 3rd ed with fp1 (read my phone, e51) and the updates (with some cool new timings) are available from http://tovganesh.googlepages.com/s60. Have fun with that too ;)

PPS: There is a small fix with the Voice communication code for MeTA Studio that is not updated in the source ... this will be done when I next update the code. Till then take a deep breath .. sounds familiar ;-)

Monday, March 26, 2007

mobihf v0.4

mobihf v0.4 is released and available for download from the usual place: http://tovganesh.googlepages.com/s60#mobihf

This version integrates mobihf and mobimol into a single app now bundled as a single SIS file (only for s60 second edition). All this was again done on Linux.
Due to time constraints some of the promised features (like parallel 2e integrals) are still missing and I will take some fare amount of time put in these things in, till then enjoy this version.

Some screen shots:


Friday, February 16, 2007

compiling mobihf python extension module on linux

As Nokia doesn't seem to provide S60 SDK on Linux (largely due to copyright issues), you could do the compilation (generating the Python extension module in my case) by using either gnupoc or using the how to at Simon Woodside.

Somehow, I was not able to get stuff working using Simon Woodside's instructions, neither gnupoc installation worked straight forward. But I was finally able to use gnupoc to get the Python extension modules compiled (for mobihf, see the previous post).

This is what I did. Follow the gnupoc instructions provided at:
http://gnupoc.sourceforge.net/HOWTO/

I used the 2.0 SDK for my work (that what is required to get programs compiled for my Nokia 6600). The only thing I am not so sure about the above instructions is whether Wine is really required to get the stuff working. What appears to me is that only if you need the emulator and a few windows only SDK tools. gnupoc use the gnu-arm cross compiler, which is natively compiled for linux and can be obtained from gnupoc site itself. In any case I have done this installation on an FC6 machine, where Wine refuses to work properly (it simply freezes up any windows program i try to execute, even winecfg). So, I have really not cared about this aspect of the SDK while performing the installation and running the tests.

After following the above procedure, I unzipped the Python SDK files from PyS60 site: http://sourceforge.net/project/showfiles.php?group_id=154155
into $EPOCROOT/. The .bash_profile file had the following entries for PATH and EPOCROOT:

export EPOCROOT=/data/sdk/gnupoc/

PATH=$PATH:/data/sdk/gnupoc/epoc32/tools:/usr/local/er6/bin:$EPOCROOT:$HOME/bin


So my SDK is installed in /data/sdk/gnupoc directory. Note that EPOCROOT needs the last '/'.
Also the GCC-ARM cross compiler is placed in /usr/local/er6/bin directory. Now, make sure that all the files in $EPOCROOT/epoc32 are executable.

You will also need to UNIXify (use dos2unix) all the .h files unzipped from the Python SDK distribution.

Finally, you need to edit bldmake.pl file in $EPOCROOT/epoc32/tools directory to replace:

$Candidate=uc $Candidate;

to :

$Candidate=lc $Candidate;

near the following line:

if ($Section eq 'PLATFORMS') {


This is to allow it to properly find the armi build directory. After this you should be able to use the SDK for compiling Python extension modules as you do in Windows using:

bldmake bldfiles
abld build armi urel
abld freez
abld build armi urel


Hope all this is of some use to somebody! :)

new version of mobihf (v0.3)

a new version of mobihf (along with the C++ compiled module for 2E integral evaluation) is available from: http://tovganesh.googlepages.com/mobihf_ext.tar.gz

this is just a bug fix release. no new "features" are added, except that now mobihf reports time and also indicates if it is using a python or C module for integral evaluation.

after the long expected "retirement" of my windows machine, i needed to fix a few bugs with the C++ module. as i was not planning for investing in a new windows vista machine immediately, i had to use gnupoc (http://gnupoc.sourceforge.net/) with a few modifications (will post soon on how i got the python module compiled for my 6600 on my linux box), till then enjoy the new version ;)