Stephen Smith's Blog

Musings on Machine Learning…

Archive for April 2020

Solving COVID-19 with Folding@Home

with 4 comments


Pretty much all of us have several computers lying around the house, most of them not doing anything for 90% of the time. The people looking to discover extraterrestrial life came up with the idea of analysing everything ever received via radio telescopes to look for patterns or messages. They devised a distributed system where any computer could run a client that would run when the computer is idle and work on a small piece of the problem. All the pieces are uploaded to a central set of servers where they are combined. This project is called seti@home and has a vast network of computers looking for ET.

Proteins are extremely complicated molecules that our body’s DNA manufactures to perform all the functions within our cells. Our DNA specifies the individual elements that make up the protein, but the true wonder of proteins comes from how this string of building blocks folds together. Studying this process is vastly complicated and until recently far beyond our computational power to model. With new algorithms and a vast network of distributed computers, the folding@home project was born and today forms the largest supercomputer the world has ever seen.

There are hundreds of problems being worked on. Each computer is given a series of work units to calculate. You get points for work accomplished that you can use for bragging rights. Folding@home has been running for twenty years, since 2000, but with problems associated with COVID-19 being added, usage has soared. I have all my household computers dedicated to this task, since as it stands it seems like solving this problem is the only way that life will return to normal.

Installation and Configuration

Folding@home will run on most Intel/AMD based computers, usually as long as they are at least 64-bit and dual-core. I’m running it on three 2008 MacBooks with core2duo processors, an 2015 HP laptop with an i3 processor and my new gaming laptop with an i7 and nVidia GPU. The installation is straightforward. You download the correct install image, for either Windows, MacOS or Linux and run the installer. This installs and configures a process that is always running and you can see in your task tray. You can access it from your browser at or via one of the configuration GUIs. Here is it running on my gaming laptop:

To get the GPU going, I needed to reboot. I suspect Tensorflow of X-Plane still owned the GPU. Then I could add a GPU slot in the advanced control configuration screen.

Joining a team is fun, you can combine your resources, note that I’m part of team 253800 which is the SunshineCoastBC_Team.

Notice the lower right where it describes the project your computer is currently working on. You can also use the protein viewer to see the associated protein.

Only Partly Open Source

I was planning on running this on my nVidia Jetson Nano and two Raspberry Pis. Sadly, I discovered that folding@home only runs on Intel/AMD processors and not ARM processors. I went to have a look to see if I could compile for ARM, but found the source code isn’t open source. Folding@home uses several open source libraries like gromacs, but they claim they don’t want to go fully open source to prevent people cheating on the points system or corrupting the results.

I think it would benefit them to support ARM processors; the millions of Raspberry Pis and other SBCs could really add to the effort. I looked at a couple of their dependent projects like gromacs and found these do have ARM support, so I don’t think it would be hard to add. Especially since they keep promising a mobile version.



There isn’t a giant claim that folding@home has cured a major disease yet. However, it has contributed quite a number of results leading it that direction. You can see all the scientific papers that have been generated from the results of all this computation here.


Watching the folding@home web page is fascinating. It enables you to contribute to solving a number of major problems in medicine. If you configure folding@home for a light load, you won’t even notice it is there. Just leave your computer turned on and let it solve the world’s problems.

Written by smist08

April 25, 2020 at 4:47 pm

Posted in Life

Tagged with , , ,

Drawing in Code by Processing

with one comment


Last time, we started to explore Arduino programming. I noted that the Arduino IDE and language is largely based on Processing. In this article we’ll look at the Processing language and environment. Processing was designed to be a simple language to allow people in the Graphical Arts world to learn programming. Hence the language is oriented around drawing and animation.

There are quite a few education oriented programming systems such as Scratch which I talked about here. Processing is nice because it is really a subset of Java, so as you learn and become proficient at Processing, you are also learning a lot of Java. The drawing library in Processing is popular and has been ported to many other languages such as Python. The drawing library draws from PostScript and OpenGL and is quite powerful, in spite of its simplicity. Khan Academy uses a JavaScript version of Processing, namely ProcessingJS to teach programming for kids.

