What are Virtual Machines?¶
Virtual Machines (VMs) essentially package a whole computer as an app that can be run.
As an example, the figure below shows a windows laptop (note the windows search button in the lower-left corner) running a virtual ubuntu machine (note the terminal outputting the operating system).
The machine running the VM is called the
Using software like VirtualBox or Vagrant, a user can create and run any number of VMs. As you could probably guess, having several VMs running at once can be a drain on memory. So just because you can run several VMs does not mean you should.
Users can download, install, backup and destroy VMs at will, which is why they are an attractive tool for sharing reproducible research. Research often requires specific pieces of software or system settings. If a researcher wishes to reproduce another’s work on their computer, making the necessary changes to their environment to run the project may impact their work. For example, in the Why This is Useful section of this chapter, we described how using a different version of Python can lead to unexpected changes in the results of an analysis. Say a researcher installs an updated version of Python to replicate an analysis because the analysis requires features only present in the updated version. By doing so, they put their own work at risk. VMs remove that risk; any tools downloaded or settings changed will only impact the VM, keeping the reproducer’s research safe. If they do inadvertently break something in the VM, they can delete it and make another one. VMs are effectively a quarantined area.
Using Virtual Machines for Reproducible Research¶
Virtual machines can be shared by exporting them as single files. Another researcher can then import that file using their own virtualisation software like VirtualBox and open up a copy of the VM which will contain all the software files and settings put in place by the person that made the VM. Therefore in practice, they will have a working version of the project without the pain of setting it up themselves.
Setting up a Virtual Machine¶
First, choose a tool for generating VMs.
Here the widely-used VirtualBox is chosen.
Download and install it on your system.
To create a new machine, click “New” in the top left.
A window will pop up where you can enter a name for the machine and select what operating system (and version) to use.
In the figure below, a machine called
demo_VM running Ubuntu is being created:
As you click through, you can adjust other features of the machine to be created, such as how much memory it should have access to. The default options are suitable for most purposes, but this process permits customisation.
Starting a Virtual Machine¶
To start a virtual machine, select the machine from the list of VMs on the left, and click the green
Start arrow at the top: