Virtual Micromagnetics – Micromagnetism With Virtual Machines

By | January 26, 2018

Installing micromagnetic software can be a challenge. There are can be complex dependencies and it’s not always clear how to get a working system. I recently stumbled across the virtual micromagnetics project which provides an entry point for researchers wanting to exploit virtual machines for micromagnetics.

I was intrigued by this idea – virtualisation plays a big part in commercial software development and deployment, so why couldn’t it also support scientific development? And are there other ways micromagnetics could make use of virtual machines?

A Little About Virtual Machines

Virtual machines have been used for some time in the world servers and software development, and could offer many benefits to virtual micromagnetics. There are, however pros and cons when it comes to virtual machines. They are not necessarily deal breakers, it is worth keeping them in mind when considering where and when virtual micromagnetics might be appropriate.

How Virtual Machines Could Help

  • Repeatable, consistent environment. A big appeal of virtual machines is being able to avoid the ‘it worked on my machine‘ problem of different people
  • Better hardware utilization. Multiple virtual machines can be run on a single physical machine and make better use of the resources available.
  • Flexibility – run different environments simultaneously. If you have software with conflicting dependencies, virtual machines are one way to run the software on the same physical machine.
  • Maintain Legacy Software Some software only runs on legacy environments or has very old dependencies. Virtual machines can extend the useful life of this software.

Some Possible Challenges

  • Performance Limitations – You should expect to have some performance loss – the exact performance you will get from a virtual machine depends on many things including your underlying physical hardware, the virtualisation software you use and what you will be using the virtual machine for.
  • Additional Software – Running a virtual machine will almost certainly require you to install and familiarise yourself with new software – either the virtualisation software or other tools. Having to go through this process may seem like more hassle than it is worth.
  • Additional Platform Complexity – Related to the issue of working with new software is having to maintain a more complex platform – introducing a virtual machine is another potential point of failure. This, again, may be more hassle and risk than it is worth for many researchers.

The Virtual Micromagnetics Project

Given the various pros and cons of virtual machines, the approach favoured by the virtual micromagnetics project is to provide an ecosystem of virtual machines and containers to help lower the barrier to using micromagnetic software.

A researcher user would download and run one of their images and be up and running without having to get their hands too dirty. The project also provides some guidance for power users to be able to build their own virtual machines and containers.

The project has clearly worked hard for a new user to get up and running. With vagrant and virtualbox installed, you just need to run:

vagrant init virtualmicromagnetics/full
vagrant up --provider virtualbox

This launches the user into the virtual machine, who is greeted with options for how to continue to use the virtual machine. It is also possible to be more selective about which micromagnetic software you want to have installed in your virtual machine:

vagrant init virtualmicromagnetics/oommf
vagrant up --provider virtualbox 

With any curated or packaged software there is the potential limitation of waiting for the latest software to be included in a release. The Virtual micromagnetics project is no exception, and users will need to judge whether the ease of use is sufficient compensation for not being at the bleeding edge.

There is some information for power users on using make files and ansible provisioning to customise their virtual machine, although the learning curve is quite steep. I do wonder if there is also space for some more intermediate-level options for users who want to tweak their virtual machines without taking on the full virtual micromagnetics infrastructure.

Some Alternatives

Given the above points, I wondered if there might be some other options for supporting micromagnetic software in virtual machines. I imagine that different researchers have different levels of knowledge and enthusiasm for solving these problems, so it may be beneficial to have a few alternatives.

The following few sections explore possible ways to approach the use of virtual machines for micromagnetics and increase in configuration complexity, stopping just short of the ‘full’ level provided by the virtual micromagnetism project.

Plain Virtual Machine

First, and most simply, there is the plain virtual machine. A user would download a disk image for their operating system of choice (probably a light-weight ubuntu distribution such as lubuntu). It is then a fairly simple process to install this on their virtual machine provider (e.g. Virtualbox). There are plenty of guides online for installing ubuntu, and I think this would not be beyond most users.

Once they have installed the operating on their virtual machine the user can use it more or less as they would a bare-metal installation. A downside is that they would need to go through the install process for any software they needed on the virtual machine – something that may not be quick, and may encounter dependency problems.

Once a virtual machine is created in this way, it is at least possible to share the full image. If a virtual box image were being shared around a team, they would likely come up against problems with versioning issues across machines used by different people, with no easy way to keep track and  deploy any changes.

Plain Virtual Machine with install scripts

Our first step towards some kind of automation is to still start with a plain virtual machine, installed from a disk image, but to also include some install scripts. An install script would just be a series of commands such as

sudo apt-get install

This would mean putting some thought into the packages and dependencies that were important to us, but might make it easier to duplicate the virtual machine if we needed to start it again.

Vagrant Box

Vagrant is a tool for managing and running virtual machines. Vagrant runs virtual machines using what it calls ‘base’ boxes which are modified versions of the operating system installation images. There are online repositories of disk images to start from (such as a basic ubuntu installation).

Vagrant works from the command line and simple commands like ‘vagrant add box’ and ‘vagrant up’ take the place of having to manually download and install a virtual machine image.

Vagrant can simplify the running of virtual machines, but we are still left with the problem of how to install the scientific software needed. Once the virtual machine is started with vagrant we can use either of the routes we used with the disk-image virtual machine: manually install our programs as we need them, or use scripts to standardise the install and make sharing a little easier.

Vagrant does also make it easier to use some more advanced installation techniques as we will see below.

Vagrant Box, Simply Provisioned

As well as simplifying the virtual machine download stage, vagrant also allows us to do something known as ‘provisioning’. Provisioning is the process of setting up a virtual machine in the way that we want it. Provisioning means that rather than having to start up the virtual machine and run install and configuration scripts ourselves, we can build the machine setup into the startup process.

The simplest form of provisioning vagrant supports is to use simple scripts (shell scripts in linux systems) which take the place of directly running commands on the virtual machine.

Provisioning scripts could be provided for installing the packages needed for a project, or at least some commonly required features, such as a desktop environment. The use of provisioning scripts in this way makes sense if you will be sharing your virtual machine environment (perhaps with multiple members of a research group).

Vagrant Box, Using Provisioning Tool

Vagrant also supports using third party provisioning tools. These work in a similar way to running a shell script on the virtual machine, but have some additional benefits such as being more intelligent about failed steps in a provisioning process.

There are upsides to using one of these third party tools. The obvious downside, however, is needing to familiarise yourself with another tool with its own configuration ‘language’.

By this stage we are getting close to what the virtual micromagnetics project advises to its power users. While it is possible to use a simple script to provision a virtual machine, a provisioning tool provides more control and resilience.

The virtual micromagnetism project provides full details of their provisioning scripts on the project github pages. This scripts are more advanced and offer additional first-run simplicity at the expense of additional behind the scenes configuration.

Which Option Is Best?

Exactly which virtual mciromagnetics option makes sense to a user will depend on their intentions and experience. I suspect more researchers will feel happier with installing a virtual machine from a disk image than building one with vagrant. It may also only be more advanced users who want to run provisioning scripts for their virtual machines. Making full use of ansible and vagrant might be purely aspirational for many people, but their use for setting up virtual machines for micromagnetism may at least show them what is possible if they do take the time.

The virtual micromagnetics project can do a lot of good if it can be sustained and supported so that less experienced researchers can make full use of it. If the virtual micromagnetism project only succeeds in lowering the barrier to entry in using micromagnetic software, then that would still be a very good achievement.