The Processing IDE and the subset of Java it uses are intended to be simple. The goal is to eliminate as much overhead as possible so you just write your program as sketches where you iteratively develop the end result. The feeling was that program design and object oriented design add too much of a barrier for non-technical people to learn programming. For artists, it is much more natural to learn by experimenting and playing rather than trying to design something before starting to program.

Drawing a Koch Snowflake

We drew a simple Koch Snowflake fractal back in my article introducing writing iOS Apps in Swift. The complete Processing code for this is at the end of the article. Notice how much simpler it is to do this in Processing than in Swift. This is part of why Processing is such a good language to learn programming with.

You enter the code into the Processing IDE:

And then hit the green play button to run the program and the following window pops up:

Feel free to play with the program (called a sketch) to do things like change the size, level or anything else.

Every Processing sketch has two routines:

  1. setup: run once when the program starts before anything else.
  2. draw: run repeatedly at the configured frame rate.

In our sketch below, the routine that does the actual drawing is the line() function. The first line in setup() is size() which configures the size of the drawing window.

All in all this is a fairly simple program to create something as complex as this fractal. This is why Processing and the Processing graphics library is so popular.


Processing is an open source language and environment, but further the folks at encourage the sharing of work. It is interesting to browse the work that other artists have done. Here are a couple of links:

Exhibition: a curated exhibition of projects.

OpenProcessing: Gallery of submitted projects.

Hour of Code: Gallery of submitted projects.

Gallery: Place to share and discuss projects.


If you are interested in learning how to code and you have an artistic temperament then Processing is a good place to start. If you’re interested in learning Java, then Processing is a good way to go. If you are a programmer and interested in learning graphics or animation then Processing is a really good place as well.


Processing source code for the Koch Snowflake fractal:

float turtleX;
float turtleY;
float turtleHeading = 0;

void setup() {
  size(600, 600);
  turtleX = width/5;
  turtleY = height/3;

void draw()
  int level = 3;
  int size = 400;

  turn( 60 );
  KockSnowflakeSide( level , size);
  turn( -120 );
  KockSnowflakeSide( level, size);
  turn( -120 );
  KockSnowflakeSide( level, size);
  turn( 180 );

void KockSnowflakeSide(int level, int size)
  if (level == 0)
      forward( size );
      KockSnowflakeSide( level - 1, size / 3 );
      turn( 60 );
      KockSnowflakeSide( level-1, size / 3);
      turn( -120 );
      KockSnowflakeSide( level-1, size / 3);
      KockSnowflakeSide( level-1, size / 3);

void forward(float amount) {
  float newX = turtleX + cos(radians(turtleHeading)) * amount;
  float newY = turtleY + sin(radians(turtleHeading)) * amount;

  line(turtleX, turtleY, newX, newY);

  turtleX = newX;
  turtleY = newY;

void turn(float degrees) {
  turtleHeading += degrees;

Written by smist08

April 11, 2020 at 4:49 pm

Learning Electronics with Arduino

with 3 comments


I’ve worked with the Raspberry Pi quite a bit, written books about it and blogged fairly extensively about it. However, many people consider the Pi overkill. After all it runs full versions of Linux and usually requires a keyboard, mouse, monitor and Internet connection. Even at $35, many people consider it too expensive for their projects.

Parallel to the Raspberry Pi, there is the Arduino project which is an open source software and hardware project for microcontrollers. The Raspberry Pi includes a full ARM 64-bit processor with up to 4Gig of RAM. The Arduino is based on various microcontrollers that are often 8-bit and only have 32Kb of RAM. These microcontrollers don’t run a full operating system, they just contain enough code to start your program, whether burned on their flash memory or downloaded via serial port from a PC.

There are a great many Arduino compatible boards that can perform all sorts of functions. A typical Arduino has a set of external pins similar to the Raspberry Pi’s GPIO ports. The big advantage of the Arduino is that they are low cost, simple to program and low power.

In this article, I’ll look at the official Arduino Starter Kit.

Package Contents

The package contains an Arduino Uno microcontroller board, a breadboard and a large assortment of discrete electronic components. It contains a project book with 15 projects you can build out of all these components.

The Arduino Uno contains the Amtel ATmega328p microcontroller and 32kb of memory. These are flexible low cost processors that are used in many embedded applications.

Programming the Arduino

You can program the Arduino with any compiler that generates the correct machine code to run on the processor you’ve chosen (or even program it in Assembly Language). However most people use the Arduino IDE. This IDE is based on Sketch and Processing. You write your programs in a limited version of C (with a few extensions). The IDE then knows how to compile and download it to a great many Arduino boards so you can test out your program.

There are libraries to provide support for common functions like controlling a servo motor or controlling a LED character display. There is a Capacitive sensor library to measure a circuit’s capacitance. There are hundreds of sensors you can wire up to your Arduino and there are libraries available for most of these, making the programming to read or control them easy.

You can debug your program by sending strings back to the PC via a serial port which you can monitor in the IDE. You can also flash a couple of LEDs.

People might point out the C is really old and shouldn’t be used due to its use of pointers and such. However C is still the best language for low level programming like this. It is also used for nearly all systems programming. Linux is entirely written in C. Learning C is both useful in itself as well as acting as a jump start to newer languages, mostly based on C such as Java or C#.

Learning Electronics

I first became interested in electronics when I took Electricity 9 in junior high school. We learned the basics of soldering and I built a Radio Shack transistor radio from a kit. With this course I could fix some basic wiring issues around the house and occasionally fix appliances, and perhaps fix a TV by replacing a tube. The difficulty when I was younger was that it was a lot of work to build anything, since the whole thing needed to be built from discrete components and equipment was expensive.

Today things are much easier. You can build a lot of simple circuits attached to the Arduino where a lot of the work is done in software on the microcontroller. Things are much cheaper today. You can purchase a complete Arduino starter kit for under $100 and test equipment is far less expensive. You can pick up a good digital multimeter for under $20 and there are even good oscilloscopes for around $300. There are many simple integrated circuits like optocouplers and H-bridges to further simplify your circuites.

The Arduino is low power, so you can’t electrocute yourself. It has short detection, so if your circuit contains a short circuit, the Arduino shuts down. This all allows you to safely play with electronic components without any risk to yourself or the Arduino.

The starter kit projects include several techniques to connect the Arduino up to external devices safely. For instance controlling a DC motor with either a transistor used as a switch or via an H-bridge. Then how to interface to another device using an optocoupler to keep both devices completely electrically separate.


Arduino provides a great platform to both learn electronics and to learn programming. The IDE is simple to use and helps with learning. Building circuits attached to an Arduino is a safe place to experiment and learn without risking damaging expensive components or equipment. I found working through the 15 labs in the Arduino Projects Book that accompanied the starter kit quite enjoyable and I learned quite a few new things.


“Unification” – My Second Novel

with 3 comments


I’m excited to announce that is available for sale in all the Amazon marketplaces:

Unification is the sequel to my first novel Influence. Here is the blurb from the back cover:

What is the future of privacy and self-determination in a world of self-aware AIs? Follow a Palestinian terrorist, the CEO of the world’s largest company, J@ck Tr@de a punk rock hacker, Humans have a terrible track record with war, famine, genocide and environmental collapse. What will a new hyper-intelligence make of all this? Follow Sa’eid, a Palestinian terrorist, Mia, the CEO of the world’s largest company, J@ck a punk hacker, Axel, a FBI agent and Dan, a biochemist, as they interact with Alpha the first self-aware AI. Are they being manipulated as they pursue their life goals? Do they know their roles in how the world is changing around them or are they unwitting accomplices in a modern day atrocity? Unification is the sequel to the book Influence, which saw the creation of the AI Alpha out of social media manipulation Bots.

Long Time Coming

I wrote most of this novel before I got the contracts from Apress to write:

Now that the second Assembly Language book is off being typeset, it gave me time to finish Unification.

Kindle Unlimited

Both Influence and Unification are enrolled in the Kindle Select program so if you subscribe to Kindle Unlimited then you can read both these books as part of that.

Related Sites

Here are some related sites for Influence and Unification:


Writing Unification was a lot of fun. I hope you pick up a copy and give it a read. Although the novel stands along, you will do better to read Influence first.

Written by smist08

April 1, 2020 at 10:57 am