Deploy IBSIMU simulation package on AWS

Use CloudFormation to bootstrap Ubuntu for IBSIMU on AWS

Andrey Shornikov
5 min readJan 19, 2021

Recently I have shown how to make use of advanced particle tracing library IBSIMU on a local/virtual UBUNTU 20.04 system. In this demo I want to spice things up a bit. We will deploy IBSIMU on Amazon Web Services (AWS) cloud EC2 instance. More than that, we will do it the right way using AWS Infrastructure as a code (IaaC) offering — CloudFormation. Let’s get started.

Architecture of our stack, collage by the author

In the first part I have shown how to install IBSIMU on Ubuntu 20.04 from the source code. It had some substantial dependencies. It also uses some GTK visualization, so standard AWS Ubuntu will lack all the GUI related software. We also would like to remotely interact with this user interface, that will require changing some permissions and even more software dependencies.
This all together means that quite a lot of installation needs to be done before our instance becomes useful. And this is exactly the point of IaaC — prepare suitable resources based on a script.

Here is what I plan to do.

On the bootstrapping phase:
1. Set proper instance type and default OS image (AMI)
2. Prepare a UserData for starting instance
3. Set a security group to allow remote GUI
After ssh/scp to the instance
4. Complete IBSIMU installation
5. Setup vnc server
6. Connect using remote GUI, upload test case and solve it

Let’s get through the steps.

Choice of instance and AMI.

My test showed that t2.medium will solve an axisymmetric problem within several minutes, and full 3D with magnetic field and multiple species — within 3h. So for 2D and axisymmetric t2.medium is enough, for full 3D I would go to a more capable instance in c4.xlarge range or more. For OS selection, I wanted to have consistence with versions running on local virtual machine, so I was going for latest Ubuntu. For AWS it has consequences, as most straightforward integration of AWS features is achieved by using Amazon Linux 2. The consequences will be discussed in the bootstrapping part. It is important to remember that same OS has different name depending on AZ. I run my EC2 resources in nearest AZ, close to Frankfurt in Germany, hence europe-central-1, and my AMI for Ubuntu 20.04 is ami-0502e817a62226e03.

Instance bootstrapping.

What we want to achieve here is to install IBSIMU dependencies and necessities for remote GUI. From the part on installation on Ubuntu you may know that direct IBSIMU dependencies are libcairo2-dev, libgsl-dev, libgtk-3-d and for build and compilation on Ubuntu automake, libtool, build-essential. For remote GUI we will install a vnc server, desktop environment and a few more things. Now we come to the consequence of choosing Ubuntu. On Ubuntu to run our UserData from our Metadata we need AWS scripts to be working. Those are not installed by default, but can be fetched from AWS S3. The problem here is that if you try to install them with let say pip from python3 it will crash and you will see all too familiar print ‘foo bar’ statements in the console as a hint to the cause of the crash. The trick is that installation requires python 2 pip, which is not present in default Ubuntu 20.04. Therefore we first install python 2 through build-essential-dev, than we fetch a script that fetches us pip, then we fetch AWS installation archive, run it, and then we install all that we need. All in all our UserData section looks like this

Security group.

By default EC2 instances come with port 22 open for ssh. We will need to also open port 5901 for vnc server. In this example I do not limit range of allowed IP addresses. For security reasons it is always advised to provide minimum
necessary access, i.e. limit the range. You can see below unnecessarily permissive security group settings.

Installation of IBSIMU.

I generally follow steps outlined in the post about local/VM installation.
Important difference here is that you may ssh into the instance while thee root user still performs bootstrapping of the machine. Since dependencies are not there yet, a premature installation will fail. Therefore first make sure that you have a file diagnostics.log in the /, which is created as the last step of the bootstrapping process. If it is present, dependencies should be satisfied. To install IBSIMU you would need to SCP to the instance (winSCP allows you to connect using your putty-converted security key). Once you are there, copy installation scripts install_ibsimu.sh, vnc_settings.sh, vnc_setup.sh into ~/ give them execute permission with chmod +x and run install_ibsimu.sh. Together with the rest of materials from this story the scripts can be found in the repository. Installation script will fetch the archive from the project website, unpack it, compile and update environmental variables in .bashrc.

Setup vncserver.

Run vnc_setup.sh. In the process it will ask you to provide a password to protect your sessions. You will use this password to connect to the remote machine.

applied xstartup settings are the following

If you decide to keep instance as stopped and not terminated between uses (I do not recommend this) you can stop vnc server by vncserver -kill :1, and restart it next time by vncserver :1.

Connect and test run.

Once you got vncserver runing, you can use tightvnc viewer on Windows client and your password to connect to it. Use your instance public DNS name and port 5901 together with your vnc password. Copy a test case to the instance (einzel lens would make a nice ‘hello world’ example), make sure that IBSIMU version referred in the case’s Makefile is the one you have actually installed (1.0.6dev). Compile and run the simulation.

On the figure below you can see a gorgeous case of a negative ion source simulated in full 3D, with electrons (yellow) and negative hydrogen ions (red) extracted together, and electrons filtered out by weak magnetic filter. This is the test case of LIISA source from IBSIMU summer school course in Jyväskylä (Finland) in 2015. Be patient, on a t2.medium instance this case will take about 3 hours to solve using default case settings.

LIISA negative ion source, case from Jyväskylä Summer School 2015, image by the author

Something similar to this ion source actually feeds the largest particle accelerator complex in the world — LHC in Geneva. And if I am not mistaken, IBSIMU was actually used to optimize it. To me that is a pretty mighty ‘hello world’. Now, that you are fully equipped for the challenge, I wish you happy ion sourcery!

--

--